From 1b5926007cbf9b91287f577acee5e4dc46fda551 Mon Sep 17 00:00:00 2001 From: fjc40 Date: Thu, 27 Jul 2017 14:07:25 +1200 Subject: [PATCH] Visualiser ConnectionController: Clicking the host button doesn't create more than one server. --- .../Controllers/ConnectionController.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/racevisionGame/src/main/java/visualiser/Controllers/ConnectionController.java b/racevisionGame/src/main/java/visualiser/Controllers/ConnectionController.java index 7652f98e..92ca8809 100644 --- a/racevisionGame/src/main/java/visualiser/Controllers/ConnectionController.java +++ b/racevisionGame/src/main/java/visualiser/Controllers/ConnectionController.java @@ -43,6 +43,13 @@ public class ConnectionController extends Controller { private ObservableList connections; + + /** + * Represents whether the client is currently hosting a game already - this is to ensure they don't launch multiple servers. + */ + private boolean currentlyHostingGame = false; + + @Override public void initialize(URL location, ResourceBundle resources) { // TODO - replace with config file @@ -104,12 +111,17 @@ public class ConnectionController extends Controller { */ public void addLocal() { try { - Event game = Event.getEvent(); - urlField.textProperty().set(game.getAddress()); - portField.textProperty().set(Integer.toString(game.getPort())); + //We don't want to host more than one game. + if (!currentlyHostingGame) { + Event game = Event.getEvent(); + urlField.textProperty().set(game.getAddress()); + portField.textProperty().set(Integer.toString(game.getPort())); + + game.start(); + addConnection(); - game.start(); - addConnection(); + currentlyHostingGame = true; + } } catch (InvalidRaceDataException e) { e.printStackTrace(); } catch (XMLReaderException e) {