diff --git a/EngineServer/src/main/java/org/petero/engineserver/EngineServer.java b/EngineServer/src/main/java/org/petero/engineserver/EngineServer.java index e7abda1..d2d9a0e 100644 --- a/EngineServer/src/main/java/org/petero/engineserver/EngineServer.java +++ b/EngineServer/src/main/java/org/petero/engineserver/EngineServer.java @@ -87,7 +87,7 @@ public class EngineServer implements ErrorHandler { } } - private void run() { + private void runGui() { window = new MainWindow(this, configs); } @@ -109,18 +109,33 @@ public class EngineServer implements ErrorHandler { System.exit(0); } + private static void usage() { + System.out.printf("Usage: engineServer [-numengines value] [-nogui]\n"); + System.exit(2); + } + public static void main(String[] args) { int numEngines = 8; - if (args.length > 0) { - try { - numEngines = Integer.valueOf(args[0]); - numEngines = Math.max(1, numEngines); - numEngines = Math.min(20, numEngines); - } catch (NumberFormatException ignore) { + boolean gui = true; + for (int i = 0; i < args.length; i++) { + if ("-numengines".equals(args[i]) && i+1 < args.length) { + try { + numEngines = Integer.valueOf(args[i+1]); + numEngines = Math.max(1, numEngines); + numEngines = Math.min(20, numEngines); + i++; + } catch (NumberFormatException e) { + usage(); + } + } else if ("-nogui".equals(args[i])) { + gui = false; + } else { + usage(); } } EngineServer server = new EngineServer(numEngines); - server.run(); + if (gui) + server.runGui(); } @Override diff --git a/EngineServer/src/main/java/org/petero/engineserver/PortListener.java b/EngineServer/src/main/java/org/petero/engineserver/PortListener.java index abb17d8..9b4a5bd 100644 --- a/EngineServer/src/main/java/org/petero/engineserver/PortListener.java +++ b/EngineServer/src/main/java/org/petero/engineserver/PortListener.java @@ -66,6 +66,10 @@ public class PortListener { serverSocket.setReuseAddress(true); serverSocket.bind(new InetSocketAddress(config.port)); + synchronized (PortListener.class) { + System.out.printf("Listening on port %d\n", config.port); + } + this.serverSocket = serverSocket; while (!shutDownFlag) { try (Socket clientSocket = serverSocket.accept()) {