From 191137282b7a49055d6dcb9f8a64bfb543f8ad66 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 22 Jul 2023 10:33:20 +0200 Subject: [PATCH] Create character blocked words (by @gpedro), just moved to settings --- system/libs/validator.php | 38 +++++++------------------------------- system/settings.php | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/system/libs/validator.php b/system/libs/validator.php index eb958583..e90d5b71 100644 --- a/system/libs/validator.php +++ b/system/libs/validator.php @@ -246,14 +246,9 @@ class Validator global $db, $config; $name_lower = strtolower($name); - $custom_first_words_blocked = []; - if (isset($config['character_name_blocked']['prefix']) && $config['character_name_blocked']['prefix']) { - $custom_first_words_blocked = $config['character_name_blocked']['prefix']; - } - $first_words_blocked = array_merge($custom_first_words_blocked, array('admin ', 'administrator ', 'gm ', 'cm ', 'god ','tutor ', "'", '-')); - foreach($first_words_blocked as $word) - { + $first_words_blocked = array_merge(["'", '-'], setting('core.create_character_name_blocked_prefix')); + foreach($first_words_blocked as $word) { if($word == substr($name_lower, 0, strlen($word))) { self::$lastError = 'Your name contains blocked words.'; return false; @@ -275,8 +270,7 @@ class Validator return false; } - if(preg_match('/ {2,}/', $name)) - { + 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; } @@ -286,26 +280,16 @@ class Validator return false; } - $custom_names_blocked = []; - if (isset($config['character_name_blocked']['names']) && $config['character_name_blocked']['names']) { - $custom_names_blocked = $config['character_name_blocked']['names']; - } - $names_blocked = array_merge($custom_names_blocked, array('admin', 'administrator', 'gm', 'cm', 'god', 'tutor')); - foreach($names_blocked as $word) - { + $names_blocked = setting('core.create_character_name_blocked_names'); + foreach($names_blocked as $word) { if($word == $name_lower) { self::$lastError = 'Your name contains blocked words.'; return false; } } - $custom_words_blocked = []; - if (isset($config['character_name_blocked']['words']) && $config['character_name_blocked']['words']) { - $custom_words_blocked = $config['character_name_blocked']['words']; - } - $words_blocked = array_merge($custom_words_blocked, array('admin', 'administrator', 'gamemaster', 'game master', 'game-master', "game'master", '--', "''","' ", " '", '- ', ' -', "-'", "'-", 'fuck', 'sux', 'suck', 'noob', 'tutor')); - foreach($words_blocked as $word) - { + $words_blocked = array_merge(['--', "''","' ", " '", '- ', ' -', "-'", "'-"], setting('core.create_character_name_blocked_words')); + foreach($words_blocked as $word) { if(!(strpos($name_lower, $word) === false)) { self::$lastError = 'Your name contains illegal words.'; return false; @@ -348,14 +332,6 @@ class Validator return false; } - if(isset($config['npc'])) - { - if(in_array($name_lower, $config['npc'])) { - self::$lastError = 'Your name cannot contains NPC name.'; - return false; - } - } - $npcCheck = config('character_name_npc_check'); if ($npcCheck) { require_once LIBS . 'npc.php'; diff --git a/system/settings.php b/system/settings.php index d31debc6..94370237 100644 --- a/system/settings.php +++ b/system/settings.php @@ -616,6 +616,43 @@ Sent by MyAAC,
'desc' => 'should country of user be automatically recognized by his IP? This makes an external API call to http://ipinfo.io', 'default' => true, ], + 'create_character' => [ + 'type' => 'section', + 'title' => 'Create Character', + ], + 'create_character_name_blocked_prefix' => [ + 'name' => 'Create Character Blocked Prefix', + 'type' => 'textarea', + 'desc' => 'Space after is important!', + 'default' => 'admin ,administrator ,gm ,cm ,god ,tutor', + 'callbacks' => [ + 'get' => function ($value) { + return explode(',', $value); + }, + ], + ], + 'create_character_name_blocked_names' => [ + 'name' => 'Create Character Blocked Names', + 'type' => 'textarea', + 'desc' => 'Separated by comma (,)', + 'default' => 'admin,administrator,gm,cm,god,tutor', + 'callbacks' => [ + 'get' => function ($value) { + return array_map('trim', explode(',', $value)); + }, + ], + ], + 'create_character_name_blocked_words' => [ + 'name' => 'Create Character Blocked Words', + 'type' => 'textarea', + 'desc' => 'Separated by comma (,)', + 'default' => "admin,administrator,gamemaster,game master,game-master,game'master,fuck,sux,suck,noob,tutor", + 'callbacks' => [ + 'get' => function ($value) { + return array_map('trim', explode(',', $value)); + }, + ], + ], 'account_mail_confirmed_reward' => [ 'type' => 'section', 'title' => 'Reward Users for confirming their E-Mails. Works only with Account Mail Verify enabled',