fix: send gamestructure to players joining a running game
This commit is contained in:
parent
2e839c1768
commit
d46471e601
@ -57,6 +57,7 @@ public class LobbyConnection implements Runnable {
|
|||||||
Logger.trace("Set client state to playing");
|
Logger.trace("Set client state to playing");
|
||||||
participant.getClient().setState(ClientState.Playing);
|
participant.getClient().setState(ClientState.Playing);
|
||||||
participant.state = ParticipantState.Playing;
|
participant.state = ParticipantState.Playing;
|
||||||
|
participant.sendMessage(generateGameStructure(participant.type));
|
||||||
}
|
}
|
||||||
if (participant.type == ParticipantType.Spectator) {
|
if (participant.type == ParticipantType.Spectator) {
|
||||||
Logger.trace("Adding spectator");
|
Logger.trace("Adding spectator");
|
||||||
@ -158,7 +159,7 @@ public class LobbyConnection implements Runnable {
|
|||||||
response.gameID = gameID;
|
response.gameID = gameID;
|
||||||
participant.sendMessage(response);
|
participant.sendMessage(response);
|
||||||
|
|
||||||
sendGameStructure(participant.equals(player1), participant.equals(player2), false);
|
participant.sendMessage(generateGameStructure(participant.type));
|
||||||
|
|
||||||
lobby.handleReconnect(participant);
|
lobby.handleReconnect(participant);
|
||||||
}
|
}
|
||||||
@ -186,7 +187,7 @@ public class LobbyConnection implements Runnable {
|
|||||||
Logger.info("Starting Lobby in main thread for lobby '{}'", gameID);
|
Logger.info("Starting Lobby in main thread for lobby '{}'", gameID);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendGameStructure(true, true, true);
|
broadcastGameStructure(true, true, true);
|
||||||
|
|
||||||
this.lobby = new Lobby(
|
this.lobby = new Lobby(
|
||||||
gameID,
|
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 gameStructureMessage = new GameStructureMessage();
|
||||||
gameStructureMessage.playerOneName = player1.id.getName();
|
gameStructureMessage.playerOneName = player1.id.getName();
|
||||||
gameStructureMessage.playerTwoName = player2.id.getName();
|
gameStructureMessage.playerTwoName = player2.id.getName();
|
||||||
@ -240,21 +248,9 @@ public class LobbyConnection implements Runnable {
|
|||||||
gameStructureMessage.matchconfig = Server.getPartyConfig();
|
gameStructureMessage.matchconfig = Server.getPartyConfig();
|
||||||
gameStructureMessage.scenarioconfig = Server.getScenarioConfig();
|
gameStructureMessage.scenarioconfig = Server.getScenarioConfig();
|
||||||
|
|
||||||
// Sending GameStructure message with fitting assignment
|
gameStructureMessage.assignment = assignment;
|
||||||
if (p1) {
|
|
||||||
gameStructureMessage.assignment = ParticipantType.PlayerOne;
|
|
||||||
player1.sendMessage(gameStructureMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p2) {
|
return gameStructureMessage;
|
||||||
gameStructureMessage.assignment = ParticipantType.PlayerTwo;
|
|
||||||
player2.sendMessage(gameStructureMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (spectators) {
|
|
||||||
gameStructureMessage.assignment = ParticipantType.Spectator;
|
|
||||||
broadcastToSpectators(gameStructureMessage);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Tuple<Participant, Request[]> pollQueueAsync() {
|
private Tuple<Participant, Request[]> pollQueueAsync() {
|
||||||
|
Loading…
Reference in New Issue
Block a user