Update existing networks with ip and hostmask if null

This commit is contained in:
Pavel Djundik 2016-11-19 22:34:05 +02:00
parent 4078abb085
commit 00548e65d7
2 changed files with 27 additions and 5 deletions

View File

@ -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) {

View File

@ -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) {