From bbcfde476e8bcaaaa98d20109c36d0f872648fb8 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Mon, 2 Feb 2015 17:53:22 +0100 Subject: [PATCH] Harden ChainPadServ --- ChainPadSrv.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ChainPadSrv.js b/ChainPadSrv.js index 865be9036..979e6c065 100644 --- a/ChainPadSrv.js +++ b/ChainPadSrv.js @@ -68,7 +68,7 @@ var sendChannelMessage = function (ctx, channel, msg, cb) { sendMsg(msg, user.socket); } catch (e) { console.log(e.stack); - dropClient(ctx, userPass); + try { dropClient(ctx, user.userPass); } catch (e) { } } }); cb && cb(); @@ -124,12 +124,13 @@ var handleMessage = function (ctx, socket, msg) { if (parsed.content[0] === REGISTER) { if (parsed.user.length === 0) { throw new Error(); } console.log("[" + userPass + "] registered"); - var client = ctx.registeredClients[userPass] = ctx.registeredClients[userPass] || { + var user = ctx.registeredClients[userPass] = ctx.registeredClients[userPass] || { channels: [parsed.channelId], userName: parsed.user }; - if (client.socket && client.socket !== socket) { client.socket.close(); } - client.socket = socket; + if (user.socket && user.socket !== socket) { user.socket.close(); } + user.socket = socket; + user.userPass = userPass; var chan = ctx.channels[parsed.channelId] = ctx.channels[parsed.channelId] || []; var newChan = (chan.length === 0);