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 2bb1876..0344d2c 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 @@ -27,6 +27,16 @@ public class Lobby { private PauseSegment pauseSegment; private final TurnTimer turnTimer; + /** + * The {@link Lobby} is where the magic happens. + * In this class is a whole {@link GameInstance game} is processed. + * To initialize the game it gets the following parameters + * @param gameID a String to identify the game + * @param connection the Connection to the {@link uulm.teamname.marvelous.server.lobbymanager.LobbyManager} + * @param partyConfig declared in Editor + * @param characterConfig declared in Editor + * @param scenarioConfig declared in Editor + */ public Lobby( String gameID, LobbyConnection connection, @@ -95,6 +105,10 @@ public class Lobby { updateTimer(); } + /** + * This method is called at the end of receiveRequests, to start a timer. + * The active player has now a specific amount of time to do his moves. + */ void updateTimer() { var currentActiveCharacterType = game.state.getActiveCharacter().type; if (pauseSegment.isPaused()) { diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/TurnTimer.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/TurnTimer.java index 5e5147b..fc28f44 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/TurnTimer.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/TurnTimer.java @@ -7,6 +7,9 @@ import java.util.Timer; import java.util.TimerTask; import java.util.function.Consumer; +/** + * The {@link TurnTimer} class is called by the {@link Lobby} to limit the amount of time a player has per round. + */ public class TurnTimer { private final Timer timer; private final Consumer callback; @@ -18,6 +21,10 @@ public class TurnTimer { this.callback = callback; } + /** + * This method checks if the participant is not a spectator. Otherwise it won't start a timer. + * @param participant the timer is for + */ public void startTurnTimer(Participant participant) { if (participant.type == ParticipantType.Spectator) throw new IllegalStateException("Spectators don't have TurnTime"); 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 index 68422de..accac3a 100644 --- 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 @@ -9,6 +9,10 @@ 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; @@ -17,7 +21,6 @@ public class DisconnectSegment implements Segment { this.parent = parent; } - @Override public void processRequests(Packet packet, List carrier, AtomicBoolean abort) { Logger.trace("DisconnectSegment received {} requests.", packet.size()); 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 index f24bab4..4ada08b 100644 --- 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 @@ -11,9 +11,14 @@ import uulm.teamname.marvelous.server.lobby.Lobby; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +/** + * The {@link GameStateSegment} handles all {@link GameInstance game} relevant {@link Request Requests}. + * Therefore it updates the game with the matching request. + */ public class GameStateSegment implements Segment { private GameInstance game; + public GameStateSegment(GameInstance game){ this.game = game; } diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Packet.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Packet.java index 1762234..1c9c9ff 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Packet.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Packet.java @@ -6,6 +6,10 @@ import uulm.teamname.marvelous.server.lobbymanager.Participant; import java.util.*; +/** + * The {@link Packet} contains all {@link Request Requests} and the belonging {@link Participant}. + * You can add and remove {@link Request Requests} at will. + */ public class Packet extends ArrayList { private final Participant origin; @@ -15,6 +19,11 @@ public class Packet extends ArrayList { addAll(Arrays.asList(requests)); } + /** + * This method checks if a {@link RequestType} is part of the {@link Packet} or not + * @param requiredType RequestType to check. + * @return boolean + */ public boolean containsRequestOfType(RequestType requiredType) { for (Request request : this) { if (request.type == requiredType) { @@ -24,11 +33,19 @@ public class Packet extends ArrayList { return false; } + /** + * This method removes all {@link Request Requests} of given {@link RequestType types} from the {@link Packet}. + * @param types RequestType(s) to remove + */ public void removeRequestsOfTypes(RequestType... types) { var listOfTypes = Arrays.asList(types); this.removeIf(request -> listOfTypes.contains(request.type)); } + /** + * This method removes all {@link Request Requests} except of given {@link RequestType types} from the {@link Packet}. + * @param types RequestType(s) to not remove + */ public void removeRequestsNotOfTypes(RequestType... types) { var listOfTypes = Arrays.asList(types); this.removeIf(request -> !listOfTypes.contains(request.type)); diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/PauseSegment.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/PauseSegment.java index 01c4c9a..067ccd4 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/PauseSegment.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/PauseSegment.java @@ -11,6 +11,9 @@ import uulm.teamname.marvelous.gamelibrary.requests.RequestType; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +/** + * The {@link PauseSegment} can pause and unpause a game. + */ public class PauseSegment implements Segment { private boolean paused; @@ -19,18 +22,23 @@ public class PauseSegment implements Segment { paused = false; } + /** + * This method pauses the game if it is not already paused. + */ public void pauseGame(){ if(!paused) { paused = true; - Logger.debug("{}: Game paused.", - Thread.currentThread().getName()); + Logger.debug("Game paused."); } } + + /** + * This method ends a paused game. + */ public void pauseEnd(){ if(paused) { paused = false; - Logger.debug("{}: Game unpaused.", - Thread.currentThread().getName()); + Logger.debug("Game unpaused."); } } 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 index 18d5b8b..f94ece3 100644 --- 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 @@ -10,10 +10,15 @@ import uulm.teamname.marvelous.server.lobby.Lobby; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +/** + * The {@link RequestGameStateSegment} handles requests of {@link RequestType} Req. + * Therefore it sends the active gamestate and clears the {@link Packet} afterwards. + */ public class RequestGameStateSegment implements Segment { private final GameInstance game; + public RequestGameStateSegment(GameInstance game) { this.game = game; }