refactor: extracted method in LobbyManager

This commit is contained in:
Yannik Bretschneider 2021-06-06 21:35:48 +02:00
parent 3ab8d57829
commit e029106a11

View File

@ -60,7 +60,7 @@ public class LobbyManager {
targetedLobby = initializeNewLobby(resourceDescriptor); targetedLobby = initializeNewLobby(resourceDescriptor);
} else { } else {
Logger.info("No free lobby spot available, sending error and disconnecting Client"); Logger.info("No free lobby spot available, sending error and disconnecting Client");
// TODO: Implement this!
} }
} else if (targetedLobby.isFull() && !message.role.equals(RoleEnum.SPECTATOR)) { } else if (targetedLobby.isFull() && !message.role.equals(RoleEnum.SPECTATOR)) {
@ -100,9 +100,9 @@ public class LobbyManager {
synchronized (lobbies) { synchronized (lobbies) {
lobbies.put(participant, targetedLobby); lobbies.put(participant, targetedLobby);
} }
if (targetedLobby.isFull() && !LobbyRunner.getInstance().isStarted(targetedLobby)) { if (targetedLobby.isFull()) {
Logger.info("Lobby '{}' was full, starting...", targetedLobby.gameID); Logger.trace("Lobby is full, checking whether to start lobby or not");
LobbyRunner.getInstance().startLobby(targetedLobby); startLobby(targetedLobby);
} }
} }
return participant; return participant;
@ -174,7 +174,14 @@ public class LobbyManager {
} }
Logger.trace("Returning local resourceDescriptor"); Logger.trace("Returning local resourceDescriptor");
return localResourceDescriptor; 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. */ /** A method to obtain the lobbies HashMap. Meant for testing, and shouldn't be used anywhere else. */