improved mainclass Server, and started a server for testing

This commit is contained in:
Yannik Bretschneider 2021-06-05 00:53:10 +02:00
parent 03b44aeb87
commit bd234a7849
1 changed files with 27 additions and 6 deletions

View File

@ -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");
}