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 7857a95..7069c9a 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 @@ -26,8 +26,8 @@ public class LobbyConnection implements Runnable { private Participant player1, player2; private final HashSet spectators = new HashSet<>(10); - private final HashMap> selection = new HashMap<>(); - public final HashMap options = new HashMap<>(); + private final HashMap> selection = new HashMap<>(2); + public final HashMap options = new HashMap<>(2); private final BlockingQueue> requestQueue = new LinkedBlockingQueue<>(); @@ -62,7 +62,11 @@ public class LobbyConnection implements Runnable { } public void removeParticipant(Participant participant) { - UserManager.getInstance().removeClient(participant.getClient(), ""); + removeParticipant(participant, "You have been disconnected."); + } + + public void removeParticipant(Participant participant, String reason) { + UserManager.getInstance().removeClient(participant.getClient(), reason); if(participant.type == ParticipantType.Spectator) { spectators.remove(participant); @@ -85,6 +89,22 @@ public class LobbyConnection implements Runnable { } } + public Participant getPlayer1() { + return player1; + } + + public Participant getPlayer2() { + return player2; + } + + public boolean hasPlayer1() { + return player1 != null; + } + + public boolean hasPlayer2() { + return player2 != null; + } + public void handleMessage(Participant participant, Request[] requests) { try { @@ -128,7 +148,7 @@ public class LobbyConnection implements Runnable { ); while (state == LobbyConnectionState.Started) { - Tuple currentRequests = pollQueueAsync(1000); + Tuple currentRequests = pollQueueAsync(); if(currentRequests != null) { lobby.receiveRequests(currentRequests.item2, currentRequests.item1); @@ -170,10 +190,10 @@ public class LobbyConnection implements Runnable { broadcastToSpectators(gameStructureMessage); } - private Tuple pollQueueAsync(int timeoutMillis) { + private Tuple pollQueueAsync() { Tuple current = null; try { - current = requestQueue.poll(timeoutMillis, TimeUnit.MILLISECONDS); + current = requestQueue.poll(1000, TimeUnit.MILLISECONDS); }catch (InterruptedException e) { } @@ -181,22 +201,6 @@ public class LobbyConnection implements Runnable { } - public Participant getPlayer1() { - return player1; - } - - public Participant getPlayer2() { - return player2; - } - - public boolean hasPlayer1() { - return player1 != null; - } - - public boolean hasPlayer2() { - return player2 != null; - } - private void broadcast(BasicMessage message) { player1.sendMessage(message); player2.sendMessage(message);