From 3ea1cc6cf5f8308758f5e31acff5e5f644ed88b6 Mon Sep 17 00:00:00 2001 From: punchready Date: Mon, 7 Jun 2021 13:11:09 +0200 Subject: [PATCH] fix: resolve some more connection opening and closing issues --- .../marvelous/server/lobbymanager/LobbyConnection.java | 4 ++-- .../teamname/marvelous/server/lobbymanager/LobbyManager.java | 4 ++++ .../teamname/marvelous/server/netconnector/UserManager.java | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java index aacd547..eb235ae 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnection.java @@ -14,8 +14,6 @@ import uulm.teamname.marvelous.server.lobby.Lobby; import uulm.teamname.marvelous.server.netconnector.SUID; import uulm.teamname.marvelous.server.netconnector.UserManager; -import javax.management.MBeanParameterInfo; -import java.time.OffsetDateTime; import java.util.*; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -54,6 +52,7 @@ public class LobbyConnection implements Runnable { public void addParticipant(Participant participant) { if(participant.type == ParticipantType.Spectator) { spectators.add(participant); + return; } if(participant.type == ParticipantType.PlayerOne) { @@ -68,6 +67,7 @@ public class LobbyConnection implements Runnable { } public void removeParticipant(Participant participant, String reason) { + LobbyManager.getInstance().removeParticipant(participant); UserManager.getInstance().removeClient(participant.getClient(), reason); if(participant.type == ParticipantType.Spectator) { diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyManager.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyManager.java index ede566b..a4d91ff 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyManager.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobbymanager/LobbyManager.java @@ -159,6 +159,10 @@ public class LobbyManager { } + public void removeParticipant(Participant participant) { + participants.remove(participant.id); + } + private void addParticipant(Client client, String lobbyID, RoleEnum role) { if(!lobbies.containsKey(lobbyID)) { if(!LobbyRunner.getInstance().canAddLobby()) { 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 4ee7874..08b7148 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 @@ -1,7 +1,6 @@ package uulm.teamname.marvelous.server.netconnector; import org.java_websocket.framing.CloseFrame; -import org.tinylog.Logger; import uulm.teamname.marvelous.gamelibrary.json.JSON; import uulm.teamname.marvelous.gamelibrary.json.ValidationUtility; import uulm.teamname.marvelous.gamelibrary.messages.BasicMessage;