Fixes to character name validation

Admin should be able to create any name
Also fixes to config.character_name_min_length being ignored
This commit is contained in:
slawkens 2021-01-20 18:02:07 +01:00
parent 8b41e144f8
commit 81b293a5a6
4 changed files with 32 additions and 14 deletions

View File

@ -35,6 +35,13 @@ class CreateCharacter
}
}
$player = new OTS_Player();
$player->find($name);
if($player->isLoaded()) {
$errors['name'] = 'Character with this name already exist.';
return false;
}
if(empty($sex) && $sex != "0")
$errors['sex'] = 'Please select the sex for your character!';
@ -214,4 +221,4 @@ class CreateCharacter
$account->logAction('Created character <b>' . $name . '</b>.');
return true;
}
}
}

View File

@ -180,14 +180,17 @@ class Validator
return false;
}
$minLength = config('character_name_min_length');
$maxLength = config('character_name_max_length');
$length = strlen($name);
if($length < 3)
if($length < $minLength)
{
self::$lastError = 'Character name is too short. Min. length <b>3</b> characters.';
return false;
}
if($length > 25)
if($length > $maxLength)
{
self::$lastError = 'Character name is too long. Max. length <b>25</b> characters.';
return false;
@ -201,7 +204,7 @@ class Validator
if(preg_match('/ {2,}/', $name))
{
self::$lastError = 'Invalid character name format. Use only A-Z and numbers 0-9 and no double spaces.';
self::$lastError = 'Invalid character name format. Use only A-Z and no double spaces.';
return false;
}
@ -289,13 +292,6 @@ class Validator
}
}
$player = new OTS_Player();
$player->find($name);
if($player->isLoaded()) {
self::$lastError = 'Character with this name already exist.';
return false;
}
//check if was namelocked previously
if($db->hasTable('player_namelocks') && $db->hasColumn('player_namelocks', 'name')) {
$namelock = $db->query('SELECT `player_id` FROM `player_namelocks` WHERE `name` = ' . $db->quote($name));

View File

@ -15,6 +15,10 @@ $character_sex = isset($_POST['sex']) ? (int)$_POST['sex'] : null;
$character_vocation = isset($_POST['vocation']) ? (int)$_POST['vocation'] : null;
$character_town = isset($_POST['town']) ? (int)$_POST['town'] : null;
if (!admin() && !empty($character_name)) {
$character_name = ucwords(strtolower($character_name));
}
$character_created = false;
$save = isset($_POST['save']) && $_POST['save'] == 1;
$errors = array();

View File

@ -13,6 +13,7 @@
require '../common.php';
require SYSTEM . 'functions.php';
require SYSTEM . 'init.php';
require SYSTEM . 'login.php';
$error = '';
if(isset($_GET['account']))
@ -54,14 +55,24 @@ else if(isset($_GET['email']))
}
else if(isset($_GET['name']))
{
$name = strtolower(stripslashes($_GET['name']));
$name = $_GET['name'];
if(!admin()) {
$name = strtolower(stripslashes($name));
}
if(!Validator::characterName($name))
error_(Validator::getLastError());
if(!Validator::newCharacterName($name))
if(!admin() && !Validator::newCharacterName($name))
error_(Validator::getLastError());
success_('Good. Your name will be:<br /><b>' . ucwords($name) . '</b>');
$player = new OTS_Player();
$player->find($name);
if($player->isLoaded()) {
error_('Character with this name already exist.');
}
success_('Good. Your name will be:<br /><b>' . (admin() ? $name : ucwords($name)) . '</b>');
}
else if(isset($_GET['password']) && isset($_GET['password2'])) {
$password = $_GET['password'];