]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/irc/ircclient.js
1 qwebirc
.irc
.IRCClient
= new Class({
2 Extends: qwebirc
.irc
.BaseIRCClient
,
7 initialize: function(options
, ui
) {
13 this.modeprefixes
= "ov";
16 this.commandparser
= new qwebirc
.irc
.CommandParser(this);
17 this.exec
= this.commandparser
.dispatch
.bind(this.commandparser
);
19 this.statusWindow
= this.ui
.newClient(this);
21 newLine: function(window
, type
, data
) {
25 var w
= this.getWindow(window
);
27 w
.addLine(type
, data
);
29 this.statusWindow
.addLine(type
, data
);
32 newChanLine: function(channel
, type
, user
, extra
) {
36 extra
["n"] = user
.hostToNick();
37 extra
["h"] = user
.hostToHost();
39 extra
["-"] = this.nickname
;
41 this.newLine(channel
, type
, extra
);
43 newServerLine: function(type
, data
) {
44 this.statusWindow
.addLine(type
, data
);
46 newActiveLine: function(type
, data
) {
47 this.ui
.getActiveWindow().addLine(type
, data
);
49 newTargetOrActiveLine: function(target
, type
, data
) {
50 if(this.getWindow(target
)) {
51 this.newLine(target
, type
, data
);
53 this.newActiveLine(type
, data
);
56 updateNickList: function(channel
) {
57 var n1
= this.tracker
.getChannel(channel
);
58 var names
= new Array();
59 var tff
= String
.fromCharCode(255);
67 if(nc
.prefixes
.length
> 0) {
68 var c
= nc
.prefixes
.charAt(0);
69 nx
= String
.fromCharCode(this.prefixes
.indexOf(c
)) + n
.toIRCLower();
72 nx
= tff
+ n
.toIRCLower();
80 var sortednames
= new Array();
81 names
.each(function(name
) {
82 sortednames
.push(nh
[name
]);
85 var w
= this.getWindow(channel
);
87 w
.updateNickList(sortednames
);
89 getWindow: function(name
) {
90 return this.windows
[name
];
92 newWindow: function(name
, type
, select
) {
93 var w
= this.getWindow(name
);
95 w
= this.windows
[name
] = this.ui
.newWindow(this, type
, name
);
97 w
.addEvent("close", function(w
) {
98 delete this.windows
[name
];
103 this.ui
.selectWindow(w
);
107 getActiveWindow: function() {
108 return this.ui
.getActiveWindow();
110 getNickname: function() {
111 return this.nickname
;
113 addPrefix: function(nickchanentry
, prefix
) {
114 var ncp
= nickchanentry
.prefixes
+ prefix
;
118 for(var i
=0;i
<this.prefixes
.length
;i
++) {
119 var pc
= this.prefixes
.charAt(i
);
120 var index
= ncp
.indexOf(pc
);
125 nickchanentry
.prefixes
= prefixes
.join("");
127 removePrefix: function(nickchanentry
, prefix
) {
128 nickchanentry
.prefixes
= nickchanentry
.prefixes
.replaceAll(prefix
, "");
131 /* from here down are events */
132 rawNumeric: function(numeric
, prefix
, params
) {
133 this.newServerLine("RAW", {"n": "numeric", "m": params
.slice(1).join(" ")});
135 signedOn: function(nickname
) {
136 this.tracker
= new qwebirc
.irc
.IRCTracker();
137 this.nickname
= nickname
;
138 this.newServerLine("SIGNON");
140 if(this.options
.autojoin
)
141 this.send("JOIN " + this.options
.autojoin
);
143 userJoined: function(user
, channel
) {
144 var nick
= user
.hostToNick();
145 var host
= user
.hostToHost();
147 if((nick
== this.nickname
) && !this.getWindow(channel
))
148 this.newWindow(channel
, qwebirc
.ui
.WINDOW_CHANNEL
, true);
149 this.tracker
.addNickToChannel(nick
, channel
);
151 if(nick
== this.nickname
) {
152 this.newChanLine(channel
, "OURJOIN", user
);
154 this.newChanLine(channel
, "JOIN", user
);
156 this.updateNickList(channel
);
158 userPart: function(user
, channel
, message
) {
159 var nick
= user
.hostToNick();
160 var host
= user
.hostToHost();
162 if(nick
== this.nickname
) {
163 this.tracker
.removeChannel(channel
);
165 this.tracker
.removeNickFromChannel(nick
, channel
);
166 this.newChanLine(channel
, "PART", user
, {"m": message
});
169 this.updateNickList(channel
);
171 if(nick
== this.nickname
) {
172 var w
= this.getWindow(channel
)
177 userKicked: function(kicker
, channel
, kickee
, message
) {
178 if(kickee
== this.nickname
) {
179 this.tracker
.removeChannel(channel
);
180 this.getWindow(channel
).close();
182 this.tracker
.removeNickFromChannel(kickee
, channel
);
183 this.updateNickList(channel
);
186 this.newChanLine(channel
, "KICK", kicker
, {"v": kickee
, "m": message
});
188 channelMode: function(user
, channel
, modes
, raw
) {
189 modes
.each(function(mo
) {
190 var direction
= mo
[0];
193 var prefixindex
= this.modeprefixes
.indexOf(mode
);
194 if(prefixindex
== -1)
198 var prefixchar
= this.prefixes
.charAt(prefixindex
);
200 var nc
= this.tracker
.getOrCreateNickOnChannel(nick
, channel
);
201 if(direction
== "-") {
202 this.removePrefix(nc
, prefixchar
);
204 this.addPrefix(nc
, prefixchar
);
208 this.newChanLine(channel
, "MODE", user
, {"m": raw
.join(" ")});
210 this.updateNickList(channel
);
212 userQuit: function(user
, message
) {
213 var nick
= user
.hostToNick();
215 var channels
= this.tracker
.getNick(nick
);
218 for(var c
in channels
) {
220 this.newChanLine(c
, "QUIT", user
, {"m": message
});
223 this.tracker
.removeNick(nick
);
225 clist
.each(function(cli
) {
226 this.updateNickList(cli
);
229 nickChanged: function(user
, newnick
) {
230 var oldnick
= user
.hostToNick();
232 if(oldnick
== this.nickname
)
233 this.nickname
= newnick
;
235 this.tracker
.renameNick(oldnick
, newnick
);
237 var channels
= this.tracker
.getNick(newnick
);
239 for(var c
in channels
) {
240 this.newChanLine(c
, "NICK", user
, {"w": newnick
});
241 /* TODO: rename queries */
242 this.updateNickList(c
);
245 this.newChanLine(undefined, "NICK", user
, {"w": newnick
});
247 channelTopic: function(user
, channel
, topic
) {
248 this.newChanLine(channel
, "TOPIC", user
, {"m": topic
});
249 this.getWindow(channel
).updateTopic(topic
);
251 initialTopic: function(channel
, topic
) {
252 this.getWindow(channel
).updateTopic(topic
);
254 channelCTCP: function(user
, channel
, type
, args
) {
255 if(args
== undefined)
258 if(type
== "ACTION") {
259 this.newChanLine(channel
, "CHANACTION", user
, {"m": args
, "c": channel
});
263 this.newChanLine(channel
, "CHANCTCP", user
, {"x": type
, "m": args
, "c": channel
});
265 userCTCP: function(user
, type
, args
) {
266 var nick
= user
.hostToNick();
267 var host
= user
.hostToHost();
268 if(args
== undefined)
271 if(type
== "ACTION") {
272 this.newWindow(nick
, qwebirc
.ui
.WINDOW_QUERY
);
273 this.newLine(nick
, "PRIVACTION", {"m": args
, "x": type
, "h": host
, "n": nick
});
277 this.newTargetOrActiveLine(nick
, "PRIVCTCP", {"m": args
, "x": type
, "h": host
, "n": nick
, "-": this.nickname
});
279 userCTCPReply: function(user
, type
, args
) {
280 var nick
= user
.hostToNick();
281 var host
= user
.hostToHost();
282 if(args
== undefined)
285 this.newTargetOrActiveLine(nick
, "CTCPREPLY", {"m": args
, "x": type
, "h": host
, "n": nick
, "-": this.nickname
});
287 channelPrivmsg: function(user
, channel
, message
) {
288 this.newChanLine(channel
, "CHANMSG", user
, {"m": message
});
290 channelNotice: function(user
, channel
, message
) {
291 this.newChanLine(channel
, "CHANNOTICE", user
, {"m": message
});
293 userPrivmsg: function(user
, message
) {
294 var nick
= user
.hostToNick();
295 var host
= user
.hostToHost();
297 this.newWindow(nick
, qwebirc
.ui
.WINDOW_QUERY
);
299 this.newLine(nick
, "PRIVMSG", {"m": message
, "h": host
, "n": nick
});
301 serverNotice: function(message
) {
302 this.newServerLine("SERVERNOTICE", {"m": message
});
304 userNotice: function(user
, message
) {
305 var nick
= user
.hostToNick();
306 var host
= user
.hostToHost();
308 this.newTargetOrActiveLine(nick
, "PRIVNOTICE", {"m": message
, "h": host
, "n": nick
});
310 userInvite: function(user
, channel
) {
311 var nick
= user
.hostToNick();
312 var host
= user
.hostToHost();
314 this.newServerLine("INVITE", {"c": channel
, "h": host
, "n": nick
});
316 userMode: function(modes
) {
317 this.newServerLine("UMODE", {"m": modes
, "n": this.nickname
});
319 channelNames: function(channel
, names
) {
320 if(names
.length
== 0) {
321 this.updateNickList(channel
);
325 names
.each(function(nick
) {
327 var splitnick
= nick
.split("");
329 splitnick
.every(function(c
, i
) {
330 if(this.prefixes
.indexOf(c
) == -1) {
331 nick
= nick
.substr(i
);
339 var nc
= this.tracker
.addNickToChannel(nick
, channel
);
340 prefixes
.each(function(p
) {
341 this.addPrefix(nc
, p
);
345 disconnected: function(message
) {
346 for(var x
in this.windows
) {
347 var w
= this.windows
[x
];
348 if(w
.type
== qwebirc
.ui
.WINDOW_CHANNEL
)
351 this.tracker
= undefined;
353 this.newServerLine("DISCONNECT", {"m": message
});
355 supported: function(key
, value
) {
356 if(key
== "PREFIX") {
357 var l
= (value
.length
- 2) / 2;
359 this.modeprefixes
= value
.substr(1, l
);
360 this.prefixes
= value
.substr(l
+ 2, l
);
363 connected: function() {
364 this.newServerLine("CONNECT");
366 serverError: function(message
) {
367 this.newServerLine("ERROR", {"m": message
});
369 quit: function(message
) {
370 this.send("QUIT :" + message
);
373 awayMessage: function(nick
, message
) {
374 this.newLine(nick
, "AWAY", {"n": nick
, "m": message
});
376 whois: function(nick
, type
, data
) {
377 var ndata
= {"n": nick
};
380 var xsend = function() {
381 this.newTargetOrActiveLine(nick
, "WHOIS" + mtype
, ndata
);
386 ndata
.h
= data
.ident
+ "@" + data
.hostname
;
389 ndata
.m
= data
.realname
;
390 } else if(type
== "server") {
392 ndata
.x
= data
.server
;
393 ndata
.m
= data
.serverdesc
;
394 } else if(type
== "oper") {
396 } else if(type
== "idle") {
398 ndata
.x
= qwebirc
.util
.longtoduration(data
.idle
);
399 ndata
.m
= qwebirc
.irc
.IRCDate(new Date(data
.connected
* 1000));
400 } else if(type
== "channels") {
402 ndata
.m
= data
.channels
;
403 } else if(type
== "account") {
405 ndata
.m
= data
.account
;
406 } else if(type
== "away") {
409 } else if(type
== "opername") {
411 ndata
.m
= data
.opername
;
412 } else if(type
== "actually") {
414 ndata
.m
= data
.hostname
;
416 } else if(type
== "end") {