From 346a728fb9f778bd5e8062ffc2e582377a6acdc3 Mon Sep 17 00:00:00 2001 From: Jona Walpert Date: Sun, 12 Apr 2026 13:53:23 +0200 Subject: [PATCH] Feat): Add STATUS param to GET_LOBBY_STATUS and client parsing --- .../casono/client/network/LobbyClient.java | 20 ++++++++++++++++++- .../GetLobbyStatusResponse.java | 7 +++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/network/LobbyClient.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/network/LobbyClient.java index 9f6f4a8..8687873 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/network/LobbyClient.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/network/LobbyClient.java @@ -32,7 +32,25 @@ public class LobbyClient { * @return A string representing the current status of the lobby, as returned by the server. */ public String fetchLobbyStatusString(int lobbyId) { - return client.processCommand("GET_LOBBY_STATUS ID=" + lobbyId).getFirst(); + List lines = client.processCommand("GET_LOBBY_STATUS ID=" + lobbyId); + + // Prefer an explicit STATUS parameter if provided by the server + List params = ClientService.convertToRequestParameters(lines); + for (RequestParameter p : params) { + if ("STATUS".equalsIgnoreCase(p.key())) { + return p.value(); + } + } + + // Fallback: look for plain status tokens in the body + for (String l : lines) { + String t = l.trim(); + if ("CREATED".equalsIgnoreCase(t) || "RUNNING".equalsIgnoreCase(t)) { + return t; + } + } + + return null; } /** diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_status/GetLobbyStatusResponse.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_status/GetLobbyStatusResponse.java index 043eb3d..11f0149 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_status/GetLobbyStatusResponse.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_status/GetLobbyStatusResponse.java @@ -26,6 +26,13 @@ public class GetLobbyStatusResponse extends SuccessResponse { "LOBBY", lb -> { lb.param("ID", lobby.getId().value()); + // STATUS indicates whether a game has been started in this + // lobby + lb.param( + "STATUS", + lobby.getGameController() == null + ? "CREATED" + : "RUNNING"); lb.param("NAME", lobby.getName()); lb.block( "PLAYERS", -- 2.52.0