yet another attempt at fixing ability to join non-existent lobbies

This commit is contained in:
IM23a-cernik
2025-04-28 14:55:25 +02:00
parent 3f9c08a43c
commit 9b649b25ae
+10 -12
View File
@@ -42,21 +42,19 @@ app.get("/lobby/join", async (req, res) => {
if (!user) { if (!user) {
return res.status(401).json({error: "User doesn't exist"}); return res.status(401).json({error: "User doesn't exist"});
} }
for (let lobby of playerMap) { if (playerMap[lobbyId]) {
if (playerMap[lobby.lobbyId] == lobbyId) { await joinLobby(lobbyId, user.username);
await joinLobby(lobbyId, user.username);
if (!playerMap[lobbyId]) { if (!playerMap[lobbyId]) {
playerMap[lobbyId] = []; playerMap[lobbyId] = [];
} }
if (!playerMap[lobbyId].includes(username)) { if (!playerMap[lobbyId].includes(username)) {
playerMap[lobbyId].push(username); playerMap[lobbyId].push(username);
} }
res.json({lobbyId, username}); res.json({lobbyId, username});
} else console.log("Lobby with " + lobbyId + " not found."); } else console.log("Lobby with " + lobbyId + " not found.");
}
}); });
app.get("/lobby/players", async (req, res) => { app.get("/lobby/players", async (req, res) => {