fix: fixed bug where spectators joining later won't be able to send events
This commit is contained in:
parent
0248eaf154
commit
383fa456fc
@ -11,6 +11,7 @@ import uulm.teamname.marvelous.gamelibrary.messages.server.*;
|
|||||||
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||||
import uulm.teamname.marvelous.server.Server;
|
import uulm.teamname.marvelous.server.Server;
|
||||||
import uulm.teamname.marvelous.server.lobby.Lobby;
|
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.SUID;
|
||||||
import uulm.teamname.marvelous.server.netconnector.UserManager;
|
import uulm.teamname.marvelous.server.netconnector.UserManager;
|
||||||
|
|
||||||
@ -48,6 +49,9 @@ public class LobbyConnection implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addParticipant(Participant participant) {
|
public void addParticipant(Participant participant) {
|
||||||
|
if (this.state == LobbyConnectionState.Started) {
|
||||||
|
participant.getClient().state = ClientState.Playing;
|
||||||
|
}
|
||||||
if(participant.type == ParticipantType.Spectator) {
|
if(participant.type == ParticipantType.Spectator) {
|
||||||
spectators.add(participant);
|
spectators.add(participant);
|
||||||
return;
|
return;
|
||||||
@ -60,19 +64,19 @@ public class LobbyConnection implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Disconnects a participant from the LobbyConnection */
|
||||||
public void removeParticipant(Participant participant) {
|
public void removeParticipant(Participant participant) {
|
||||||
removeParticipant(participant, "You have been disconnected.");
|
removeParticipant(participant, "You have been disconnected.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Disconnects a participant from the LobbyConnection */
|
||||||
public void removeParticipant(Participant participant, String reason) {
|
public void removeParticipant(Participant participant, String reason) {
|
||||||
LobbyManager.getInstance().removeParticipant(participant);
|
LobbyManager.getInstance().removeParticipant(participant);
|
||||||
UserManager.getInstance().removeClient(participant.getClient(), reason);
|
UserManager.getInstance().removeClient(participant.getClient(), reason);
|
||||||
|
|
||||||
if(participant.type == ParticipantType.Spectator) {
|
if(participant.type == ParticipantType.Spectator) {
|
||||||
spectators.remove(participant);
|
spectators.remove(participant);
|
||||||
}
|
} else if(participant.type == ParticipantType.PlayerOne) {
|
||||||
|
|
||||||
if(participant.type == ParticipantType.PlayerOne) {
|
|
||||||
player1 = null;
|
player1 = null;
|
||||||
}else {
|
}else {
|
||||||
player2 = null;
|
player2 = null;
|
||||||
@ -104,6 +108,8 @@ public class LobbyConnection implements Runnable {
|
|||||||
return player2;
|
return player2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashSet<Participant> getSpectators() {return spectators;}
|
||||||
|
|
||||||
public boolean hasPlayer1() {
|
public boolean hasPlayer1() {
|
||||||
return player1 != null;
|
return player1 != null;
|
||||||
}
|
}
|
||||||
@ -246,10 +252,12 @@ public class LobbyConnection implements Runnable {
|
|||||||
|
|
||||||
|
|
||||||
public void sendEvents(Participant recipient, Event... events) {
|
public void sendEvents(Participant recipient, Event... events) {
|
||||||
EventMessage message = new EventMessage();
|
if (recipient != null) {
|
||||||
message.messages = events;
|
EventMessage message = new EventMessage();
|
||||||
|
message.messages = events;
|
||||||
|
|
||||||
recipient.sendMessage(message);
|
recipient.sendMessage(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void broadcastEvents(List<Event> events) {
|
public void broadcastEvents(List<Event> events) {
|
||||||
|
Loading…
Reference in New Issue
Block a user