]>
jfr.im git - irc/quakenet/qwebirc.git/blob - static/js/irc/baseirc.js
fbc2d3b99547f734f97b7e3a8671c7de5e060a6a
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"}
3 function BaseIRCClient(nickname
, view
) {
5 this.nickname
= nickname
;
7 this.pmodes
= ["b", "k,", "o", "l", "v"];
9 /* attempt javascript inheritence! */
10 this.dispatch = function(data
) {
11 var message
= data
[0];
12 if(message
== "connect") {
14 } else if(message
== "disconnect") {
16 } else if(message
== "c") {
17 var command
= data
[1];
21 var n
= Numerics
[command
];
27 var o
= view
["irc_" + n
];
32 var r
= o(prefix
, sl
);
34 view
.rawNumeric(command
, prefix
, sl
);
36 view
.rawNumeric(command
, prefix
, sl
);
41 this.irc_RPL_WELCOME = function(prefix
, params
) {
42 self
.nickname
= params
[0];
45 view
.signedOn(self
.nickname
);
48 this.irc_ERR_NICKNAMEINUSE = function(prefix
, params
) {
49 if(self
.signedOn
== false) {
50 var newnick
= params
[1] + "_";
51 if(newnick
== self
.lastnick
)
52 newnick
= "webchat" + Math
.floor(Math
.random() * 1024 * 1024);
54 self
.send("NICK " + newnick
);
55 self
.lastnick
= newnick
;
59 this.irc_NICK = function(prefix
, params
) {
61 var oldnick
= user
.split("!", 1);
62 var newnick
= params
[0];
64 if(self
.nickname
== oldnick
)
65 self
.nickname
= newnick
;
67 view
.nickChanged(user
, newnick
);
72 this.irc_QUIT = function(prefix
, params
) {
75 var message
= ANI(params
, -1);
77 view
.userQuit(user
, message
);
82 this.irc_PART = function(prefix
, params
) {
84 var channel
= params
[0];
85 var message
= params
[1];
87 view
.userPart(user
, channel
, message
);
92 this.irc_KICK = function(prefix
, params
) {
94 var channel
= params
[0];
95 var kickee
= params
[1];
96 var message
= params
[2];
98 view
.userKicked(kicker
, channel
, kickee
, message
);
103 this.irc_PING = function(prefix
, params
) {
104 self
.send("PONG :" + ANI(params
, -1));
109 this.irc_JOIN = function(prefix
, params
) {
110 var channel
= params
[0];
113 view
.userJoined(user
, channel
);
118 this.irc_TOPIC = function(prefix
, params
) {
120 var channel
= params
[0];
121 var topic
= ANI(params
, -1);
123 view
.channelTopic(user
, channel
, topic
);
128 this.irc_PRIVMSG = function(prefix
, params
) {
130 var target
= params
[0];
131 var message
= ANI(params
, -1);
133 if(target
== self
.nickname
) {
134 view
.userPrivmsg(user
, message
);
136 view
.channelPrivmsg(user
, target
, message
);
142 this.irc_NOTICE = function(prefix
, params
) {
144 var target
= params
[0];
145 var message
= ANI(params
, -1);
148 view
.serverNotice(message
);
149 } else if(target
== self
.nickname
) {
150 view
.userNotice(user
, message
);
152 view
.channelNotice(user
, target
, message
);
158 this.irc_INVITE = function(prefix
, params
) {
160 var channel
= ANI(params
, -1);
162 view
.userInvite(user
, channel
);
167 this.irc_ERROR = function(prefix
, params
) {
168 var message
= ANI(params
, -1);
170 view
.serverError(message
);
175 this.irc_MODE = function(prefix
, params
) {
177 var target
= params
[0];
178 var args
= params
.slice(1);
180 if(target
== self
.nickname
) {
183 var modes
= args
[0].split("");
184 var xargs
= args
.slice(1);
191 forEach(modes
, function(mode
) {
192 if((mode
== "+") || (mode
== "-")) {
197 if(self
.pmodes
[mode
]) {
198 d
= [cmode
, mode
, xargs
[carg
++]]
206 view
.channelMode(user
, target
, data
, args
);
212 this.irc_RPL_ISUPPORT = function(prefix
, params
) {
213 var supported
= params
.slice(1, -1);
214 var supportedhash
= {};
216 for(var i
=0;i
<supported
.length
;i
++) {
217 var l
= supported
[i
].split("=", 2);
218 view
.supported(l
[0], l
[1]);
222 this.irc_RPL_MYINFO = function(prefix
, params
) {
223 var pmodes
= params
[5].split("");
225 forEach(pmodes
, function(pmode
) {
226 self
.pmodes
[pmode
] = true;
230 this.irc_RPL_NAMREPLY = function(prefix
, params
) {
231 var channel
= params
[2];
232 var names
= params
[3];
234 view
.channelNames(channel
, names
.split(" "));
239 this.irc_RPL_ENDOFNAMES = function(prefix
, params
) {
240 var channel
= params
[1];
242 view
.channelNames(channel
, []);
246 this.irc_RPL_NOTOPIC = function(prefix
, params
) {
250 this.irc_RPL_TOPIC = function(prefix
, params
) {
251 var channel
= params
[1];
252 var topic
= ANI(params
, -1);
254 view
.initialTopic(channel
, topic
);
258 this.irc_RPL_TOPICWHOTIME = function(prefix
, params
) {
262 this.connection
= new TCPConnection(nickname
, this);
263 this.send
= this.connection
.send
;
264 this.connect
= this.connection
.connect
;
265 this.disconnect
= this.connection
.disconnect
;