]>
jfr.im git - irc/quakenet/qwebirc.git/blob - static/js/irc/baseirc.js
f5f2a258bd8b6ea80baca6be82b8b3d93ac8fdcb
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
) { return "qwebirc v" + QWEBIRC_VERSION
+ ", copyright (C) Chris Porter 2008."; },
5 "USERINFO": function(x
) { return "qwebirc"; },
6 "TIME": function(x
) { function pad(x
) { x
= "" + x
; if(x
.length
== 1) x
= "0" + x
; return x
; }var d
= new Date(); return DaysOfWeek
[d
.getDay()] + " " + MonthsOfYear
[d
.getMonth()] + " " + pad(d
.getDate()) + " " + pad(d
.getHours()) + ":" + pad(d
.getMinutes()) + ":" + pad(d
.getSeconds()) + " " + d
.getFullYear() },
7 "PING": function(x
) { return x
; },
8 "CLIENTINFO": function(x
) { return "PING VERSION TIME USERINFO CLIENTINFO"; },
11 function BaseIRCClient(nickname
, view
) {
13 this.nickname
= nickname
;
14 this.signedOn
= false;
15 this.pmodes
= ["b", "k,", "o", "l", "v"];
19 /* attempt javascript inheritence! */
20 this.dispatch = function(data
) {
21 var message
= data
[0];
22 if(message
== "connect") {
24 } else if(message
== "disconnect") {
26 } else if(message
== "c") {
27 var command
= data
[1];
31 var n
= Numerics
[command
];
37 var o
= view
["irc_" + n
];
42 var r
= o(prefix
, sl
);
44 view
.rawNumeric(command
, prefix
, sl
);
46 view
.rawNumeric(command
, prefix
, sl
);
51 this.irc_RPL_WELCOME = function(prefix
, params
) {
52 self
.nickname
= params
[0];
55 view
.signedOn(self
.nickname
);
58 this.irc_ERR_NICKNAMEINUSE = function(prefix
, params
) {
59 if(self
.signedOn
== false) {
60 var newnick
= params
[1] + "_";
61 if(newnick
== self
.lastnick
)
62 newnick
= "webchat" + Math
.floor(Math
.random() * 1024 * 1024);
64 self
.send("NICK " + newnick
);
65 self
.lastnick
= newnick
;
69 this.irc_NICK = function(prefix
, params
) {
71 var oldnick
= hosttonick(user
);
72 var newnick
= params
[0];
74 if(self
.nickname
== oldnick
)
75 self
.nickname
= newnick
;
77 view
.nickChanged(user
, newnick
);
82 this.irc_QUIT = function(prefix
, params
) {
85 var message
= ANI(params
, -1);
87 view
.userQuit(user
, message
);
92 this.irc_PART = function(prefix
, params
) {
94 var channel
= params
[0];
95 var message
= params
[1];
97 var nick
= hosttonick(user
);
99 if((nick
== self
.nickname
) && self
.channels
[channel
])
100 delete self
.channels
[channel
];
101 view
.userPart(user
, channel
, message
);
106 this.irc_KICK = function(prefix
, params
) {
108 var channel
= params
[0];
109 var kickee
= params
[1];
110 var message
= params
[2];
112 if((kickee
== self
.nickname
) && self
.channels
[channel
])
113 delete self
.channels
[channel
];
114 view
.userKicked(kicker
, channel
, kickee
, message
);
119 this.irc_PING = function(prefix
, params
) {
120 self
.send("PONG :" + ANI(params
, -1));
125 this.irc_JOIN = function(prefix
, params
) {
126 var channel
= params
[0];
128 var nick
= hosttonick(user
);
130 if(nick
== self
.nickname
)
131 self
.channels
[channel
] = true;
133 view
.userJoined(user
, channel
);
138 this.irc_TOPIC = function(prefix
, params
) {
140 var channel
= params
[0];
141 var topic
= ANI(params
, -1);
143 view
.channelTopic(user
, channel
, topic
);
148 var processCTCP = function(message
) {
149 if(message
.charAt(0) == "\x01") {
150 if(message
.charAt(message
.length
- 1) == "\x01") {
151 message
= message
.substr(1, message
.length
- 2);
153 message
= message
.substr(1);
155 return message
.splitMax(" ", 2);
159 this.irc_PRIVMSG = function(prefix
, params
) {
161 var target
= params
[0];
162 var message
= ANI(params
, -1);
164 var ctcp
= processCTCP(message
);
166 var type
= ctcp
[0].toUpperCase();
168 var replyfn
= registeredCTCPs
[type
];
170 var t
= new Date().getTime() / 1000;
172 self
.send("NOTICE " + hosttonick(user
) + " :\x01" + type
+ " " + replyfn(ctcp
[1]) + "\x01");
176 if(target
== self
.nickname
) {
177 view
.userCTCP(user
, type
, ctcp
[1]);
179 view
.channelCTCP(user
, target
, type
, ctcp
[1]);
182 if(target
== self
.nickname
) {
183 view
.userPrivmsg(user
, message
);
185 view
.channelPrivmsg(user
, target
, message
);
192 this.irc_NOTICE = function(prefix
, params
) {
194 var target
= params
[0];
195 var message
= ANI(params
, -1);
198 view
.serverNotice(message
);
199 } else if(target
== self
.nickname
) {
200 var ctcp
= processCTCP(message
);
202 view
.userCTCPReply(user
, ctcp
[0], ctcp
[1]);
204 view
.userNotice(user
, message
);
207 view
.channelNotice(user
, target
, message
);
213 this.irc_INVITE = function(prefix
, params
) {
215 var channel
= ANI(params
, -1);
217 view
.userInvite(user
, channel
);
222 this.irc_ERROR = function(prefix
, params
) {
223 var message
= ANI(params
, -1);
225 view
.serverError(message
);
230 this.irc_MODE = function(prefix
, params
) {
232 var target
= params
[0];
233 var args
= params
.slice(1);
235 if(target
== self
.nickname
) {
238 var modes
= args
[0].split("");
239 var xargs
= args
.slice(1);
246 forEach(modes
, function(mode
) {
247 if((mode
== "+") || (mode
== "-")) {
252 if(self
.pmodes
[mode
]) {
253 d
= [cmode
, mode
, xargs
[carg
++]]
261 view
.channelMode(user
, target
, data
, args
);
267 this.irc_RPL_ISUPPORT = function(prefix
, params
) {
268 var supported
= params
.slice(1, -1);
269 var supportedhash
= {};
271 for(var i
=0;i
<supported
.length
;i
++) {
272 var l
= supported
[i
].splitMax("=", 2);
273 view
.supported(l
[0], l
[1]);
277 this.irc_RPL_MYINFO = function(prefix
, params
) {
278 var pmodes
= params
[5].split("");
280 forEach(pmodes
, function(pmode
) {
281 self
.pmodes
[pmode
] = true;
285 this.irc_RPL_NAMREPLY = function(prefix
, params
) {
286 var channel
= params
[2];
287 var names
= params
[3];
289 view
.channelNames(channel
, names
.split(" "));
294 this.irc_RPL_ENDOFNAMES = function(prefix
, params
) {
295 var channel
= params
[1];
297 view
.channelNames(channel
, []);
301 this.irc_RPL_NOTOPIC = function(prefix
, params
) {
305 this.irc_RPL_TOPIC = function(prefix
, params
) {
306 var channel
= params
[1];
307 var topic
= ANI(params
, -1);
309 if(self
.channels
[channel
]) {
310 view
.initialTopic(channel
, topic
);
315 this.irc_RPL_TOPICWHOTIME = function(prefix
, params
) {
319 this.connection
= new TCPConnection(nickname
, this);
320 this.send
= this.connection
.send
;
321 this.connect
= this.connection
.connect
;
322 this.disconnect
= this.connection
.disconnect
;