From 6eb16a2514758a868207d5eaa5eccea8be512e50 Mon Sep 17 00:00:00 2001 From: Richard Reiber Date: Mon, 31 May 2021 19:49:48 +0200 Subject: [PATCH] update: added some Segments for Pipelining --- .../marvelous/server/lobby/Lobby.java | 10 +++++ .../lobby/pipelining/DisconnectSegment.java | 35 +++++++++++++++ .../lobby/pipelining/GameStateSegment.java | 43 +++++++++++++++++++ .../pipelining/RequestGameStateSegment.java | 27 ++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/DisconnectSegment.java create mode 100644 Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/GameStateSegment.java create mode 100644 Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameStateSegment.java diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java index 9e4aa05..8922cb6 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java @@ -8,6 +8,9 @@ import uulm.teamname.marvelous.gamelibrary.gamelogic.EventObserver; import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance; import uulm.teamname.marvelous.gamelibrary.requests.Request; import uulm.teamname.marvelous.gamelibrary.requests.RequestType; +import uulm.teamname.marvelous.server.lobby.pipelining.PauseSegment; +import uulm.teamname.marvelous.server.lobby.pipelining.Pipeline; +import uulm.teamname.marvelous.server.lobby.pipelining.RequestGameStateSegment; import uulm.teamname.marvelous.server.lobbymanager.LobbyConnection; import uulm.teamname.marvelous.server.lobbymanager.Participant; @@ -17,6 +20,9 @@ public class Lobby extends EventObserver { public final String gameID; public final LobbyConnection connection; public final GameInstance game; + public final Pipeline pipeline; + public final PauseSegment pauseSegment; + public final RequestGameStateSegment reqSegment; private final PauseHandler pause = new PauseHandler(); public Lobby(String gameID, IntVector2 mapSize, LobbyConnection connection) { @@ -25,6 +31,10 @@ public class Lobby extends EventObserver { game = new GameInstance(mapSize); game.addObserver(this); + + this.pipeline = new Pipeline(); + this.pauseSegment = new PauseSegment(); + this.reqSegment = new RequestGameStateSegment(this); } @Override diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/DisconnectSegment.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/DisconnectSegment.java new file mode 100644 index 0000000..e687130 --- /dev/null +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/DisconnectSegment.java @@ -0,0 +1,35 @@ +package uulm.teamname.marvelous.server.lobby.pipelining; + +import uulm.teamname.marvelous.gamelibrary.entities.Entity; +import uulm.teamname.marvelous.gamelibrary.events.EntityEvent; +import uulm.teamname.marvelous.gamelibrary.events.Event; +import uulm.teamname.marvelous.gamelibrary.events.EventBuilder; +import uulm.teamname.marvelous.gamelibrary.events.EventType; +import uulm.teamname.marvelous.gamelibrary.requests.Request; +import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder; +import uulm.teamname.marvelous.gamelibrary.requests.RequestType; +import uulm.teamname.marvelous.server.lobby.Lobby; +import uulm.teamname.marvelous.server.lobbymanager.Participant; + +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +public class DisconnectSegment implements Segment { + private final Lobby parent; + private final Participant player; + public DisconnectSegment(Lobby parent, Participant player){ + this.parent = parent; + this.player = player; + } + + + @Override + public void processRequests(List packet, List carrier, AtomicBoolean abort) { + if (packet.contains(new RequestBuilder(RequestType.DisconnectRequest).buildGameRequest())) { + carrier.add(new EventBuilder(EventType.DisconnectEvent).buildGameEvent()); + parent.connection.removePlayer(player); + } + + packet.clear(); + } +} diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/GameStateSegment.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/GameStateSegment.java new file mode 100644 index 0000000..dd1cde1 --- /dev/null +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/GameStateSegment.java @@ -0,0 +1,43 @@ +package uulm.teamname.marvelous.server.lobby.pipelining; + +import uulm.teamname.marvelous.gamelibrary.events.Event; +import uulm.teamname.marvelous.gamelibrary.events.EventBuilder; +import uulm.teamname.marvelous.gamelibrary.events.EventType; +import uulm.teamname.marvelous.gamelibrary.requests.Request; +import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder; +import uulm.teamname.marvelous.gamelibrary.requests.RequestType; +import uulm.teamname.marvelous.server.lobby.Lobby; + +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +public class GameStateSegment implements Segment{ + private Lobby parent; + + public GameStateSegment(Lobby parent){ + this.parent = parent; + } + + @Override + public void processRequests(List packet, List carrier, AtomicBoolean abort) { + if (packet.contains(new RequestBuilder(RequestType.MeleeAttackRequest).buildGameRequest())) { + carrier.add(new EventBuilder(EventType.MeleeAttackEvent).buildGameEvent()); + } + if (packet.contains(new RequestBuilder(RequestType.RangedAttackRequest).buildGameRequest())) { + carrier.add(new EventBuilder(EventType.RangedAttackEvent).buildGameEvent()); + } + if (packet.contains(new RequestBuilder(RequestType.MoveRequest).buildGameRequest())) { + carrier.add(new EventBuilder(EventType.MoveEvent).buildGameEvent()); + } + if (packet.contains(new RequestBuilder(RequestType.ExchangeInfinityStoneRequest).buildGameRequest())) { + carrier.add(new EventBuilder(EventType.ExchangeInfinityStoneEvent).buildGameEvent()); + } + if (packet.contains(new RequestBuilder(RequestType.UseInfinityStoneRequest).buildGameRequest())) { + carrier.add(new EventBuilder(EventType.UseInfinityStoneEvent).buildGameEvent()); + } + if (packet.contains(new RequestBuilder(RequestType.EndRoundRequest).buildGameRequest())) { + //TODO what to do after EndRoundRequest + //carrier.add(new EventBuilder(EventType.EndRoundEvent).buildGameEvent()); + } + } +} diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameStateSegment.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameStateSegment.java new file mode 100644 index 0000000..d1946d3 --- /dev/null +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameStateSegment.java @@ -0,0 +1,27 @@ +package uulm.teamname.marvelous.server.lobby.pipelining; + +import uulm.teamname.marvelous.gamelibrary.events.Event; +import uulm.teamname.marvelous.gamelibrary.requests.Request; +import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder; +import uulm.teamname.marvelous.gamelibrary.requests.RequestType; +import uulm.teamname.marvelous.server.lobby.Lobby; + +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +public class RequestGameStateSegment implements Segment { + + private Lobby parent; + + public RequestGameStateSegment(Lobby parent) { + this.parent = parent; + } + + @Override + public void processRequests(List packet, List carrier, AtomicBoolean abort) { + if (packet.contains(new RequestBuilder(RequestType.Req).buildGameRequest())) { + carrier.add(parent.game.getGameStateEvent()); + } + packet.clear(); + } +}