automatically join lobby when selfhosting

This commit is contained in:
Johannes Schmelz 2024-11-24 21:36:03 +01:00
parent 6b78733a5d
commit dcf10e0819
2 changed files with 11 additions and 6 deletions

View File

@ -39,10 +39,9 @@ public class CreateGameMenu extends SimpleDialog {
private final NetworkSupport network; private final NetworkSupport network;
private final TextField host = new TextField(LOCALHOST); private final TextField host = new TextField(LOCALHOST);
private final TextField port = new TextField(DEFAULT_PORT); private final TextField port = new TextField(DEFAULT_PORT);
// private final Button serverButton = new Button(lookup("client.server-star")); private final Button serverButton = new Button("Selber hosten");
private final Button serverButton = new Button(lookup("client.server-start")); private final Button cancelButton = new Button("Abbrechen");
private final Button cancelButton = addChild(new Button("Abbrechen")); private final Button joinButton = new Button("Beitreten");
private final Button joinButton = addChild(new Button("Beitreten"));
private String hostname; private String hostname;
private int portNumber; private int portNumber;
private Future<Object> connectionFuture; private Future<Object> connectionFuture;
@ -175,7 +174,6 @@ public class CreateGameMenu extends SimpleDialog {
Thread serverThread = new Thread(() -> { Thread serverThread = new Thread(() -> {
try { try {
MonopolyServer.main(null); MonopolyServer.main(null);
connect();
} catch (Exception e) { } catch (Exception e) {
serverButton.setEnabled(true); serverButton.setEnabled(true);
LOGGER.log(Level.ERROR, "Server could not be started", e); LOGGER.log(Level.ERROR, "Server could not be started", e);
@ -183,5 +181,12 @@ public class CreateGameMenu extends SimpleDialog {
} }
}); });
serverThread.start(); serverThread.start();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
connect();
} }
} }

View File

@ -28,7 +28,7 @@ public class MonopolyConfig extends Config {
* The default port number for the Monopoly server. * The default port number for the Monopoly server.
*/ */
@Property("port") @Property("port")
private int port = 4321; private int port = 42069;
/** /**
* The width of the game map in terms of grid units. * The width of the game map in terms of grid units.