Merge branch 'feat/lobby-status' into 'main'
Feat: Add STATUS param to GET_LOBBY_STATUS and client parsing See merge request cs108-fs26/Gruppe-13!120
This commit was merged in pull request #276.
This commit is contained in:
@@ -32,7 +32,25 @@ public class LobbyClient {
|
|||||||
* @return A string representing the current status of the lobby, as returned by the server.
|
* @return A string representing the current status of the lobby, as returned by the server.
|
||||||
*/
|
*/
|
||||||
public String fetchLobbyStatusString(int lobbyId) {
|
public String fetchLobbyStatusString(int lobbyId) {
|
||||||
return client.processCommand("GET_LOBBY_STATUS ID=" + lobbyId).getFirst();
|
List<String> lines = client.processCommand("GET_LOBBY_STATUS ID=" + lobbyId);
|
||||||
|
|
||||||
|
// Prefer an explicit STATUS parameter if provided by the server
|
||||||
|
List<RequestParameter> 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+7
@@ -26,6 +26,13 @@ public class GetLobbyStatusResponse extends SuccessResponse {
|
|||||||
"LOBBY",
|
"LOBBY",
|
||||||
lb -> {
|
lb -> {
|
||||||
lb.param("ID", lobby.getId().value());
|
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.param("NAME", lobby.getName());
|
||||||
lb.block(
|
lb.block(
|
||||||
"PLAYERS",
|
"PLAYERS",
|
||||||
|
|||||||
Reference in New Issue
Block a user