]>
jfr.im git - irc/quakenet/qwebirc.git/blob - static/js/irc/baseirc.js
12139042187b1d5cd6b922cad440f7694f47bf97
1 Numerics
= {"001": "RPL_WELCOME", "433": "ERR_NICKNAMEINUSE", "004": "RPL_MYINFO", "005": "RPL_ISUPPORT", "353": "RPL_NAMREPLY", "366": "RPL_ENDOFNAMES", "331": "RPL_NOTOPIC", "332": "RPL_TOPIC", "333": "RPL_TOPICWHOTIME"};
4 "VERSION": function(x
) {
5 return "qwebirc v" + QWEBIRC_VERSION
+ ", copyright (C) Chris Porter 2008 -- user agent: " + getBrowserDetails();
7 "USERINFO": function(x
) { return "qwebirc"; },
9 function pad(x
) { x
= "" + x
; if(x
.length
== 1) x
= "0" + x
; return x
; }
13 return DaysOfWeek
[d
.getDay()] + " " + MonthsOfYear
[d
.getMonth()] + " " + pad(d
.getDate()) + " " + pad(d
.getHours()) + ":" + pad(d
.getMinutes()) + ":" + pad(d
.getSeconds()) + " " + d
.getFullYear()
15 "PING": function(x
) { return x
; },
16 "CLIENTINFO": function(x
) { return "PING VERSION TIME USERINFO CLIENTINFO"; }
19 function BaseIRCClient(nickname
, view
) {
21 this.nickname
= nickname
;
22 this.signedOn
= false;
23 this.pmodes
= ["b", "k,", "o", "l", "v"];
27 /* attempt javascript inheritence! */
28 this.dispatch = function(data
) {
29 var message
= data
[0];
30 if(message
== "connect") {
32 } else if(message
== "disconnect") {
34 } else if(message
== "c") {
35 var command
= data
[1];
39 var n
= Numerics
[command
];
45 var o
= view
["irc_" + n
];
50 var r
= o(prefix
, sl
);
52 view
.rawNumeric(command
, prefix
, sl
);
54 view
.rawNumeric(command
, prefix
, sl
);
59 this.irc_RPL_WELCOME = function(prefix
, params
) {
60 self
.nickname
= params
[0];
63 view
.signedOn(self
.nickname
);
66 this.irc_ERR_NICKNAMEINUSE = function(prefix
, params
) {
67 if(self
.signedOn
== false) {
68 var newnick
= params
[1] + "_";
69 if(newnick
== self
.lastnick
)
70 newnick
= "webchat" + Math
.floor(Math
.random() * 1024 * 1024);
72 self
.send("NICK " + newnick
);
73 self
.lastnick
= newnick
;
77 this.irc_NICK = function(prefix
, params
) {
79 var oldnick
= hosttonick(user
);
80 var newnick
= params
[0];
82 if(self
.nickname
== oldnick
)
83 self
.nickname
= newnick
;
85 view
.nickChanged(user
, newnick
);
90 this.irc_QUIT = function(prefix
, params
) {
93 var message
= indexFromEnd(params
, -1);
95 view
.userQuit(user
, message
);
100 this.irc_PART = function(prefix
, params
) {
102 var channel
= params
[0];
103 var message
= params
[1];
105 var nick
= hosttonick(user
);
107 if((nick
== self
.nickname
) && self
.channels
[channel
])
108 delete self
.channels
[channel
];
109 view
.userPart(user
, channel
, message
);
114 this.irc_KICK = function(prefix
, params
) {
116 var channel
= params
[0];
117 var kickee
= params
[1];
118 var message
= params
[2];
120 if((kickee
== self
.nickname
) && self
.channels
[channel
])
121 delete self
.channels
[channel
];
122 view
.userKicked(kicker
, channel
, kickee
, message
);
127 this.irc_PING = function(prefix
, params
) {
128 self
.send("PONG :" + indexFromEnd(params
, -1));
133 this.irc_JOIN = function(prefix
, params
) {
134 var channel
= params
[0];
136 var nick
= hosttonick(user
);
138 if(nick
== self
.nickname
)
139 self
.channels
[channel
] = true;
141 view
.userJoined(user
, channel
);
146 this.irc_TOPIC = function(prefix
, params
) {
148 var channel
= params
[0];
149 var topic
= indexFromEnd(params
, -1);
151 view
.channelTopic(user
, channel
, topic
);
156 var processCTCP = function(message
) {
157 if(message
.charAt(0) == "\x01") {
158 if(message
.charAt(message
.length
- 1) == "\x01") {
159 message
= message
.substr(1, message
.length
- 2);
161 message
= message
.substr(1);
163 return message
.splitMax(" ", 2);
167 this.irc_PRIVMSG = function(prefix
, params
) {
169 var target
= params
[0];
170 var message
= indexFromEnd(params
, -1);
172 var ctcp
= processCTCP(message
);
174 var type
= ctcp
[0].toUpperCase();
176 var replyfn
= registeredCTCPs
[type
];
178 var t
= new Date().getTime() / 1000;
180 self
.send("NOTICE " + hosttonick(user
) + " :\x01" + type
+ " " + replyfn(ctcp
[1]) + "\x01");
184 if(target
== self
.nickname
) {
185 view
.userCTCP(user
, type
, ctcp
[1]);
187 view
.channelCTCP(user
, target
, type
, ctcp
[1]);
190 if(target
== self
.nickname
) {
191 view
.userPrivmsg(user
, message
);
193 view
.channelPrivmsg(user
, target
, message
);
200 this.irc_NOTICE = function(prefix
, params
) {
202 var target
= params
[0];
203 var message
= indexFromEnd(params
, -1);
206 view
.serverNotice(message
);
207 } else if(target
== self
.nickname
) {
208 var ctcp
= processCTCP(message
);
210 view
.userCTCPReply(user
, ctcp
[0], ctcp
[1]);
212 view
.userNotice(user
, message
);
215 view
.channelNotice(user
, target
, message
);
221 this.irc_INVITE = function(prefix
, params
) {
223 var channel
= indexFromEnd(params
, -1);
225 view
.userInvite(user
, channel
);
230 this.irc_ERROR = function(prefix
, params
) {
231 var message
= indexFromEnd(params
, -1);
233 view
.serverError(message
);
238 this.irc_MODE = function(prefix
, params
) {
240 var target
= params
[0];
241 var args
= params
.slice(1);
243 if(target
== self
.nickname
) {
246 var modes
= args
[0].split("");
247 var xargs
= args
.slice(1);
254 forEach(modes
, function(mode
) {
255 if((mode
== "+") || (mode
== "-")) {
260 if(self
.pmodes
[mode
]) {
261 d
= [cmode
, mode
, xargs
[carg
++]]
269 view
.channelMode(user
, target
, data
, args
);
275 this.irc_RPL_ISUPPORT = function(prefix
, params
) {
276 var supported
= params
.slice(1, -1);
277 var supportedhash
= {};
279 for(var i
=0;i
<supported
.length
;i
++) {
280 var l
= supported
[i
].splitMax("=", 2);
281 view
.supported(l
[0], l
[1]);
285 this.irc_RPL_MYINFO = function(prefix
, params
) {
286 var pmodes
= params
[5].split("");
288 forEach(pmodes
, function(pmode
) {
289 self
.pmodes
[pmode
] = true;
293 this.irc_RPL_NAMREPLY = function(prefix
, params
) {
294 var channel
= params
[2];
295 var names
= params
[3];
297 view
.channelNames(channel
, names
.split(" "));
302 this.irc_RPL_ENDOFNAMES = function(prefix
, params
) {
303 var channel
= params
[1];
305 view
.channelNames(channel
, []);
309 this.irc_RPL_NOTOPIC = function(prefix
, params
) {
313 this.irc_RPL_TOPIC = function(prefix
, params
) {
314 var channel
= params
[1];
315 var topic
= indexFromEnd(params
, -1);
317 if(self
.channels
[channel
]) {
318 view
.initialTopic(channel
, topic
);
323 this.irc_RPL_TOPICWHOTIME = function(prefix
, params
) {
327 this.connection
= new TCPConnection(nickname
, this);
328 this.send
= this.connection
.send
;
329 this.connect
= this.connection
.connect
;
330 this.disconnect
= this.connection
.disconnect
;