Visualiser ConnectionController:

Clicking the host button doesn't create more than one server.
main
fjc40 9 years ago
parent f91f7055de
commit 1b5926007c

@ -43,6 +43,13 @@ public class ConnectionController extends Controller {
private ObservableList<RaceConnection> connections; private ObservableList<RaceConnection> 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 @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
// TODO - replace with config file // TODO - replace with config file
@ -104,12 +111,17 @@ public class ConnectionController extends Controller {
*/ */
public void addLocal() { public void addLocal() {
try { try {
Event game = Event.getEvent(); //We don't want to host more than one game.
urlField.textProperty().set(game.getAddress()); if (!currentlyHostingGame) {
portField.textProperty().set(Integer.toString(game.getPort())); Event game = Event.getEvent();
urlField.textProperty().set(game.getAddress());
portField.textProperty().set(Integer.toString(game.getPort()));
game.start();
addConnection();
game.start(); currentlyHostingGame = true;
addConnection(); }
} catch (InvalidRaceDataException e) { } catch (InvalidRaceDataException e) {
e.printStackTrace(); e.printStackTrace();
} catch (XMLReaderException e) { } catch (XMLReaderException e) {

Loading…
Cancel
Save