From 3be518f13b0e9459680a9629ec3fed80592fe206 Mon Sep 17 00:00:00 2001 From: punchready Date: Mon, 7 Jun 2021 09:04:18 +0200 Subject: [PATCH] fix: send GameStructure on reconnect --- .../server/lobbymanager/LobbyConnection.java | 27 ++++++++++++------- .../server/lobbymanager/Participant.java | 9 +++++++ 2 files changed, 26 insertions(+), 10 deletions(-) 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 5782d6f..aacd547 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 @@ -119,14 +119,15 @@ public class LobbyConnection implements Runnable { public void handleDisconnect(Participant participant) { participant.disconnected = true; - if(lobby != null) { + if(state == LobbyConnectionState.Started) { lobby.handleDisconnect(participant); } } public void handleReconnect(Participant participant) { participant.disconnected = false; - if(lobby != null) { + if(state == LobbyConnectionState.Started) { + sendGameStructure(participant.equals(player1), participant.equals(player2), false); lobby.handleReconnect(participant); } } @@ -144,7 +145,7 @@ public class LobbyConnection implements Runnable { Logger.info("Starting Lobby thread for lobby '{}'", gameID); - sendGameStructure(); + sendGameStructure(true, true, true); this.lobby = new Lobby( gameID, @@ -170,7 +171,7 @@ public class LobbyConnection implements Runnable { } - private void sendGameStructure() { + private void sendGameStructure(boolean p1, boolean p2, boolean spectators) { GameStructureMessage gameStructureMessage = new GameStructureMessage(); gameStructureMessage.playerOneName = player1.id.getName(); gameStructureMessage.playerTwoName = player2.id.getName(); @@ -190,14 +191,20 @@ public class LobbyConnection implements Runnable { gameStructureMessage.scenarioconfig = Server.getScenarioConfig(); // Sending GameStructure message with fitting assignment - gameStructureMessage.assignment = ParticipantType.PlayerOne; - player1.sendMessage(gameStructureMessage); + if(p1) { + gameStructureMessage.assignment = ParticipantType.PlayerOne; + player1.sendMessage(gameStructureMessage); + } - gameStructureMessage.assignment = ParticipantType.PlayerTwo; - player2.sendMessage(gameStructureMessage); + if(p2) { + gameStructureMessage.assignment = ParticipantType.PlayerTwo; + player2.sendMessage(gameStructureMessage); + } - gameStructureMessage.assignment = ParticipantType.Spectator; - broadcastToSpectators(gameStructureMessage); + if(spectators) { + gameStructureMessage.assignment = ParticipantType.Spectator; + broadcastToSpectators(gameStructureMessage); + } } private Tuple pollQueueAsync() { diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/Participant.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/Participant.java index db52ca2..56a72f3 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/Participant.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/Participant.java @@ -2,6 +2,7 @@ package uulm.teamname.marvelous.server.lobbymanager; import uulm.teamname.marvelous.gamelibrary.messages.BasicMessage; import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType; +import uulm.teamname.marvelous.server.lobby.Lobby; import uulm.teamname.marvelous.server.netconnector.Client; import uulm.teamname.marvelous.server.netconnector.SUID; @@ -41,4 +42,12 @@ public class Participant { } return client.sendMessage(message); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Participant other = (Participant) o; + return other.id.equals(id); + } }