Feat: Add addPlayer command on sever side #258

Merged
jona.walpert merged 13 commits from feat/97-add-joinlobby-command-on-server-side into main 2026-04-11 19:49:57 +02:00
3 changed files with 17 additions and 21 deletions
Showing only changes of commit de0d0f93f8 - Show all commits
@@ -13,12 +13,10 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatch
/** /**
* Handler for the `JOIN_LOBBY` command. * Handler for the `JOIN_LOBBY` command.
* *
* <p> * <p>Resolves the username from the session (requires {@link UserLoggedInCheck}), looks up the
* Resolves the username from the session (requires {@link UserLoggedInCheck}), * target lobby and attempts to add the user. On success an `+OK` response is dispatched; on failure
* looks up the target lobby and attempts to add the user. On success an * an appropriate {@link ErrorResponse} with one of the error codes `LOBBY_NOT_FOUND`,
* `+OK` response is dispatched; on failure an appropriate {@link ErrorResponse} * `USER_NOT_LOGGED_IN` or `LOBBY_FULL_OR_ALREADY_IN` is returned.
* with one of the error codes `LOBBY_NOT_FOUND`, `USER_NOT_LOGGED_IN` or
* `LOBBY_FULL_OR_ALREADY_IN` is returned.
*/ */
public class JoinLobbyHandler extends CommandHandler<JoinLobbyRequest> { public class JoinLobbyHandler extends CommandHandler<JoinLobbyRequest> {
private final LobbyManager lobbyManager; private final LobbyManager lobbyManager;
@@ -27,8 +25,7 @@ public class JoinLobbyHandler extends CommandHandler<JoinLobbyRequest> {
/** /**
* Create a new {@link JoinLobbyHandler}. * Create a new {@link JoinLobbyHandler}.
* *
* @param responseDispatcher dispatcher used to send responses back to the * @param responseDispatcher dispatcher used to send responses back to the client
* client
* @param lobbyManager manager providing lobby state and operations * @param lobbyManager manager providing lobby state and operations
* @param userRegistry registry to resolve session -> user mappings * @param userRegistry registry to resolve session -> user mappings
*/ */
@@ -7,15 +7,14 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.accessor.
/** /**
* Parser for the `JOIN_LOBBY` command. * Parser for the `JOIN_LOBBY` command.
* *
* <p> * <p>Expected request parameters:
* Expected request parameters: *
* <ul> * <ul>
* <li>`ID` (int) — numeric lobby identifier (required) * <li>`ID` (int) — numeric lobby identifier (required)
* </ul> * </ul>
* *
* <p> * <p>The parser builds a {@link JoinLobbyRequest} containing the parsed lobby id and the original
* The parser builds a {@link JoinLobbyRequest} containing the parsed lobby id * request context.
* and the original request context.
*/ */
public class JoinLobbyParser implements CommandParser<JoinLobbyRequest> { public class JoinLobbyParser implements CommandParser<JoinLobbyRequest> {
/** /**
@@ -26,7 +25,8 @@ public class JoinLobbyParser implements CommandParser<JoinLobbyRequest> {
*/ */
@Override @Override
public JoinLobbyRequest parse(PrimitiveRequest primitiveRequest) { public JoinLobbyRequest parse(PrimitiveRequest primitiveRequest) {
RequestParameterAccessor accessor = new RequestParameterAccessor(primitiveRequest.parameters()); RequestParameterAccessor accessor =
new RequestParameterAccessor(primitiveRequest.parameters());
int id = accessor.require("ID", Integer::parseInt); int id = accessor.require("ID", Integer::parseInt);
return new JoinLobbyRequest(primitiveRequest.context(), id); return new JoinLobbyRequest(primitiveRequest.context(), id);
} }
@@ -6,9 +6,8 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestCo
/** /**
* Request data for the `JOIN_LOBBY` command. * Request data for the `JOIN_LOBBY` command.
* *
* <p> * <p>Contains the lobby id the client wants to join and inherits the {@link Request} contextual
* Contains the lobby id the client wants to join and inherits the * information.
* {@link Request} contextual information.
*/ */
public class JoinLobbyRequest extends Request { public class JoinLobbyRequest extends Request {
private final int id; private final int id;