From 872d4d06e9861ed8bdffb86787865265f7d910b2 Mon Sep 17 00:00:00 2001 From: Harmonic Date: Wed, 1 Apr 2020 06:22:03 -0400 Subject: [PATCH 1/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0938f94f..bce205b9 100644 --- a/README.md +++ b/README.md @@ -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). ## 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) Compiled Download: https://git.krews.org/morningstar/Arcturus-Community/releases From ea92573dc81a17f459665ca23c1e463af8b6a5d0 Mon Sep 17 00:00:00 2001 From: Thijmen Stavenuiter Date: Sun, 19 Apr 2020 14:46:17 +0200 Subject: [PATCH 2/2] Allow settings via ENV-variables --- .../eu/habbo/core/ConfigurationManager.java | 73 +++++++++++++++---- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/eu/habbo/core/ConfigurationManager.java b/src/main/java/com/eu/habbo/core/ConfigurationManager.java index 446c028f..719fc4e4 100644 --- a/src/main/java/com/eu/habbo/core/ConfigurationManager.java +++ b/src/main/java/com/eu/habbo/core/ConfigurationManager.java @@ -2,6 +2,7 @@ package com.eu.habbo.core; import com.eu.habbo.Emulator; import com.eu.habbo.plugin.events.emulator.EmulatorConfigUpdatedEvent; +import gnu.trove.map.hash.THashMap; import java.io.File; import java.io.FileInputStream; @@ -31,28 +32,72 @@ public class ConfigurationManager { InputStream input = null; - try { - File f = new File(this.configurationPath); - input = new FileInputStream(f); - this.properties.load(input); + String envDbHostname = System.getenv("DB_HOSTNAME"); - } 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(); + boolean useEnvVarsForDbConnection = envDbHostname != null && envDbHostname.length() > 1; + + if (!useEnvVarsForDbConnection) { + try { + File f = new File(this.configurationPath); + input = new FileInputStream(f); + this.properties.load(input); + + } 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 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 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) { this.loadFromDatabase(); } + this.isLoading = false; Emulator.getLogging().logStart("Configuration Manager -> Loaded!"); @@ -183,4 +228,4 @@ public class ConfigurationManager { this.update(key, value); } -} \ No newline at end of file +}