diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java index 4f6affe..01d0835 100644 --- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java +++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LobbyScreen.java @@ -47,6 +47,7 @@ public class LobbyScreen extends AbstractScreen { startGameButton.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { + roboRallyWrapper.server.startGame(); Map playernames = roboRallyWrapper.server.getPlayerNames(); List playerlist = IOUtil.playerGenerator(playernames, roboRallyWrapper.server.getRobotID()); diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java index d13c68c..4cd3a25 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java @@ -66,6 +66,13 @@ public class RoboRallyServer { server.sendToAllTCP(object); } + /** + * Does necessary cleanup of dangling connections before game is started + */ + public void startGame() { + listener.startGame(); + } + /** * Sends an object to a specific client * diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java index 88ba4ba..a6a8182 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java @@ -58,6 +58,25 @@ class RoboRallyServerListener extends Listener { } } + /** + * Does necessary cleanup of dangling connections before game is started + * + *

Disconnects all connections which have not yet sent a player name.

+ */ + public void startGame() { + List connectionsToDrop = new ArrayList<>(); + for (Connection connection : clients.keySet()) { + if (playerNames.get(connection) == null) { + connectionsToDrop.add(connection); + } + } + for (Connection connection : connectionsToDrop) { + clients.remove(connection); + deadPlayers.add(connection); + connection.close(); + } + } + /** * Gets a map between connections and their player name * @@ -110,9 +129,7 @@ class RoboRallyServerListener extends Listener { */ private void receiveContinuePowerDown(Connection connection, Boolean bool) { stayInPowerDown.put(connection, bool); - System.out.println("fuuuuuuuuuuuuuuuuu"); if (receivedDataFromAllConnections(stayInPowerDown)) { - System.out.println("fuuuuuuuuuuuuuuuuasdasdasdasdasdasdasdu"); Map powerDowns = new HashMap<>(); for (Connection connected : stayInPowerDown.keySet()) { powerDowns.put(playerNames.get(connected), stayInPowerDown.get(connected)); @@ -151,10 +168,7 @@ class RoboRallyServerListener extends Listener { */ private boolean receivedDataFromAllConnections(Map data) { Set connections = clients.keySet(); - System.out.println("keys "+data.keySet()); - System.out.println(connections); connections.removeAll(deadPlayers); - System.out.println(connections); return data.keySet().containsAll(connections); }