From 00548e65d79dcd1f083c9068412362c8d334d5ba Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sat, 19 Nov 2016 22:34:05 +0200 Subject: [PATCH] Update existing networks with ip and hostmask if null --- src/client.js | 26 +++++++++++++++++++++++++- src/server.js | 6 ++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/client.js b/src/client.js index e9310e65..919a3f90 100644 --- a/src/client.js +++ b/src/client.js @@ -463,7 +463,31 @@ Client.prototype.quit = function() { }; Client.prototype.clientAttach = function(socketId) { - this.attachedClients[socketId] = this.lastActiveChannel; + var client = this; + var save = false; + + client.attachedClients[socketId] = client.lastActiveChannel; + + // Update old networks to store ip and hostmask + client.networks.forEach(network => { + if (!network.ip) { + save = true; + network.ip = (client.config && client.config.ip) || client.ip; + } + + if (!network.hostname) { + var hostmask = (client.config && client.config.hostname) || client.hostname; + + if (hostmask) { + save = true; + network.hostmask = hostmask; + } + } + }); + + if (save) { + client.save(); + } }; Client.prototype.clientDetach = function(socketId) { diff --git a/src/server.js b/src/server.js index f77a3748..94df9003 100644 --- a/src/server.js +++ b/src/server.js @@ -143,15 +143,13 @@ function init(socket, client) { } else { socket.emit("authorized"); + client.ip = getClientIp(socket.request); + socket.on("disconnect", function() { client.clientDetach(socket.id); }); client.clientAttach(socket.id); - if (!client.ip) { - client.ip = getClientIp(socket.request); - } - socket.on( "input", function(data) {