fix: fixed bug where sending reoconnect while not able to do so breaks the server

This commit is contained in:
Yannik Bretschneider 2021-06-07 17:26:59 +02:00
parent 8d26c3f2ea
commit 3c49c5bbd8
2 changed files with 12 additions and 6 deletions

View File

@ -4,5 +4,5 @@ public enum ClientState {
Blank,
Ready,
Assigned,
Playing
Reconnect, Playing
}

View File

@ -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)) {
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;
}
}