Merge branch 'master' into 'dobby-integration'

Allow settings via ENV-variables

See merge request morningstar/Arcturus-Community!111
This commit is contained in:
Harmonic 2020-04-20 10:18:41 -04:00
commit 84ed2b4fce
2 changed files with 60 additions and 15 deletions

View File

@ -11,7 +11,7 @@ TheGeneral's own words were "dont like it then dont use it". We did not like wha
Arcturus Morningstar is released under the [GNU General Public License v3](https://www.gnu.org/licenses/gpl-3.0.txt). Arcturus Morningstar is released under the [GNU General Public License v3](https://www.gnu.org/licenses/gpl-3.0.txt).
## Versions ## ## Versions ##
![image](https://img.shields.io/badge/VERSION-2.3.0-success.svg?style=for-the-badge&logo=appveyor) ![image](https://img.shields.io/badge/VERSION-2.3.1-success.svg?style=for-the-badge&logo=appveyor)
![image](https://img.shields.io/badge/STATUS-STABLE-green.svg?style=for-the-badge&logo=appveyor) ![image](https://img.shields.io/badge/STATUS-STABLE-green.svg?style=for-the-badge&logo=appveyor)
Compiled Download: https://git.krews.org/morningstar/Arcturus-Community/releases Compiled Download: https://git.krews.org/morningstar/Arcturus-Community/releases

View File

@ -2,6 +2,7 @@ package com.eu.habbo.core;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.plugin.events.emulator.EmulatorConfigUpdatedEvent; import com.eu.habbo.plugin.events.emulator.EmulatorConfigUpdatedEvent;
import gnu.trove.map.hash.THashMap;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -31,28 +32,72 @@ public class ConfigurationManager {
InputStream input = null; InputStream input = null;
try { String envDbHostname = System.getenv("DB_HOSTNAME");
File f = new File(this.configurationPath);
input = new FileInputStream(f);
this.properties.load(input);
} catch (IOException ex) { boolean useEnvVarsForDbConnection = envDbHostname != null && envDbHostname.length() > 1;
Emulator.getLogging().logErrorLine("[CRITICAL] FAILED TO LOAD CONFIG FILE! (" + this.configurationPath + ")");
ex.printStackTrace(); if (!useEnvVarsForDbConnection) {
} finally { try {
if (input != null) { File f = new File(this.configurationPath);
try { input = new FileInputStream(f);
input.close(); this.properties.load(input);
} catch (IOException e) {
e.printStackTrace(); } catch (IOException ex) {
Emulator.getLogging().logErrorLine("[CRITICAL] FAILED TO LOAD CONFIG FILE! (" + this.configurationPath + ")");
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} else {
Map<String, String> envMapping = new THashMap<>();
// Database section
envMapping.put("db.hostname", "DB_HOSTNAME");
envMapping.put("db.port", "DB_PORT");
envMapping.put("db.database", "DB_DATABASE");
envMapping.put("db.username", "DB_USERNAME");
envMapping.put("db.password", "DB_PASSWORD");
envMapping.put("db.params", "DB_PARAMS");
// Game Configuration
envMapping.put("game.host", "EMU_HOST");
envMapping.put("game.port", "EMU_PORT");
// RCON
envMapping.put("rcon.host", "RCON_HOST");
envMapping.put("rcon.port", "RCON_PORT");
envMapping.put("rcon.allowed", "RCON_ALLOWED");
// Runtime
envMapping.put("runtime.threads", "RT_THREADS");
envMapping.put("logging.errors.runtime", "RT_LOG_ERRORS");
for (Map.Entry<String, String> entry : envMapping.entrySet()) {
String envValue = System.getenv(entry.getValue());
if (envValue == null || envValue.length() == 0) {
Emulator.getLogging().logStart("Cannot find environment-value for variable `" + entry.getValue() + "`");
} else {
this.properties.setProperty(entry.getKey(), envValue);
} }
} }
} }
if (this.loaded) { if (this.loaded) {
this.loadFromDatabase(); this.loadFromDatabase();
} }
this.isLoading = false; this.isLoading = false;
Emulator.getLogging().logStart("Configuration Manager -> Loaded!"); Emulator.getLogging().logStart("Configuration Manager -> Loaded!");