1 package rero.client.user; 2 3 import rero.client.*; 4 import rero.client.server.*; 5 import rero.client.user.*; 6 import rero.client.output.*; 7 8 import rero.client.notify.*; 9 import rero.client.script.*; 10 11 import rero.dialogs.*; 12 import java.io.*; 13 14 import rero.net.*; 15 import java.net.*; 16 17 import rero.config.*; 18 19 import rero.ircfw.*; 20 import rero.ircfw.interfaces.*; 21 22 import rero.util.*; 23 24 import java.util.*; 25 26 import text.AttributedString; 27 28 import rero.gui.*; 29 30 public class BuiltInCommands extends Feature implements ClientCommand 31 { 32 public static final int AME = 64921; public static final int AWAY = 2022126; public static final int BACK = 2030823; public static final int BANSTAT = 381185731; public static final int CHAT = 2067288; public static final int CLEAR = 64208429; public static final int CLEARALL = 1572926516; public static final int CLOAK = 64218032; 45 public static final int CLS = 66826; public static final int CPING = 64331829; public static final int CTCP = 2078878; public static final int CREPLY = 1996016743; public static final int CYCLE = 64594118; public static final int DEOP = 2094626; public static final int DESCRIBE = 1800840907; public static final int DEVOICE = -2016999119; public static final int DEBUG = 64921139; public static final int DH = 2180; public static final int DNS = 67849; public static final int DO = 2187; public static final int DOP = 67877; public static final int DV = 2194; public static final int EVAL = 2140316; public static final int EXEC = 2142353; public static final int EXIT = 2142494; public static final int HELP = 2213697; public static final int HO = 2311; public static final int HOP = 71721; public static final int IGNORE = -2137067054; public static final int INVITE = -2130369783; public static final int J = 74; public static final int JOIN = 2282794; public static final int K = 75; public static final int KB = 2391; public static final int KICK = 2306630; public static final int L = 76; public static final int LEAVE = 72308375; public static final int LIST = 2336926; public static final int LL = 2432; 76 public static final int LOAD = 2342118; public static final int M = 77; public static final int ME = 2456; public static final int MODE = 2372003; public static final int MSG = 76641; public static final int MSGLOG = -2011679709; public static final int N = 78; public static final int NEWSERVER = -1201786685; public static final int NOTICE = -1986360616; public static final int NOTIFY = -1986360503; public static final int O = 79; public static final int OP = 2529; public static final int OV = 2535; public static final int P = 80; public static final int PA = 2545; public static final int PART = 2448371; public static final int PING = 2455922; public static final int QUERY = 77406376; public static final int QUIT = 2497103; public static final int QUOTE = 77416028; public static final int RAW = 80904; public static final int REDIR = 77851994; 98 public static final int RELOAD = -1881311847; public static final int RUN = 81515; public static final int SC = 2640; public static final int SEND = 2541448; public static final int SERVER = -1852497085; public static final int ST = 2657; public static final int UT = 2719; public static final int SM = 2650; public static final int SV = 2659; public static final int THEME = 79789481; public static final int TOPIC = 80008463; public static final int TSEND = 80117212; 110 public static final int UNBAN = 80888502; public static final int UNIGNORE = 478733739; public static final int UNLOAD = -1787112705; public static final int V = 86; public static final int VER = 84867; public static final int VOICE = 81848594; public static final int WALL = 2656714; public static final int WALLEX = -1741862915; public static final int WHOIS = 82569544; public static final int WHOLEFT = 2039998629; 120 public static final int WI = 2770; public static final int WII = 85943; public static final int WINDOW = -1734422544; public static final int WW = 2784; public static final int LAGC = 2328849; 126 UICapabilities gui; 127 ChatCapabilities chatCommands; 128 InternalDataList ircData; 129 130 public void init() 131 { 132 gui = getCapabilities().getUserInterface(); 133 chatCommands = getCapabilities().getChatCapabilities(); 134 ircData = (InternalDataList)getCapabilities().getDataStructure("clientInformation"); 135 } 136 137 public void runAlias(String command, String parms) 138 { 139 command = command.toUpperCase(); 140 141 TokenizedString tokens = new TokenizedString(parms); 142 tokens.tokenize(" "); 143 144 String target, nick, channel, temp; 145 146 switch (command.hashCode()) 147 { 148 case AME: 149 Iterator i = ircData.getMyUser().getChannels().iterator(); 150 while (i.hasNext()) 151 { 152 chatCommands.sendAction(((Channel)i.next()).getName(), parms); 153 } 154 break; 155 case AWAY: 156 getCapabilities().sendln("AWAY :" + parms); 157 break; 158 case BACK: 159 getCapabilities().sendln("AWAY"); 160 break; 161 case BANSTAT: 162 target = gui.getQuery(); 163 if (parms.length() > 0) 164 { 165 target = parms; 166 } 167 getCapabilities().sendln("MODE " + target + " +b"); 168 break; 169 case CLS: 170 case CLEAR: 171 getCapabilities().getUserInterface().clearScreen(parms); 172 break; 173 case CLEARALL: 174 getCapabilities().getUserInterface().clearScreen("%ALL%"); 175 System.gc(); 176 break; 177 case CREPLY: 178 getCapabilities().getChatCapabilities().sendReply(tokens.getToken(0), tokens.getToken(1), tokens.getTokenFrom(2)); 179 break; 180 case CTCP: 181 if (tokens.getToken(1).equals("KOW1")) 182 { 183 getCapabilities().getGlobalCapabilities().showCoolAbout(); 184 return; 185 } 186 187 getCapabilities().getChatCapabilities().sendRequest(tokens.getToken(0), tokens.getToken(1), tokens.getTokenFrom(2)); 188 break; 189 case DEBUG: 190 ((ScriptManager)getCapabilities().getDataStructure(DataStructures.ScriptManager)).setDebug(tokens.getToken(0), tokens.getTokenFrom(1)); 191 break; 192 case DO: 193 case DOP: 194 case DEOP: 195 temp = " -"; 196 target = ""; 197 for (int x = 0; x < tokens.getTotalTokens(); x++) 198 { 199 target = ircData.nickComplete(tokens.getToken(x), gui.getQuery()) + " " + target; 200 temp = temp + "o"; 201 } 202 getCapabilities().sendln("MODE " + gui.getQuery() + temp + " " + target.trim()); 203 break; 204 case DV: 205 case DEVOICE: 206 temp = " -"; 207 target = ""; 208 for (int x = 0; x < tokens.getTotalTokens(); x++) 209 { 210 target = ircData.nickComplete(tokens.getToken(x), gui.getQuery()) + " " + target; 211 temp = temp + "v"; 212 } 213 getCapabilities().sendln("MODE " + gui.getQuery() + temp + " " + target); 214 break; 215 case DH: 216 temp = " -"; 217 target = ""; 218 for (int x = 0; x < tokens.getTotalTokens(); x++) 219 { 220 target = ircData.nickComplete(tokens.getToken(x), gui.getQuery()) + " " + target; 221 temp = temp + "h"; 222 } 223 getCapabilities().sendln("MODE " + gui.getQuery() + temp + " " + target); 224 break; 225 case DESCRIBE: 226 chatCommands.sendAction(tokens.getToken(0), tokens.getTokenFrom(1)); 227 break; 228 case DNS: 229 User userD = ircData.getUser(parms); 230 if (userD != null && userD.getAddress().length() > 0) 231 { 232 new Thread (new ResolveHost(userD.getAddress().substring(userD.getAddress().indexOf('@') + 1, userD.getAddress().length()))).start(); 233 } 234 else 235 { 236 new Thread (new ResolveHost(parms)).start(); 237 } 238 break; 239 case EXEC: 240 case RUN: 241 Thread athread = new Thread (new QuickProcess(parms)); 242 athread.start(); 243 break; 244 case EVAL: 245 ((ScriptManager)getCapabilities().getDataStructure(DataStructures.ScriptManager)).evalScript(parms); 246 break; 247 case EXIT: 248 getCapabilities().getGlobalCapabilities().QuitClient(); 249 break; 250 case HELP: 251 getCapabilities().getGlobalCapabilities().showHelpDialog(parms); 252 break; 253 case HO: 254 temp = " +"; 255 target = ""; 256 for (int x = 0; x < tokens.getTotalTokens(); x++) 257 { 258 target = ircData.nickComplete(tokens.getToken(x), gui.getQuery()) + " " + target; 259 temp = temp + "h"; 260 } 261 getCapabilities().sendln("MODE " + gui.getQuery() + temp + " " + target); 262 break; 263 case HOP: 264 case CYCLE: 265 target = gui.getQuery(); 266 267 String keych = ""; 268 if (ircData.getChannel(target).getKey() != null && ircData.getChannel(target).getKey().length() > 0) 269 { 270 keych = " " + ircData.getChannel(target).getKey(); 271 } 272 273 getCapabilities().sendln("PART " + target); 274 getCapabilities().sendln("JOIN " + target + keych); 275 break; 276 case IGNORE: 277 if (parms.length() < 1) { break; } 278 279 if (! StringUtils.iswm("*!*@*", parms)) 280 { 281 parms = parms + "!*@*"; 282 } 283 284 StringList templ = ClientState.getClientState().getStringList("ignore.masks"); 285 templ.add(parms); 286 templ.save(); 287 288 getCapabilities().getOutputCapabilities().fireSetActive(ClientUtils.getEventHashMap("add", parms), "SET_IGNORE"); 289 break; 290 case INVITE: 291 if (parms.length() < 1) { break; } 292 293 target = gui.getQuery(); 294 295 if (tokens.getTotalTokens() > 1) 296 { 297 target = tokens.getToken(1); 298 } 299 300 getCapabilities().sendln("INVITE " + tokens.getToken(0) + " " + target); 301 break; 302 case J: 303 case JOIN: 304 if (!ClientUtils.isChannel(parms)) 305 { 306 parms = "#" + parms; 307 } 308 if (ircData.getChannel(parms) != null && ircData.isOn(ircData.getMyUser(), ircData.getChannel(parms))) 309 { 310 getCapabilities().getUserInterface().setQuery(parms); 311 } 312 else 313 { 314 getCapabilities().sendln("JOIN " + parms); 315 } 316 break; 317 case K: 318 temp = ClientState.getClientState().getString("kick.message", "I know... I'm a \002jIRC\002"); 319 target = ircData.nickComplete(tokens.getToken(0), gui.getQuery()); 320 321 if (tokens.getTotalTokens() > 1) 322 { 323 temp = tokens.getTokenFrom(1); 324 } 325 326 getCapabilities().sendln("KICK " + gui.getQuery() + " " + target + " :" + temp); 327 break; 328 case KB: 329 temp = ClientState.getClientState().getString("kick.message", "I know... I'm a \002jIRC\002"); 330 target = ircData.nickComplete(tokens.getToken(0), gui.getQuery()); 331 332 if (tokens.getTotalTokens() > 1) 333 { 334 temp = tokens.getTokenFrom(1); 335 } 336 337 User user = ircData.getUser(target); 338 if (user != null && user.getAddress().length() > 0) 339 { 340 getCapabilities().sendln("MODE " + gui.getQuery() + " -o+b " + target + " " + ClientUtils.mask(user.getNick()+"!"+user.getAddress(), 2)); 341 getCapabilities().sendln("KICK " + gui.getQuery() + " " + target + " :" + temp); 342 } 343 else 344 { 345 getCapabilities().sendln("MODE " + gui.getQuery() + " -o+b " + target + " " + target+"!*@*"); 346 getCapabilities().sendln("KICK " + gui.getQuery() + " " + target + " :" + temp); 347 } 348 349 break; 350 case KICK: 351 temp = ClientState.getClientState().getString("kick.message", "I know... I'm a \002jIRC\002"); 352 353 if (tokens.getTotalTokens() > 2) 354 { 355 temp = tokens.getTokenFrom(2); 356 } 357 358 getCapabilities().sendln("KICK " + tokens.getToken(0) + " " + tokens.getToken(1) + " :" + temp); 359 break; 360 case LIST: 361 if (tokens.getTotalTokens() == 1) 362 { 363 if (tokens.getToken(0).equals("-gui")) 364 { 365 gui.openListWindow(); 366 } 367 else 368 { 369 getCapabilities().addTemporaryListener(new ListFilter(tokens.getToken(0))); 370 } 371 372 getCapabilities().sendln("LIST"); 373 } 374 else if (tokens.getTotalTokens() > 1) 375 { 376 getCapabilities().sendln("LIST :" + parms); 377 } 378 else 379 { 380 getCapabilities().sendln("LIST"); 381 } 382 break; 383 case LAGC: 384 long freememory = Runtime.getRuntime().freeMemory(); 385 System.gc(); 386 freememory = Runtime.getRuntime().freeMemory() - freememory; 387 388 System.out.println("Profiler Output:"); 389 System.out.println("<=================> "); 390 392 394 System.out.println("Free'd Memory : " + rero.util.ClientUtils.formatBytes(freememory)); 395 break; 396 case LOAD: 397 if (parms.length() == 0) 398 { 399 File tempf = DialogUtilities.showFileDialog("Select a script", "Load", null); 400 if (tempf != null) 401 parms = tempf.getAbsolutePath(); 402 } 403 404 if (parms == null) break; 405 406 ((ScriptManager)getCapabilities().getDataStructure(DataStructures.ScriptManager)).addScript(parms); 407 break; 408 case M: 409 case MSG: 410 getCapabilities().getChatCapabilities().sendMessage(tokens.getToken(0), tokens.getTokenFrom(1)); 411 break; 412 case ME: 413 chatCommands.sendAction(gui.getQuery(), parms); 414 break; 415 case SM: 416 case MODE: 417 if (tokens.getTotalTokens() == 0) 418 { 419 getCapabilities().sendln("MODE " + gui.getQuery()); 420 } 421 else if (tokens.getTotalTokens() == 1) 422 { 423 getCapabilities().sendln("MODE " + tokens.getToken(0)); 424 } 425 else if (tokens.getTotalTokens() == 2) 426 { 427 getCapabilities().sendln("MODE " + tokens.getToken(0) + " " + tokens.getToken(1)); 428 } 429 else 430 { 431 getCapabilities().sendln("MODE " + tokens.getToken(0) + " " + tokens.getToken(1) + " " + tokens.getTokenFrom(2)); 432 } 433 break; 434 case N: 435 case NOTICE: 436 getCapabilities().getChatCapabilities().sendNotice(tokens.getToken(0), tokens.getTokenFrom(1)); 437 break; 438 case NOTIFY: 439 if (tokens.getTotalTokens() <= 0) 440 break; 441 442 if (tokens.getTotalTokens() == 1) 443 { 444 ((NotifyData)getCapabilities().getDataStructure(DataStructures.NotifyData)).addUser(tokens.getToken(0)); 445 getCapabilities().getOutputCapabilities().fireSetActive(ClientUtils.getEventHashMap("add", tokens.getToken(0)), "SET_NOTIFY"); 446 } 447 else if (tokens.getToken(0).equals("add") && tokens.getTotalTokens() == 2) 448 { 449 ((NotifyData)getCapabilities().getDataStructure(DataStructures.NotifyData)).addUser(tokens.getToken(1)); 450 getCapabilities().getOutputCapabilities().fireSetActive(ClientUtils.getEventHashMap("add", tokens.getToken(1)), "SET_NOTIFY"); 451 } 452 else if ((tokens.getToken(0).equals("remove") || tokens.getToken(1).equals("rem")) && tokens.getTotalTokens() == 2) 453 { 454 ((NotifyData)getCapabilities().getDataStructure(DataStructures.NotifyData)).removeUser(tokens.getToken(1)); 455 getCapabilities().getOutputCapabilities().fireSetActive(ClientUtils.getEventHashMap("remove", tokens.getToken(1)), "SET_NOTIFY"); 456 } 457 break; 458 case NEWSERVER: 459 getCapabilities().getGlobalCapabilities().createNewServer(); 460 461 if (parms.length() > 0) 462 SessionManager.getGlobalCapabilities().getActiveSession().executeCommand("/server " + parms); 463 464 break; 465 case O: 466 case OP: 467 temp = " +"; 468 target = ""; 469 for (int x = 0; x < tokens.getTotalTokens(); x++) 470 { 471 target = ircData.nickComplete(tokens.getToken(x), gui.getQuery()) + " " + target; 472 temp = temp + "o"; 473 } 474 getCapabilities().sendln("MODE " + gui.getQuery() + temp + " " + target.trim()); 475 break; 476 case PA: 477 getCapabilities().sendln("JOIN 0"); 478 break; 479 case L: 480 case LEAVE: 481 case PART: 482 target = gui.getQuery(); 483 parms = parms; 484 if (parms.length() > 0 && ClientUtils.isChannel(tokens.getToken(0))) 485 { 486 target = tokens.getToken(0); 487 parms = tokens.getTokenFrom(1); 488 } 489 490 if (ClientState.getClientState().isOption("auto.part", ClientDefaults.auto_option) && gui.isWindow(target)) 491 { 492 getCapabilities().getUserInterface().closeWindow(target); 493 } 494 else 495 { 496 getCapabilities().sendln("PART " + target + " :" + parms); 497 } 498 499 break; 500 case P: 501 case CPING: 502 case PING: 503 target = gui.getQuery(); 504 if (parms.length() > 0) 505 { 506 target = ircData.nickComplete(parms, gui.getQuery()); 507 } 508 chatCommands.sendRequest(target, "PING", ""); 509 break; 510 case QUERY: 511 if (parms == null || parms.length() == 0) 512 { 513 Set mychs = ircData.getMyUser().getChannels(); 514 Iterator seti = mychs.iterator(); 515 516 StringBuffer rv = new StringBuffer (); 517 518 while (seti.hasNext()) 519 { 520 rv.append(((Channel)seti.next()).getName()); 521 rv.append(" "); 522 } 523 524 getCapabilities().getOutputCapabilities().fireSetActive(ClientUtils.getEventHashMap("-", rv.toString()), "ON_CHANNELS"); 525 } 526 else 527 { 528 getCapabilities().getUserInterface().setQuery(parms); 529 } 530 break; 531 case QUOTE: 532 case RAW: 533 getCapabilities().sendln(parms); 534 break; 535 case QUIT: 536 if (parms.length() == 0) 537 { 538 parms = ClientState.getClientState().getString("message.quit", ircData.getMyNick() + " has no reason"); 539 } 540 541 if (getCapabilities().isConnected()) 542 { 543 getCapabilities().sendln("QUIT :" + parms); 544 ircData.reset(); ((NotifyData)getCapabilities().getDataStructure(DataStructures.NotifyData)).reset(); 546 } 547 break; 548 case REDIR: 549 break; 550 case RELOAD: ((ScriptManager)getCapabilities().getDataStructure(DataStructures.ScriptManager)).reloadScript(parms); 552 break; 553 case SC: 554 target = gui.getQuery(); 555 if (parms.length() > 0) 556 { 557 target = parms; 558 } 559 getCapabilities().sendln("NAMES " + target); 560 break; 561 case SERVER: 562 connectToServer(parms); 563 break; 564 565 case ST: 568 target = gui.getQuery(); 569 if (parms.length() > 0) 570 { 571 target = tokens.getToken(0); 572 } 573 574 getCapabilities().sendln("TOPIC " + target); 575 break; 576 case SV: 577 chatCommands.sendMessage(gui.getQuery(), ClientUtils.ShowVersion()); 578 break; 579 case THEME: 580 ((ScriptManager)getCapabilities().getDataStructure(DataStructures.ScriptManager)).loadTheme(parms); 581 break; 582 case TOPIC: 583 584 target = gui.getQuery(); 586 587 if (parms.length() > 0) 589 { 590 target = tokens.getToken(0); 591 } 592 593 if (tokens.getTotalTokens() > 1) { 595 596 getCapabilities().sendln("TOPIC " + target + " :" + tokens.getTokenFrom(1)); 598 } 599 else { 600 601 getCapabilities().sendln("TOPIC " + target); 603 } 604 break; 605 606 case UT: 608 609 target = gui.getQuery(); 611 612 if (parms.length() > 0) 614 { 615 target = tokens.getToken(0); 616 } 617 618 getCapabilities().sendln("TOPIC " + target + " :"); 620 break; 621 622 case UNBAN: 623 if (parms.indexOf('!') > -1) 624 { 625 target = parms; 626 } 627 else 628 { 629 User luser = ircData.getUser(parms); 630 631 if (luser != null && luser.getAddress().length() > 0) 632 { 633 target = luser.getNick() + "!" + luser.getAddress(); 634 } 635 else 636 { 637 target = parms + "!*@*"; 638 } 639 } 640 641 getCapabilities().addTemporaryListener(new UnbanHandler(target, gui.getQuery())); 642 getCapabilities().sendln("MODE " + gui.getQuery() + " +b"); 643 break; 644 case UNIGNORE: 645 StringList templw = ClientState.getClientState().getStringList("ignore.masks"); 646 templw.remove(parms); 647 templw.save(); 648 649 getCapabilities().getOutputCapabilities().fireSetActive(ClientUtils.getEventHashMap("remove", parms), "SET_IGNORE"); 650 break; 651 case UNLOAD: 652 ((ScriptManager)getCapabilities().getDataStructure(DataStructures.ScriptManager)).removeScript(parms); 653 break; 654 case VER: 655 target = gui.getQuery(); 656 if (parms.length() > 0) 657 { 658 target = ircData.nickComplete(parms, gui.getQuery()); 659 } 660 chatCommands.sendRequest(target, "VERSION", ""); 661 break; 662 case V: 663 case VOICE: 664 temp = " +"; 665 target = ""; 666 for (int x = 0; x < tokens.getTotalTokens(); x++) 667 { 668 target = ircData.nickComplete(tokens.getToken(x), gui.getQuery()) + " " + target; 669 temp = temp + "v"; 670 } 671 getCapabilities().sendln("MODE " + gui.getQuery() + temp + " " + target); 672 break; 673 case WALL: 674 Set chops = ircData.getUsersWithMode(gui.getQuery(), 'o'); 675 chops.remove(ircData.getMyUser()); 676 String [] chopsZ = groupUsers(chops); 677 678 for (int z = 0; z < chopsZ.length; z++) 679 { 680 getCapabilities().sendln("NOTICE " + chopsZ[z] + " :["+AttributedString.bold+"wall"+AttributedString.bold+"/" + gui.getQuery() + "]: " + parms); 681 } 682 683 getCapabilities().getOutputCapabilities().fireSetActive(ClientUtils.getEventHashMap(gui.getQuery(), parms), "SEND_WALL"); 684 685 break; 686 case WALLEX: 687 Set chops2 = new HashSet(); 688 chops2.addAll(ircData.getUsersWithMode(gui.getQuery(), 'o')); 689 chops2.addAll(ircData.getUsersWithMode(gui.getQuery(), 'h')); 690 chops2.addAll(ircData.getUsersWithMode(gui.getQuery(), 'v')); 691 692 String [] removeUsers = tokens.getToken(0).split(","); 693 for (int y = 0; y < removeUsers.length; y++) 694 { 695 if (removeUsers[y].equals("@")) 696 { 697 chops2.removeAll(ircData.getUsersWithMode(gui.getQuery(), 'o')); 698 } 699 else if (removeUsers[y].equals("+")) 700 { 701 chops2.removeAll(ircData.getUsersWithMode(gui.getQuery(), 'v')); 702 } 703 else if (removeUsers[y].equals("%")) 704 { 705 chops2.removeAll(ircData.getUsersWithMode(gui.getQuery(), 'h')); 706 } 707 else 708 { 709 removeUsers[y] = ircData.nickComplete(removeUsers[y], gui.getQuery()); 710 chops2.remove(ircData.getUser(removeUsers[y])); 711 } 712 } 713 714 chops2.remove(ircData.getMyUser()); 715 716 String boozer = joinNicks(removeUsers); 717 718 String [] chopsZZ = groupUsers(chops2); 719 720 for (int z = 0; z < chopsZZ.length; z++) 721 { 722 getCapabilities().sendln("NOTICE " + chopsZZ[z] + " :["+AttributedString.bold+"wall-x"+AttributedString.bold+"/" + boozer + "]" + tokens.getTokenFrom(1)); 723 } 724 725 getCapabilities().getOutputCapabilities().fireSetActive(ClientUtils.getEventHashMap(boozer, tokens.getTokenFrom(1)), "SEND_WALLEX"); 726 727 break; 728 case WHOIS: 729 case WI: 730 getCapabilities().sendln("WHOIS " + parms); 731 break; 732 case WII: 733 getCapabilities().sendln("WHOIS " + parms + " " + parms); 734 break; 735 case WINDOW: 736 if (parms.length() == 0) 737 break; 738 739 if (getCapabilities().getUserInterface().getQuery().toUpperCase().equals(parms.toUpperCase())) 740 { 741 getCapabilities().getOutputCapabilities().cycleQuery(); 742 } 743 744 if (ClientUtils.isChannel(parms)) 745 { 746 gui.openChannelWindow(ircData.getChannel(parms)); 747 } 748 else 749 { 750 gui.openQueryWindow(parms, true); 751 } 752 753 break; 754 case WW: 755 getCapabilities().sendln("WHOWAS " + parms); 756 break; 757 default: 758 getCapabilities().sendln(command + " " + parms); 759 } 760 } 761 762 public void connectToServer(String parms) 763 { 764 boolean secure = false; 765 String host = ""; 766 int port = 6667; 767 String password = null; 768 769 StringStack stack = new StringStack(parms); 770 771 String temp = stack.pop(); 772 if (temp.equals("-ssl") || temp.equals("-s")) 773 { 774 secure = true; 775 temp = stack.pop(); 776 } 777 778 if (temp.equals("-pass") || temp.equals("-p")) 779 { 780 password = stack.pop(); 781 temp = stack.pop(); 782 } 783 784 host = temp; 785 786 if (!stack.isEmpty()) 787 { 788 port = Integer.parseInt(stack.pop()); 789 } 790 791 if (getCapabilities().isConnected()) { 793 ircData.reset(); ((NotifyData)getCapabilities().getDataStructure(DataStructures.NotifyData)).reset(); 795 getCapabilities().sendln("QUIT :switching servers"); 796 } 797 798 getCapabilities().getSocketConnection().connect(host, port, 0, password, secure); 799 getCapabilities().getOutputCapabilities().fireSetStatus(ClientUtils.getEventHashMap(host, host + " " + port + " " + password + " " + secure), "IRC_ATTEMPT_CONNECT"); 800 } 801 802 private String [] groupUsers(Set users) 803 { 804 StringBuffer rv = new StringBuffer (); 805 806 int x = 1; 807 Iterator i = users.iterator(); 808 while (i.hasNext()) 809 { 810 String temp = ((User)i.next()).getNick(); 811 rv.append(temp); 812 if ((x % 4) == 0 && x > 1) { rv.append("="); } 813 else { rv.append(","); } 814 815 x++; 816 } 817 818 819 if (rv.toString().length() > 1) 820 { 821 return rv.toString().substring(0, rv.toString().length() - 1).split("="); 822 } 823 return new String [0]; 824 } 825 826 private class QuickProcess implements Runnable 827 { 828 private Process process; 829 private BufferedReader reader = null; 830 private String command; 831 832 public QuickProcess(String parms) 833 { 834 command = parms; 835 } 836 837 public void run() 838 { 839 try 840 { 841 process = Runtime.getRuntime().exec(command); 842 reader = new BufferedReader(new InputStreamReader(process.getInputStream())); 843 844 String data; 845 846 while ((data = reader.readLine()) != null) 847 { 848 getCapabilities().getOutputCapabilities().fireSetActive(ClientUtils.getEventHashMap("process", data), "PROCESS_DATA"); 849 } 850 } 851 catch (Exception ex) 852 { 853 getCapabilities().getOutputCapabilities().fireSetActive(ClientUtils.getEventHashMap("error", ex.getMessage()), "PROCESS_DATA"); 854 } 855 } 856 } 857 858 private static String joinNicks(String [] stuff) 859 { 860 StringBuffer temp = new StringBuffer (); 861 for (int x = 0; x < stuff.length; x++) 862 { 863 temp.append(stuff[x]); 864 if ((x + 1) < stuff.length) 865 { 866 temp.append(","); 867 } 868 } 869 870 return temp.toString(); 871 } 872 873 private class ResolveHost implements Runnable 874 { 875 private String host; 876 877 public ResolveHost(String _host) 878 { 879 host = _host; 880 } 881 882 public void run() 883 { 884 try 885 { 886 InetAddress info = InetAddress.getByName(host); 887 888 HashMap eventDescription = new HashMap(); 889 eventDescription.put("$data", host + " " + info.getHostAddress() + " " + info.getHostName()); 890 eventDescription.put("$parms", info.getHostAddress() + " " + info.getHostName()); 891 getCapabilities().getOutputCapabilities().fireSetActive(eventDescription, "RESOLVED_HOST"); 892 } 893 catch (UnknownHostException ex) 894 { 895 HashMap eventDescription = new HashMap(); 896 eventDescription.put("$data", host); 897 eventDescription.put("$parms", ""); 898 getCapabilities().getOutputCapabilities().fireSetActive(eventDescription, "RESOLVED_HOST"); 899 } 900 } 901 } 902 903 private class UnbanHandler implements ChatListener 904 { 905 protected String channel; 906 protected String target; 907 908 public UnbanHandler(String _target, String _channel) 909 { 910 target = _target.toUpperCase(); 911 channel = _channel.toUpperCase(); 912 } 913 914 public boolean isChatEvent(String event, HashMap eventId) 915 { 916 return event.equals("367") || event.equals("368"); 917 } 918 919 public int fireChatEvent(HashMap eventDescription) 920 { 921 if (eventDescription.get("$event").toString().equals("368")) 922 return ChatListener.EVENT_HALT | ChatListener.REMOVE_LISTENER; 923 924 TokenizedString data = new TokenizedString((String )eventDescription.get("$parms")); 925 data.tokenize(" "); 926 927 if (data.getToken(0).toUpperCase().equals(channel)) 928 { 929 if (StringUtils.iswm(data.getToken(1).toUpperCase(), target)) 930 { 931 getCapabilities().sendln("MODE " + channel + " -b " + data.getToken(1)); 932 } 933 } 934 935 return ChatListener.EVENT_HALT; 936 } 937 } 938 } 939 | Popular Tags |