]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/irc/ircclient.js
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");
134 this.send("JOIN " + this.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 this.newChanLine(channel
, "JOIN", user
);
145 this.updateNickList(channel
);
147 userPart: function(user
, channel
, message
) {
148 var nick
= user
.hostToNick();
149 var host
= user
.hostToHost();
151 if(nick
== this.nickname
) {
152 this.tracker
.removeChannel(channel
);
154 this.tracker
.removeNickFromChannel(nick
, channel
);
155 this.newChanLine(channel
, "PART", user
, {"m": message
});
158 this.updateNickList(channel
);
160 var w
= this.getWindow(channel
)
164 userKicked: function(kicker
, channel
, kickee
, message
) {
165 if(kickee
== this.nickname
) {
166 this.tracker
.removeChannel(channel
);
167 this.getWindow(channel
).close();
169 this.tracker
.removeNickFromChannel(kickee
, channel
);
170 this.updateNickList(channel
);
173 this.newChanLine(channel
, "KICK", kicker
, {"v": kickee
, "m": message
});
175 channelMode: function(user
, channel
, modes
, raw
) {
176 modes
.each(function(mo
) {
177 var direction
= mo
[0];
180 var prefixindex
= this.modeprefixes
.indexOf(mode
);
181 if(prefixindex
== -1)
185 var prefixchar
= this.prefixes
.charAt(prefixindex
);
187 var nc
= this.tracker
.getOrCreateNickOnChannel(nick
, channel
);
188 if(direction
== "-") {
189 this.removePrefix(nc
, prefixchar
);
191 this.addPrefix(nc
, prefixchar
);
195 this.newChanLine(channel
, "MODE", user
, {"m": raw
.join(" ")});
197 this.updateNickList(channel
);
199 userQuit: function(user
, message
) {
200 var nick
= user
.hostToNick();
202 var channels
= this.tracker
.getNick(nick
);
205 for(var c
in channels
) {
207 this.newChanLine(c
, "QUIT", user
, {"m": message
});
210 this.tracker
.removeNick(nick
);
212 clist
.each(function(cli
) {
213 this.updateNickList(cli
);
216 nickChanged: function(user
, newnick
) {
217 var oldnick
= user
.hostToNick();
219 if(oldnick
== this.nickname
)
220 this.nickname
= newnick
;
222 this.tracker
.renameNick(oldnick
, newnick
);
224 var channels
= this.tracker
.getNick(newnick
);
226 for(var c
in channels
) {
227 this.newChanLine(c
, "NICK", user
, {"w": newnick
});
228 /* TODO: rename queries */
229 this.updateNickList(c
);
232 channelTopic: function(user
, channel
, topic
) {
233 this.newChanLine(channel
, "TOPIC", user
, {"m": topic
});
234 this.getWindow(channel
).updateTopic(topic
);
236 initialTopic: function(channel
, topic
) {
237 this.getWindow(channel
).updateTopic(topic
);
239 channelCTCP: function(user
, channel
, type
, args
) {
240 if(args
== undefined)
243 if(type
== "ACTION") {
244 this.newChanLine(channel
, "CHANACTION", user
, {"m": args
, "c": channel
});
248 this.newChanLine(channel
, "CHANCTCP", user
, {"x": type
, "m": args
, "c": channel
});
250 userCTCP: function(user
, type
, args
) {
251 var nick
= user
.hostToNick();
252 var host
= user
.hostToHost();
253 if(args
== undefined)
256 if(type
== "ACTION") {
257 this.newWindow(nick
, WINDOW_QUERY
);
258 this.newLine(nick
, "PRIVACTION", {"m": args
, "x": type
, "h": host
, "n": nick
});
262 if(this.getWindow(nick
)) {
263 this.newLine(nick
, "PRIVCTCP", {"m": args
, "x": type
, "h": host
, "n": nick
, "-": this.nickname
});
265 this.newActiveLine("PRIVCTCP", {"m": args
, "x": type
, "h": host
, "n": nick
, "-": this.nickname
});
268 userCTCPReply: function(user
, type
, args
) {
269 var nick
= user
.hostToNick();
270 var host
= user
.hostToHost();
271 if(args
== undefined)
274 if(this.getWindow(nick
)) {
275 this.newLine(nick
, "CTCPREPLY", {"m": args
, "x": type
, "h": host
, "n": nick
, "-": this.nickname
});
277 this.newActiveLine("CTCPREPLY", {"m": args
, "x": type
, "h": host
, "n": nick
, "-": this.nickname
});
280 channelPrivmsg: function(user
, channel
, message
) {
281 this.newChanLine(channel
, "CHANMSG", user
, {"m": message
});
283 channelNotice: function(user
, channel
, message
) {
284 this.newChanLine(channel
, "CHANNOTICE", user
, {"m": message
});
286 userPrivmsg: function(user
, message
) {
287 var nick
= user
.hostToNick();
288 var host
= user
.hostToHost();
290 this.newWindow(nick
, WINDOW_QUERY
);
292 this.newLine(nick
, "PRIVMSG", {"m": message
, "h": host
, "n": nick
});
294 serverNotice: function(message
) {
295 this.newServerLine("SERVERNOTICE", {"m": message
});
297 userNotice: function(user
, message
) {
298 var nick
= user
.hostToNick();
299 var host
= user
.hostToHost();
301 if(this.getWindow(nick
)) {
302 this.newLine(nick
, "PRIVNOTICE", {"m": message
, "h": host
, "n": nick
});
304 this.newActiveLine("PRIVNOTICE", {"m": message
, "h": host
, "n": nick
});
307 userInvite: function(user
, channel
) {
308 var nick
= user
.hostToNick();
309 var host
= user
.hostToHost();
311 this.newServerLine("INVITE", {"c": channel
, "h": host
, "n": nick
});
313 userMode: function(modes
) {
314 this.newServerLine("UMODE", {"m": modes
, "n": this.nickname
});
316 channelNames: function(channel
, names
) {
317 if(names
.length
== 0) {
318 this.updateNickList(channel
);
322 names
.each(function(nick
) {
324 var splitnick
= nick
.split("");
326 splitnick
.every(function(c
, i
) {
327 if(this.prefixes
.indexOf(c
) == -1) {
328 nick
= nick
.substr(i
);
336 var nc
= this.tracker
.addNickToChannel(nick
, channel
);
337 prefixes
.each(function(p
) {
338 this.addPrefix(nc
, p
);
342 disconnected: function() {
343 for(var x
in this.parent
.channels
)
344 this.ui
.closeWindow(x
);
346 this.tracker
= undefined;
348 this.newServerLine("DISCONNECT");
350 supported: function(key
, value
) {
351 if(key
== "PREFIX") {
352 var l
= (value
.length
- 2) / 2;
354 this.modeprefixes
= value
.substr(1, l
);
355 this.prefixes
= value
.substr(l
+ 2, l
);
358 connected: function() {
359 this.newServerLine("CONNECT");
361 serverError: function(message
) {
362 this.newServerLine("ERROR", {"m": message
});