fix: fixed bug where spectators joining later won't be able to send events

This commit is contained in:
Yannik Bretschneider 2021-06-07 17:47:22 +02:00
parent 0248eaf154
commit 383fa456fc
1 changed files with 14 additions and 6 deletions

View File

@ -11,6 +11,7 @@ import uulm.teamname.marvelous.gamelibrary.messages.server.*;
import uulm.teamname.marvelous.gamelibrary.requests.Request;
import uulm.teamname.marvelous.server.Server;
import uulm.teamname.marvelous.server.lobby.Lobby;
import uulm.teamname.marvelous.server.netconnector.ClientState;
import uulm.teamname.marvelous.server.netconnector.SUID;
import uulm.teamname.marvelous.server.netconnector.UserManager;
@ -48,6 +49,9 @@ public class LobbyConnection implements Runnable {
}
public void addParticipant(Participant participant) {
if (this.state == LobbyConnectionState.Started) {
participant.getClient().state = ClientState.Playing;
}
if(participant.type == ParticipantType.Spectator) {
spectators.add(participant);
return;
@ -60,19 +64,19 @@ public class LobbyConnection implements Runnable {
}
}
/** Disconnects a participant from the LobbyConnection */
public void removeParticipant(Participant participant) {
removeParticipant(participant, "You have been disconnected.");
}
/** Disconnects a participant from the LobbyConnection */
public void removeParticipant(Participant participant, String reason) {
LobbyManager.getInstance().removeParticipant(participant);
UserManager.getInstance().removeClient(participant.getClient(), reason);
if(participant.type == ParticipantType.Spectator) {
spectators.remove(participant);
}
if(participant.type == ParticipantType.PlayerOne) {
} else if(participant.type == ParticipantType.PlayerOne) {
player1 = null;
}else {
player2 = null;
@ -104,6 +108,8 @@ public class LobbyConnection implements Runnable {
return player2;
}
public HashSet<Participant> getSpectators() {return spectators;}
public boolean hasPlayer1() {
return player1 != null;
}
@ -246,10 +252,12 @@ public class LobbyConnection implements Runnable {
public void sendEvents(Participant recipient, Event... events) {
EventMessage message = new EventMessage();
message.messages = events;
if (recipient != null) {
EventMessage message = new EventMessage();
message.messages = events;
recipient.sendMessage(message);
recipient.sendMessage(message);
}
}
public void broadcastEvents(List<Event> events) {