diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/netconnector/ClientState.java b/Server/src/main/java/uulm/teamname/marvelous/server/netconnector/ClientState.java index 3a99278..b58b6df 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/netconnector/ClientState.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/netconnector/ClientState.java @@ -4,5 +4,5 @@ public enum ClientState { Blank, Ready, Assigned, - Playing + Reconnect, Playing } diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/netconnector/UserManager.java b/Server/src/main/java/uulm/teamname/marvelous/server/netconnector/UserManager.java index 234171f..5bae0cb 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/netconnector/UserManager.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/netconnector/UserManager.java @@ -152,7 +152,13 @@ public class UserManager { Logger.trace("forwarding message to the LobbyManager"); AtomicBoolean running = new AtomicBoolean(false); if(LobbyManager.getInstance().handleConnect(client, running)) { - client.state = ClientState.Ready; + + var clientHasRunningGame = running.get(); + if (clientHasRunningGame) { + client.state = ClientState.Reconnect; + } else { + client.state = ClientState.Ready; + } HelloClientMessage response = new HelloClientMessage(); response.runningGame = running.get(); @@ -164,8 +170,8 @@ public class UserManager { /** Handles a reconnectMessage, and reconnects the client if needed */ private void handleReconnectMessage(Client client, ReconnectMessage message) { - if(client.state != ClientState.Ready) { - client.sendError("Invalid message."); + if(client.state != ClientState.Reconnect) { + client.sendError("Invalid message, as client is not in reconnect-ready state"); return; } @@ -179,8 +185,8 @@ public class UserManager { client.sendError("You could not be reconnected to the Lobby"); } } else { - Logger.trace("No reconnect requested, changing ClientState to blank"); - client.state = ClientState.Blank; + Logger.trace("No reconnect requested, setting client to ready to connect state"); + client.state = ClientState.Ready; } }