diff --git a/src/engine/Enum.java b/src/engine/Enum.java index 7bfa1d5f..4d312b41 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/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/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index 38e6c8f0..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. @@ -99,9 +104,14 @@ 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; } + // compile regex here + + regex.put(MB_LOGIN_FNAME_REGEX, Pattern.compile(MB_LOGIN_FNAME_REGEX.getValue())); + return true; } 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/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(); 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; diff --git a/src/engine/util/MiscUtils.java b/src/engine/util/MiscUtils.java index 550d21f5..bb2e2ec0 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; @@ -16,20 +17,13 @@ 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) || (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) { @@ -43,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; - } - }