Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added library support for the RPL_ISUPPORT server reply #114

Merged
merged 2 commits into from

2 participants

Quentin Sheets Martyn Smith
Quentin Sheets

Adds structure for resolving issues before reaching the server and applying server features using RPL_ISUPPORT

  • Can override user setting of channel types based on what the server supports (i.e. the user has # and & channel types enabled and connects to Freenode; the user now has only # enabled because that's what is supported by the server)
  • Defines supported user and channel modes
  • Produces a categorised list of channel modes based on parameter necessity.
Martyn Smith martynsmith merged commit 1356b4d into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 26, 2012
  1. Quentin Sheets
  2. Quentin Sheets

    Fixed spacing

    qsheets authored
This page is out of date. Refresh to see the latest.
Showing with 98 additions and 10 deletions.
  1. +8 −0 lib/codes.js
  2. +90 −10 lib/irc.js
8 lib/codes.js
View
@@ -1,4 +1,12 @@
module.exports = { // {{{
+ "004" : {
+ "name" : "rpl_myinfo",
+ "type" : "reply"
+ },
+ "005" : {
+ "name" : "rpl_isupport",
+ "type" : "reply"
+ },
"200" : {
"name" : "rpl_tracelink",
"type" : "reply"
100 lib/irc.js
View
@@ -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,17 +103,77 @@ 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;
}
}
});
@@ -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() ) {
Something went wrong with that request. Please try again.