42 lines
1.6 KiB
Java
42 lines
1.6 KiB
Java
package uulm.teamname.marvelous.server.lobby.pipelining;
|
|
|
|
import org.tinylog.Logger;
|
|
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
|
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType;
|
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
|
import uulm.teamname.marvelous.server.lobby.Lobby;
|
|
|
|
import java.util.List;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
/**
|
|
* The {@link DisconnectSegment} handles requests of {@link RequestType} DisconnectRequest. Therefore it removes the
|
|
* disconnecting player-connection from the {@link Lobby}.
|
|
*/
|
|
public class DisconnectSegment implements Segment {
|
|
|
|
private final Lobby parent;
|
|
|
|
public DisconnectSegment(Lobby parent) {
|
|
this.parent = parent;
|
|
}
|
|
|
|
@Override
|
|
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort) {
|
|
Logger.trace("DisconnectSegment received {} requests.", packet.size());
|
|
if (packet.containsRequestOfType(RequestType.DisconnectRequest)) {
|
|
Logger.debug("Player of Type {} sent DisconnectRequest", packet.getOrigin().type);
|
|
parent.getConnection().removeParticipant(packet.getOrigin());
|
|
|
|
if (packet.getOrigin().type != ParticipantType.Spectator) {
|
|
if (parent.getConnection().hasPlayer1()) {
|
|
parent.triggerWin(parent.getConnection().getPlayer1());
|
|
} else if (parent.getConnection().hasPlayer2()) {
|
|
parent.triggerWin(parent.getConnection().getPlayer2());
|
|
}
|
|
}
|
|
packet.clear();
|
|
}
|
|
}
|
|
}
|