IE8 support - indexOf
[KiwiIRC.git] / server / irc / server.js
index 2a989ec9efd6a328b252878c46fe15a3253fee95..d1fc35360b40a6c2a2b18f94ac84b7c1c75271f2 100755 (executable)
@@ -7,7 +7,7 @@ var IrcServer = function (irc_connection) {
 
     this.list_buffer = [];
     this.motd_buffer = '';
-    
+
     this.irc_events = {
         connect:                onConnect,
         options:                onOptions,
@@ -27,13 +27,15 @@ var IrcServer = function (irc_connection) {
         not_on_channel:         onNotOnChannel,
         channel_is_full:        onChannelIsFull,
         invite_only_channel:    onInviteOnlyChannel,
+        user_on_channel:        onUserAlreadyInChannel,
         banned_from_channel:    onBannedFromChannel,
         bad_channel_key:        onBadChannelKey,
         chanop_privs_needed:    onChanopPrivsNeeded,
-        nickname_in_use:        onNicknameInUse
+        nickname_in_use:        onNicknameInUse,
+        erroneus_nickname:      onErroneusNickname,
+        unknown_command:        onUnknownCommand
     };
     EventBinder.bindIrcEvents('server *', this.irc_events, this, this.irc_connection);
-    
 
 };
 
@@ -52,20 +54,20 @@ function onConnect(event) {
     this.irc_connection.clientEvent('connect', {
         nick: event.nick
     });
-};
+}
 
 function onOptions(event) {
     this.irc_connection.clientEvent('options', {
         options: event.options,
         cap: event.cap
     });
-};
+}
 
 function onListStart(event) {
     this.irc_connection.clientEvent('list_start', {});
     this.list_buffer = [];
     this.busy_listing = true;
-};
+}
 
 function onListChannel(event) {
     var buf;
@@ -77,7 +79,7 @@ function onListChannel(event) {
         num_users: event.num_users,
         topic: event.topic
     });
-    
+
     if (this.list_buffer.length > 200) {
         buf = _.sortBy(this.list_buffer, function (channel) {
             // sortBy sorts in ascending order, we want to sort by descending, hence using 0 - num_users.
@@ -88,11 +90,11 @@ function onListChannel(event) {
         });
         this.list_buffer = [];
     }
-};
+}
 
 function onListEnd(event) {
     var buf;
-    
+
     buf = _.sortBy(this.list_buffer, function (channel) {
         // sortBy sorts in ascending order, we want to sort by descending, hence using 0 - num_users.
         return 0 - channel.num_users;
@@ -102,30 +104,30 @@ function onListEnd(event) {
     });
     this.list_buffer = [];
     this.busy_listing = false;
-    
+
     this.irc_connection.clientEvent('list_end', {});
-};
+}
 
 function onMotdStart(event) {
     this.motd_buffer = '';
-};
+}
 
 function onMotd(event) {
     this.motd_buffer += event.motd;
-};
+}
 
 function onMotdEnd(event) {
     this.irc_connection.clientEvent('motd', {
         msg: this.motd_buffer
     });
-};
+}
 
 function onError(event) {
     this.irc_connection.clientEvent('irc_error', {
         error: 'error',
         reason: event.reason
     });
-};
+}
 
 function onPasswordMismatch(event) {
     this.irc_connection.clientEvent('irc_error', {
@@ -138,7 +140,7 @@ function onChannelRedirect(event) {
         from: event.from,
         to: event.to
     });
-};
+}
 
 function onNoSuchNick(event) {
     this.irc_connection.clientEvent('irc_error', {
@@ -146,7 +148,7 @@ function onNoSuchNick(event) {
         nick: event.nick,
         reason: event.reason
     });
-};
+}
 
 function onCannotSendToChan(event) {
     this.irc_connection.clientEvent('irc_error', {
@@ -154,7 +156,7 @@ function onCannotSendToChan(event) {
         channel: event.channel,
         reason: event.reason
     });
-};
+}
 
 function onTooManyChannels(event) {
     this.irc_connection.clientEvent('irc_error', {
@@ -162,7 +164,7 @@ function onTooManyChannels(event) {
         channel: event.channel,
         reason: event.reason
     });
-};
+}
 
 function onUserNotInChannel(event) {
     this.irc_connection.clientEvent('irc_error', {
@@ -171,7 +173,7 @@ function onUserNotInChannel(event) {
         channel: event.channel,
         reason: event.reason
     });
-};
+}
 
 function onNotOnChannel(event) {
     this.irc_connection.clientEvent('irc_error', {
@@ -179,7 +181,7 @@ function onNotOnChannel(event) {
         channel: event.channel,
         reason: event.reason
     });
-};
+}
 
 function onChannelIsFull(event) {
     this.irc_connection.clientEvent('irc_error', {
@@ -187,7 +189,7 @@ function onChannelIsFull(event) {
         channel: event.channel,
         reason: event.reason
     });
-};
+}
 
 function onInviteOnlyChannel(event) {
     this.irc_connection.clientEvent('irc_error', {
@@ -195,7 +197,15 @@ function onInviteOnlyChannel(event) {
         channel: event.channel,
         reason: event.reason
     });
-};
+}
+
+function onUserAlreadyInChannel(event) {
+    this.irc_connection.clientEvent('irc_error', {
+        error: 'user_on_channel',
+        channel: event.channel,
+        nick: event.nick
+    });
+}
 
 function onBannedFromChannel(event) {
     this.irc_connection.clientEvent('irc_error', {
@@ -203,7 +213,7 @@ function onBannedFromChannel(event) {
         channel: event.channel,
         reason: event.reason
     });
-};
+}
 
 function onBadChannelKey(event) {
     this.irc_connection.clientEvent('irc_error', {
@@ -211,7 +221,7 @@ function onBadChannelKey(event) {
         channel: event.channel,
         reason: event.reason
     });
-};
+}
 
 function onChanopPrivsNeeded(event) {
     this.irc_connection.clientEvent('irc_error', {
@@ -219,7 +229,7 @@ function onChanopPrivsNeeded(event) {
         channel: event.channel,
         reason: event.reason
     });
-};
+}
 
 function onNicknameInUse(event) {
     this.irc_connection.clientEvent('irc_error', {
@@ -227,4 +237,20 @@ function onNicknameInUse(event) {
         nick: event.nick,
         reason: event.reason
     });
-};
+}
+
+function onErroneusNickname(event) {
+    this.irc_connection.clientEvent('irc_error', {
+        error: 'erroneus_nickname',
+        nick: event.nick,
+        reason: event.reason
+    });
+}
+
+function onUnknownCommand(event) {
+    this.irc_connection.clientEvent('unknown_command', {
+        error: 'unknown_command',
+        command: event.command,
+        params: event.params
+    });
+}