From 26322e8fe5e3a662b442f14496632b2e6402a132 Mon Sep 17 00:00:00 2001 From: Darren Date: Mon, 29 Oct 2012 20:02:46 +0000 Subject: [PATCH] Server: Removing console.logs, comments, formatting --- server/client.js | 4 ++++ server/kiwi.js | 23 +++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/server/client.js b/server/client.js index a020f89..1dc47e2 100755 --- a/server/client.js +++ b/server/client.js @@ -13,7 +13,11 @@ var Client = function (websocket) { events.EventEmitter.call(this); this.websocket = websocket; + + // Clients address this.real_address = this.websocket.handshake.real_address; + + // A hash to identify this client instance this.hash = crypto.createHash('sha256').update(this.real_address).update('' + Date.now()).digest('hex'); this.irc_connections = []; diff --git a/server/kiwi.js b/server/kiwi.js index 1c9fd82..1a4d313 100755 --- a/server/kiwi.js +++ b/server/kiwi.js @@ -56,13 +56,11 @@ if ((!config.get().servers) || (config.get().servers.length < 1)) { -/* - * Web listeners - */ - // Holder for all the connected clients -global.clients = { clients: Object.create(null), +global.clients = { + clients: Object.create(null), addresses: Object.create(null), + add: function (client) { this.clients[client.hash] = client; if (typeof this.addresses[client.real_address] === 'undefined') { @@ -70,6 +68,7 @@ global.clients = { clients: Object.create(null), } this.addresses[client.real_address][client.hash] = client; }, + remove: function (client) { if (typeof this.clients[client.hash] !== 'undefined') { delete this.clients[client.hash]; @@ -79,6 +78,7 @@ global.clients = { clients: Object.create(null), } } }, + numOnAddress: function (addr) { if (typeof this.addresses[addr] !== 'undefined') { return Object.keys(this.addresses[addr]).length; @@ -88,17 +88,24 @@ global.clients = { clients: Object.create(null), } }; + + + +/* + * Web listeners + */ + + // Start up a weblistener for each found in the config _.each(config.get().servers, function (server) { var wl = new WebListener(server, config.get().transports); + wl.on('connection', function (client) { clients.add(client); - console.log(clients); }); + wl.on('destroy', function (client) { clients.remove(client); - //client.dispose(); - console.log(clients); }); }); -- 2.25.1