fix: fixed a bug where spectators that join aren't in the playing state

This commit is contained in:
Yannik Bretschneider 2021-06-07 17:57:13 +02:00
parent 17eb44ce49
commit 2da32cb397
3 changed files with 14 additions and 7 deletions

View File

@ -2,7 +2,9 @@ package uulm.teamname.marvelous.server.lobby.pipelining;
import org.tinylog.Logger;
import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance;
import uulm.teamname.marvelous.gamelibrary.messages.server.EventMessage;
import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder;
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
import uulm.teamname.marvelous.server.lobby.Lobby;
@ -28,7 +30,10 @@ public class RequestGameStateSegment implements Segment {
Logger.trace("RequestGameStateSegment received {} requests", packet.size());
if (packet.containsRequestOfType(RequestType.Req)) {
Logger.trace("Req event found. Returning Gamestate, and clearing entire RequestList");
carrier.add(game.getGameStateEvent());
var gamestateEventMessage = new EventMessage();
gamestateEventMessage.messages = new Event[] {game.getGameStateEvent()};
packet.getOrigin().sendMessage(gamestateEventMessage);
carrier.clear();
packet.clear();
}
}

View File

@ -49,17 +49,18 @@ public class LobbyConnection implements Runnable {
}
public void addParticipant(Participant participant) {
if (this.state == LobbyConnectionState.Started) {
if (this.state == LobbyConnectionState.Started || this.player1.state == ParticipantState.Playing) {
Logger.trace("Set client state to playing");
participant.getClient().state = ClientState.Playing;
participant.state = ParticipantState.Playing;
}
if(participant.type == ParticipantType.Spectator) {
Logger.trace("Adding spectator");
spectators.add(participant);
return;
}
if(participant.type == ParticipantType.PlayerOne) {
} else if(participant.type == ParticipantType.PlayerOne) {
player1 = participant;
}else {
} else {
player2 = participant;
}
}

View File

@ -4,5 +4,6 @@ public enum ClientState {
Blank,
Ready,
Assigned,
Reconnect, Playing
Reconnect,
Playing
}