From 509759fdd144f365775914882ea6b1547f0d293a Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Wed, 22 Apr 2020 12:46:18 +0200 Subject: [PATCH] =?UTF-8?q?Kaster=20ut=20spillere=20som=20pr=C3=B8ver=20?= =?UTF-8?q?=C3=A5=20bli=20med=20etter=20at=20spillet=20har=20startet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roborally/networking/RoboRallyServerListener.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java index a6a8182..a4968b9 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java @@ -27,6 +27,7 @@ class RoboRallyServerListener extends Listener { private Connection host; private Map stayInPowerDown; private Map programs; + private boolean gameStarted = false; /** * Instantiates a new Robo Rally server listener @@ -75,6 +76,7 @@ class RoboRallyServerListener extends Listener { deadPlayers.add(connection); connection.close(); } + this.gameStarted = true; } /** @@ -174,6 +176,11 @@ class RoboRallyServerListener extends Listener { @Override public void connected(Connection connection) { + //Prevent players from joining after the game has started + if (gameStarted) { + connection.close(); + return; + } //The first client to connect is assumed to be the host if (host == null) { host = connection; @@ -191,7 +198,7 @@ class RoboRallyServerListener extends Listener { @Override public void disconnected(Connection connection) { - if (deadPlayers.contains(connection)) { + if (deadPlayers.contains(connection) || !clients.keySet().contains(connection)) { //Remove all traces of the player ever existing clients.remove(connection); playerNames.remove(connection);