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
Showing only changes of commit 15d1ea4edd - Show all commits
@@ -86,26 +86,31 @@ public class ServerApp {
SESSION_DISCONNECT_JOB_PERIOD, SESSION_DISCONNECT_JOB_PERIOD,
TimeUnit.SECONDS); TimeUnit.SECONDS);
registerCommands(dispatcher, router, responseDispatcher, userRegistry); LobbyManager lobbyManager = new LobbyManager();
registerCommands(dispatcher, router, responseDispatcher, userRegistry, lobbyManager);
NetworkManager networkManager = new NetworkManager(port, sessionManager, router); NetworkManager networkManager = new NetworkManager(port, sessionManager, router);
networkManager.start(); networkManager.start();
} }
/** /**
* Registers command parsers and handlers. * Registers command parsers and handlers.
* *
* @param parserDispatcher the dispatcher responsible for parsing incoming commands * @param parserDispatcher the dispatcher responsible for parsing incoming
* @param commandRouter the router that dispatches parsed commands to appropriate handlers * commands
* @param responseDispatcher the dispatcher responsible for sending responses back to clients * @param commandRouter the router that dispatches parsed commands to
*/ * appropriate handlers
private static void registerCommands( * @param responseDispatcher the dispatcher responsible for sending responses
CommandParserDispatcher parserDispatcher, * back to clients
CommandRouter commandRouter, */
ResponseDispatcher responseDispatcher, private static void registerCommands(
UserRegistry userRegistry) { CommandParserDispatcher parserDispatcher,
parserDispatcher.register("PING", new PingParser()); CommandRouter commandRouter,
commandRouter.register(PingRequest.class, new PingHandler(responseDispatcher)); ResponseDispatcher responseDispatcher,
UserRegistry userRegistry,
LobbyManager lobbyManager) {
parserDispatcher.register("PING", new PingParser());
commandRouter.register(PingRequest.class, new PingHandler(responseDispatcher));
parserDispatcher.register("CHECK_USERNAME", new CheckUsernameParser()); parserDispatcher.register("CHECK_USERNAME", new CheckUsernameParser());
commandRouter.register( commandRouter.register(
@@ -134,8 +139,17 @@ public class ServerApp {
GetNextMessageRequest.class, GetNextMessageRequest.class,
new GetNextMessageHandler(responseDispatcher, userRegistry)); new GetNextMessageHandler(responseDispatcher, userRegistry));
parserDispatcher.register("LIST_USERS", new ListUsersParser()); parserDispatcher.register("LIST_USERS", new ListUsersParser());
commandRouter.register( commandRouter.register(
ListUsersRequest.class, new ListUsersHandler(responseDispatcher, userRegistry)); ListUsersRequest.class, new ListUsersHandler(responseDispatcher, userRegistry));
}
// JOIN_LOBBY registration
parserDispatcher.register(
"JOIN_LOBBY",
new ch.unibas.dmi.dbis.cs108.casono.server.app.commands.lobby.join_lobby.JoinLobbyParser());
commandRouter.register(
ch.unibas.dmi.dbis.cs108.casono.server.app.commands.lobby.join_lobby.JoinLobbyRequest.class,
(ch.unibas.dmi.dbis.cs108.casono.server.network.command.execution.CommandHandler<ch.unibas.dmi.dbis.cs108.casono.server.app.commands.lobby.join_lobby.JoinLobbyRequest>) new ch.unibas.dmi.dbis.cs108.casono.server.app.commands.lobby.join_lobby.JoinLobbyHandler(
responseDispatcher, lobbyManager, userRegistry));
}
} }