L2JMobius

High Five characters allowed in pets' names

kinghanker · 1 · 939

Offline kinghanker

  • Black Sheep
  • Knight
  • ***
    • Posts: 90
I was testing some restrictions on the server and came across a problem restricting the characters used when naming pets

I tried to limit it to just letters and numbers but it continued to accept symbols


Code: [Select]
# This setting restricts names players can give to their pets.
# See CnameTemplate for details
PetNameTemplate = ([a-zA-Z0-9]{1,16})

I made a small correction and it solved the problem

Code: [Select]
/java/org/l2jmobius/gameserver/data/sql/PetNameTable.java
 
  public boolean isValidPetName(String name)
{
if (Config.PET_NAME_TEMPLATE.equals(".*"))
{
return true;
}

if (!isAlphaNumeric(name))
{
return false;
}

Pattern pattern;
try
{
pattern = Pattern.compile(Config.PET_NAME_TEMPLATE);
}
catch (PatternSyntaxException e)
{
LOGGER.warning(getClass().getSimpleName() + ": Pet name pattern in config is invalid!");
return false;
}

return pattern.matcher(name).matches();
}

private boolean isAlphaNumeric(String text)
{
if ((text == null) || text.isEmpty())
{
return false;
}

for (char aChar : text.toCharArray())
{
if (!Character.isLetterOrDigit(aChar))
{
return false;
}
}
return true;
}
 
  private static class SingletonHolder

The problem will present itself in different ways because when there is alphanumeric verification it will block any symbol even if it is in the permitted group. Wouldn't it be better if it was defined that the names of players, pets and clans NEVER use symbols under any circumstances? we could remove the configs from the server.ini file