diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java index b25f55d..0d69d39 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java @@ -57,6 +57,7 @@ public class LobbyConnection implements Runnable { Logger.trace("Set client state to playing"); participant.getClient().setState(ClientState.Playing); participant.state = ParticipantState.Playing; + participant.sendMessage(generateGameStructure(participant.type)); } if (participant.type == ParticipantType.Spectator) { Logger.trace("Adding spectator"); @@ -158,7 +159,7 @@ public class LobbyConnection implements Runnable { response.gameID = gameID; participant.sendMessage(response); - sendGameStructure(participant.equals(player1), participant.equals(player2), false); + participant.sendMessage(generateGameStructure(participant.type)); lobby.handleReconnect(participant); } @@ -186,7 +187,7 @@ public class LobbyConnection implements Runnable { Logger.info("Starting Lobby in main thread for lobby '{}'", gameID); } - sendGameStructure(true, true, true); + broadcastGameStructure(true, true, true); this.lobby = new Lobby( gameID, @@ -221,7 +222,14 @@ public class LobbyConnection implements Runnable { } - private void sendGameStructure(boolean p1, boolean p2, boolean spectators) { + private void broadcastGameStructure() { + // Sending GameStructure message with fitting assignment + player1.sendMessage(generateGameStructure(ParticipantType.PlayerOne)); + player2.sendMessage(generateGameStructure(ParticipantType.PlayerTwo)); + broadcastToSpectators(generateGameStructure(ParticipantType.Spectator)); + } + + private GameStructureMessage generateGameStructure(ParticipantType assignment) { GameStructureMessage gameStructureMessage = new GameStructureMessage(); gameStructureMessage.playerOneName = player1.id.getName(); gameStructureMessage.playerTwoName = player2.id.getName(); @@ -240,21 +248,9 @@ public class LobbyConnection implements Runnable { gameStructureMessage.matchconfig = Server.getPartyConfig(); gameStructureMessage.scenarioconfig = Server.getScenarioConfig(); - // Sending GameStructure message with fitting assignment - if (p1) { - gameStructureMessage.assignment = ParticipantType.PlayerOne; - player1.sendMessage(gameStructureMessage); - } + gameStructureMessage.assignment = assignment; - if (p2) { - gameStructureMessage.assignment = ParticipantType.PlayerTwo; - player2.sendMessage(gameStructureMessage); - } - - if (spectators) { - gameStructureMessage.assignment = ParticipantType.Spectator; - broadcastToSpectators(gameStructureMessage); - } + return gameStructureMessage; } private Tuple pollQueueAsync() {