Server/Server/src/main/java/uulm/teamname/marvelous/server/game/pipelining/FilterEndRoundRequestSegmen...

42 lines
1.7 KiB
Java

package uulm.teamname.marvelous.server.game.pipelining;
import org.tinylog.Logger;
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance;
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType;
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
import uulm.teamname.marvelous.server.game.GameSession;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* {@link Segment} that checks for an {@link RequestType#EndRoundRequest}, and
* if it exists, checks for the player that has sent it. If the player sending
* this request is not the active player, it flags the message as an error.
*/
public class FilterEndRoundRequestSegment implements Segment {
private final GameSession parent;
public FilterEndRoundRequestSegment(GameSession parent) {
this.parent = parent;
}
@Override
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
Logger.trace("FilterEndRoundSegment has received {} requests", packet.size());
if(packet.containsRequestOfType(RequestType.EndRoundRequest)) {
Logger.trace("Packet contains EndRoundRequest");
var active = parent.getInstance().state.getActiveCharacter().type;
var from = packet.getOrigin().getType() == ParticipantType.PlayerOne ? EntityType.P1 : EntityType.P2;
if(active != from) {
Logger.trace("Invalid endRoundRequest. Expected {} but got {}. Aborting...", active, from);
abort.set(true);
}
}
}
}