1 package zirc.base ; 2 3 import java.io.* ; 4 import java.net.* ; 5 import java.util.* ; 6 7 import java.awt.* ; 8 import javax.swing.* ; 9 10 import zirc.gui.* ; 11 import zirc.gui.smiliesWindow.* ; 12 import zirc.threads.* ; 13 14 27 34 35 public class IRCconnexion 36 { 37 IRCconnexion ircConnexion = this ; 38 39 private Locale language; 41 SmiliesCollection smilies ; 43 44 static ArrayList serverArray = new ArrayList() ; 46 47 ListDialog chanList ; 49 50 private AbstractChatFrame FrameWithFocus = null ; 52 private StatusFrame statusFrm ; private ArrayList chatFramesArray = new ArrayList() ; private ArrayList privateFrameArray = new ArrayList() ; 56 private MainFrame mainFrm ; 58 private ConnectThread ct ; 60 61 private ThreadProcessor tLanceur = new ThreadProcessor() ; 63 64 private BufferedReader mainSockIn ; 66 private PrintWriter mainSockOut ; 67 private Socket mainSock ; 68 69 private String mainSockPort ; 71 private String mainSockServer ; 72 73 private String user_operatingSys ; 75 private String user_realName ; 76 private String user_hote ; 77 private String user_nickName ; 78 private String user_serverName ; 79 private String user_email ; 80 81 private String user_nomUser ; private static int identPort = 113 ; 84 85 String partMSG ; 87 String quitMSG ; 88 89 public static Font FIXEDSYS ; 91 92 public IRCconnexion(String name, String email, String nick, String server, String port, MainFrame _fenetre, SmiliesCollection _smilies, 93 String _quitMSG, String _partMSG,Locale _language) 94 { 95 mainSockPort = port ; 97 mainSockServer = server ; 98 mainFrm = _fenetre ; 99 user_email = email ; 100 user_nickName = nick ; 101 user_nomUser = getLocalHostName() ; 102 user_operatingSys = System.getProperty("os.version") ; 103 user_realName = name ; 104 user_hote = getLocalHostName() ; 105 user_serverName = server ; 106 smilies = _smilies ; 107 quitMSG = _quitMSG ; 108 partMSG = _partMSG ; 109 language=_language; 110 111 chargeFixedSys() ; 113 114 chanList = new ListDialog(mainFrm, this,language ) ; 116 117 serverArray.add(this) ; 119 } 120 121 private String getLocalHostName() 122 { 123 String lName = null ; 124 try 126 { 127 lName = InetAddress.getLocalHost().getHostName() ; 128 } 129 catch (UnknownHostException ex) 130 { 131 ex.printStackTrace() ; 132 } 133 return lName ; 134 } 135 136 public void connect() 137 { 138 142 statusFrm = createStatusFrame() ; 144 ct = new ConnectThread(this) ; 146 ct.start() ; 147 } 148 149 public void disconnect() 151 { 152 ct.stopConnexion() ; 153 154 while (chatFramesArray.size() > 0) 156 { 157 ((ChatFrame)(chatFramesArray.get(0))).destroy() ; 158 } 159 160 while (privateFrameArray.size() > 0) 162 { 163 ((PrivateFrame)(privateFrameArray.get(0))).destroy() ; 164 } 165 166 } 167 168 private StatusFrame createStatusFrame() 169 { 170 StatusFrame frm = new StatusFrame(this) ; 174 frm.setTitle("Status " + mainSockServer + " ( " + mainSockPort + " )") ; 175 mainFrm.getMdiPanel().add(frm) ; 176 frm.setVisible(true) ; 177 178 return frm ; 179 } 180 181 public ChatFrame createChatFrame(String chanName) 182 { 183 ChatFrame frm = new ChatFrame(this, chanName) ; 187 frm.setTitle(chanName) ; 188 mainFrm.getMdiPanel().add(frm) ; 189 frm.setVisible(true) ; 190 191 chatFramesArray.add(frm) ; 193 return frm ; 194 } 195 196 public PrivateFrame createPrivateFrame(String user) 197 { 198 PrivateFrame frm = new PrivateFrame(this, user) ; 202 frm.setTitle(user) ; 203 mainFrm.getMdiPanel().add(frm) ; 204 frm.setVisible(true) ; 205 206 privateFrameArray.add(frm) ; 208 return frm ; 209 } 210 211 public void sendCommand(String command) 212 { 213 try 217 { 218 mainSockOut.println(command) ; 219 mainSockOut.flush() ; 220 } 221 catch (NullPointerException ex) 222 { 223 224 } 225 } 226 227 public void addChanToList(String line) 228 { 229 String chan = "" ; 230 String users = "" ; 231 StringTokenizer str = new StringTokenizer(line, " ") ; 233 str.nextElement() ; 234 try 235 { 236 str.nextElement() ; 237 str.nextElement() ; 238 chan = str.nextElement().toString() ; 239 users = str.nextElement().toString() ; 240 } 241 catch (NoSuchElementException e) 242 {} 243 244 if (chan.length() > 3) 246 { chanList.addChan(chan + " " + users + " users") ; 248 } 249 250 if (line.equals("END")) 251 { 252 chanList.addChan("END") ; 253 chanList.setLocation((int)mainFrm.getBounds().getX()+40,(int)mainFrm.getBounds().getY()+40); 254 chanList.show() ; 255 } 256 } 257 258 public void ajouteTache(PseudoThread _tr) 259 { 260 tLanceur.addThread(_tr) ; 261 } 262 263 public static void chargeFixedSys() 264 { 265 269 if (FIXEDSYS == null) 270 { 271 File fp = new File("fichiers" + File.separatorChar + "fixedSys.ttf") ; 272 System.out.println(fp.getAbsolutePath()) ; 273 274 try 275 { 276 FIXEDSYS = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(fp)) ; 278 } 279 catch (Exception e) 280 { 281 System.out.println("Exception instanciation fonte irc") ; ; 282 FIXEDSYS = Font.getFont("verdana") ; 284 } 285 286 } 287 288 } 289 290 public int[] getServerPortList() 292 { 293 ArrayList portArray = new ArrayList() ; 294 StringTokenizer str = new StringTokenizer(GetMainSockPort() + "", ",") ; 295 while (str.hasMoreElements()) { 297 portArray.add(str.nextElement()) ; 298 } 299 300 for (int i = 0 ; i < portArray.size() ; i++) { 302 if (portArray.get(i).toString().length() > 4) 303 { 304 StringTokenizer str2 = new StringTokenizer(portArray.get(i).toString(), "-") ; 305 int p1 = Integer.parseInt(str2.nextElement().toString()) ; 306 int p2 = Integer.parseInt(str2.nextElement().toString()) ; 307 int pmin = Math.min(p1, p2) ; 308 int pmax = Math.max(p1, p2) ; 309 for (int j = pmin ; j <= pmax ; j++) 310 { 311 portArray.add(j + "") ; 312 } 313 } 314 } 315 316 for (int i = 0 ; i < portArray.size() ; i++) 318 { 319 if (portArray.get(i).toString().length() > 4) 320 { 321 portArray.remove(i) ; 322 } 323 } 324 325 int[] portList = new int[portArray.size()] ; 326 for (int i = 0 ; i < portArray.size() ; i++) 328 { 329 portList[i] = Integer.parseInt(portArray.get(i).toString()) ; 330 } 331 332 Arrays.sort(portList) ; 334 335 return portList ; 336 } 337 338 342 public StatusFrame GetStatusFrm() 343 { 344 return statusFrm ; 345 } 346 347 352 public MainFrame GetMainFrm() 353 { 354 return mainFrm ; 355 } 356 357 public JDesktopPane getMainDesktopPane() 358 { 359 return mainFrm.getMdiPanel() ; 360 } 361 362 public BufferedReader getMainSockIn() 363 { 364 return mainSockIn ; 365 } 366 367 public void setMainSockIn(BufferedReader _in) 368 { 369 this.mainSockIn = _in ; 370 } 371 372 public void setMainSockPort(String port) 373 { 374 this.mainSockPort = port ; 375 } 376 377 public PrintWriter GetMainSockOut() 378 { 379 return mainSockOut ; 380 } 381 382 public void setMainSockOut(PrintWriter _pw) 383 { 384 this.mainSockOut = _pw ; 385 } 386 387 public Socket getMainSock() 388 { 389 return mainSock ; 390 } 391 392 public void setMainSock(Socket _s) 393 { 394 mainSock = _s ; 395 } 396 397 public void set_userRealName(String name) 398 { 399 this.user_realName = name ; 400 } 401 402 public void set_userEmail(String email) 403 { 404 this.user_email = email ; 405 } 406 407 public void setUser_NickName(String nick) 408 { 409 this.user_nickName = nick ; 410 } 411 412 public void setChatFrameWithFocus(JInternalFrame frm) 413 { 414 if (frm instanceof ChatFrame) 415 { 416 FrameWithFocus = (ChatFrame)frm ; 417 } 418 else 419 { 420 if(frm instanceof PrivateFrame) 421 { 422 FrameWithFocus = (PrivateFrame)frm ; 423 } 424 else 425 { 426 FrameWithFocus = null ; 427 } 428 } 429 } 430 431 public String GetMainSockPort() 432 { 433 return mainSockPort ; 434 } 435 436 public String GetMainSockServer() 437 { 438 return mainSockServer ; 439 } 440 441 public String GetUser_operatingSys() 443 { 444 return user_operatingSys ; 445 } 446 447 public String getUser_realName() 448 { 449 return user_realName ; 450 } 451 452 public String GetUser_hote() 453 { 454 return user_hote ; 455 } 456 457 public String GetUser_nickName() 458 { 459 return user_nickName ; 460 } 461 462 public String GetUser_serverName() 463 { 464 return user_serverName ; 465 } 466 467 public String getUser_nomUser() 468 { 469 return user_nomUser ; 470 } 471 472 public static int getIdentPort() 473 { 474 return identPort ; 475 } 476 477 public ArrayList getOpenChanArray() 478 { 479 return chatFramesArray ; 480 } 481 482 public static ArrayList getServerArray() 483 { 484 return serverArray ; 485 } 486 487 public SmiliesCollection getSmiliesCollection() 488 { 489 return smilies ; 490 } 491 492 public void removeChan(ChatFrame frm) 493 { 494 chatFramesArray.remove(frm) ; 495 } 496 497 public ChatFrame GetFenetreDuChan(String _chan) 498 { 499 500 for (int i = 0 ; i < chatFramesArray.size() ; i++) 501 { 502 if (((ChatFrame)(chatFramesArray.get(i))).getChan().equalsIgnoreCase(_chan)) 503 { 504 return (ChatFrame)(chatFramesArray.get(i)) ; 505 } 506 } 507 508 return null ; 509 } 510 511 public void removePrivate(PrivateFrame frm) 512 { 513 privateFrameArray.remove(frm) ; 514 } 515 516 public PrivateFrame GetFenetreDuPrive(String _user) 517 { 518 519 for (int i = 0 ; i < privateFrameArray.size() ; i++) 520 { 521 if (((PrivateFrame)(privateFrameArray.get(i))).getCorrespondant().equalsIgnoreCase(_user)) 522 { 523 return (PrivateFrame)(privateFrameArray.get(i)) ; 524 } 525 } 526 527 return null ; 528 } 529 530 public ArrayList getAllChatFrames() 531 { 532 return chatFramesArray ; 533 } 534 535 public AbstractChatFrame getChatFrameWithFocus() 536 { 537 return FrameWithFocus ; 538 } 539 540 public ArrayList getAllPrivateFrames() 541 { 542 return privateFrameArray ; 543 } 544 545 public String getQuitMSG() 546 { 547 return quitMSG ; 548 } 549 550 public String getPartMSG() 551 { 552 return partMSG ; 553 } 554 555 public void setLanguage(Locale lang) 556 { 557 chanList.setLanguage(lang); 558 } 559 } 560 | Popular Tags |