Fixes in create new character nick

+ fixed config.character_name_min/max_length being ignored in change_name.php

(cherry picked from commit d148b71f0f)
This commit is contained in:
slawkens
2020-05-09 13:12:45 +02:00
parent 1d6afea9c4
commit 2f52e5d9f3
3 changed files with 35 additions and 41 deletions

View File

@@ -85,6 +85,12 @@ class Validator
return false;
}
if(preg_match('/ {2,}/', $name))
{
self::$lastError = 'Invalid account name format. Use only A-Z and numbers 0-9 and no double spaces.';
return false;
}
if(!preg_match("/[A-Z0-9]/i", $name))
{
self::$lastError = 'Invalid account name format. Use only A-Z and numbers 0-9.';
@@ -179,13 +185,13 @@ class Validator
$length = strlen($name);
if($length < 3)
{
self::$lastError = 'Character name is too short. Min. lenght <b>3</b> characters.';
self::$lastError = 'Character name is too short. Min. length <b>3</b> characters.';
return false;
}
if($length > 25)
{
self::$lastError = 'Character name is too long. Max. lenght <b>25</b> characters.';
self::$lastError = 'Character name is too long. Max. length <b>25</b> characters.';
return false;
}
@@ -194,6 +200,13 @@ class Validator
self::$lastError = "Invalid name format. Use only A-Z, spaces and '.";
return false;
}
if(preg_match('/ {2,}/', $name))
{
self::$lastError = 'Invalid character name format. Use only A-Z and numbers 0-9 and no double spaces.';
return false;
}
if(!preg_match("/[A-z ']/", $name))
{
self::$lastError = "Invalid name format. Use only A-Z, spaces and '.";
@@ -216,7 +229,7 @@ class Validator
$name_lower = strtolower($name);
$first_words_blocked = array('admin ', 'administrator ', 'gm ', 'cm ', 'god ','tutor ', "'", '-');
$first_words_blocked = array('admin ', 'administrator ', 'gm ', 'cm ', 'god ','tutor ');
foreach($first_words_blocked as $word)
{
if($word == substr($name_lower, 0, strlen($word))) {
@@ -240,6 +253,12 @@ class Validator
return false;
}
if(preg_match('/ {2,}/', $name))
{
self::$lastError = 'Invalid character name format. Use only A-Z and numbers 0-9 and no double spaces.';
return false;
}
if(strtolower($config['lua']['serverName']) == $name_lower) {
self::$lastError = 'Your name cannot be same as server name.';
return false;
@@ -272,14 +291,6 @@ class Validator
}
}
for($i = 0; $i < $name_length; $i++)
{
if(isset($name_lower[$i - 1]) && $name_lower[$i - 1] == ' ' && isset($name_lower[$i + 1]) && $name_lower[$i + 1] == ' ') {
self::$lastError = 'Your name contains too many spaces.';
return false;
}
}
$player = new OTS_Player();
$player->find($name);
if($player->isLoaded()) {
@@ -327,13 +338,7 @@ class Validator
return false;
}
if($name_length < 3 || $name_length > 28) {
self::$lastError = 'Your name cannot be shorter than 3 characters and longer than 28 characters.';
return false;
}
if(!preg_match("/[A-z ']{3,28}/", $name)) {
if(!preg_match("/[A-z ']/", $name)) {
self::$lastError = 'Your name containst illegal characters.';
return false;
}