From 9f728a2e94ba17a59063bf072e41833b2f81b909 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 3 Jan 2019 21:02:21 -0700 Subject: [PATCH] Fix longstanding bug with node IDs --- core/client_connections.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/core/client_connections.js b/core/client_connections.js index 558d0a0f..33f1df8a 100644 --- a/core/client_connections.js +++ b/core/client_connections.js @@ -60,12 +60,25 @@ function getActiveConnectionList(authUsersOnly) { } function addNewClient(client, clientSock) { - const id = client.session.id = clientConnections.push(client) - 1; - const remoteAddress = client.remoteAddress = clientSock.remoteAddress; + // + // Assign ID/client ID to next lowest & available # + // + let id = 0; + for(let i = 0; i < clientConnections.length; ++i) { + if(clientConnections[i].id > id) { + break; + } + id++; + } + client.session.id = id; + const remoteAddress = client.remoteAddress = clientSock.remoteAddress; // create a unique identifier one-time ID for this session client.session.uniqueId = new hashids('ENiGMA½ClientSession').encode([ id, moment().valueOf() ]); + clientConnections.push(client); + clientConnections.sort( (c1, c2) => c1.session.id - c2.session.id); + // Create a client specific logger // Note that this will be updated @ login with additional information client.log = logger.log.child( { clientId : id, sessionId : client.session.uniqueId } );