From 3c49c5bbd82868520ee9605e229f8eec2a2c09b2 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Mon, 7 Jun 2021 17:26:59 +0200 Subject: [PATCH] fix: fixed bug where sending reoconnect while not able to do so breaks the server --- .../server/netconnector/ClientState.java | 2 +- .../server/netconnector/UserManager.java | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) 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; } }