From b7de24c85f161e6c01c55fe7e0735a1548291740 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sat, 30 Oct 2021 01:31:17 -0400 Subject: [PATCH] PadMessageHandler: Fix readability of duplicate user check --- src/node/handler/PadMessageHandler.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index a005eb922..38c359a39 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -847,13 +847,15 @@ const handleClientReady = async (socket, message) => { // Check if this author is already on the pad, if yes, kick the other sessions! const roomSockets = _getRoomSockets(pad.id); - for (const socket of roomSockets) { - const sinfo = sessioninfos[socket.id]; + for (const otherSocket of roomSockets) { + // The user shouldn't have joined the room yet, but check anyway just in case. + if (otherSocket.id === socket.id) continue; + const sinfo = sessioninfos[otherSocket.id]; if (sinfo && sinfo.author === sessionInfo.author) { // fix user's counter, works on page refresh or if user closes browser window and then rejoins - sessioninfos[socket.id] = {}; - socket.leave(padIds.padId); - socket.json.send({disconnect: 'userdup'}); + sessioninfos[otherSocket.id] = {}; + otherSocket.leave(padIds.padId); + otherSocket.json.send({disconnect: 'userdup'}); } }