From e029106a1167549d78fd83d8fa5bfd220e5e5998 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Sun, 6 Jun 2021 21:35:48 +0200 Subject: [PATCH] refactor: extracted method in LobbyManager --- .../server/lobbymanager/LobbyManager.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyManager.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyManager.java index c02e45f..b31d366 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyManager.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyManager.java @@ -60,7 +60,7 @@ public class LobbyManager { targetedLobby = initializeNewLobby(resourceDescriptor); } else { Logger.info("No free lobby spot available, sending error and disconnecting Client"); - + // TODO: Implement this! } } else if (targetedLobby.isFull() && !message.role.equals(RoleEnum.SPECTATOR)) { @@ -100,9 +100,9 @@ public class LobbyManager { synchronized (lobbies) { lobbies.put(participant, targetedLobby); } - if (targetedLobby.isFull() && !LobbyRunner.getInstance().isStarted(targetedLobby)) { - Logger.info("Lobby '{}' was full, starting...", targetedLobby.gameID); - LobbyRunner.getInstance().startLobby(targetedLobby); + if (targetedLobby.isFull()) { + Logger.trace("Lobby is full, checking whether to start lobby or not"); + startLobby(targetedLobby); } } return participant; @@ -174,7 +174,14 @@ public class LobbyManager { } Logger.trace("Returning local resourceDescriptor"); return localResourceDescriptor; + } + /** Checks whether the current lobby is already started, and if that is not the case, starts it */ + private void startLobby(LobbyConnection targetedLobby) { + if (!LobbyRunner.getInstance().isStarted(targetedLobby)) { + Logger.info("Starting Lobby '{}' ...", targetedLobby.gameID); + LobbyRunner.getInstance().startLobby(targetedLobby); + } } /** A method to obtain the lobbies HashMap. Meant for testing, and shouldn't be used anywhere else. */