another attempt at fixing ability to join non-existent lobbies
This commit is contained in:
@@ -16,10 +16,10 @@ async function createLobby() {
|
||||
}
|
||||
|
||||
async function joinLobby(lobbyId, player_name) {
|
||||
if (playerMap[lobbyId]) {
|
||||
let response = await fetch(`https://www.deckofcardsapi.com/api/deck/${lobbyId}/pile/${player_name}/add/?cards=`)
|
||||
console.log(response);
|
||||
} else console.log("Lobby with "+lobbyId+" not found.");
|
||||
|
||||
let response = await fetch(`https://www.deckofcardsapi.com/api/deck/${lobbyId}/pile/${player_name}/add/?cards=`)
|
||||
console.log(response);
|
||||
|
||||
}
|
||||
|
||||
app.get("/lobby/create", async (req, res) => {
|
||||
@@ -42,18 +42,21 @@ 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);
|
||||
|
||||
await joinLobby(lobbyId, user.username);
|
||||
if (!playerMap[lobbyId]) {
|
||||
playerMap[lobbyId] = [];
|
||||
}
|
||||
|
||||
if (!playerMap[lobbyId]) {
|
||||
playerMap[lobbyId] = [];
|
||||
if (!playerMap[lobbyId].includes(username)) {
|
||||
playerMap[lobbyId].push(username);
|
||||
}
|
||||
|
||||
res.json({lobbyId, username});
|
||||
} else console.log("Lobby with " + lobbyId + " not found.");
|
||||
}
|
||||
|
||||
if (!playerMap[lobbyId].includes(username)) {
|
||||
playerMap[lobbyId].push(username);
|
||||
}
|
||||
|
||||
res.json({lobbyId, username});
|
||||
});
|
||||
|
||||
app.get("/lobby/players", async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user