* new account.login view for tibiacom template

* added new indicator icons for create account, create character and change character name
* attempt to fix incorrect views counter behavior (its resetting to 0 in some cases)
* moved check_* functions to class Validator
* from now all validators ajax requests will fire onblur instead of onkeyup
* ajax requests returns now json instead of xml
* added 404 response when file is not found
* fixed gallery
This commit is contained in:
slawkens
2017-10-16 16:49:35 +02:00
parent dd572b00d0
commit 4daaa67710
263 changed files with 886 additions and 539 deletions

View File

@@ -383,294 +383,6 @@ function delete_guild($id)
return true;
}
/**
* Validate character name.
* Name lenght must be 3-25 chars
*
* @param string $name Name to check
* @param string $error Error description will be placed here
* @return bool Is name valid?
*/
function check_name($name, &$error = '')
{
if(!isset($name[0]))
{
$error = 'Please enter character name.';
return false;
}
$length = strlen($name);
if($length < 3)
{
$error = 'Character name is too short. Min. lenght <b>3</b> characters.';
return false;
}
if($length > 25)
{
$error = 'Character name is too long. Max. lenght <b>25</b> characters.';
return false;
}
if(strspn($name, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM- [ ] '") != $length)
{
$error = 'Invalid name format. Use only A-Z.';
return false;
}
return preg_match("/[A-z ']/", $name);
}
/**
* Validate account id
* Id lenght must be 6-10 chars
*
* @param string $name Account name to check
* @param string $error Error description will be placed here
* @return bool Is account name valid?
*/
function check_account_id($id, &$error = '')
{
if(!isset($id[0]))
{
$error = 'Please enter an account.';
return false;
}
if(!check_number($id)) {
$error = 'Invalid account name format. Use only numbers 0-9.';
return false;
}
$length = strlen($id);
if($length < 6)
{
$error = 'Account is too short (min. 6 chars).';
return false;
}
if($length > 10)
{
$error = 'Account is too long (max. 10 chars).';
return false;
}
return true;
}
/**
* Validate account name
* Name lenght must be 3-32 chars
*
* @param string $name Account name to check
* @param string $error Error description will be placed here
* @return bool Is account name valid?
*/
function check_account_name($name, &$error = '')
{
if(!isset($name[0]))
{
$error = 'Please enter an account name.';
return false;
}
$length = strlen($name);
if($length < 3)
{
$error = 'Account name is too short (min. 3 chars).';
return false;
}
if($length > 32)
{
$error = 'Account name is too long (max. 32 chars).';
return false;
}
if(strspn($name, "QWERTYUIOPASDFGHJKLZXCVBNM0123456789") != $length)
{
$error = 'Invalid account name format. Use only A-Z and numbers 0-9.';
return false;
}
return preg_match("/[A-Z0-9]/", $name);
}
//is it valid nick for new char?
function check_name_new_char($name, &$error = '')
{
global $db, $config;
$name_lower = strtolower($name);
$first_words_blocked = array('admin ', 'administrator ', 'gm ', 'cm ', 'god ','tutor ', "'", '-');
foreach($first_words_blocked as $word)
{
if($word == substr($name_lower, 0, strlen($word))) {
$error = 'Your name contains blocked words.';
return false;
}
}
if(substr($name_lower, -1) == "'" || substr($name_lower, -1) == "-") {
$error = 'Your name contains illegal characters.';
return false;
}
if(substr($name_lower, 1, 1) == ' ') {
$error = 'Your name contains illegal space.';
return false;
}
if(substr($name_lower, -2, 1) == " ") {
$error = 'Your name contains illegal space.';
return false;
}
if(strtolower($config['lua']['serverName']) == $name_lower) {
$error = 'Your name cannot be same as server name.';
return false;
}
$names_blocked = array('admin', 'administrator', 'gm', 'cm', 'god', 'tutor');
foreach($names_blocked as $word)
{
if($word == $name_lower) {
$error = 'Your name contains blocked words.';
return false;
}
}
$words_blocked = array('admin', 'administrator', 'gamemaster', 'game master', 'game-master', "game'master", '--', "''","' ", " '", '- ', ' -', "-'", "'-", 'fuck', 'sux', 'suck', 'noob', 'tutor');
foreach($words_blocked as $word)
{
if(!(strpos($name_lower, $word) === false)) {
$error = 'Your name contains illegal words.';
return false;
}
}
$name_length = strlen($name_lower);
for($i = 0; $i < $name_length; $i++)
{
if(isset($name_lower[$i]) && isset($name_lower[$i + 1]) && $name_lower[$i] == $name_lower[$i + 1] && isset($name_lower[$i + 2]) && $name_lower[$i] == $name_lower[$i + 2]) {
$error = 'Your name is invalid.';
return false;
}
}
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] == ' ') {
$error = 'Your name contains too many spaces.';
return false;
}
}
if(isset($config['monsters']))
{
if(in_array($name_lower, $config['monsters'])) {
$error = 'Your name cannot contains monster name.';
return false;
}
}
$player = new OTS_Player();
$player->find($name);
if($player->isLoaded()) {
$error = 'Character with this name already exist.';
return false;
}
//check if was namelocked previously
if(tableExist('player_namelocks') && fieldExist('name', 'player_namelocks')) {
$namelock = $db->query('SELECT `player_id` FROM `player_namelocks` WHERE `name` = ' . $db->quote($name));
if($namelock->rowCount() > 0) {
$error = 'Character with this name has been namelocked.';
return false;
}
}
$monsters = $db->query('SELECT `name` FROM `' . TABLE_PREFIX . 'monsters` WHERE `name` LIKE ' . $db->quote($name_lower));
if($monsters->rowCount() > 0) {
$error = 'Your name cannot contains monster name.';
return false;
}
$spells_name = $db->query('SELECT `name` FROM `' . TABLE_PREFIX . 'spells` WHERE `name` LIKE ' . $db->quote($name_lower));
if($spells_name->rowCount() > 0) {
$error = 'Your name cannot contains spell name.';
return false;
}
$spells_words = $db->query('SELECT `words` FROM `' . TABLE_PREFIX . 'spells` WHERE `words` = ' . $db->quote($name_lower));
if($spells_words->rowCount() > 0) {
$error = 'Your name cannot contains spell name.';
return false;
}
if(isset($config['npc']))
{
if(in_array($name_lower, $config['npc'])) {
$error = 'Your name cannot contains NPC name.';
return false;
}
}
if(strspn($name, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM- '") != $name_length) {
$error = 'This name contains invalid letters, words or format. Please use only a-Z, - , \' and space.';
return false;
}
if($name_length < 3 || $name_length > 28) {
$error = 'Your name cannot be shorter than 3 characters and longer than 28 characters.';
return false;
}
if(!preg_match("/[A-z ']{3,28}/", $name)) {
$error = 'Your name containst illegal characters.';
return false;
}
return true;
}
function check_rank_name($name)
{
if(strspn($name, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789-[ ] ") != strlen($name))
return false;
return preg_match("/[A-z ]{1,32}/", $name);
}
function check_guild_name($name)
{
if(strspn($name, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789- ") != strlen($name))
return false;
return preg_match("/[A-z ]{3,32}/", $name);
}
function check_password($pass)
{
if(strspn($pass, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890") != strlen($pass))
return false;
return preg_match("/[A-z0-9]/", $pass);
}
function check_mail($email)
{
return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[A-z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $email);
//return preg_match("/[A-z0-9._-]+@[A-z0-9-]+\.[A-z]{2,4}/", $email);
}
function check_number($number)
{
return preg_match ("/^([0-9]+)$/", $number);
}
//################### DISPLAY FUNCTIONS #####################
//return shorter text (news ticker)
function short_text($text, $limit)
@@ -1224,10 +936,13 @@ function load_config_lua($filename)
}
function str_replace_first($search, $replace, $subject) {
$pos = strpos($subject, $search);
if ($pos !== false) {
return substr_replace($subject, $replace, $pos, strlen($search));
}
return $subject;
$pos = strpos($subject, $search);
if ($pos !== false) {
return substr_replace($subject, $replace, $pos, strlen($search));
}
return $subject;
}
// validator functions
require_once(LIBS . 'validator.php');
?>