From 50052b72ffd952aa47afcd8c489f508cfe2d3078 Mon Sep 17 00:00:00 2001 From: Jona Walpert Date: Sat, 11 Apr 2026 21:11:40 +0200 Subject: [PATCH 1/3] Feat: Add get_lobby_listcommand to server --- .../get_lobby_list/GetLobbyListHandler.java | 28 ++++++++++++++ .../get_lobby_list/GetLobbyListParser.java | 17 +++++++++ .../get_lobby_list/GetLobbyListRequest.java | 15 ++++++++ .../get_lobby_list/GetLobbyListResponse.java | 37 +++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListHandler.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListParser.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListRequest.java create mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListResponse.java diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListHandler.java new file mode 100644 index 0000000..49e49d8 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListHandler.java @@ -0,0 +1,28 @@ +package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.lobby.get_lobby_list; + +import ch.unibas.dmi.dbis.cs108.casono.server.domain.lobby.LobbyManager; +import ch.unibas.dmi.dbis.cs108.casono.server.network.command.execution.CommandHandler; +import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher; +import java.util.Collection; + +/** + * Handler for the `GET_LOBBY_LIST` command. + * + *

Queries the {@link LobbyManager} for all available lobbies and dispatches a {@link + * GetLobbyListResponse} containing basic metadata for each lobby (`ID`, `NAME`, `PLAYER_COUNT`). + */ +public class GetLobbyListHandler extends CommandHandler { + private final LobbyManager lobbyManager; + + public GetLobbyListHandler(ResponseDispatcher responseDispatcher, LobbyManager lobbyManager) { + super(responseDispatcher); + this.lobbyManager = lobbyManager; + } + + @Override + public void execute(GetLobbyListRequest request) { + Collection l = + lobbyManager.getAllLobbies(); + responseDispatcher.dispatch(new GetLobbyListResponse(request.getContext(), l)); + } +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListParser.java new file mode 100644 index 0000000..e6dce38 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListParser.java @@ -0,0 +1,17 @@ +package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.lobby.get_lobby_list; + +import ch.unibas.dmi.dbis.cs108.casono.server.network.command.parsing.CommandParser; +import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.PrimitiveRequest; + +/** + * Parser for the `GET_LOBBY_LIST` command. + * + *

Parses the incoming primitive request and produces a {@link GetLobbyListRequest}. This command + * takes no parameters. + */ +public class GetLobbyListParser implements CommandParser { + @Override + public GetLobbyListRequest parse(PrimitiveRequest primitiveRequest) { + return new GetLobbyListRequest(primitiveRequest.context()); + } +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListRequest.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListRequest.java new file mode 100644 index 0000000..ec41e1d --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListRequest.java @@ -0,0 +1,15 @@ +package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.lobby.get_lobby_list; + +import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.Request; +import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestContext; + +/** + * Request object for the `GET_LOBBY_LIST` command. + * + *

Contains only the request context; this command does not require parameters. + */ +public class GetLobbyListRequest extends Request { + public GetLobbyListRequest(RequestContext context) { + super(context); + } +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListResponse.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListResponse.java new file mode 100644 index 0000000..3737189 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/lobby/get_lobby_list/GetLobbyListResponse.java @@ -0,0 +1,37 @@ +package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.lobby.get_lobby_list; + +import ch.unibas.dmi.dbis.cs108.casono.server.domain.lobby.Lobby; +import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestContext; +import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.SuccessResponse; +import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBody; +import java.util.Collection; + +/** + * Success response for `GET_LOBBY_LIST`. + * + *

Builds a `LOBBIES` collection with repeated `LOBBY` blocks containing `ID`, `NAME` and + * `PLAYER_COUNT`. + */ +public class GetLobbyListResponse extends SuccessResponse { + public GetLobbyListResponse(RequestContext context, Collection lobbies) { + super( + context, + ResponseBody.builder() + .block( + "LOBBIES", + lobbies_block -> { + for (Lobby lobby : lobbies) { + lobbies_block.block( + "LOBBY", + lb -> { + lb.param("ID", lobby.getId().value()); + lb.param("NAME", lobby.getName()); + lb.param( + "PLAYER_COUNT", + lobby.getPlayerNames().size()); + }); + } + }) + .build()); + } +} -- 2.52.0 From 13d03637dabe100c2fe887d522083c3c10370a72 Mon Sep 17 00:00:00 2001 From: Jona Walpert Date: Sat, 11 Apr 2026 21:12:03 +0200 Subject: [PATCH 2/3] Add: register get_lobby_list command --- .../dmi/dbis/cs108/casono/server/ServerApp.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/ServerApp.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/ServerApp.java index 881705a..946e711 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/ServerApp.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/ServerApp.java @@ -140,6 +140,20 @@ public class ServerApp { commandRouter.register( ListUsersRequest.class, new ListUsersHandler(responseDispatcher, userRegistry)); + // GET_LOBBY_LIST registration + parserDispatcher.register( + "GET_LOBBY_LIST", + new ch.unibas.dmi.dbis.cs108.casono.server.app.commands.lobby.get_lobby_list + .GetLobbyListParser()); + commandRouter.register( + ch.unibas.dmi.dbis.cs108.casono.server.app.commands.lobby.get_lobby_list + .GetLobbyListRequest.class, + (ch.unibas.dmi.dbis.cs108.casono.server.network.command.execution.CommandHandler< + ch.unibas.dmi.dbis.cs108.casono.server.app.commands.lobby + .get_lobby_list.GetLobbyListRequest>) + new ch.unibas.dmi.dbis.cs108.casono.server.app.commands.lobby.get_lobby_list + .GetLobbyListHandler(responseDispatcher, lobbyManager)); + // JOIN_LOBBY registration parserDispatcher.register( "JOIN_LOBBY", -- 2.52.0 From f467d9ebe216ead3f8ae5c52a7b04e352c5a273a Mon Sep 17 00:00:00 2001 From: Jona Walpert Date: Sat, 11 Apr 2026 21:12:30 +0200 Subject: [PATCH 3/3] Docs: Add new get_lobby_list command --- .../networking/commands/protocol-document.md | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/documents/docs/networking/commands/protocol-document.md b/documents/docs/networking/commands/protocol-document.md index 266bb29..e953ba2 100644 --- a/documents/docs/networking/commands/protocol-document.md +++ b/documents/docs/networking/commands/protocol-document.md @@ -50,6 +50,12 @@ This document describes the protocol for client-server communication in our appl - [Error Response](#error-response-6) - [Example Request](#example-request-4) - [Example Response](#example-response-4) + - [GET_LOBBY_LIST command](#get_lobby_list-command) + - [Required pre-execution checks](#required-pre-execution-checks) + - [Request Parameters](#request-parameters) + - [Success Response](#success-response) + - [Example Request](#example-request) + - [Example Response](#example-response) @@ -515,6 +521,60 @@ END END ``` +## GET_LOBBY_LIST command + +The `GET_LOBBY_LIST` command requests the server to return a list of currently available lobbies with basic metadata. + +### Required pre-execution checks +None. + +### Request Parameters +No parameters. + +### Implementation notes + +- Parser: `GetLobbyListParser` — creates `GetLobbyListRequest` (no parameters). +- Handler: `GetLobbyListHandler` — queries `LobbyManager#getAllLobbies()` and returns `GetLobbyListResponse`. +- Response: `GetLobbyListResponse` — builds a `LOBBIES` collection with repeated `LOBBY` blocks containing `ID`, `NAME`, `PLAYER_COUNT`. + +### Success Response + +The response contains a `LOBBIES` collection with nested `LOBBY` entries. + +Example response structure: + +``` ++OK + LOBBIES + LOBBY + ID=1 + NAME=Room 1 + PLAYER_COUNT=2 + END + LOBBY + ID=2 + NAME=Room 2 + PLAYER_COUNT=3 + END + END +END +``` + +### Example Request + +``` +GET_LOBBY_LIST +``` + +### Example Response (error) + +``` +-ERR + CODE=NO_LOBBIES_AVAILABLE + MESSAGE=No lobbies available +END +``` + ## GET_LOBBY_STATUS command The `GET_LOBBY_STATUS` command requests the server to return the current state of a lobby, including the list of players and their ready state. -- 2.52.0