Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added library support for the RPL_ISUPPORT server reply

  • Loading branch information...
commit 96c16803315f1b342d15b073ed58f0f34e616bd6 1 parent 6e14122
@qsheets qsheets authored
Showing with 100 additions and 12 deletions.
  1. +8 −0 lib/codes.js
  2. +92 −12 lib/irc.js
View
8 lib/codes.js
@@ -1,4 +1,12 @@
module.exports = { // {{{
+ "004" : {
+ "name" : "rpl_myinfo",
+ "type" : "reply"
+ },
+ "005" : {
+ "name" : "rpl_isupport",
+ "type" : "reply"
+ },
"200" : {
"name" : "rpl_tracelink",
"type" : "reply"
View
104 lib/irc.js
@@ -52,6 +52,26 @@ function Client(server, nick, opt) {
channelPrefixes: "&#",
messageSplit: 512
};
+
+ // Features supported by the server
+ // (initial values are RFC 1459 defaults. Zeros signify
+ // no default or unlimited value)
+ self.supported = {
+ channel: {
+ idlength: [],
+ length: 200,
+ limit: [],
+ modes: { a: '', b: '', c: '', d: ''},
+ types: self.opt.channelPrefixes
+ },
+ kicklength: 0,
+ maxlist: [],
+ maxtargets: [],
+ modes: 3,
+ nicklength: 9,
+ topiclength: 0,
+ usermodes: ''
+ };
if (typeof arguments[2] == 'object') {
var keys = Object.keys(self.opt);
@@ -83,19 +103,79 @@ function Client(server, nick, opt) {
break;
case "002":
case "003":
- case "004":
+ case "rpl_myinfo":
+ self.supported.usermodes = message.args[3];
break;
- case "005":
+ case "rpl_isupport":
message.args.forEach(function(arg) {
var match;
- if ( match = arg.match(/PREFIX=\((.*?)\)(.*)/) ) {
- match[1] = match[1].split('');
- match[2] = match[2].split('');
- while ( match[1].length ) {
- self.modeForPrefix[match[2][0]] = match[1][0];
- self.prefixForMode[match[1].shift()] = match[2].shift();
- }
- }
+ if ( match = arg.match(/([A-Z]+)=(.*)/) ) {
+ var param = match[1];
+ var value = match[2];
+ switch(param) {
+ case 'CHANLIMIT':
+ value.split(',').forEach(function(val) {
+ val = val.split(':');
+ self.supported.channel.limit[val[0]] = parseInt(val[1]);
+ });
+ break;
+ case 'CHANMODES':
+ value = value.split(',');
+ var type = ['a','b','c','d']
+ for (var i = 0; i < type.length; i++) {
+
+ self.supported.channel.modes[type[i]] += value[i];
+ }
+ break;
+ case 'CHANTYPES':
+ self.supported.channel.types = value;
+ break;
+ case 'CHANNELLEN':
+ self.supported.channel.length = parseInt(value);
+ break;
+ case 'IDCHAN':
+ value.split(',').forEach(function(val) {
+ val = val.split(':');
+ self.supported.channel.idlength[val[0]] = val[1];
+ });
+ break;
+ case 'KICKLEN':
+ self.supported.kicklength = value;
+ break;
+ case 'MAXLIST':
+ value.split(',').forEach(function(val) {
+ val = val.split(':');
+ self.supported.maxlist[val[0]] = parseInt(val[1]);
+ });
+ break;
+ case 'NICKLEN':
+ self.supported.nicklength = parseInt(value);
+ break;
+ case 'PREFIX':
+ if (match = value.match(/\((.*?)\)(.*)/)) {
+ match[1] = match[1].split('');
+ match[2] = match[2].split('');
+ while ( match[1].length ) {
+ self.modeForPrefix[match[2][0]] = match[1][0];
+ self.supported.channel.modes.b += match[1][0];
+ self.prefixForMode[match[1].shift()] = match[2].shift();
+ }
+ }
+ break;
+ case 'STATUSMSG':
+ break;
+ case 'TARGMAX':
+ value.split(',').forEach(function(val) {
+ val = val.split(':');
+ val[1] = (!val[1]) ? 0 : parseInt(val[1]);
+ self.supported.maxtargets[val[0]] = val[1];
+ });
+ break;
+ case 'TOPICLEN':
+ self.supported.topiclength = parseInt(value);
+ break;
+ }
+ }
});
break;
case "rpl_luserclient":
@@ -147,7 +227,7 @@ function Client(server, nick, opt) {
if ( mode == '+' ) { adding = true; return; }
if ( mode == '-' ) { adding = false; return; }
if ( mode in self.prefixForMode ) {
- // user modes
+ // channel user modes
var user = modeArgs.shift();
if ( adding ) {
if ( channel.users[user].indexOf(self.prefixForMode[mode]) === -1 )
@@ -389,7 +469,7 @@ function Client(server, nick, opt) {
break;
}
self.emit('message', from, to, text, message);
- if ( self.opt.channelPrefixes.indexOf(to.charAt(0)) !== -1 ) {
+ if ( self.supported.channel.types.indexOf(to.charAt(0)) !== -1 ) {
self.emit('message#', from, to, text, message);
self.emit('message' + to, from, text, message);
if ( to != to.toLowerCase() ) {
Please sign in to comment.
Something went wrong with that request. Please try again.