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 } );