Character name template pattern moved to Config class.

This commit is contained in:
MobiusDev 2018-05-24 16:44:17 +00:00
parent 118fd7f0cb
commit 9dc3fb10b8
2 changed files with 18 additions and 24 deletions

View File

@ -45,6 +45,8 @@ import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@ -867,7 +869,7 @@ public final class Config
public static String BACKUP_PATH;
public static int BACKUP_DAYS;
public static int MAXIMUM_ONLINE_USERS;
public static String CNAME_TEMPLATE;
public static Pattern CHARNAME_TEMPLATE_PATTERN;
public static String PET_NAME_TEMPLATE;
public static String CLAN_NAME_TEMPLATE;
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
@ -1398,7 +1400,20 @@ public final class Config
DATAPACK_ROOT = new File(".");
}
CNAME_TEMPLATE = serverSettings.getString("CnameTemplate", ".*");
Pattern charNamePattern;
try
{
charNamePattern = Pattern.compile(serverSettings.getString("CnameTemplate", ".*"));
}
catch (PatternSyntaxException e)
{
LOGGER.log(Level.WARNING, "Character name pattern is invalid!", e);
charNamePattern = Pattern.compile(".*");
}
CHARNAME_TEMPLATE_PATTERN = charNamePattern;
PET_NAME_TEMPLATE = serverSettings.getString("PetNameTemplate", ".*");
CLAN_NAME_TEMPLATE = serverSettings.getString("ClanNameTemplate", ".*");

View File

@ -18,9 +18,6 @@ package com.l2jmobius.gameserver.network.clientpackets;
import java.util.List;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import com.l2jmobius.Config;
import com.l2jmobius.commons.network.PacketReader;
@ -247,25 +244,7 @@ public final class CharacterCreate implements IClientIncomingPacket
private boolean isValidName(String text)
{
boolean result = true;
final String test = text;
Pattern pattern;
// UnAfraid: TODO: Move that into Config
try
{
pattern = Pattern.compile(Config.CNAME_TEMPLATE);
}
catch (PatternSyntaxException e) // case of illegal pattern
{
LOGGER.warning("ERROR : Character name pattern of config is wrong!");
pattern = Pattern.compile(".*");
}
final Matcher regexp = pattern.matcher(test);
if (!regexp.matches())
{
result = false;
}
return result;
return Config.CHARNAME_TEMPLATE_PATTERN.matcher(text).matches();
}
private void initNewChar(L2GameClient client, L2PcInstance newChar)