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,14 +191,20 @@ 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
gameStructureMessage.assignment = ParticipantType.PlayerOne; if(p1) {
player1.sendMessage(gameStructureMessage); gameStructureMessage.assignment = ParticipantType.PlayerOne;
player1.sendMessage(gameStructureMessage);
}
gameStructureMessage.assignment = ParticipantType.PlayerTwo; if(p2) {
player2.sendMessage(gameStructureMessage); gameStructureMessage.assignment = ParticipantType.PlayerTwo;
player2.sendMessage(gameStructureMessage);
}
gameStructureMessage.assignment = ParticipantType.Spectator; if(spectators) {
broadcastToSpectators(gameStructureMessage); gameStructureMessage.assignment = ParticipantType.Spectator;
broadcastToSpectators(gameStructureMessage);
}
} }
private Tuple<Participant, Request[]> pollQueueAsync() { private Tuple<Participant, Request[]> pollQueueAsync() {

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);
}
} }