Files
Server/src/engine/gameManager/ConfigManager.java
T

180 lines
5.2 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.gameManager;
import engine.mbEnums;
2022-04-30 09:41:17 -04:00
import engine.server.login.LoginServer;
import engine.server.world.WorldServer;
import org.pmw.tinylog.Logger;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
2022-04-30 09:41:17 -04:00
import java.util.HashMap;
import java.util.Map;
2022-06-06 04:28:44 -04:00
import java.util.regex.Pattern;
2022-04-30 09:41:17 -04:00
public enum ConfigManager {
2024-04-25 20:26:13 -04:00
// MB Dev notes:
// Magicbane configuration is loaded from environment variables
//
// On boot the game first looks in /mb.conf for the file magicbane.conf.
//
// If not found, a default config is loaded from /mb.data to enable bootstrap.
// This version should never be modified.
2024-04-25 20:25:16 -04:00
2022-04-30 09:41:17 -04:00
MB_BIND_ADDR,
MB_EXTERNAL_ADDR,
2024-02-15 11:31:22 -05:00
2022-04-30 09:41:17 -04:00
// Database connection config
MB_DATABASE_ADDRESS,
MB_DATABASE_PORT,
MB_DATABASE_NAME,
MB_DATABASE_USER,
MB_DATABASE_PASS,
// Data warehouse remote connection
MB_WAREHOUSE_ADDR,
MB_WAREHOUSE_USER,
MB_WAREHOUSE_PASS,
// Login server config
MB_LOGIN_PORT,
2022-04-30 14:05:05 -04:00
MB_LOGIN_AUTOREG,
2022-06-06 04:28:44 -04:00
MB_LOGIN_FNAME_REGEX,
2022-04-30 09:41:17 -04:00
MB_MAJOR_VER,
MB_MINOR_VER,
// Worldserver configuration
MB_WORLD_NAME,
MB_WORLD_MAPID,
MB_WORLD_REALMMAP,
2022-04-30 09:41:17 -04:00
MB_WORLD_PORT,
MB_WORLD_ACCESS_LVL,
MB_WORLD_WAREHOUSE_PUSH,
MB_WORLD_MAINTENANCE,
MB_WORLD_GREETING,
MB_WORLD_KEYCLONE_MAX,
2023-06-27 16:09:55 -04:00
MB_USE_RUINS,
2024-02-15 11:31:22 -05:00
MB_RULESET,
2023-06-27 16:09:55 -04:00
// Mobile AI modifiers
MB_AI_CAST_FREQUENCY,
2023-06-27 16:13:25 -04:00
MB_AI_AGGRO_RANGE,
2022-04-30 09:41:17 -04:00
//drop rates
2023-02-24 10:45:46 -05:00
MB_NORMAL_EXP_RATE,
MB_NORMAL_DROP_RATE,
MB_NORMAL_GOLD_RATE,
2023-02-24 10:45:46 -05:00
MB_HOTZONE_EXP_RATE,
MB_HOTZONE_DROP_RATE,
MB_HOTZONE_GOLD_RATE,
MB_HOTZONE_DURATION,
2023-02-23 16:38:23 -05:00
MB_HOTZONE_MIN_LEVEL,
2023-02-24 09:48:15 -05:00
MB_PRODUCTION_RATE,
2022-04-30 09:41:17 -04:00
// MagicBot configuration.
MB_MAGICBOT_SERVERID,
MB_MAGICBOT_BOTTOKEN,
MB_MAGICBOT_ROLEID,
MB_MAGICBOT_ANNOUNCE,
MB_MAGICBOT_SEPTIC,
MB_MAGICBOT_CHANGELOG,
MB_MAGICBOT_POLITICAL,
MB_MAGICBOT_GENERAL,
MB_MAGICBOT_FORTOFIX,
MB_MAGICBOT_RECRUIT,
2023-03-02 08:06:17 -05:00
MB_MAGICBOT_MAGICBOX,
2023-06-27 16:19:15 -04:00
MB_MAGICBOT_ADMINLOG;
2022-04-30 09:41:17 -04:00
// Map to hold our config pulled in from the environment
// We also use the config to point to the current message pump
// and determine the server type at runtime.
2023-06-07 14:53:15 -04:00
public static final String DEFAULT_DATA_DIR = "mb.data/";
2024-04-25 20:22:29 -04:00
public static final Map<String, String> configMap = new HashMap(System.getenv());
public static mbEnums.ServerType serverType = mbEnums.ServerType.NONE;
2022-04-30 09:41:17 -04:00
public static WorldServer worldServer;
public static LoginServer loginServer;
2024-04-25 20:22:29 -04:00
public static final Map<ConfigManager, Pattern> regex = new HashMap<>();
2022-04-30 09:41:17 -04:00
public static String currentRepoBranch = "";
2022-04-30 09:41:17 -04:00
// Called at bootstrap: ensures that all config values are loaded.
public static boolean init() {
Logger.info("Loading config from environment.");
2022-04-30 09:41:17 -04:00
for (ConfigManager configSetting : ConfigManager.values())
if (configMap.containsKey(configSetting.name()))
Logger.info(configSetting.name() + ":" + configSetting.getValue());
else {
Logger.error("Missing Config: " + configSetting.name());
2024-04-25 20:22:29 -04:00
Logger.error("This codebase requires >= MagicBox v1.5.2");
2022-06-26 10:47:08 -04:00
Logger.error("docker pull magicbane/magicbox:latest");
2022-04-30 09:41:17 -04:00
return false;
}
Logger.info("Determine current Repo branch");
File file = new File("mbbranch.sh");
if (file.exists() && !file.isDirectory()) {
2023-08-13 09:44:28 -04:00
String[] command = {"./mbbranch.sh"};
try {
Process process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String string;
while (true) {
if ((string = reader.readLine()) == null)
break;
currentRepoBranch += string;
}
Logger.info(currentRepoBranch);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
2023-02-19 08:39:28 -05:00
// compile regex here
Logger.info("Compiling regex");
2022-06-06 04:28:44 -04:00
2023-02-19 08:39:28 -05:00
regex.put(MB_LOGIN_FNAME_REGEX, Pattern.compile(MB_LOGIN_FNAME_REGEX.getValue()));
return true;
2022-04-30 09:41:17 -04:00
}
// Get the value associated with this enumeration
2023-07-15 09:23:48 -04:00
public String getValue() {
return configMap.get(this.name());
}
public void setValue(String value) {
configMap.put(this.name(), value);
2022-04-30 09:41:17 -04:00
}
}