Fix nodeID being updated at the wrong place

This commit is contained in:
2023-07-31 23:05:52 +02:00
parent 1ffeb082b6
commit 81e23807a8

View File

@@ -87,11 +87,11 @@ wss.on('connection', function connection(ws) {
if(request["register"]){ if(request["register"]){
if(request["register"]["auth_key"] !== process.env.NODE_AUTH_KEY) { if(request["register"]["auth_key"] !== process.env.NODE_AUTH_KEY) {
nodeID = `${nodeID}-${request["register"]["hostname"]}`;
console.log("INVALID AUTH KEY. Disconnecting ", nodeID); console.log("INVALID AUTH KEY. Disconnecting ", nodeID);
ws.close(4000, "Invalid auth key"); ws.close(4000, "Invalid auth key");
return; return;
} }
nodeID = `${nodeID}-${request["register"]["hostname"]}`;
ws.send(JSON.stringify({"welcome": { "clientId": nodeID }})); ws.send(JSON.stringify({"welcome": { "clientId": nodeID }}));
ws.nodeID = nodeID; ws.nodeID = nodeID;
nodes[nodeID] = ws nodes[nodeID] = ws