feat: implemented proper validation of configs
This commit is contained in:
parent
689cfef838
commit
e318b02db7
@ -5,9 +5,11 @@ import com.beust.jcommander.ParameterException;
|
||||
import org.tinylog.Logger;
|
||||
import org.tinylog.configuration.Configuration;
|
||||
import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
|
||||
import uulm.teamname.marvelous.gamelibrary.config.FieldType;
|
||||
import uulm.teamname.marvelous.gamelibrary.config.PartyConfig;
|
||||
import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig;
|
||||
import uulm.teamname.marvelous.gamelibrary.json.JSON;
|
||||
import uulm.teamname.marvelous.gamelibrary.json.ValidationUtility;
|
||||
import uulm.teamname.marvelous.server.args.ServerArgs;
|
||||
import uulm.teamname.marvelous.server.netconnector.MarvelousServer;
|
||||
|
||||
@ -124,7 +126,30 @@ public class Server {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
// TODO: Check whether Scenario Config is valid
|
||||
Logger.trace("Validating configuration file...");
|
||||
|
||||
var violations = ValidationUtility.validate(config.get());
|
||||
|
||||
if (violations.isPresent()) {
|
||||
Logger.error("Scenario Configuration vas invalid: {}", violations.get());
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
int grassFields = 0;
|
||||
|
||||
for (FieldType[] row: config.get().scenario) {
|
||||
for (FieldType type: row) {
|
||||
if (type == FieldType.GRASS) grassFields++;
|
||||
}
|
||||
if (grassFields > 18) break;
|
||||
}
|
||||
|
||||
if (grassFields <= 18) {
|
||||
Logger.error(
|
||||
"Scenario Configuration vas invalid: Only {} grass fields found, which is less than 18"
|
||||
, grassFields);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
Logger.info("Scenario Config file loaded");
|
||||
|
||||
@ -144,8 +169,12 @@ public class Server {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
var violations = ValidationUtility.validate(config.get());
|
||||
|
||||
// TODO: Check whether Character Config is valid
|
||||
if (violations.isPresent()) {
|
||||
Logger.error("Scenario Configuration vas invalid: {}", violations.get());
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
Logger.info("Character Config file loaded");
|
||||
|
||||
@ -165,7 +194,13 @@ public class Server {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
// TODO: Check whether Party Config is valid
|
||||
|
||||
var violations = ValidationUtility.validate(config.get());
|
||||
|
||||
if (violations.isPresent()) {
|
||||
Logger.error("Party Configuration vas invalid: {}", violations.get());
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
Logger.info("Party Config file loaded");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user