Server: Fix for no channel prefixes yet set errors
authorDarren <darren@darrenwhitlen.com>
Thu, 20 Dec 2012 22:25:03 +0000 (22:25 +0000)
committerDarren <darren@darrenwhitlen.com>
Thu, 20 Dec 2012 22:25:03 +0000 (22:25 +0000)
server/irc/commands.js

index ca710ad18364cd9775f4c5a8b31b5f078eb04c96..fc8e6f8122b84cb55bc1a7d7491a53519058ec42 100644 (file)
@@ -177,14 +177,19 @@ var listeners = {
         var i = 0;
         _.each(members, function (member) {
             var j, k, modes = [];
-            for (j = 0; j < member.length; j++) {
-                for (k = 0; k < that.irc_connection.options.PREFIX.length; k++) {
-                    if (member.charAt(j) === that.irc_connection.options.PREFIX[k].symbol) {
-                        modes.push(that.irc_connection.options.PREFIX[k].mode);
-                        i++;
+
+            // Make sure we have some prefixes already
+            if (that.irc_connection.options.PREFIX) {
+                for (j = 0; j < member.length; j++) {
+                    for (k = 0; k < that.irc_connection.options.PREFIX.length; k++) {
+                        if (member.charAt(j) === that.irc_connection.options.PREFIX[k].symbol) {
+                            modes.push(that.irc_connection.options.PREFIX[k].mode);
+                            i++;
+                        }
                     }
                 }
             }
+
             member_list.push({nick: member, modes: modes});
             if (i++ >= 50) {
                 that.client.sendIrcCommand('userlist', {server: that.con_num, users: member_list, channel: command.params[2]});
@@ -252,12 +257,18 @@ var listeners = {
         this.client.sendIrcCommand('nick', {server: this.con_num, nick: command.nick, ident: command.ident, hostname: command.hostname, newnick: command.trailing || command.params[0]});
     },
     'TOPIC': function (command) {
-        this.client.sendIrcCommand('topic', {server: this.con_num, nick: command.nick, channel: command.params[0], topic: command.trailing});
+        // If we don't have an associated channel, no need to continue
+        if (!command.params[0]) return;
+
+        var channel = command.params[0],
+            topic = command.trailing || '';
+
+        this.client.sendIrcCommand('topic', {server: this.con_num, nick: command.nick, channel: channel, topic: topic});
     },
     'MODE': function (command) {                
-        var chanmodes = this.irc_connection.options.CHANMODES,
-            prefixes = this.irc_connection.options.PREFIX,
-            always_param = chanmodes[0].concat(chanmodes[1]),
+        var chanmodes = this.irc_connection.options.CHANMODES || [],
+            prefixes = this.irc_connection.options.PREFIX || [],
+            always_param = (chanmodes[0] || '').concat((chanmodes[1] || '')),
             modes = [],
             has_param, i, j, add;
         
@@ -272,7 +283,7 @@ var listeners = {
                 return m === mode;
             })) {
                 return true;
-            } else if (add && _.find(chanmodes[2].split(''), function (m) {
+            } else if (add && _.find((chanmodes[2] || '').split(''), function (m) {
                 return m === mode;
             })) {
                 return true;