Character name template pattern moved to Config class.
This commit is contained in:
parent
118fd7f0cb
commit
9dc3fb10b8
@ -45,6 +45,8 @@ import java.util.Set;
|
|||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.regex.PatternSyntaxException;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
@ -867,7 +869,7 @@ public final class Config
|
|||||||
public static String BACKUP_PATH;
|
public static String BACKUP_PATH;
|
||||||
public static int BACKUP_DAYS;
|
public static int BACKUP_DAYS;
|
||||||
public static int MAXIMUM_ONLINE_USERS;
|
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 PET_NAME_TEMPLATE;
|
||||||
public static String CLAN_NAME_TEMPLATE;
|
public static String CLAN_NAME_TEMPLATE;
|
||||||
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
|
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
|
||||||
@ -1398,7 +1400,20 @@ public final class Config
|
|||||||
DATAPACK_ROOT = new File(".");
|
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", ".*");
|
PET_NAME_TEMPLATE = serverSettings.getString("PetNameTemplate", ".*");
|
||||||
CLAN_NAME_TEMPLATE = serverSettings.getString("ClanNameTemplate", ".*");
|
CLAN_NAME_TEMPLATE = serverSettings.getString("ClanNameTemplate", ".*");
|
||||||
|
|
||||||
|
@ -18,9 +18,6 @@ package com.l2jmobius.gameserver.network.clientpackets;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Logger;
|
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.Config;
|
||||||
import com.l2jmobius.commons.network.PacketReader;
|
import com.l2jmobius.commons.network.PacketReader;
|
||||||
@ -247,25 +244,7 @@ public final class CharacterCreate implements IClientIncomingPacket
|
|||||||
|
|
||||||
private boolean isValidName(String text)
|
private boolean isValidName(String text)
|
||||||
{
|
{
|
||||||
boolean result = true;
|
return Config.CHARNAME_TEMPLATE_PATTERN.matcher(text).matches();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initNewChar(L2GameClient client, L2PcInstance newChar)
|
private void initNewChar(L2GameClient client, L2PcInstance newChar)
|
||||||
|
Loading…
Reference in New Issue
Block a user