From 24d96f24b2b6552433976ee7e1fffb6e9f57539c Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 6 Jun 2022 04:28:44 -0400 Subject: [PATCH] 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) {