home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / chatzilla.jar / content / chatzilla / handlers.js < prev    next >
Text File  |  2000-09-13  |  51KB  |  1,995 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * The contents of this file are subject to the Mozilla Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/MPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is JSIRC Test Client #3
  14.  *
  15.  * The Initial Developer of the Original Code is New Dimensions Consulting,
  16.  * Inc. Portions created by New Dimensions Consulting, Inc. are
  17.  * Copyright (C) 1999 New Dimenstions Consulting, Inc. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s): 
  21.  *
  22.  *
  23.  * Contributor(s):
  24.  *  Robert Ginda, rginda@ndcico.com, original author
  25.  */
  26.  
  27. function onLoad()
  28. {
  29.     
  30.     initHost(client);
  31.     readIRCPrefs();
  32.     setOutputStyle (client.DEFAULT_STYLE); 
  33.     /* 
  34.        Called in a callback once the document loads due to a current bug
  35.     */
  36.     mainStep();
  37.     
  38. }
  39.  
  40. function onUnload()
  41. {
  42.  
  43.     client.quit ("ChatZilla! [" + navigator.userAgent + "]");
  44.     
  45. }
  46.  
  47. function onNotImplemented()
  48. {
  49.  
  50.     alert ("'We're accepting patches'");
  51.     
  52. }
  53.  
  54. /* toolbaritem click */
  55. function onTBIClick (id)
  56. {
  57.     
  58.     var tbi = document.getElementById (id);
  59.     var view = client.viewsArray[tbi.getAttribute("viewKey")];
  60.  
  61.     setCurrentObject (view.source);
  62.     
  63. }
  64.  
  65. /* popup click in user list */
  66. function onUserListPopupClick (e)
  67. {
  68.  
  69.     var code = e.target.getAttribute("code");
  70.     var ary = code.substr(1, code.length).match (/(\S+)? ?(.*)/);    
  71.  
  72.     if (!ary)
  73.         return;
  74.  
  75.     var command = ary[1];
  76.  
  77.     var ev = new CEvent ("client", "input-command", client,
  78.                          "onInputCommand");
  79.     ev.command = command;
  80.     ev.inputData =  ary[2] ? stringTrim(ary[2]) : "";    
  81.     ev.target = client.currentObject;
  82.  
  83.     getObjectDetails (ev.target, ev);
  84.  
  85.     client.eventPump.addEvent (ev);
  86. }
  87.  
  88.  
  89. function onToggleTraceHook()
  90. {
  91.     var h = client.eventPump.getHook ("event-tracer");
  92.     
  93.     h.enabled = !h.enabled;
  94.     document.getElementById("menu-dmessages").setAttribute ("checked",
  95.                                                             h.enabled);
  96.     
  97. }   
  98.  
  99. function onToggleToolbarIcons()
  100. {
  101.     client.ICONS_IN_TOOLBAR = !client.ICONS_IN_TOOLBAR;
  102.     
  103.     var newclass = "menubutton " + ((client.ICONS_IN_TOOLBAR) ?
  104.         "activity-button-image" : "activity-button-text");
  105.  
  106.     for (var i in client.viewsArray)
  107.         client.viewsArray[i].tb.setAttribute ("class", newclass);
  108.  
  109. }
  110.  
  111. function onToggleVisibility(thing)
  112. {    
  113.     var menu = document.getElementById("menu-view-" + thing);
  114.     var ids = new Array();
  115.     
  116.     switch (thing)
  117.     {
  118.         case "toolbar":
  119.             ids = ["views-tbox"];
  120.             break;
  121.             
  122.         case "info":
  123.             ids = ["user-list-box", "main-splitter"];            
  124.             break;
  125.             
  126.         case "status":
  127.             ids = ["status-bar-tbox"];
  128.             break;
  129.  
  130.         default:
  131.             dd ("** Unknown element '" + menuId + 
  132.                 "' passed to onToggleVisibility. **");
  133.             return;
  134.     }
  135.  
  136.  
  137.     var newState;
  138.     var elem = document.getElementById(ids[0]);
  139.     var d = elem.getAttribute("collapsed");
  140.     
  141.     if (d == "true")
  142.     {
  143.         newState = "false";
  144.         menu.setAttribute ("checked", "true");
  145.         client.uiState[thing] = true;
  146.     }
  147.     else
  148.     {
  149.         newState = "true";
  150.         menu.setAttribute ("checked", "false");
  151.         client.uiState[thing] = false;
  152.     }
  153.     
  154.     for (var i in ids)
  155.     {
  156.         elem = document.getElementById(ids[i]);
  157.         elem.setAttribute ("collapsed", newState);
  158.     }
  159.  
  160.     updateTitle();
  161.  
  162. }
  163.  
  164. function onDoStyleChange (newStyle)
  165. {
  166.  
  167.     if (newStyle == "other")
  168.         newStyle = window.prompt ("Enter stylesheet filename " +
  169.                                   "(relative to chrome://chatzilla/skin/)");
  170.  
  171.     if (newStyle)
  172.     {
  173.         setOutputStyle (newStyle);
  174.         setCurrentObject(client.currentObject);
  175.     }
  176.     
  177. }
  178.  
  179. function onHideCurrentView()
  180. {
  181.     var tb = getTBForObject(client.currentObject);
  182.     
  183.     if (tb)
  184.     {
  185.         var i = deleteToolbutton (tb);
  186.         if (i != -1)
  187.         {
  188.             if (i >= client.viewsArray.length)
  189.                 i = client.viewsArray.length - 1;
  190.             
  191.             setCurrentObject (client.viewsArray[i].source);
  192.         }
  193.         
  194.     }
  195.     
  196. }
  197.  
  198. function onDeleteCurrentView()
  199. {
  200.     var tb = getTBForObject(client.currentObject);
  201.     
  202.     if (tb)
  203.     {
  204.         var i = deleteToolbutton (tb);
  205.         if (i != -1)
  206.         {
  207.             delete client.currentObject.messages;
  208.  
  209.             if (i >= client.viewsArray.length)
  210.                 i = client.viewsArray.length - 1;            
  211.             setCurrentObject (client.viewsArray[i].source);
  212.         }
  213.         
  214.     }
  215.     
  216. }
  217.  
  218. function onClearCurrentView()
  219. {
  220.  
  221.     if (client.output.firstChild)
  222.         client.output.removeChild (client.output.firstChild);
  223.  
  224.     client.currentObject.messages = (void 0);
  225.     delete client.currentObject.messages;
  226.  
  227.     client.currentObject.display ("Messages Cleared.", "INFO");
  228.  
  229.     client.output.appendChild (client.currentObject.messages);
  230.     
  231. }
  232.  
  233. function onSortCol(sortColName)
  234. {
  235.     const nsIXULSortService = Components.interfaces.nsIXULSortService;
  236.     const isupports_uri = "@mozilla.org/rdf/xul-sort-service;1";
  237.     
  238.     var node = document.getElementById(sortColName);
  239.     // determine column resource to sort on
  240.     var sortResource = node.getAttribute('resource');
  241.     if (!node)
  242.         return false;
  243.  
  244.     var sortDirection = "ascending";
  245.         //node.setAttribute("sortActive", "true");
  246.  
  247.     switch (sortColName)
  248.     {
  249.         case "usercol-op":
  250.             document.getElementById("usercol-voice")
  251.                 .setAttribute("sortDirection", "natural");
  252.             document.getElementById("usercol-nick")
  253.                 .setAttribute("sortDirection", "natural");
  254.             break;
  255.         case "usercol-voice":
  256.             document.getElementById("usercol-op")
  257.                 .setAttribute("sortDirection", "natural");
  258.             document.getElementById("usercol-nick")
  259.                 .setAttribute("sortDirection", "natural");
  260.             break;
  261.         case "usercol-nick":
  262.             document.getElementById("usercol-voice")
  263.                 .setAttribute("sortDirection", "natural");
  264.             document.getElementById("usercol-op")
  265.                 .setAttribute("sortDirection", "natural");
  266.             break;
  267.     }
  268.     
  269.     var currentDirection = node.getAttribute('sortDirection');
  270.     
  271.     if (currentDirection == "ascending")
  272.         sortDirection = "descending";
  273.     else if (currentDirection == "descending")
  274.         sortDirection = "natural";
  275.     else
  276.         sortDirection = "ascending";
  277.     
  278.     node.setAttribute ("sortDirection", sortDirection);
  279.  
  280.     var xulSortService =
  281.         Components.classes[isupports_uri].getService(nsIXULSortService);
  282.     if (!xulSortService)
  283.         return false;
  284.     try
  285.     {
  286.         xulSortService.Sort(node, sortResource, sortDirection);
  287.     }
  288.     catch(ex)
  289.     {
  290.             //dd("Exception calling xulSortService.Sort()");
  291.     }
  292.     
  293.     return false;
  294. }
  295.  
  296. function onToggleMunger()
  297. {
  298.  
  299.     client.munger.enabled = !client.munger.enabled;
  300.     document.getElementById("menu-munger").setAttribute ("checked",
  301.                                                          client.munger.enabled);
  302.  
  303. }
  304.  
  305. function onInputKeyUp (e)
  306. {
  307.     
  308.     switch (e.keyCode)
  309.     {        
  310.         case 13: /* CR */
  311.             e.line = e.target.value;
  312.             onInputCompleteLine (e);
  313.             break;
  314.  
  315.         case 38: /* up */
  316.             if (client.lastHistoryReferenced < client.inputHistory.length - 1)
  317.                 e.target.value =
  318.                     client.inputHistory[++client.lastHistoryReferenced];
  319.             break;
  320.  
  321.         case 40: /* down */
  322.             if (client.lastHistoryReferenced > 0)
  323.                 e.target.value =
  324.                     client.inputHistory[--client.lastHistoryReferenced];
  325.             else
  326.             {
  327.                 client.lastHistoryReferenced = -1;
  328.                 e.target.value = client.incompleteLine;
  329.             }
  330.             
  331.             break;
  332.  
  333.         case 9: /* tab */
  334.             e.preventDefault();
  335.             onTabCompleteRequest(e);
  336.             break;       
  337.             
  338.         default:
  339.             client.incompleteLine = e.target.value;
  340.  
  341.             
  342.     }
  343.  
  344. }
  345.  
  346. function onTabCompleteRequest (e)
  347. {
  348.     var selStart = e.target.selectionStart;
  349.     var selEnd = e.target.selectionEnd;            
  350.     var v = e.target.value;
  351.  
  352.     if (selStart != selEnd) 
  353.     {
  354.         /* text is highlighted, just move caret to end and exit */
  355.         e.target.selectionStart = e.target.selectionEnd = v.length;
  356.         return;
  357.     }
  358.  
  359.     var firstSpace = v.indexOf(" ");
  360.     if (firstSpace == -1)
  361.         firstSpace = v.length;
  362.     
  363.     if ((v[0] == client.COMMAND_CHAR) && (selStart <= firstSpace))
  364.     {
  365.         /* complete a command */                
  366.         var partialCommand = v.substring(1, firstSpace).toLowerCase();
  367.         var cmds = client.commands.listNames(partialCommand);
  368.             
  369.         if (cmds.length == 1)
  370.         {
  371.             /* partial matched exactly one command */
  372.             var pfx = client.COMMAND_CHAR + cmds[0];
  373.             if (firstSpace == v.length)
  374.                 v =  pfx + " ";
  375.             else
  376.                 v = pfx + v.substr (firstSpace);
  377.             
  378.             e.target.value = v;
  379.             e.target.selectionStart = e.target.selectionEnd = 
  380.                 pfx.length + 1;
  381.         }
  382.         else if (cmds.length > 1)
  383.         {
  384.             /* partial matched more than one command */
  385.             var d = new Date();
  386.             if ((d - client.lastTabUp) <= client.DOUBLETAB_TIME)
  387.                 client.currentObject.display
  388.                     ("Commands matching ``" + partialCommand + 
  389.                      "'' are [" + cmds.join(", ") + "]", "INFO");
  390.             else
  391.                 client.lastTabUp = d;
  392.             
  393.             var pfx = client.COMMAND_CHAR + getCommonPfx(cmds);
  394.             if (firstSpace == v.length)
  395.                 v =  pfx;
  396.             else
  397.                 v = pfx + v.substr (firstSpace);
  398.             
  399.             e.target.value = v;
  400.             e.target.selectionStart = e.target.selectionEnd = pfx.length;
  401.             
  402.         }
  403.         else
  404.             client.currentObject.display ("No commands matching " +
  405.                                           partialCommand, "ERROR");
  406.         
  407.     }
  408.     else if (client.currentObject.users)
  409.     {
  410.         /* complete a nickname */
  411.         var users = client.currentObject.users;
  412.         var nicks = new Array();
  413.         
  414.         for (var n in users)
  415.             nicks.push (users[n].nick);
  416.         
  417.         var nickStart = v.lastIndexOf(" ", selStart) + 1;
  418.         var nickEnd = v.indexOf (" ", selStart);
  419.         if (nickEnd == -1)
  420.             nickEnd = v.length;
  421.         
  422.         var partialNick = v.substring(nickStart, nickEnd).toLowerCase();
  423.         
  424.         var matchingNicks = matchEntry (partialNick, nicks);
  425.         
  426.         if (matchingNicks.length > 0)
  427.         {
  428.             var subst;
  429.             
  430.             if (matchingNicks.length == 1)
  431.             {   /* partial matched exactly one nick */
  432.                 subst = 
  433.                     client.currentObject.users[matchingNicks[0]].properNick;
  434.                 if (nickStart == 0)
  435.                     subst += client.ADDRESSED_NICK_SEP;
  436.                 else
  437.                     subst += " ";
  438.             }
  439.             else
  440.             {   /* partial matched more than one command */
  441.                 var d = new Date();
  442.                 if ((d - client.lastTabUp) <= client.DOUBLETAB_TIME)
  443.                     client.currentObject.display
  444.                         ("Users matching ``" + partialNick +
  445.                          "'' are [" + matchingNicks.join(", ") + "]",
  446.                          "INFO");
  447.                 else
  448.                     client.lastTabUp = d;
  449.                 
  450.                 subst = getCommonPfx(matchingNicks);
  451.             }
  452.             
  453.             v = v.substr (0, nickStart) + subst + v.substr (nickEnd);
  454.             e.target.value = v;
  455.             
  456.         }
  457.         
  458.     }
  459.  
  460. }
  461.  
  462. function onWindowKeyPress (e)
  463. {
  464.     var code = Number (e.keyCode)
  465.     switch (code)
  466.     {
  467.         case 112: /* F1 */
  468.         case 113: /* ... */
  469.         case 114:
  470.         case 115:
  471.         case 116:
  472.         case 117:
  473.         case 118:
  474.         case 119:
  475.         case 120:
  476.         case 121: /* F10 */
  477.             var idx = code - 112;
  478.             if ((client.viewsArray[idx]) && (client.viewsArray[idx].source))
  479.                 setCurrentObject(client.viewsArray[idx].source);
  480.             
  481.             return false;
  482.             break;
  483.  
  484.         case 33: /* pgup */
  485.             var w = window.frames[0];
  486.             var newOfs = w.pageYOffset - (w.innerHeight / 2);
  487.             if (newOfs > 0)
  488.                 w.scrollTo (w.pageXOffset, newOfs);
  489.             else
  490.                 w.scrollTo (w.pageXOffset, 0);
  491.             break;
  492.             
  493.         case 34: /* pgdn */
  494.             var w = window.frames[0];
  495.             var newOfs = w.pageYOffset + (w.innerHeight / 2);
  496.             if (newOfs < (w.innerHeight + w.pageYOffset))
  497.                 w.scrollTo (w.pageXOffset, newOfs);
  498.             else
  499.                 w.scrollTo (w.pageXOffset, (w.innerHeight + w.pageYOffset));
  500.             break;
  501.  
  502.         case 9: /* tab */
  503.             e.preventDefault();
  504.             break;
  505.             
  506.         default:
  507.             
  508.     }
  509.  
  510. }
  511.  
  512. function onInputCompleteLine(e)
  513. {
  514.  
  515.     if (e.target.getAttribute ("expanded") != "YES")
  516.     {
  517.         e.line = e.line.replace (/\n/g, "");
  518.  
  519.         if (client.inputHistory[0] != e.line)
  520.             client.inputHistory.unshift (e.line);
  521.  
  522.         if (client.inputHistory.length > client.MAX_HISTORY)
  523.             client.inputHistory.pop();
  524.         
  525.         client.lastHistoryReferenced = -1;
  526.         client.incompleteLine = "";
  527.         
  528.         if (e.line[0] == client.COMMAND_CHAR)
  529.         {
  530.             var ary = e.line.substr(1, e.line.length).match (/(\S+)? ?(.*)/);
  531.             var command = ary[1];
  532.             
  533.             if (command[0].search (/[\[\{\(]/) == 0) /* request to expand */
  534.             {
  535.                 e.target.setAttribute("expanded", "YES");
  536.                 switch (command[0])
  537.                 {
  538.                     case "[":
  539.                         e.target.setAttribute("collapseChar", "]");
  540.                         break;
  541.  
  542.                     case "{":
  543.                         e.target.setAttribute("collapseChar", "}");
  544.                         break;
  545.                         
  546.                     case "(":
  547.                         e.target.setAttribute("collapseChar", ")");
  548.                         break;        
  549.                 }
  550.                 e.target.style.height = client.EXPAND_HEIGHT;
  551.             }
  552.             else /* normal command */
  553.             {
  554.                 var ev = new CEvent ("client", "input-command", client,
  555.                                      "onInputCommand");
  556.                 ev.command = command;
  557.                 ev.inputData =  ary[2] ? stringTrim(ary[2]) : "";
  558.  
  559.                 ev.target = client.currentObject;
  560.                 getObjectDetails (ev.target, ev);
  561.                 client.eventPump.addEvent (ev);
  562.                 e.target.value = "";            
  563.             }
  564.         }
  565.         else /* plain text */
  566.         {
  567.             client.sayToCurrentTarget (e.line);
  568.             e.target.value = "";            
  569.         }
  570.     }
  571.     else /* input-box is expanded */
  572.     {
  573.         var lines = e.target.value.split("\n");
  574.         for (i in lines)
  575.             if (lines[i] == "")
  576.                 arrayRemoveAt (lines, i);
  577.         var lastLine = lines[lines.length - 1];
  578.  
  579.         if (lastLine.replace(/s*$/,"") ==
  580.             e.target.getAttribute ("collapseChar"))
  581.         {
  582.             dd ("collapsing...");
  583.             
  584.             e.target.setAttribute("expanded", "NO");
  585.             e.target.style.height = client.COLLAPSE_HEIGHT;
  586.             e.target.value = "";
  587.             client.sayToCurrentTarget (lines[i]);
  588.             e.target.value = "";            
  589.         }
  590.     }
  591.     
  592. }
  593.  
  594.  
  595. client.onInputCommand = 
  596. function cli_icommand (e)
  597. {
  598.     var ary = client.commands.list (e.command);
  599.     
  600.     switch (ary.length)
  601.     {        
  602.         case 0:
  603.             client.currentObject.display ("Unknown command '" + e.command +
  604.                                           "'.", "ERROR");
  605.             break;
  606.             
  607.         case 1:
  608.             if (typeof client[ary[0].func] == "undefined")        
  609.                 client.currentObject.display ("Sorry, '" + ary[0].name +
  610.                                               "' has not been implemented.", 
  611.                                               "ERROR");
  612.             else
  613.             {
  614.                 e.commandEntry = ary[0];
  615.                 if (!client[ary[0].func](e))
  616.                     client.currentObject.display (ary[0].name + " " +
  617.                                                   ary[0].usage, "USAGE");
  618.             }
  619.             break;
  620.             
  621.         default:
  622.             client.currentObject.display ("Ambiguous command: '" + e.command +
  623.                                           "'", "ERROR");
  624.             var str = "";
  625.             for (var i in ary)
  626.                 str += str ? ", " + ary[i].name : ary[i].name;
  627.             client.currentObject.display (ary.length + " commands match: " +
  628.                                           str, "ERROR");
  629.     }
  630.  
  631. }
  632.  
  633. client.onInputHelp =
  634. function cli_ihelp (e)
  635. {
  636.     var ary = client.commands.list (e.inputData);
  637.  
  638.     if (ary.length == 0)
  639.     {
  640.         client.currentObject.display ("No such command, '" + e.inputData +
  641.                                       "'.", "ERROR");
  642.         return false;
  643.     }
  644.  
  645.     var saveDir = client.PRINT_DIRECTION;
  646.     client.PRINT_DIRECTION = 1;
  647.     
  648.     for (var i in ary)
  649.     {        
  650.         client.currentObject.display (ary[i].name + " " + ary[i].usage,
  651.                                       "USAGE");
  652.         client.currentObject.display (ary[i].help, "HELP");
  653.     }
  654.  
  655.     client.PRINT_DIRECTION = saveDir;
  656.     
  657.     return true;
  658.     
  659. }
  660.  
  661. client.onInputTestDisplay =
  662. function cli_testdisplay (e)
  663. {
  664.  
  665.     client.currentObject.display ("Hello World!", "HELLO");
  666.     client.currentObject.display ("Nothing is wrong.", "ERROR");
  667.     client.currentObject.display ("Use not, want not.", "USAGE");
  668.     client.currentObject.display ("Don't Panic", "HELP");
  669.     client.currentObject.display ("NOTICE this!", "NOTICE", "Mozilla");
  670.     client.currentObject.display ("And hear this.", "PRIVMSG", "Mozilla");
  671.     client.currentObject.display ("But dont do this?", "ACTION", "Mozilla");
  672.     client.currentObject.display ("or you'll get KICKed", "KICK", "Mozilla");
  673.     client.currentObject.display ("JOIN in the fun.", "JOIN", "Mozilla");
  674.     client.currentObject.display ("PART when you want.", "PART", "Mozilla");
  675.     client.currentObject.display ("But never QUIT", "QUIT", "Mozilla");
  676.  
  677.     if (client.currentObject.TYPE == "IRCChannel")
  678.     {
  679.         var mynick = e.server.me.nick;
  680.         client.currentObject.display ("NOTICE this!", "NOTICE", "!ME");
  681.         client.currentObject.display ("And hear this.", "PRIVMSG", "!ME");
  682.         client.currentObject.display ("But dont do this?", "ACTION", "!ME");
  683.         client.currentObject.display ("or you'll get KICKed", "KICK", "!ME");
  684.         client.currentObject.display ("JOIN in the fun.", "JOIN", "!ME");
  685.         client.currentObject.display ("PART when you want.", "PART", "!ME");
  686.         client.currentObject.display ("But never QUIT", "QUIT", "!ME");
  687.     }
  688.  
  689.     return true;
  690.     
  691. }   
  692.  
  693. client.onInputNetwork =
  694. function cli_inetwork (e)
  695. {
  696.     if (!e.inputData)
  697.         return false;
  698.  
  699.     var net = client.networks[e.inputData];
  700.  
  701.     if (net)
  702.     {
  703.         client.lastNetwork = net;
  704.         setCurrentObject (net);    
  705.     }
  706.     else
  707.     {
  708.         client.currentObject.display ("Unknown network '" + e.inputData + "'",
  709.                                       "ERROR");
  710.         return false;
  711.     }
  712.     
  713.     return true;
  714.     
  715. }
  716.  
  717. client.onInputServer =
  718. function cli_iserver (e)
  719. {
  720.     if (!e.inputData)
  721.         return false;
  722.  
  723.     var ary = e.inputData.match(/^([^\s\:]+)[\s\:]?(\d+)? ?(\S+)?/);
  724.     var pass = (ary[2]) ? ary[2] : "";
  725.     
  726.     if (ary == null)
  727.         return false;
  728.  
  729.     if (!ary[2])
  730.         ary[2] = 6667;
  731.     
  732.     client.networks[ary[1]] =
  733.         new CIRCNetwork (ary[1], [{name: ary[1], port: ary[2]}],
  734.                          client.eventPump);
  735.     
  736.     client.onInputAttach ({inputData: ary[1] + " " + pass});
  737.     
  738.     return true;
  739.  
  740. }
  741.  
  742. client.onInputQuit =
  743. function cli_quit (e)
  744. {
  745.     if (!e.server)
  746.     {
  747.         client.currentObject.display ("Quit can only be used in the context " +
  748.                                       "of a network, perhaps you meant /exit?",
  749.                                       "ERROR");
  750.         return false;
  751.     }
  752.  
  753.     if (!e.server.connection.isConnected)
  754.     {
  755.         client.currentObject.display ("Not connected", "ERROR");
  756.         return false;
  757.     }
  758.  
  759.     e.server.logout (e.inputData);
  760.  
  761.     return true;
  762.     
  763. }
  764.  
  765. client.onInputExit =
  766. function cli_exit (e)
  767. {
  768.     
  769.     client.quit(e.inputData);    
  770.     window.close();
  771.     
  772. }
  773.  
  774. client.onInputDelete =
  775. function cli_idelete (e)
  776. {
  777.     
  778.     onDeleteCurrentView();
  779.     return true;
  780.  
  781. }
  782.  
  783. client.onInputHide=
  784. function cli_ihide (e)
  785. {
  786.     
  787.     onHideCurrentView();
  788.     return true;
  789.  
  790. }
  791.  
  792. client.onInputClear =
  793. function cli_iclear (e)
  794. {
  795.     
  796.     onClearCurrentView();
  797.     return true;
  798.  
  799. }
  800.  
  801. client.onInputNames =
  802. function cli_inames ()
  803. {
  804.     
  805.     onToggleVisibility ("info");
  806.     return true;
  807.     
  808. }
  809.  
  810. client.onInputToolbar =
  811. function cli_itbar ()
  812. {
  813.     
  814.     onToggleVisibility ("toolbar");
  815.     return true;
  816.  
  817. }
  818.  
  819. client.onInputStatusbar =
  820. function cli_isbar ()
  821. {
  822.     
  823.     onToggleVisibility ("status");
  824.     return true;
  825.  
  826. }
  827.  
  828. client.onInputCommands =
  829. function cli_icommands (e)
  830. {
  831.     
  832.     if (e && e.inputData)
  833.         client.currentObject.display ("Currently implemented commands " +
  834.                                       "matching the pattern ``" + e.inputData +
  835.                                       "'' are ["  + 
  836.                                       client.commands.listNames(e.inputData)
  837.                                       .join(", ") + "].", "INFO");
  838.     else
  839.         client.currentObject.display ("Currently implemented commands are ["  + 
  840.                                       client.commands.listNames().join(", ") +
  841.                                       "].", "INFO");
  842.     return true;
  843. }
  844.  
  845. client.onInputAttach =
  846. function cli_iattach (e)
  847. {
  848.     var net;
  849.     var pass;
  850.     
  851.     if (!e.inputData)
  852.     {
  853.         if (client.lastNetwork)
  854.         {        
  855.             client.currentObject.display ("No network specified network, " +
  856.                                           "Using '" + client.lastNetwork.name +
  857.                                           "'", "NOTICE");
  858.             net = client.lastNetwork;
  859.         }
  860.         else
  861.         {
  862.             client.currentObject.display ("No network specified, and no " +
  863.                                           "default network is in place.",
  864.                                           "ERROR");
  865.             return false;
  866.         }
  867.     }
  868.     else
  869.     {
  870.         var ary = e.inputData.match (/(\S+) ?(\S+)?/);
  871.         net = client.networks[ary[1]];
  872.         pass = ary[2];
  873.         
  874.         if (!net)
  875.         {
  876.             client.currentObject.display ("Unknown network '" +
  877.                                           e.inputData + "'", "ERROR");
  878.             return false;
  879.         }
  880.         client.lastNetwork = net;
  881.     }
  882.  
  883.     if (CIRCNetwork.prototype.INITIAL_NICK == client.defaultNick)
  884.         CIRCNetwork.prototype.INITIAL_NICK =
  885.             prompt ("Please select a nickname", client.defaultNick);
  886.     
  887.     net.connect(pass);
  888.     net.display ("Connecting...", "INFO");
  889.     setCurrentObject(net);
  890.     return true;
  891.     
  892. }
  893.     
  894. client.onInputMe =
  895. function cli_ime (e)
  896. {
  897.     if (!e.channel)
  898.     {
  899.         client.currentObject.display ("Me can only be used from channels.",
  900.                                       "ERROR");
  901.         return false;
  902.     }
  903.  
  904.     e.inputData = filterOutput (e.inputData, "ACTION", "!ME");
  905.     e.channel.act (e.inputData);
  906.     
  907.     return true;
  908. }
  909.  
  910. client.onInputMsg =
  911. function cli_imsg (e)
  912. {
  913.  
  914.     if (!e.network || !e.network.isConnected())
  915.     {
  916.         client.currentObject.display ("You must be connected to a network " +
  917.                                       "to use msg", "ERROR");
  918.         return false;
  919.     }
  920.  
  921.     var ary = e.inputData.match (/(\S+)\s+(.*)/);
  922.     if (ary == null)
  923.         return false;
  924.  
  925.     var usr = e.network.primServ.addUser(ary[1].toLowerCase());
  926.  
  927.     if (!usr.messages)
  928.         usr.display ("Chat with " + usr.nick + " opened.", "INFO");
  929.     setCurrentObject (usr);
  930.     var msg = filterOutput(ary[2], "PRIVMSG", "!ME");
  931.     usr.say (ary[2]);
  932.  
  933.     return true;
  934.  
  935. }
  936.  
  937. client.onInputNick =
  938. function cli_inick (e)
  939. {
  940.  
  941.     if (!e.inputData)
  942.         return false;
  943.     
  944.     if (e.server) 
  945.         e.server.sendData ('NICK ' + e.inputData + '\n');
  946.     else
  947.         CIRCNetwork.prototype.INITIAL_NICK = e.inputData;
  948.     
  949.     return true;
  950.     
  951.     
  952. }
  953.  
  954. client.onInputName =
  955. function cli_iname (e)
  956. {
  957.  
  958.     if (!e.inputData)
  959.         return false;
  960.     
  961.     CIRCNetwork.prototype.INITIAL_NAME = e.inputData;
  962.  
  963.     return true;
  964.     
  965. }
  966.  
  967. client.onInputDesc =
  968. function cli_idesc (e)
  969. {
  970.  
  971.     if (!e.inputData)
  972.         return false;
  973.     
  974.     CIRCNetwork.prototype.INITIAL_DESC = e.inputData;
  975.     
  976.     return true;
  977.     
  978. }
  979.  
  980. client.onInputQuote =
  981. function cli_iquote (e)
  982. {
  983.     if (!e.network || !e.network.isConnected())
  984.     {
  985.         client.currentObject.display ("You must be connected to a network " +
  986.                                       "to use quote.", "ERROR");
  987.         return false;
  988.     }
  989.  
  990.     e.server.sendData (e.inputData + "\n");
  991.     
  992.     return true;
  993.     
  994. }
  995.  
  996. client.onInputEval =
  997. function cli_ieval (e)
  998. {
  999.     if (!e.inputData)
  1000.         return false;
  1001.     
  1002.     if (e.inputData.indexOf ("\n") != -1)
  1003.         e.inputData = "\n" + e.inputData + "\n";
  1004.     
  1005.     try
  1006.     {
  1007.         client.currentObject.doEval = function (s) { return eval(s); }
  1008.         
  1009.         rv = String(client.currentObject.doEval (e.inputData));
  1010.         if (rv.indexOf ("\n") == -1)
  1011.             client.currentObject.display ("{" + e.inputData + "} " + rv,
  1012.                                           "EVAL");
  1013.         else
  1014.             client.currentObject.display ("{" + e.inputData + "}\n" + rv,
  1015.                                           "EVAL");
  1016.     }
  1017.     catch (ex)
  1018.     {
  1019.         client.currentObject.display (String(ex), "ERROR");
  1020.     }
  1021.     
  1022.     return true;
  1023.     
  1024. }
  1025.  
  1026. client.onInputCTCP =
  1027. function cli_ictcp (e)
  1028. {
  1029.     if (!e.inputData)
  1030.         return false;
  1031.  
  1032.     if (!e.server)
  1033.     {
  1034.         client.currentObject.display ("You must be connected to a server to " +
  1035.                                       "use CTCP.", "ERROR");
  1036.         return false;
  1037.     }
  1038.  
  1039.     var ary = e.inputData.match(/^(\S+) (\S+)$/);
  1040.     if (ary == null)
  1041.         return false;
  1042.     
  1043.     e.server.ctcpTo (ary[1], ary[2]);
  1044.     
  1045.     return true;
  1046.     
  1047. }
  1048.  
  1049.  
  1050. client.onInputJoin =
  1051. function cli_ijoin (e)
  1052. {
  1053.     if (!e.network || !e.network.isConnected())
  1054.     {
  1055.         if (!e.network)
  1056.             client.currentObject.display ("No network selected.", "ERROR");
  1057.         else
  1058.             client.currentObject.display ("Network '" + e.network.name +
  1059.                                           " is not connected.", "ERROR");        
  1060.         return false;
  1061.     }
  1062.     
  1063.     var ary = e.inputData.match(/(\S+) ?(\S+)?/);
  1064.     if (!ary)
  1065.         return false;
  1066.     
  1067.     var name = ary[1];
  1068.     var key = (ary[2]) ? ary[2] : "";
  1069.  
  1070.     if ((name[0] != "#") && (name[0] != "&") && (name[0] != "+"))
  1071.         name = "#" + name;
  1072.  
  1073.     e.channel = e.server.addChannel (name);
  1074.     e.channel.join(key);
  1075.     e.channel.display ("Joining...", "INFO");
  1076.     setCurrentObject(e.channel);
  1077.     
  1078.     return true;
  1079.     
  1080. }
  1081.  
  1082. client.onInputLeave =
  1083. function cli_ipart (e)
  1084. {
  1085.     if (!e.channel)
  1086.     {            
  1087.         client.currentObject.display ("Leave can only be used from channels.",
  1088.                                       "ERROR");
  1089.         return false;
  1090.     }
  1091.  
  1092.     e.channel.part();
  1093.  
  1094.     return true;
  1095.     
  1096. }
  1097.  
  1098. client.onInputZoom =
  1099. function cli_izoom (e)
  1100. {
  1101.     client.currentObject.display ("**WARNING** Zoom is busted at this time :(",
  1102.                                   "WARNING");
  1103.  
  1104.     if (!e.inputData)
  1105.         return false;
  1106.     
  1107.     if (!e.channel)
  1108.     {
  1109.         client.currentObject.display ("Zoom can only be used from channels.",
  1110.                                      "ERROR");
  1111.         return false;
  1112.     }
  1113.     
  1114.     var cuser = e.channel.getUser(e.inputData);
  1115.     
  1116.     if (!cuser)
  1117.     {
  1118.         client.currentObject.display ("User '" + e.inputData + "' not found.",
  1119.                                       "ERROR");
  1120.         return false;
  1121.     }
  1122.     
  1123.     setCurrentObject(cuser);
  1124.  
  1125.     return true;
  1126.     
  1127. }    
  1128.  
  1129. /**
  1130.  * Performs a whois on a user.
  1131.  */
  1132. client.onInputWhoIs = 
  1133. function cli_whois (e) 
  1134. {
  1135.     if (!e.network || !e.network.isConnected())
  1136.     {
  1137.         client.currentObject.display ("You must be connected to a network " +
  1138.                                       "to use whois", "ERROR");
  1139.         return false;
  1140.     }
  1141.  
  1142.     if (!e.inputData)
  1143.     {
  1144.         var nicksAry = e.channel.getSelectedUsers();
  1145.  
  1146.         if (nicksAry)
  1147.         {
  1148.             dd ("Sending [" + nicksAry.length + "] nicks the whois call\n");
  1149.             mapObjFunc(nicksAry, "whois", null);
  1150.             return true;
  1151.         }
  1152.         else
  1153.         {
  1154.             return false;
  1155.         }
  1156.     }
  1157.     // Otherwise, there is no guarantee that the username
  1158.     // is currently a user
  1159.     var nick = e.inputData.match( /\S+/ );
  1160.  
  1161.     e.server.whois (nick);
  1162.     
  1163.     return true;
  1164. }
  1165.  
  1166. client.onInputTopic =
  1167. function cli_itopic (e)
  1168. {
  1169.     if (!e.channel)
  1170.     {
  1171.         client.currentObject.display ("Topic can only be used from channels.",
  1172.                                       "ERROR");
  1173.         return false;
  1174.     }
  1175.     
  1176.     if (!e.inputData)
  1177.     {
  1178.         if (e.channel.topic)
  1179.         {
  1180.             client.currentObject.display ("Topic: " + e.channel.topic,
  1181.                                           "TOPIC");
  1182.             client.currentObject.display ("Set by " + e.channel.topicBy +
  1183.                                           " on " + e.channel.topicDate + ".",
  1184.                                           "TOPIC");
  1185.         }
  1186.         else
  1187.             client.currentObject.display ("No topic.", "TOPIC");
  1188.     }
  1189.     else
  1190.     {
  1191.         if (!e.channel.setTopic(e.inputData))
  1192.             client.currentObject.display ("Could not set topic.", "ERROR");
  1193.     }
  1194.  
  1195.     return true;
  1196.     
  1197. }
  1198.  
  1199. client.onInputAway =
  1200. function cli_iaway (e)
  1201.     if (!e.network || !e.network.isConnected())
  1202.     {
  1203.         client.currentObject.display ("You must be connected to a network " +
  1204.                                       "to use away.", "ERROR");
  1205.         return false;
  1206.     }
  1207.     else if (!e.inputData) 
  1208.     {
  1209.         e.server.sendData ("AWAY\n");
  1210.     }
  1211.     else
  1212.     {
  1213.         e.server.sendData ("AWAY " + e.inputData + "\n");
  1214.     }
  1215.  
  1216.     return true;
  1217. }    
  1218.  
  1219. /**
  1220.  * Removes operator status from a user.
  1221.  */
  1222. client.onInputDeop = 
  1223. function cli_ideop (e) 
  1224. {
  1225.     /* NOTE: See the next function for a well commented explanation
  1226.        of the general form of these Multiple-Target type functions */
  1227.  
  1228.     if (!e.channel)
  1229.     {
  1230.         client.currentObject.display ("You must be on a channel to use " +
  1231.                                       "to use deop.", "ERROR");
  1232.         return false;
  1233.     }    
  1234.     
  1235.     if (!e.inputData)
  1236.     {
  1237.         var nicksAry = e.channel.getSelectedUsers();
  1238.  
  1239.  
  1240.         if (nicksAry)
  1241.         {
  1242.             mapObjFunc(nicksAry, "setOp", false);
  1243.             return true;
  1244.         }
  1245.         else
  1246.         {
  1247.             return false;
  1248.         }
  1249.     }
  1250.  
  1251.     var cuser = e.channel.getUser(e.inputData);
  1252.     
  1253.     if (!cuser)
  1254.     {
  1255.         /* use e.inputData so the case is retained */
  1256.         client.currentObject.display ("User '" + e.inputData + "' not found.",
  1257.                                       "ERROR");
  1258.         return false;
  1259.     }
  1260.     
  1261.     cuser.setOp(false);
  1262.  
  1263.     return true;
  1264. }
  1265.  
  1266.  
  1267. /**
  1268.  * Gives operator status to a channel user.
  1269.  */
  1270. client.onInputOp = 
  1271. function cli_iop (e) 
  1272. {
  1273.     if (!e.channel)
  1274.     {
  1275.         client.currentObject.display ("You must be connected to a network " +
  1276.                                       "to use op.", "ERROR");
  1277.         return false;
  1278.     }
  1279.     
  1280.     
  1281.     if (!e.inputData)
  1282.     {
  1283.         /* Since no param is passed, check for selection */
  1284.         var nicksAry = e.channel.getSelectedUsers();
  1285.  
  1286.         /* If a valid array of user objects, then call the mapObjFunc */
  1287.         if (nicksAry)
  1288.         {
  1289.             /* See test3-utils.js: this simply
  1290.                applies the setOp function to every item
  1291.                in nicksAry with the parameter of "true" 
  1292.                each time 
  1293.             */
  1294.             mapObjFunc(nicksAry, "setOp", true);
  1295.             return true;
  1296.         }
  1297.         else
  1298.         {
  1299.             /* If no input and no selection, return false
  1300.                to display the usage */
  1301.             return false;
  1302.         }
  1303.     }
  1304.  
  1305.     /* We do have inputData, so use that, rather than any
  1306.        other option */
  1307.  
  1308.     var cuser = e.channel.getUser(e.inputData);
  1309.     
  1310.     if (!cuser)
  1311.     {
  1312.         client.currentObject.display ("User '" + e.inputData + "' not found.",
  1313.                                       "ERROR");
  1314.         return false;
  1315.     }
  1316.     
  1317.     cuser.setOp(true);
  1318.  
  1319.     return true;   
  1320.     
  1321. }
  1322.  
  1323. /**
  1324.  * Gives voice status to a user.
  1325.  */
  1326. client.onInputVoice = 
  1327. function cli_ivoice (e) 
  1328. {
  1329.     if (!e.channel)
  1330.     {
  1331.         client.currentObject.display ("You must be on a channel " +
  1332.                                       "to use voice.", "ERROR");
  1333.         return false;
  1334.     }    
  1335.     
  1336.     if (!e.inputData)
  1337.     {
  1338.         var nicksAry = e.channel.getSelectedUsers();
  1339.  
  1340.         if (nicksAry)
  1341.         {
  1342.             mapObjFunc(nicksAry, "setVoice", true);
  1343.             return true;
  1344.         }
  1345.         else
  1346.         {
  1347.             return false;
  1348.         }
  1349.     }
  1350.  
  1351.     var cuser = e.channel.getUser(e.inputData);
  1352.     
  1353.     if (!cuser)
  1354.     {
  1355.         client.currentObject.display ("User '" + e.inputData + "' not found.",
  1356.                                       "ERROR");
  1357.         return false;
  1358.     }
  1359.     
  1360.     cuser.setVoice(true);
  1361.  
  1362.     return true;
  1363. }
  1364.  
  1365. /**
  1366.  * Removes voice status from a user.
  1367.  */
  1368. client.onInputDevoice = 
  1369. function cli_devoice (e) 
  1370. {
  1371.     if (!e.channel)
  1372.     {
  1373.         client.currentObject.display ("You must be on a channel " +
  1374.                                       "to use devoice.", "ERROR");
  1375.         return false;
  1376.     }    
  1377.     
  1378.     if (!e.inputData)
  1379.     {
  1380.         var nicksAry = e.channel.getSelectedUsers();
  1381.  
  1382.         if (nicksAry)
  1383.         {
  1384.             mapObjFunc(nicksAry, "setVoice", false);
  1385.             return true;
  1386.         }
  1387.         else
  1388.         {
  1389.             return false;
  1390.         }
  1391.     }
  1392.     
  1393.     var cuser = e.channel.getUser(e.inputData);
  1394.     
  1395.     if (!cuser)
  1396.     {
  1397.         client.currentObject.display ("User '" + e.inputData + "' not found.",
  1398.                                       "ERROR");
  1399.         return false;
  1400.     }
  1401.     
  1402.     cuser.setVoice(false);
  1403.  
  1404.     return true;
  1405. }
  1406.  
  1407. /**
  1408.  * Displays input to the current view, but doesn't send it to the server.
  1409.  */
  1410. client.onInputEcho =
  1411. function cli_iecho (e)
  1412. {
  1413.     if (!e.inputData)
  1414.     {
  1415.         return false;
  1416.     }
  1417.     else 
  1418.     {
  1419.         client.currentObject.display (e.inputData, "ECHO");
  1420.         
  1421.         return true;
  1422.     }
  1423. }
  1424.  
  1425. client.onInputInvite =
  1426. function cli_iinvite (e) 
  1427. {
  1428.  
  1429.     if (!e.network || !e.network.isConnected())
  1430.     {
  1431.         client.currentObject.display ("You must be connected to a network " +
  1432.                                       "to use invite.", "ERROR");
  1433.         return false;
  1434.     }     
  1435.     else if (!e.channel)
  1436.     {
  1437.         client.currentObject.display 
  1438.         ("You must be in a channel to use invite", "ERROR");
  1439.         return false;
  1440.     }    
  1441.     
  1442.     if (!e.inputData) {
  1443.         return false;
  1444.     }
  1445.     else 
  1446.     {
  1447.         var ary = e.inputData.split( /\s+/ );
  1448.         
  1449.         if (ary.length == 1)
  1450.         {
  1451.             e.channel.invite (ary[0]);
  1452.         }
  1453.         else
  1454.         {
  1455.             var chan = e.server.channels[ary[1].toLowerCase()];
  1456.  
  1457.             if (chan == undefined) 
  1458.             {
  1459.                 client.currentObject.display ("You must be on " + ary[1] + 
  1460.                                               " to use invite.", "ERROR");
  1461.                 return false;
  1462.             }            
  1463.  
  1464.             chan.invite (ary[0]);
  1465.         }   
  1466.         
  1467.         return true;
  1468.     }
  1469. }
  1470.  
  1471.  
  1472. client.onInputKick =
  1473. function cli_ikick (e) 
  1474. {
  1475.     if (!e.channel)
  1476.     {
  1477.         client.currentObject.display ("You must be on a channel to use " +
  1478.                                       "kick.", "ERROR");
  1479.         return false;
  1480.     }    
  1481.     
  1482.     if (!e.inputData)
  1483.     {
  1484.         var nicksAry = e.channel.getSelectedUsers();
  1485.  
  1486.         if (nicksAry)
  1487.         {
  1488.             mapObjFunc(nicksAry, "kick", "");
  1489.             return true;
  1490.         }
  1491.         else
  1492.         {
  1493.             return false;
  1494.         }
  1495.     }
  1496.  
  1497.     var ary = e.inputData.match ( /(\S+)? ?(.*)/ );
  1498.  
  1499.     var cuser = e.channel.getUser(ary[1]);
  1500.     
  1501.     if (!cuser)
  1502.     {    
  1503.         client.currentObject.display ("User '" + e.inputData + "' not found.",
  1504.                                       "ERROR");
  1505.         return false;
  1506.     }
  1507.  
  1508.     if (ary.length > 2)
  1509.     {               
  1510.         cuser.kick(ary[2]);
  1511.     }
  1512.     else     
  1513.  
  1514.     cuser.kick();    
  1515.             
  1516.     return true;
  1517. }
  1518.  
  1519. client.onInputStalk =
  1520. function cli_istalk ( e )
  1521. {
  1522.     if (!e.inputData)
  1523.     {
  1524.         if ( client.stalkingVictims.length == 0 ) {
  1525.             client.currentObject.display( "No stalking victims.", "STALK" );
  1526.         } else {
  1527.             client.currentObject.display( "Currently stalking [" +
  1528.                                       client.stalkingVictims.join(", ") + "]",
  1529.                                       "STALK");
  1530.         }
  1531.         return true;
  1532.     }
  1533.     client.stalkingVictims[client.stalkingVictims.length] = e.inputData;
  1534.     client.currentObject.display( "Now stalking " + e.inputData, "STALK"
  1535. );
  1536.     return true;
  1537. }
  1538.  
  1539. client.onInputUnstalk =
  1540. function cli_iunstalk ( e )
  1541. {
  1542.     if ( !e.inputData )
  1543.         return false;
  1544.  
  1545.     for ( i in client.stalkingVictims ) {
  1546.         if ( client.stalkingVictims[i].match( "^" + e.inputData +"$", "i" ) ) {
  1547.             client.stalkingVictims.splice(i,1);
  1548.             client.currentObject.display( "No longer stalking " +
  1549.                 e.inputData, "UNSTALK" );
  1550.             return true;
  1551.         }
  1552.     }
  1553.  
  1554.     client.currentObject.display( "Not stalking " + e.inputData,
  1555.         "UNSTALK" );
  1556.     return true;
  1557. }
  1558.  
  1559. /* 'private' function, should only be used from inside */
  1560. CIRCChannel.prototype._addUserToGraph =
  1561. function my_addtograph (user)
  1562. {
  1563.     if (!user.TYPE)
  1564.         dd (getStackTrace());
  1565.     
  1566.     client.rdf.Assert (this.getGraphResource(), client.rdf.resChanUser,
  1567.                        user.getGraphResource(), true);
  1568.     
  1569. }
  1570.  
  1571. /* 'private' function, should only be used from inside */
  1572. CIRCChannel.prototype._removeUserFromGraph =
  1573. function my_remfgraph (user)
  1574. {
  1575.  
  1576.     client.rdf.Unassert (this.getGraphResource(), client.rdf.resChanUser,
  1577.                          user.getGraphResource());
  1578.     
  1579. }
  1580.  
  1581. CIRCNetwork.prototype.onNotice = 
  1582. CIRCNetwork.prototype.on001 = /* Welcome! */
  1583. CIRCNetwork.prototype.on002 = /* your host is */
  1584. CIRCNetwork.prototype.on003 = /* server born-on date */
  1585. CIRCNetwork.prototype.on004 = /* server id */
  1586. CIRCNetwork.prototype.on251 = /* users */
  1587. CIRCNetwork.prototype.on252 = /* opers online (in params[2]) */
  1588. CIRCNetwork.prototype.on254 = /* channels found (in params[2]) */
  1589. CIRCNetwork.prototype.on255 = /* link info */
  1590. CIRCNetwork.prototype.on265 = /* local user details */
  1591. CIRCNetwork.prototype.on266 = /* global user details */
  1592. CIRCNetwork.prototype.on375 = /* start of MOTD */
  1593. CIRCNetwork.prototype.on372 = /* MOTD line */
  1594. CIRCNetwork.prototype.on376 = /* end of MOTD */
  1595. function my_showtonet (e)
  1596. {
  1597.     var p = (e.params[2]) ? e.params[2] + " " : "";
  1598.     var str = "";
  1599.  
  1600.     switch (e.code)
  1601.     {
  1602.         case "004":
  1603.             str = e.params.slice(1).join (" ");
  1604.             break;
  1605.  
  1606.         case "001":
  1607.             updateTitle(this);
  1608.             updateNetwork (this);
  1609.             if (this.pendingURLs)
  1610.             {
  1611.                 var url = this.pendingURLs.pop();
  1612.                 while (url)
  1613.                 {
  1614.                     gotoIRCURL(url);
  1615.                     url = this.pendingURLs.pop();
  1616.                 }
  1617.                 delete this.pendingURLs;
  1618.             }
  1619.             str = e.meat;
  1620.             break;
  1621.             
  1622.         case "372":
  1623.         case "375":
  1624.         case "376":
  1625.             if (this.IGNORE_MOTD)
  1626.                 return;
  1627.             /* no break */
  1628.  
  1629.         default:
  1630.             str = e.meat;
  1631.             break;
  1632.     }
  1633.  
  1634.     this.display (p + str, e.code.toUpperCase());
  1635.     
  1636. }
  1637.  
  1638. CIRCNetwork.prototype.on311 = /* whois name */
  1639. CIRCNetwork.prototype.on319 = /* whois channels */
  1640. CIRCNetwork.prototype.on312 = /* whois server */
  1641. CIRCNetwork.prototype.on317 = /* whois idle time */
  1642. CIRCNetwork.prototype.on318 = /* whois end of whois*/
  1643. function my_whoisreply (e)
  1644. {
  1645.     var text = "egads!";
  1646.     
  1647.     switch (Number(e.code))
  1648.     {
  1649.         case 311:
  1650.             text = e.params[2] + " (" + e.params[3] + "@" + e.params[4] +
  1651.                 ") is " + e.meat;
  1652.             break;
  1653.             
  1654.         case 319:
  1655.             text = e.params[2] + " is a member of " + e.meat;
  1656.             break;
  1657.             
  1658.         case 312:
  1659.             text = e.params[2] + " is attached to " + e.params[3]
  1660.             break;
  1661.             
  1662.         case 317:
  1663.             text = e.params[2] + " has been idle for " + e.params[3] +
  1664.                 " seconds (on since " + new Date(Number(e.params[4]) * 1000) +
  1665.                 ")";
  1666.             break;
  1667.             
  1668.         case 318:
  1669.             text = "End of whois information for " + e.params[2];
  1670.             break;
  1671.             
  1672.     }
  1673.  
  1674.     e.server.parent.display(text, e.code);
  1675.     
  1676. }
  1677.  
  1678. CIRCNetwork.prototype.on433 = /* nickname in use */
  1679. function my_433 (e)
  1680. {
  1681.  
  1682.     e.server.parent.display ("The nickname '" + e.params[2] +
  1683.                              "' is already in use.", e.code);
  1684.     
  1685. }
  1686.  
  1687. CIRCNetwork.prototype.onError =
  1688. function my_neterror (e)
  1689. {
  1690.  
  1691.     e.server.parent.display (e.meat, "ERROR");
  1692.     
  1693. }
  1694.  
  1695. CIRCNetwork.prototype.onPing =
  1696. function my_netping (e)
  1697. {
  1698.  
  1699.     updateNetwork (e.network);
  1700.     
  1701. }
  1702.  
  1703. CIRCNetwork.prototype.onPong =
  1704. function my_netpong (e)
  1705. {
  1706.  
  1707.     updateNetwork (e.network);
  1708.     
  1709. }
  1710.  
  1711. CIRCChannel.prototype.onPrivmsg =
  1712. function my_cprivmsg (e)
  1713. {
  1714.     
  1715.     e.user.display (e.meat, "PRIVMSG");
  1716.     
  1717.     if (e.meat.indexOf (client.prefix) == 0)
  1718.     {
  1719.         try
  1720.         {
  1721.             var v = eval(e.meat.substring (client.prefix.length,
  1722.                                            e.meat.length));
  1723.         }
  1724.         catch (ex)
  1725.         {
  1726.             this.say (e.user.nick + ": " + String(ex));
  1727.             return false;
  1728.         }
  1729.         
  1730.         if (typeof (v) != "undefined")
  1731.         {                        
  1732.             if (v != null)                
  1733.                 v = String(v);
  1734.             else
  1735.                 v = "null";
  1736.             
  1737.             var rsp = e.user.nick + ", your result is,";
  1738.             
  1739.             if (v.indexOf ("\n") != -1)
  1740.                 rsp += "\n";
  1741.             else
  1742.                 rsp += " ";
  1743.             
  1744.             this.say (rsp + v);
  1745.         }
  1746.     }
  1747.  
  1748.     return true;
  1749.     
  1750. }
  1751.  
  1752. /* end of names */
  1753. CIRCChannel.prototype.on366 =
  1754. function my_366 (e)
  1755. {
  1756.  
  1757.     if (client.currentObject == this)    
  1758.         /* hide the tree while we add (possibly tons) of nodes */
  1759.         client.rdf.setTreeRoot("user-list", client.rdf.resNullChan);
  1760.     
  1761.     client.rdf.clearTargets(this.getGraphResource(), client.rdf.resChanUser);
  1762.  
  1763.     for (var u in this.users)
  1764.     {
  1765.         this.users[u].updateGraphResource();
  1766.         this._addUserToGraph (this.users[u]);
  1767.     }
  1768.  
  1769.     
  1770.     if (client.currentObject == this)
  1771.         /* redisplay the tree */
  1772.         client.rdf.setTreeRoot("user-list", this.getGraphResource());
  1773.     
  1774. }    
  1775.  
  1776. CIRCChannel.prototype.onTopic = /* user changed topic */
  1777. CIRCChannel.prototype.on332 = /* TOPIC reply */
  1778. function my_topic (e)
  1779. {
  1780.  
  1781.     if (e.code == "TOPIC")
  1782.         e.channel.display (e.channel.topicBy + " has changed the topic to '" +
  1783.                            e.channel.topic + "'", "TOPIC");
  1784.     
  1785.     updateChannel (e.channel);
  1786.     updateTitle (e.channel);
  1787.     
  1788. }
  1789.  
  1790.  
  1791. CIRCChannel.prototype.onNotice =
  1792. function my_notice (e)
  1793. {
  1794.  
  1795.     e.user.display (e.meat, "NOTICE", e.user.nick);
  1796.     
  1797. }
  1798.  
  1799. CIRCChannel.prototype.onCTCPAction =
  1800. function my_caction (e)
  1801. {
  1802.  
  1803.     e.user.display (e.CTCPData, "ACTION");
  1804.  
  1805. }
  1806.  
  1807. CIRCChannel.prototype.onUnknownCTCP =
  1808. function my_unkctcp (e)
  1809. {
  1810.  
  1811.     this.display ("Unknown CTCP " + e.CTCPCode + "(" + e.CTCPData +
  1812.                   ") from " + e.user.properNick, "BAD-CTCP");
  1813.     
  1814. }   
  1815.  
  1816. CIRCChannel.prototype.onJoin =
  1817. function my_cjoin (e)
  1818. {
  1819.  
  1820.     if (userIsMe (e.user))
  1821.     {
  1822.         this.display ("YOU have joined " + e.channel.name, "JOIN", "!ME");
  1823.         setCurrentObject(this);
  1824.     }
  1825.     else
  1826.         this.display(e.user.properNick + " (" + e.user.name + " @ " +
  1827.                      hyphenateWord(e.user.host, client.MAX_WORD_DISPLAY) +
  1828.                      ") has joined " + e.channel.name, "JOIN", e.user.nick);
  1829.  
  1830.     this._addUserToGraph (e.user);
  1831.     
  1832.     updateChannel (e.channel);
  1833.     
  1834. }
  1835.  
  1836. CIRCChannel.prototype.onPart =
  1837. function my_cpart (e)
  1838. {
  1839.  
  1840.     this._removeUserFromGraph(e.user);
  1841.  
  1842.     if (userIsMe (e.user))
  1843.     {
  1844.         this.display ("YOU have left " + e.channel.name, "PART", "!ME");
  1845.         if (client.currentObject == this)    
  1846.             /* hide the tree while we remove (possibly tons) of nodes */
  1847.             client.rdf.setTreeRoot("user-list", client.rdf.resNullChan);
  1848.         
  1849.         client.rdf.clearTargets(this.getGraphResource(),
  1850.                                 client.rdf.resChanUser, true);
  1851.  
  1852.         if (client.currentObject == this)
  1853.             /* redisplay the tree */
  1854.             client.rdf.setTreeRoot("user-list", this.getGraphResource());
  1855.     }
  1856.     else
  1857.         this.display (e.user.properNick + " has left " + e.channel.name,
  1858.                       "PART");
  1859.  
  1860.  
  1861.     updateChannel (e.channel);
  1862.     
  1863. }
  1864.  
  1865. CIRCChannel.prototype.onKick =
  1866. function my_ckick (e)
  1867. {
  1868.  
  1869.     if (userIsMe (e.lamer))
  1870.         this.display ("YOU have been booted from " + e.channel.name +
  1871.                       " by " + e.user.properNick + " (" + e.reason + ")",
  1872.                       "KICK", e.user.nick);
  1873.     else
  1874.     {
  1875.         var enforcerProper, enforcerNick;
  1876.         if (userIsMe (e.user))
  1877.         {
  1878.             enforcerProper = "YOU";
  1879.             enforcerNick = "!ME";
  1880.         }
  1881.         else
  1882.         {
  1883.             enforcerProper = e.user.properNick;
  1884.             enforcerNick = e.user.nick;
  1885.         }
  1886.         
  1887.         this.display (e.lamer.properNick + " was booted from " +
  1888.                       e.channel.name + " by " + enforcerProper + " (" +
  1889.                       e.reason + ")", "KICK", enforcerNick);
  1890.     }
  1891.     
  1892.     this._removeUserFromGraph(e.lamer);
  1893.  
  1894.     updateChannel (e.channel);
  1895.     
  1896. }
  1897.  
  1898. CIRCChannel.prototype.onChanMode =
  1899. function my_cmode (e)
  1900. {
  1901.  
  1902.     if (e.user)
  1903.         this.display ("Mode " + e.params.slice(1).join(" ") + " by " +
  1904.                       e.user.nick, "MODE");
  1905.  
  1906.     for (var u in e.usersAffected)
  1907.         e.usersAffected[u].updateGraphResource();
  1908.  
  1909.     updateChannel (e.channel);
  1910.     updateTitle (e.channel);
  1911.     
  1912. }
  1913.  
  1914.     
  1915.  
  1916. CIRCChannel.prototype.onNick =
  1917. function my_cnick (e)
  1918. {
  1919.  
  1920.     if (userIsMe (e.user))
  1921.     {
  1922.         this.display ("YOU are now known as " + e.user.properNick, "NICK",
  1923.                       "!ME");
  1924.         updateNetwork();
  1925.     }
  1926.     else
  1927.         this.display (e.oldNick + " is now known as " + e.user.properNick,
  1928.                       "NICK");
  1929.  
  1930.     /*
  1931.       dd ("updating resource " + e.user.getGraphResource().Value +
  1932.         " to new nickname " + e.user.properNick);
  1933.     */
  1934.  
  1935.     e.user.updateGraphResource();
  1936.     
  1937. }
  1938.  
  1939.  
  1940. CIRCChannel.prototype.onQuit =
  1941. function my_cquit (e)
  1942. {
  1943.  
  1944.     if (userIsMe(e.user)) /* I dont think this can happen */
  1945.         this.display ("YOU have left " + e.server.parent.name +
  1946.                       " (" + e.reason + ")", "QUIT", "!ME");
  1947.     else
  1948.         this.display (e.user.properNick + " has left " + e.server.parent.name +
  1949.                       " (" + e.reason + ")", "QUIT");
  1950.  
  1951.     this._removeUserFromGraph(e.user);
  1952.  
  1953.     updateChannel (e.channel);
  1954.     
  1955. }
  1956.  
  1957. CIRCUser.prototype.onPrivmsg =
  1958. function my_cprivmsg (e)
  1959. {
  1960.     
  1961.     this.display (e.meat, "PRIVMSG");
  1962.     
  1963. }
  1964.  
  1965. CIRCUser.prototype.onNick =
  1966. function my_unick (e)
  1967. {
  1968.  
  1969.     if (userIsMe(e.user))
  1970.     {
  1971.         updateNetwork();
  1972.         updateTitle (e.channel);
  1973.     }
  1974.     
  1975. }
  1976.  
  1977. CIRCUser.prototype.onNotice =
  1978. function my_notice (e)
  1979. {
  1980.  
  1981.     this.display (e.meat, "NOTICE");
  1982.     
  1983. }
  1984.  
  1985. CIRCUser.prototype.onUnknownCTCP =
  1986. function my_unkctcp (e)
  1987. {
  1988.  
  1989.     this.parent.parent.display ("Unknown CTCP " + e.CTCPCode + "(" +
  1990.                                 e.CTCPData + ") from " + e.user.properNick,
  1991.                                 "BAD-CTCP");
  1992.     
  1993. }
  1994.