From d89cd97eb6af30e33074a11d47fc02270442cc1a Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 6 Jun 2022 03:13:07 -0400 Subject: [PATCH 1/5] Missing config suggests outdated MagicBox. --- src/engine/gameManager/ConfigManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index 38e6c8f0..9d3fa882 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -99,6 +99,7 @@ public enum ConfigManager { Logger.info(configSetting.name() + ":" + configSetting.getValue()); else { Logger.error("Missing Config: " + configSetting.name()); + Logger.error("Update your MagicBox: docker pull magicbane/magicbox:latest"); return false; } From d5d957a91062ef2cf80c250359dff6a97b9603e6 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 6 Jun 2022 03:21:27 -0400 Subject: [PATCH 2/5] bugfix: ignore case with boolean config values. --- src/engine/db/archive/DataWarehouse.java | 2 +- src/engine/gameManager/MaintenanceManager.java | 2 +- src/engine/server/login/LoginServerMsgHandler.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/engine/db/archive/DataWarehouse.java b/src/engine/db/archive/DataWarehouse.java index 3947d72d..5483e18b 100644 --- a/src/engine/db/archive/DataWarehouse.java +++ b/src/engine/db/archive/DataWarehouse.java @@ -39,7 +39,7 @@ public class DataWarehouse implements Runnable { // If WarehousePush is disabled // then early exit - if ( ConfigManager.MB_WORLD_WAREHOUSE_PUSH.getValue().equals("false")) { + if ( ConfigManager.MB_WORLD_WAREHOUSE_PUSH.getValue().equalsIgnoreCase("false")) { Logger.info("Warehouse Remote Connection disabled along with push"); return; } diff --git a/src/engine/gameManager/MaintenanceManager.java b/src/engine/gameManager/MaintenanceManager.java index 35185ebd..89ef12a3 100644 --- a/src/engine/gameManager/MaintenanceManager.java +++ b/src/engine/gameManager/MaintenanceManager.java @@ -349,7 +349,7 @@ public enum MaintenanceManager { // Run maintenance on player buildings - if ((boolean) ConfigManager.MB_WORLD_MAINTENANCE.getValue().equals("true")) + if ((boolean) ConfigManager.MB_WORLD_MAINTENANCE.getValue().equalsIgnoreCase("true")) processBuildingMaintenance(); else Logger.info("Maintenance Costings: DISABLED"); diff --git a/src/engine/server/login/LoginServerMsgHandler.java b/src/engine/server/login/LoginServerMsgHandler.java index 36f45917..3fd17ed5 100644 --- a/src/engine/server/login/LoginServerMsgHandler.java +++ b/src/engine/server/login/LoginServerMsgHandler.java @@ -180,7 +180,7 @@ public class LoginServerMsgHandler implements NetMsgHandler { if (account == null) { - if (ConfigManager.MB_LOGIN_AUTOREG.getValue().equals("FALSE")) { + if (ConfigManager.MB_LOGIN_AUTOREG.getValue().equalsIgnoreCase("false")) { this.KickToLogin(MBServerStatics.LOGINERROR_INVALID_USERNAME_PASSWORD, "Could not find account (" + uname + ')', clientConnection); Logger.info("Could not find account (" + uname + ')'); return; From ad4678ab3c5e68554558be45b9c566d178647ee7 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 6 Jun 2022 03:26:34 -0400 Subject: [PATCH 3/5] Version info pulled from config. --- src/engine/server/MBServerStatics.java | 10 ---------- src/engine/server/login/LoginServer.java | 4 ++-- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/engine/server/MBServerStatics.java b/src/engine/server/MBServerStatics.java index 6c2b46fb..31ed073b 100644 --- a/src/engine/server/MBServerStatics.java +++ b/src/engine/server/MBServerStatics.java @@ -124,16 +124,6 @@ public class MBServerStatics { public static final int CHM_THREAD_MED = 2; public static final int CHM_THREAD_LOW = 1; - /* - * LoginServer related - */ - - public static final String PCMajorVer = "1.2.25.5"; - public static final String PCMinorVer = "5.25.5"; - - public static final String MACMajorVer = "1.2.24.3"; - public static final String MACMinorVer = "5.24.3"; - /* * LoginErrorMsg related */ diff --git a/src/engine/server/login/LoginServer.java b/src/engine/server/login/LoginServer.java index b7ad18e9..5a44bd09 100644 --- a/src/engine/server/login/LoginServer.java +++ b/src/engine/server/login/LoginServer.java @@ -169,8 +169,8 @@ public class LoginServer { // Configure the VersionInfoMsgs: - this.versionInfoMessage = new VersionInfoMsg(MBServerStatics.PCMajorVer, - MBServerStatics.PCMinorVer); + this.versionInfoMessage = new VersionInfoMsg(ConfigManager.MB_MAJOR_VER.getValue(), + ConfigManager.MB_MINOR_VER.getValue()); Logger.info("Initializing Database Pool"); initDatabasePool(); From 24d96f24b2b6552433976ee7e1fffb6e9f57539c Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 6 Jun 2022 04:28:44 -0400 Subject: [PATCH 4/5] Moving Fname regex to config --- src/engine/Enum.java | 1 + src/engine/gameManager/ConfigManager.java | 9 +++++++++ src/engine/util/MiscUtils.java | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/engine/Enum.java b/src/engine/Enum.java index 43d8f499..a7a5257c 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.concurrent.ThreadLocalRandom; +import java.util.regex.Pattern; /* * MagicBane engine enumeration class. diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index 9d3fa882..61161c62 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -16,10 +16,12 @@ import engine.Enum; import engine.net.NetMsgHandler; import engine.server.login.LoginServer; import engine.server.world.WorldServer; +import jdk.nashorn.internal.runtime.regexp.joni.ast.StringNode; import org.pmw.tinylog.Logger; import java.util.HashMap; import java.util.Map; +import java.util.regex.Pattern; public enum ConfigManager { @@ -47,6 +49,8 @@ public enum ConfigManager { MB_LOGIN_PORT, MB_LOGIN_AUTOREG, + MB_LOGIN_FNAME_REGEX, + MB_MAJOR_VER, MB_MINOR_VER, @@ -87,6 +91,7 @@ public enum ConfigManager { public static NetMsgHandler handler; public static WorldServer worldServer; public static LoginServer loginServer; + public static Map regex = new HashMap<>(); // Called at bootstrap: ensures that all config values are loaded. @@ -103,6 +108,10 @@ public enum ConfigManager { return false; } + // compile regex here + + regex.put(MB_LOGIN_FNAME_REGEX, Pattern.compile(MB_LOGIN_FNAME_REGEX.getValue())); + return true; } diff --git a/src/engine/util/MiscUtils.java b/src/engine/util/MiscUtils.java index 550d21f5..cb42e93c 100644 --- a/src/engine/util/MiscUtils.java +++ b/src/engine/util/MiscUtils.java @@ -9,6 +9,7 @@ package engine.util; +import engine.gameManager.ConfigManager; import engine.server.MBServerStatics; import java.util.regex.Pattern; @@ -29,7 +30,7 @@ public class MiscUtils { || (firstName.length() < MBServerStatics.MIN_NAME_LENGTH)) { return true; } - return (!firstNameRegex.matcher(firstName).matches()); + return (!ConfigManager.regex.get(ConfigManager.MB_LOGIN_FNAME_REGEX).matcher(firstName).matches()); } public static boolean checkIfLastNameInvalid(String lastName) { From 4f2954041dc7a208c8fd45e4d56644d2d9fab4b9 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 6 Jun 2022 04:48:04 -0400 Subject: [PATCH 5/5] Removed unused code. --- src/engine/util/MiscUtils.java | 55 ---------------------------------- 1 file changed, 55 deletions(-) diff --git a/src/engine/util/MiscUtils.java b/src/engine/util/MiscUtils.java index cb42e93c..bb2e2ec0 100644 --- a/src/engine/util/MiscUtils.java +++ b/src/engine/util/MiscUtils.java @@ -17,13 +17,6 @@ import java.util.regex.Pattern; public class MiscUtils { - // no need to recompile these each call, put them in object scope and - // compile just once. - private static final Pattern lastNameRegex = Pattern - .compile("^[A-Za-z][-'A-Za-z\\x20]*$"); - private static final Pattern firstNameRegex = Pattern - .compile("^[A-Za-z]+$"); - public static boolean checkIfFirstNameInvalid(String firstName) { if ((firstName == null) || (firstName.length() == 0) || (firstName.length() > MBServerStatics.MAX_NAME_LENGTH) @@ -44,52 +37,4 @@ public class MiscUtils { // empty last names are fine, return false return false; } - - public static String getCallingMethodName() { - StackTraceElement e[] = Thread.currentThread().getStackTrace(); - int numElements = e.length; - - if (numElements < 1) { - return "NoStack"; - } - - if (numElements == 1) { - return e[0].getMethodName(); - } else if (numElements == 2) { - return e[1].getMethodName(); - } else if (numElements == 3) { - return e[2].getMethodName(); - } else { - return e[3].getMethodName(); - } - } - - public static String getCallStackAsString() { - String out = ""; - - StackTraceElement e[] = Thread.currentThread().getStackTrace(); - int numElements = e.length; - - for (int i = (numElements - 1); i > 1; --i) { - - String[] classStack = e[i].getClassName().split("\\."); - String methName = e[i].getMethodName(); - - String className = classStack[classStack.length - 1]; - - if (methName.equals("")) { - methName = className; - } - - out += className + '.' + methName + "()"; - - if (i > 2) { - out += " -> "; - } - - } - - return out; - } - }