making it librejs compliant
[KiwiIRC.git] / server / irc / server.js
index 49f06d831d65c90617e98c46455e87e9bfc5f93b..42e32dff0b1e71886c74bb0419c125e384342725 100755 (executable)
@@ -1,6 +1,7 @@
 var util    = require('util'),
     EventBinder  = require('./eventbinder.js'),
-    _ = require('lodash');
+    _ = require('lodash'),
+    Stats = require('../stats.js');
 
 var IrcServer = function (irc_connection) {
     this.irc_connection = irc_connection;
@@ -8,6 +9,9 @@ var IrcServer = function (irc_connection) {
     this.list_buffer = [];
     this.motd_buffer = '';
 
+    // Date when registeration with the IRCd had completed
+    this.registered = false;
+
     this.irc_events = {
         connect:                onConnect,
         options:                onOptions,
@@ -27,10 +31,13 @@ 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);
 
@@ -46,8 +53,18 @@ IrcServer.prototype.dispose = function (){
 };
 
 
+IrcServer.prototype.reset = function() {
+    this.registered = false;
+    this.list_buffer = [];
+    this.motd_buffer = '';
+};
+
+
 
 function onConnect(event) {
+    Stats.incr('irc.connection.registered');
+    this.registered = new Date();
+
     this.irc_connection.clientEvent('connect', {
         nick: event.nick
     });
@@ -149,7 +166,7 @@ function onNoSuchNick(event) {
 
 function onCannotSendToChan(event) {
     this.irc_connection.clientEvent('irc_error', {
-        error: 'cannot_send_to_chan',
+        error: 'cannot_send_to_channel',
         channel: event.channel,
         reason: event.reason
     });
@@ -196,6 +213,14 @@ function onInviteOnlyChannel(event) {
     });
 }
 
+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', {
         error: 'banned_from_channel',
@@ -227,3 +252,19 @@ function onNicknameInUse(event) {
         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
+    });
+}