From 9b649b25aed070c06552d093622141650f7ca22e Mon Sep 17 00:00:00 2001 From: IM23a-cernik Date: Mon, 28 Apr 2025 14:55:25 +0200 Subject: [PATCH] yet another attempt at fixing ability to join non-existent lobbies --- lobby.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lobby.js b/lobby.js index 1d1da9d..d7b7a91 100644 --- a/lobby.js +++ b/lobby.js @@ -42,21 +42,19 @@ app.get("/lobby/join", async (req, res) => { if (!user) { return res.status(401).json({error: "User doesn't exist"}); } - for (let lobby of playerMap) { - if (playerMap[lobby.lobbyId] == lobbyId) { - await joinLobby(lobbyId, user.username); + if (playerMap[lobbyId]) { + await joinLobby(lobbyId, user.username); - if (!playerMap[lobbyId]) { - playerMap[lobbyId] = []; - } + if (!playerMap[lobbyId]) { + playerMap[lobbyId] = []; + } - if (!playerMap[lobbyId].includes(username)) { - playerMap[lobbyId].push(username); - } + if (!playerMap[lobbyId].includes(username)) { + playerMap[lobbyId].push(username); + } - res.json({lobbyId, username}); - } else console.log("Lobby with " + lobbyId + " not found."); - } + res.json({lobbyId, username}); + } else console.log("Lobby with " + lobbyId + " not found."); }); app.get("/lobby/players", async (req, res) => {