Refactor
This commit is contained in:
@@ -238,9 +238,11 @@ app.get("/lobby/join", authenticateToken, async (req, res) => {
|
||||
app.delete("/lobby/leave", authenticateToken, async (req, res) => {
|
||||
const lobbyId = req.query.lobbyId;
|
||||
const username = req.query.username;
|
||||
|
||||
if (!lobbyId || !username) {
|
||||
return res.status(400).json({ error: "Missing lobbyId or username" });
|
||||
}
|
||||
|
||||
if (lobbyId in playerMap) {
|
||||
const index = playerMap[lobbyId].indexOf(username);
|
||||
if (index > -1) {
|
||||
@@ -250,9 +252,11 @@ app.delete("/lobby/leave", authenticateToken, async (req, res) => {
|
||||
return res.status(404).json({ error: "User not in lobby" });
|
||||
}
|
||||
}
|
||||
|
||||
res.status(404).json({ error: "Lobby not found" });
|
||||
});
|
||||
|
||||
|
||||
app.get("/lobby/players", authenticateToken, async (req, res) => {
|
||||
let lobbyId = req.query.lobbyId;
|
||||
let players = playerMap[lobbyId] || [];
|
||||
|
||||
Reference in New Issue
Block a user