mirror of
https://github.com/array-in-a-matrix/brainwine.git
synced 2025-04-02 11:11:58 -04:00
Add game config override support
This commit is contained in:
parent
5c99ee5351
commit
e2c763592c
1 changed files with 22 additions and 0 deletions
|
@ -2,6 +2,8 @@ package brainwine.gameserver;
|
|||
|
||||
import static brainwine.shared.LogMarkers.SERVER_MARKER;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
@ -50,6 +52,7 @@ public class GameConfiguration {
|
|||
options.setMaxAliasesForCollections(Short.MAX_VALUE);
|
||||
yaml = new Yaml(options);
|
||||
loadConfigFiles();
|
||||
loadConfigOverrides();
|
||||
logger.info(SERVER_MARKER, "Configuring ...");
|
||||
configure();
|
||||
logger.info(SERVER_MARKER, "Caching versioned configurations ...");
|
||||
|
@ -203,6 +206,25 @@ public class GameConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
private static void loadConfigOverrides() {
|
||||
try {
|
||||
File configOverridesFile = new File("config_overrides.yml");
|
||||
|
||||
if(!configOverridesFile.exists()) {
|
||||
logger.info(SERVER_MARKER, "No config overrides found. To override game config properties, put them in a file called 'config_overrides.yml'");
|
||||
return;
|
||||
}
|
||||
|
||||
try(FileInputStream inputStream = new FileInputStream(configOverridesFile)) {
|
||||
Map<String, Object> configOverrides = yaml.load(inputStream);
|
||||
merge(baseConfig, configOverrides);
|
||||
logger.warn(SERVER_MARKER, "Configuration overrides have been loaded, proceed with caution.");
|
||||
}
|
||||
} catch(Exception e) {
|
||||
logger.error(SERVER_MARKER, "Could not load configuration overrides", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void merge(Map<String, Object> dst, Map<String, Object> src) {
|
||||
src.forEach((k, v) -> {
|
||||
if(dst.containsKey(k)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue