fix: send GameStructure on reconnect

This commit is contained in:
punchready 2021-06-07 09:04:18 +02:00
parent efa5ce3848
commit 3be518f13b
2 changed files with 26 additions and 10 deletions

View File

@ -119,14 +119,15 @@ public class LobbyConnection implements Runnable {
public void handleDisconnect(Participant participant) { public void handleDisconnect(Participant participant) {
participant.disconnected = true; participant.disconnected = true;
if(lobby != null) { if(state == LobbyConnectionState.Started) {
lobby.handleDisconnect(participant); lobby.handleDisconnect(participant);
} }
} }
public void handleReconnect(Participant participant) { public void handleReconnect(Participant participant) {
participant.disconnected = false; participant.disconnected = false;
if(lobby != null) { if(state == LobbyConnectionState.Started) {
sendGameStructure(participant.equals(player1), participant.equals(player2), false);
lobby.handleReconnect(participant); lobby.handleReconnect(participant);
} }
} }
@ -144,7 +145,7 @@ public class LobbyConnection implements Runnable {
Logger.info("Starting Lobby thread for lobby '{}'", gameID); Logger.info("Starting Lobby thread for lobby '{}'", gameID);
sendGameStructure(); sendGameStructure(true, true, true);
this.lobby = new Lobby( this.lobby = new Lobby(
gameID, 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 gameStructureMessage = new GameStructureMessage();
gameStructureMessage.playerOneName = player1.id.getName(); gameStructureMessage.playerOneName = player1.id.getName();
gameStructureMessage.playerTwoName = player2.id.getName(); gameStructureMessage.playerTwoName = player2.id.getName();
@ -190,15 +191,21 @@ public class LobbyConnection implements Runnable {
gameStructureMessage.scenarioconfig = Server.getScenarioConfig(); gameStructureMessage.scenarioconfig = Server.getScenarioConfig();
// Sending GameStructure message with fitting assignment // Sending GameStructure message with fitting assignment
if(p1) {
gameStructureMessage.assignment = ParticipantType.PlayerOne; gameStructureMessage.assignment = ParticipantType.PlayerOne;
player1.sendMessage(gameStructureMessage); player1.sendMessage(gameStructureMessage);
}
if(p2) {
gameStructureMessage.assignment = ParticipantType.PlayerTwo; gameStructureMessage.assignment = ParticipantType.PlayerTwo;
player2.sendMessage(gameStructureMessage); player2.sendMessage(gameStructureMessage);
}
if(spectators) {
gameStructureMessage.assignment = ParticipantType.Spectator; gameStructureMessage.assignment = ParticipantType.Spectator;
broadcastToSpectators(gameStructureMessage); broadcastToSpectators(gameStructureMessage);
} }
}
private Tuple<Participant, Request[]> pollQueueAsync() { private Tuple<Participant, Request[]> pollQueueAsync() {
Tuple<Participant, Request[]> current = null; Tuple<Participant, Request[]> current = null;

View File

@ -2,6 +2,7 @@ package uulm.teamname.marvelous.server.lobbymanager;
import uulm.teamname.marvelous.gamelibrary.messages.BasicMessage; import uulm.teamname.marvelous.gamelibrary.messages.BasicMessage;
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType; 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.Client;
import uulm.teamname.marvelous.server.netconnector.SUID; import uulm.teamname.marvelous.server.netconnector.SUID;
@ -41,4 +42,12 @@ public class Participant {
} }
return client.sendMessage(message); 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);
}
} }