X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=server%2Fkiwi.js;h=6e697f75a7b306c780af3cc6f3bd003abb455568;hb=e35f86f072142d04d00ee9e834f2ce2a3c897478;hp=014cac09a19ff74f40424b5f530d6da97614fb17;hpb=38ef70863202157b786294332ee5004e1547a19b;p=KiwiIRC.git diff --git a/server/kiwi.js b/server/kiwi.js index 014cac0..6e697f7 100755 --- a/server/kiwi.js +++ b/server/kiwi.js @@ -109,6 +109,36 @@ global.clients = { } }; +global.servers = { + servers: Object.create(null), + + addConnection: function (connection) { + var host = connection.irc_host.hostname; + if (!this.servers[host]) { + this.servers[host] = []; + } + this.servers[host].push(connection); + }, + + removeConnection: function (connection) { + var host = connection.irc_host.hostname + if (this.servers[host]) { + this.servers[host] = _.without(this.servers[host], connection); + if (this.servers[host].length === 0) { + delete this.servers[host]; + } + } + }, + + numOnHost: function (host) { + if (this.servers[host]) { + return this.servers[host].length; + } else { + return 0; + } + } +}; + @@ -142,7 +172,16 @@ _.each(global.config.servers, function (server) { clients.remove(client); }); - wl.on('listening', webListenerRunning); + wl.on('listening', function () { + console.log('Listening on %s:%s %s SSL', server.address, server.port, (server.ssl ? 'with' : 'without')); + webListenerRunning(); + }); + + wl.on('error', function (err) { + console.log('Error listening on %s:%s: %s', server.address, server.port, err.code); + // TODO: This should probably be refactored. ^JA + webListenerRunning(); + }); }); // Once all the listeners are listening, set the processes UID/GID