2
* The contents of this file are subject to the Mozilla Public
3
* License Version 1.1 (the "License"); you may not use this file
4
* except in compliance with the License. You may obtain a copy of
5
* the License at http://www.mozilla.org/MPL/
7
* Software distributed under the License is distributed on an "AS
8
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9
* implied. See the License for the specific language governing
10
* rights and limitations under the License.
12
* The Original Code is JSIRC Test Client #1
14
* The Initial Developer of the Original Code is New Dimensions Consulting,
15
* Inc. Portions created by New Dimensions Consulting, Inc. are
16
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
20
* Robert Ginda, rginda@ndcico.com, original author
23
var client = new Object();
25
client.COMMAND_CHAR = "/";
26
client.STEP_TIMEOUT = 500;
27
client.UPDATE_DELAY = 500;
29
client.INITIAL_ALIASES =
31
{name: "connect", value: "e.network.connect();"},
33
value: "client.quit(e.inputData ? e.inputData : 'no reason');"},
35
value: "if (e.server && e.inputData) " +
36
"e.server.sendData ('NICK ' + e.inputData + '\\n');"},
37
{name: "network", value: "setCurrentNetwork(e.inputData); onListChannels();"},
38
{name: "channel", value: "setCurrentChannel(e.inputData); onListUsers();"},
39
{name: "me", value: "if (e.channel) e.channel.act (e.inputData);"}
43
client.addAlias = function cli_addalias (name, value)
45
var funcName = "onInput" + name[0].toUpperCase() +
46
name.substr (1, name.length).toLowerCase();
51
client[funcName] = eval ("f = function alias_" + name + " (e) { " +
57
display ("Error adding alias (" + name + "): " + ex);
62
client.removeAlias = function cli_remalias (name)
65
delete client[funcName];
69
client.quit = function cli_quit (reason)
72
for (var n in client.networks)
73
if (client.networks[n].primServ)
74
client.networks[n].quit (reason);
78
CIRCUser.prototype.getDecoratedNick = function usr_decoratednick()
82
if (typeof this.isOp != "undefined")
85
if (this.__proto__ == this.parent.parent.me)
87
pfx += this.isOp ? "O" : "X";
88
pfx += this.isVoice ? "V" : "X";
92
if (this == this.parent.me)
97
return pfx + this.nick;
101
CIRCNetwork.prototype.getDecoratedName = function usr_decoratedname()
105
pfx += this.isConnected() ? "online" : "offline";
108
return pfx + this.name;
112
function initStatic()
115
CIRCNetwork.prototype.INITIAL_NICK = "test1";
116
CIRCNetwork.prototype.INITIAL_NAME = "test1";
117
CIRCNetwork.prototype.INITIAL_DESC = "New Now Know How";
118
CIRCNetwork.prototype.INITIAL_CHANNEL = "";
119
CIRCServer.prototype.READ_TIMEOUT = 0;
121
var list = document.getElementById("lstQuickList");
122
list.onclick = onListClick;
127
* One time initilization stuff
132
obj.networks = new Object();
133
obj.eventPump = new CEventPump (10);
135
obj.networks["efnet"] =
136
new CIRCNetwork ("efnet", [{name: "irc.primenet.com", port: 6667},
137
{name: "irc.cs.cmu.edu", port: 6667}],
139
obj.networks["linuxnet"] =
140
new CIRCNetwork ("linuxnet", [{name: "irc.mozilla.org", port: 6667}],
142
obj.networks["hybridnet"] =
143
new CIRCNetwork ("hybridnet", [{name: "irc.ssc.net", port: 6667}],
146
obj.primNet = obj.networks["efnet"];
149
/* hook all events EXCEPT server.poll and *.event-end types
150
* (the 4th param inverts the match) */
151
obj.eventPump.addHook ([{type: "poll", set: /^(server|dcc-chat)$/},
152
{type: "event-end"}], event_tracer,
153
"event-tracer", true /* negate */);
157
function listClear (list)
160
while (list.options.length > 0)
161
list.options[0] = null;
165
function listFill (list, source, prop, callFlag /* optional */)
167
var ary = new Array();
171
for (var o in source)
173
ary.push (source[o][prop]);
175
ary.push (source[o][prop]());
179
for (var i = 0; i < ary.length; i++)
180
list.add (new Option(ary[i]), null);
184
function listGetSelectedIndex (list)
186
var sels = new Array();
188
for (o in list.options)
189
if (list.options[o].selected)
190
sels[sels.length] = o;
192
if (sels.length == 1)
199
function display (line)
201
var output = document.getElementById ("output");
203
output.value = line + "\n" + output.value;
210
client.eventPump.stepEvents();
211
setTimeout ("mainstep()", client.STEP_TIMEOUT);
216
* Hook used to trace events.
218
function event_tracer (e)
220
var name="", data="";
225
name = e.destObject.connection.host;
226
if (e.type == "rawdata")
227
data = "'" + e.data + "'";
231
name = e.destObject.name;
235
name = e.destObject.nick;
239
name = e.destObject.server + e.destObject.path;
240
if (e.destObject.state != "complete")
241
data = "state: '" + e.destObject.state + "', recieved " +
242
e.destObject.data.length;
244
dd ("document done:\n" + dumpObjectTree (this));
248
name = e.destObject.host + ":" + e.destObject.port;
249
if (e.type == "rawdata")
250
data = "'" + e.data + "'";
254
if (e.type == "do-connect")
255
data = "attempt: " + e.attempt + "/" +
256
e.destObject.MAX_CONNECT_ATTEMPTS;
264
name = "[" + name + "]";
266
str = "Level " + e.level + ": '" + e.type + "', " +
267
e.set + name + "." + e.destMethod;
269
str += "\ndata : " + data;
277
function updateList ()
280
if (!client.updateTimeout)
281
client.updateTimeout = setTimeout ("updateListNow()",
282
client.UPDATE_DELAY);
285
function updateListNow()
288
var quickList = document.getElementById("lstQuickList");
290
if (client.updateTimeout)
292
clearTimeout (client.updateTimeout);
293
delete client.updateTimeout;
296
switch (client.lastListType)
300
listFill (quickList, client.networks, "getDecoratedName",
305
listFill (quickList, client.network.primServ.users,
306
"getDecoratedNick", true);
310
listFill (quickList, client.network.primServ.channels, "name",
315
listFill (quickList, client.channel.users, "getDecoratedNick",
326
function updateStatus()
328
var status = document.getElementById ("status");
330
var netName = (client.network) ? client.network.name : "[no-network]";
331
var chanName = (client.channel) ? client.channel.name : "[no-channel]";
333
status.value = netName + " " + chanName;
337
function setCurrentNetwork (o)
339
var oldnetwork = client.network;
348
var v = client.networks[o];
354
dd ("setCurrentNetwork: typeof o (" + typeof o + ") confused me.");
358
if (client.network != oldnetwork)
360
client.channel = (void 0);
361
client.user = (void 0);
362
client.cuser = (void 0);
365
var props = document.getElementById ("txtProperties");
366
props.value = "network: " + client.network.name + "\n" +
367
dumpObjectTree (client.network, 1) +
368
"\n============\nclient object:\n" + dumpObjectTree (client, 1);
373
function setCurrentUser (o)
382
if (!client.network.primServ)
385
var v = client.network.primServ.users[o];
394
var props = document.getElementById ("txtProperties");
395
props.value = "network user: " + client.user.nick + "\n" +
396
dumpObjectTree (client.user, 1) +
397
"\n============\nclient object:\n" + dumpObjectTree (client, 1);
402
function setCurrentChannel (o)
404
var oldchannel = client.channel;
413
if (!client.network.primServ)
416
var v = client.network.primServ.channels[o];
425
if (client.channel != oldchannel)
426
client.cuser = (void 0);
428
var props = document.getElementById ("txtProperties");
429
props.value = "channel: " + client.channel.name + "\n" +
430
dumpObjectTree (client.channel, 1) +
431
"\n============\nclient object:\n" + dumpObjectTree (client, 1);
435
function setCurrentCUser (o)
447
var v = client.channel.users[o];
456
setCurrentUser (o.__proto__);
457
var props = document.getElementById ("txtProperties");
458
props.value = "channel user: " + client.cuser.nick + "\n" +
459
dumpObjectTree (client.cuser, 1) +
460
"\n============\nclient object:\n" + dumpObjectTree (client, 1);