Sets the minimun lenght and maximun at config (#54)

* Sets the minimun lenght and maximun at config

* Update codes
This commit is contained in:
vankk 2018-05-27 08:41:07 -03:00 committed by slawkens
parent cfef209cb7
commit 46ca6262b5
2 changed files with 16 additions and 8 deletions

View File

@ -139,6 +139,11 @@ $config = array(
// won't be displayed if there is only one item (rookgaard for example) // won't be displayed if there is only one item (rookgaard for example)
'character_towns' => array(1), 'character_towns' => array(1),
// characters lenght
// This is the minimum and the maximum length that a player can create a character. It is highly recommend the maximum lenght be 21.
'character_name_min_length' => 4,
'character_name_max_length' => 21
// list of towns // list of towns
'towns' => array( 'towns' => array(
0 => 'No town', 0 => 'No town',

View File

@ -19,12 +19,15 @@ $newchar_town = isset($_POST['town']) ? $_POST['town'] : NULL;
$newchar_created = false; $newchar_created = false;
$save = isset($_POST['save']) && $_POST['save'] == 1; $save = isset($_POST['save']) && $_POST['save'] == 1;
if($save) { if($save) {
$minLength = $config['character_name_min_length'];
$maxLength = $config['character_name_max_length'];
if(empty($newchar_name)) if(empty($newchar_name))
$errors['name'] = 'Please enter a name for your character!'; $errors['name'] = 'Please enter a name for your character!';
else if(strlen($newchar_name) > 21) else if(strlen($newchar_name) > $maxLength)
$errors['name'] = 'Name is too long. Max. lenght <b>21</b> letters.'; $errors['name'] = 'Name is too long. Max. lenght <b>'.$maxLength.'</b> letters.';
else if(strlen($newchar_name) < 4) else if(strlen($newchar_name) < $minLength)
$errors['name'] = 'Name is too short. Min. lenght <b>4</b> letters.'; $errors['name'] = 'Name is too short. Min. lenght <b>'.$minLength.'</b> letters.';
else { else {
if(!admin() && !Validator::newCharacterName($newchar_name)) { if(!admin() && !Validator::newCharacterName($newchar_name)) {
$errors['name'] = Validator::getLastError(); $errors['name'] = Validator::getLastError();