diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/Server.java b/Server/src/main/java/uulm/teamname/marvelous/server/Server.java index 2801442..a5d15d8 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/Server.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/Server.java @@ -1,6 +1,7 @@ package uulm.teamname.marvelous.server; import com.beust.jcommander.JCommander; +import com.beust.jcommander.ParameterException; import org.tinylog.Logger; import org.tinylog.configuration.Configuration; import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig; @@ -32,14 +33,21 @@ public class Server { ServerArgs serverArgs = new ServerArgs(); - JCommander.newBuilder() - .addObject(serverArgs) - .build() - .parse(args); + try { + JCommander.newBuilder() + .addObject(serverArgs) + .build() + .parse(args); + } catch (ParameterException e) { + Logger.error("Invalid parameters: {}", e.getMessage()); + System.exit(1); + } System.out.println(serverArgs); - if (serverArgs.isVerbose()) { + if (serverArgs.isVerbose() || serverArgs.isCheckConfig()) { + // If checkConfig, the LogLevel is also set to max, because more information + // is exactly what checking the requirements means setLogLevel(5); } else { setLogLevel(serverArgs.getLogLevel()); @@ -50,9 +58,22 @@ public class Server { CharacterConfig characterConfig = readCharacterConfig(serverArgs.getCharacterConfigFile()); PartyConfig partyConfig = readPartyConfig(serverArgs.getMatchConfigFile()); - InetSocketAddress address = new InetSocketAddress(serverArgs.getPort()); + // If only configurations should be checked, the server exits here + if (serverArgs.isCheckConfig()) { + Logger.info("Exiting as configuration file check is done"); + System.exit(0); + } + + InetSocketAddress address = new InetSocketAddress("localhost", serverArgs.getPort()); Logger.trace("Inet address {} created", address); + var json = new JSON(characterConfig); + Logger.trace("New JSON instance created with characterConfig"); + + MarvelousServer netConnector = new MarvelousServer(address, json); + System.out.println("Starting server"); + netConnector.start(); + System.out.println("Server started"); }