]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/irc/ircclient.js
e0e78b299361451da0e648141eb8dcfda103feed
1 var IRCClient
= new Class({
2 Extends: BaseIRCClient
,
7 initialize: function(options
, ui
) {
13 this.modeprefixes
= "ov";
16 this.commandparser
= new 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 updateNickList: function(channel
) {
50 var n1
= this.tracker
.getChannel(channel
);
51 var names
= new Array();
52 var tff
= String
.fromCharCode(255);
60 if(nc
.prefixes
.length
> 0) {
61 var c
= nc
.prefixes
.charAt(0);
62 nx
= String
.fromCharCode(this.prefixes
.indexOf(c
)) + n
.toIRCLower();
65 nx
= tff
+ n
.toIRCLower();
73 var sortednames
= new Array();
74 names
.each(function(name
) {
75 sortednames
.push(nh
[name
]);
78 var w
= this.getWindow(channel
);
80 w
.updateNickList(sortednames
);
82 getWindow: function(name
) {
83 return this.windows
[name
];
85 newWindow: function(name
, type
, select
) {
86 var w
= this.getWindow(name
);
88 w
= this.windows
[name
] = this.ui
.newWindow(this, type
, name
);
90 w
.addEvent("close", function(w
) {
91 delete this.windows
[name
];
96 this.ui
.selectWindow(w
);
100 getActiveWindow: function() {
101 return this.ui
.getActiveWindow();
103 getNickname: function() {
104 return this.nickname
;
106 addPrefix: function(nickchanentry
, prefix
) {
107 var ncp
= nickchanentry
.prefixes
+ prefix
;
111 for(var i
=0;i
<this.prefixes
.length
;i
++) {
112 var pc
= this.prefixes
.charAt(i
);
113 var index
= ncp
.indexOf(pc
);
118 nickchanentry
.prefixes
= prefixes
.join("");
120 removePrefix: function(nickchanentry
, prefix
) {
121 nickchanentry
.prefixes
= nickchanentry
.prefixes
.replaceAll(prefix
, "");
124 /* from here down are events */
125 rawNumeric: function(numeric
, prefix
, params
) {
126 this.newServerLine("RAW", {"n": "numeric", "m": params
.slice(1).join(" ")});
128 signedOn: function(nickname
) {
129 this.tracker
= new IRCTracker();
130 this.nickname
= nickname
;
131 this.newServerLine("SIGNON");
133 if(this.options
.autojoin
)
134 this.send("JOIN " + this.options
.autojoin
);
136 userJoined: function(user
, channel
) {
137 var nick
= user
.hostToNick();
138 var host
= user
.hostToHost();
140 if((nick
== this.nickname
) && !this.getWindow(channel
))
141 this.newWindow(channel
, WINDOW_CHANNEL
, true);
142 this.tracker
.addNickToChannel(nick
, channel
);
144 if(nick
== this.nickname
) {
145 this.newChanLine(channel
, "OURJOIN", user
);
147 this.newChanLine(channel
, "JOIN", user
);
149 this.updateNickList(channel
);
151 userPart: function(user
, channel
, message
) {
152 var nick
= user
.hostToNick();
153 var host
= user
.hostToHost();
155 if(nick
== this.nickname
) {
156 this.tracker
.removeChannel(channel
);
158 this.tracker
.removeNickFromChannel(nick
, channel
);
159 this.newChanLine(channel
, "PART", user
, {"m": message
});
162 this.updateNickList(channel
);
164 if(nick
== this.nickname
) {
165 var w
= this.getWindow(channel
)
170 userKicked: function(kicker
, channel
, kickee
, message
) {
171 if(kickee
== this.nickname
) {
172 this.tracker
.removeChannel(channel
);
173 this.getWindow(channel
).close();
175 this.tracker
.removeNickFromChannel(kickee
, channel
);
176 this.updateNickList(channel
);
179 this.newChanLine(channel
, "KICK", kicker
, {"v": kickee
, "m": message
});
181 channelMode: function(user
, channel
, modes
, raw
) {
182 modes
.each(function(mo
) {
183 var direction
= mo
[0];
186 var prefixindex
= this.modeprefixes
.indexOf(mode
);
187 if(prefixindex
== -1)
191 var prefixchar
= this.prefixes
.charAt(prefixindex
);
193 var nc
= this.tracker
.getOrCreateNickOnChannel(nick
, channel
);
194 if(direction
== "-") {
195 this.removePrefix(nc
, prefixchar
);
197 this.addPrefix(nc
, prefixchar
);
201 this.newChanLine(channel
, "MODE", user
, {"m": raw
.join(" ")});
203 this.updateNickList(channel
);
205 userQuit: function(user
, message
) {
206 var nick
= user
.hostToNick();
208 var channels
= this.tracker
.getNick(nick
);
211 for(var c
in channels
) {
213 this.newChanLine(c
, "QUIT", user
, {"m": message
});
216 this.tracker
.removeNick(nick
);
218 clist
.each(function(cli
) {
219 this.updateNickList(cli
);
222 nickChanged: function(user
, newnick
) {
223 var oldnick
= user
.hostToNick();
225 if(oldnick
== this.nickname
)
226 this.nickname
= newnick
;
228 this.tracker
.renameNick(oldnick
, newnick
);
230 var channels
= this.tracker
.getNick(newnick
);
232 for(var c
in channels
) {
233 this.newChanLine(c
, "NICK", user
, {"w": newnick
});
234 /* TODO: rename queries */
235 this.updateNickList(c
);
238 this.newChanLine(undefined, "NICK", user
, {"w": newnick
});
240 channelTopic: function(user
, channel
, topic
) {
241 this.newChanLine(channel
, "TOPIC", user
, {"m": topic
});
242 this.getWindow(channel
).updateTopic(topic
);
244 initialTopic: function(channel
, topic
) {
245 this.getWindow(channel
).updateTopic(topic
);
247 channelCTCP: function(user
, channel
, type
, args
) {
248 if(args
== undefined)
251 if(type
== "ACTION") {
252 this.newChanLine(channel
, "CHANACTION", user
, {"m": args
, "c": channel
});
256 this.newChanLine(channel
, "CHANCTCP", user
, {"x": type
, "m": args
, "c": channel
});
258 userCTCP: function(user
, type
, args
) {
259 var nick
= user
.hostToNick();
260 var host
= user
.hostToHost();
261 if(args
== undefined)
264 if(type
== "ACTION") {
265 this.newWindow(nick
, WINDOW_QUERY
);
266 this.newLine(nick
, "PRIVACTION", {"m": args
, "x": type
, "h": host
, "n": nick
});
270 if(this.getWindow(nick
)) {
271 this.newLine(nick
, "PRIVCTCP", {"m": args
, "x": type
, "h": host
, "n": nick
, "-": this.nickname
});
273 this.newActiveLine("PRIVCTCP", {"m": args
, "x": type
, "h": host
, "n": nick
, "-": this.nickname
});
276 userCTCPReply: function(user
, type
, args
) {
277 var nick
= user
.hostToNick();
278 var host
= user
.hostToHost();
279 if(args
== undefined)
282 if(this.getWindow(nick
)) {
283 this.newLine(nick
, "CTCPREPLY", {"m": args
, "x": type
, "h": host
, "n": nick
, "-": this.nickname
});
285 this.newActiveLine("CTCPREPLY", {"m": args
, "x": type
, "h": host
, "n": nick
, "-": this.nickname
});
288 channelPrivmsg: function(user
, channel
, message
) {
289 this.newChanLine(channel
, "CHANMSG", user
, {"m": message
});
291 channelNotice: function(user
, channel
, message
) {
292 this.newChanLine(channel
, "CHANNOTICE", user
, {"m": message
});
294 userPrivmsg: function(user
, message
) {
295 var nick
= user
.hostToNick();
296 var host
= user
.hostToHost();
298 this.newWindow(nick
, WINDOW_QUERY
);
300 this.newLine(nick
, "PRIVMSG", {"m": message
, "h": host
, "n": nick
});
302 serverNotice: function(message
) {
303 this.newServerLine("SERVERNOTICE", {"m": message
});
305 userNotice: function(user
, message
) {
306 var nick
= user
.hostToNick();
307 var host
= user
.hostToHost();
309 if(this.getWindow(nick
)) {
310 this.newLine(nick
, "PRIVNOTICE", {"m": message
, "h": host
, "n": nick
});
312 this.newActiveLine("PRIVNOTICE", {"m": message
, "h": host
, "n": nick
});
315 userInvite: function(user
, channel
) {
316 var nick
= user
.hostToNick();
317 var host
= user
.hostToHost();
319 this.newServerLine("INVITE", {"c": channel
, "h": host
, "n": nick
});
321 userMode: function(modes
) {
322 this.newServerLine("UMODE", {"m": modes
, "n": this.nickname
});
324 channelNames: function(channel
, names
) {
325 if(names
.length
== 0) {
326 this.updateNickList(channel
);
330 names
.each(function(nick
) {
332 var splitnick
= nick
.split("");
334 splitnick
.every(function(c
, i
) {
335 if(this.prefixes
.indexOf(c
) == -1) {
336 nick
= nick
.substr(i
);
344 var nc
= this.tracker
.addNickToChannel(nick
, channel
);
345 prefixes
.each(function(p
) {
346 this.addPrefix(nc
, p
);
350 disconnected: function(message
) {
351 for(var x
in this.windows
) {
352 var w
= this.windows
[x
];
353 if(w
.type
== WINDOW_CHANNEL
)
356 this.tracker
= undefined;
358 this.newServerLine("DISCONNECT", {"m": message
});
360 supported: function(key
, value
) {
361 if(key
== "PREFIX") {
362 var l
= (value
.length
- 2) / 2;
364 this.modeprefixes
= value
.substr(1, l
);
365 this.prefixes
= value
.substr(l
+ 2, l
);
368 connected: function() {
369 this.newServerLine("CONNECT");
371 serverError: function(message
) {
372 this.newServerLine("ERROR", {"m": message
});
374 quit: function(message
) {
375 this.send("QUIT :" + message
);