From 35dfaa28edfe3686a9e07f9f4e4bb83cd811ae69 Mon Sep 17 00:00:00 2001 From: slawkens Date: Thu, 9 Jan 2025 20:57:23 +0100 Subject: [PATCH 01/79] Update index.php --- templates/tibiacom/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/tibiacom/index.php b/templates/tibiacom/index.php index 2152b043..c19b1d12 100644 --- a/templates/tibiacom/index.php +++ b/templates/tibiacom/index.php @@ -348,7 +348,7 @@ foreach($config['menu_categories'] as $id => $cat) { } $link_color = '#' . (strlen($menu['color']) == 0 ? $default_menu_color : $menu['color']); ?> - '> + '> Date: Fri, 17 Jan 2025 16:36:05 +0100 Subject: [PATCH 28/79] Additional fix to previous commit --- templates/tibiacom/index.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/templates/tibiacom/index.php b/templates/tibiacom/index.php index 852ac47e..aa8785ff 100644 --- a/templates/tibiacom/index.php +++ b/templates/tibiacom/index.php @@ -326,14 +326,22 @@ if(isset($config['boxes'])) $cat) { + if (!isset($menus[$id]) || ($id == MENU_CATEGORY_SHOP && !setting('core.gifts_system'))) { + continue; + } + + $countElements++; +} + $i = 0; foreach($config['menu_categories'] as $id => $cat) { - $i++; - if(!isset($menus[$id]) || ($id == MENU_CATEGORY_SHOP && !setting('core.gifts_system'))) { continue; } + + $i++; ?>
' class='menuitem'> @@ -373,7 +381,7 @@ foreach($config['menu_categories'] as $id => $cat) { ?>
Date: Fri, 17 Jan 2025 17:12:21 +0100 Subject: [PATCH 29/79] functions_custom.php are not optional --- system/functions.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/system/functions.php b/system/functions.php index 11926f51..89f45676 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1679,4 +1679,7 @@ function getAccountIdentityColumn(): string require_once SYSTEM . 'compat/base.php'; // custom functions -require SYSTEM . 'functions_custom.php'; +$customFunctions = SYSTEM . 'functions_custom.php'; +if (is_file($customFunctions)) { + require $customFunctions; +} From 4f6178eca0a34ac98f1d132e284502e2456ad7bd Mon Sep 17 00:00:00 2001 From: slawkens Date: Fri, 17 Jan 2025 21:07:02 +0100 Subject: [PATCH 30/79] Initialize menus with menu_categories If user add custom categories, it will fix an issue where Menu is not collapsed --- templates/tibiacom/index.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/templates/tibiacom/index.php b/templates/tibiacom/index.php index aa8785ff..a03ff3e3 100644 --- a/templates/tibiacom/index.php +++ b/templates/tibiacom/index.php @@ -115,6 +115,15 @@ if(isset($config['boxes'])) menu[0] = {}; var unloadhelper = false; + + // load the menu and set the active submenu item by using the variable 'activeSubmenuItem' function LoadMenu() { @@ -122,7 +131,7 @@ if(isset($config['boxes'])) document.getElementById("ActiveSubmenuItemIcon_"+activeSubmenuItem).style.visibility = "visible"; menus = localStorage.getItem('menus'); if(menus == null || menus.lastIndexOf("&") === -1) { - menus = "news=1&account=0&community=0&library=0&forum=0&"; + menus = ""; } FillMenuArray(); InitializeMenu(); From 13a1598a464d87e4d4252f54c6f4e1367e925224 Mon Sep 17 00:00:00 2001 From: slawkens Date: Fri, 17 Jan 2025 22:38:27 +0100 Subject: [PATCH 31/79] Nothing important: Convert spaces to tabs --- system/libs/pot/OTS_Player.php | 2824 ++++++++++++++++---------------- 1 file changed, 1412 insertions(+), 1412 deletions(-) diff --git a/system/libs/pot/OTS_Player.php b/system/libs/pot/OTS_Player.php index 478450b5..d0b6a831 100644 --- a/system/libs/pot/OTS_Player.php +++ b/system/libs/pot/OTS_Player.php @@ -90,7 +90,7 @@ class OTS_Player extends OTS_Row_DAO * @version 0.1.2 * @var array */ - private $data = array('group_id' => 1, 'sex' => 0, 'vocation' => 0, 'experience' => 0, 'level' => 1, 'maglevel' => 0, 'health' => 100, 'healthmax' => 100, 'mana' => 100, 'manamax' => 100, 'manaspent' => 0, 'soul' => 0, 'lookbody' => 10, 'lookfeet' => 10, 'lookhead' => 10, 'looklegs' => 10, 'looktype' => 136, 'lookaddons' => 0, 'posx' => 0, 'posy' => 0, 'posz' => 0, 'cap' => 0, 'lastlogin' => 0, 'lastip' => 0, 'save' => true, 'skulltime' => 0, 'skull' => 0, 'balance' => 0, 'lastlogout' => 0, 'blessings' => 0, 'stamina' => 0, 'online' => 0, 'comment' => '', 'created' => 0, 'hide' => 0); + private $data = array('group_id' => 1, 'sex' => 0, 'vocation' => 0, 'experience' => 0, 'level' => 1, 'maglevel' => 0, 'health' => 100, 'healthmax' => 100, 'mana' => 100, 'manamax' => 100, 'manaspent' => 0, 'soul' => 0, 'lookbody' => 10, 'lookfeet' => 10, 'lookhead' => 10, 'looklegs' => 10, 'looktype' => 136, 'lookaddons' => 0, 'posx' => 0, 'posy' => 0, 'posz' => 0, 'cap' => 0, 'lastlogin' => 0, 'lastip' => 0, 'save' => true, 'skulltime' => 0, 'skull' => 0, 'balance' => 0, 'lastlogout' => 0, 'blessings' => 0, 'stamina' => 0, 'online' => 0, 'comment' => '', 'created' => 0, 'hide' => 0); /** * Player skills. @@ -99,7 +99,7 @@ class OTS_Player extends OTS_Row_DAO * @since 0.0.2 * @var array */ - private $skills = array( + private $skills = array( POT::SKILL_FIST => array('value' => 0, 'tries' => 0), POT::SKILL_CLUB => array('value' => 0, 'tries' => 0), POT::SKILL_SWORD => array('value' => 0, 'tries' => 0), @@ -117,10 +117,10 @@ class OTS_Player extends OTS_Row_DAO * @version 0.0.4 * @since 0.0.4 */ - public function __sleep() - { - return array('data', 'skills'); - } + public function __sleep() + { + return array('data', 'skills'); + } /** * Loads player with given id. @@ -129,8 +129,8 @@ class OTS_Player extends OTS_Row_DAO * @param int $id Player's ID. * @throws PDOException On PDO operation error. */ - public function load($id, $fields = null, $load_skills = true) - { + public function load($id, $fields = null, $load_skills = true) + { global $__load; if(!isset($__load['loss_experience'])) @@ -234,9 +234,9 @@ class OTS_Player extends OTS_Row_DAO $this->data = $this->db->query('SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`' . ($this->db->hasColumn('players', 'lookaddons') ? ', `lookaddons`' : '') . ', `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `save`, `conditions`, `' . $__load['skull_time'] . '` as `skulltime`, `' . $__load['skull_type'] . '` as `skull`' . $__load['guild_info'] . ', `town_id`' . $__load['loss_experience'] . $__load['loss_items'] . ', `balance`' . ($__load['blessings'] ? ', `blessings`' : '') . ($__load['direction'] ? ', `direction`' : '') . ($__load['stamina'] ? ', `stamina`' : '') . ($__load['world_id'] ? ', `world_id`' : '') . ($__load['online'] ? ', `online`' : '') . ', `' . ($__load['deletion'] ? 'deletion' : 'deleted') . '`' . ($__load['promotion'] ? ', `promotion`' : '') . ($__load['marriage'] ? ', `marriage`' : '') . ', `comment`, `created`, `hide` FROM `players` WHERE `id` = ' . (int)$id)->fetch(); } - // loads skills - if( $this->isLoaded() && $load_skills) - { + // loads skills + if( $this->isLoaded() && $load_skills) + { if($this->db->hasColumn('players', 'skill_fist')) { $skill_ids = array( @@ -271,8 +271,8 @@ class OTS_Player extends OTS_Row_DAO $this->skills[ $skill['skillid'] ] = array('value' => $skill['value'], 'tries' => $skill['count']); } } - } - } + } + } /** * Loads player by it's name. @@ -282,27 +282,27 @@ class OTS_Player extends OTS_Row_DAO * @param string $name Player's name. * @throws PDOException On PDO operation error. */ - public function find($name) - { - // finds player's ID - $id = $this->db->query('SELECT `id` FROM `players` WHERE `name` = ' . $this->db->quote($name) )->fetch(); + public function find($name) + { + // finds player's ID + $id = $this->db->query('SELECT `id` FROM `players` WHERE `name` = ' . $this->db->quote($name) )->fetch(); - // if anything was found - if( isset($id['id']) ) - { - $this->load($id['id']); - } - } + // if anything was found + if( isset($id['id']) ) + { + $this->load($id['id']); + } + } /** * Checks if object is loaded. * * @return bool Load state. */ - public function isLoaded() - { - return isset($this->data['id']); - } + public function isLoaded() + { + return isset($this->data['id']); + } /** * Saves player in database. @@ -314,8 +314,8 @@ class OTS_Player extends OTS_Row_DAO * @version 0.1.2 * @throws PDOException On PDO operation error. */ - public function save() - { + public function save() + { $skull_type = 'skull'; if($this->db->hasColumn('players', 'skull_type')) { $skull_type = 'skull_type'; @@ -359,9 +359,9 @@ class OTS_Player extends OTS_Row_DAO if(!isset($this->data['town_id'])) $this->data['town_id'] = 1; - // updates existing player - if( isset($this->data['id']) ) - { + // updates existing player + if( isset($this->data['id']) ) + { $loss = ''; if($this->db->hasColumn('players', 'loss_experience')) { $loss = ', `loss_experience` = ' . $this->data['loss_experience'] . ', `loss_mana` = ' . $this->data['loss_mana'] . ', `loss_skills` = ' . $this->data['loss_skills']; @@ -397,12 +397,12 @@ class OTS_Player extends OTS_Row_DAO $lookaddons = ', `lookaddons` = ' . $this->db->quote($this->data['lookaddons']); } - // UPDATE query on database - $this->db->query('UPDATE ' . $this->db->tableName('players') . ' SET ' . $this->db->fieldName('name') . ' = ' . $this->db->quote($this->data['name']) . ', ' . $this->db->fieldName('account_id') . ' = ' . $this->data['account_id'] . ', ' . $this->db->fieldName('group_id') . ' = ' . $this->data['group_id'] . ', ' . $this->db->fieldName('sex') . ' = ' . $this->data['sex'] . ', ' . $this->db->fieldName('vocation') . ' = ' . $this->data['vocation'] . ', ' . $this->db->fieldName('experience') . ' = ' . $this->data['experience'] . ', ' . $this->db->fieldName('level') . ' = ' . $this->data['level'] . ', ' . $this->db->fieldName('maglevel') . ' = ' . $this->data['maglevel'] . ', ' . $this->db->fieldName('health') . ' = ' . $this->data['health'] . ', ' . $this->db->fieldName('healthmax') . ' = ' . $this->data['healthmax'] . ', ' . $this->db->fieldName('mana') . ' = ' . $this->data['mana'] . ', ' . $this->db->fieldName('manamax') . ' = ' . $this->data['manamax'] . ', ' . $this->db->fieldName('manaspent') . ' = ' . $this->data['manaspent'] . ', ' . $this->db->fieldName('soul') . ' = ' . $this->data['soul'] . ', ' . $this->db->fieldName('lookbody') . ' = ' . $this->data['lookbody'] . ', ' . $this->db->fieldName('lookfeet') . ' = ' . $this->data['lookfeet'] . ', ' . $this->db->fieldName('lookhead') . ' = ' . $this->data['lookhead'] . ', ' . $this->db->fieldName('looklegs') . ' = ' . $this->data['looklegs'] . ', ' . $this->db->fieldName('looktype') . ' = ' . $this->data['looktype'] . $lookaddons . ', ' . $this->db->fieldName('posx') . ' = ' . $this->data['posx'] . ', ' . $this->db->fieldName('posy') . ' = ' . $this->data['posy'] . ', ' . $this->db->fieldName('posz') . ' = ' . $this->data['posz'] . ', ' . $this->db->fieldName('cap') . ' = ' . $this->data['cap'] . ', ' . $this->db->fieldName('lastlogin') . ' = ' . $this->data['lastlogin'] . ', ' . $this->db->fieldName('lastlogout') . ' = ' . $this->data['lastlogout'] . ', ' . $this->db->fieldName('lastip') . ' = ' . $this->db->quote($this->data['lastip']) . ', ' . $this->db->fieldName('save') . ' = ' . (int) $this->data['save'] . ', ' . $this->db->fieldName('conditions') . ' = ' . $this->db->quote($this->data['conditions']) . ', `' . $skull_time . '` = ' . $this->data['skulltime'] . ', `' . $skull_type . '` = ' . (int) $this->data['skull'] . $guild_info . ', ' . $this->db->fieldName('town_id') . ' = ' . $this->data['town_id'] . $loss . $loss_items . ', ' . $this->db->fieldName('balance') . ' = ' . $this->data['balance'] . $blessings . $stamina . $direction . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']); - } - // creates new player - else - { + // UPDATE query on database + $this->db->query('UPDATE ' . $this->db->tableName('players') . ' SET ' . $this->db->fieldName('name') . ' = ' . $this->db->quote($this->data['name']) . ', ' . $this->db->fieldName('account_id') . ' = ' . $this->data['account_id'] . ', ' . $this->db->fieldName('group_id') . ' = ' . $this->data['group_id'] . ', ' . $this->db->fieldName('sex') . ' = ' . $this->data['sex'] . ', ' . $this->db->fieldName('vocation') . ' = ' . $this->data['vocation'] . ', ' . $this->db->fieldName('experience') . ' = ' . $this->data['experience'] . ', ' . $this->db->fieldName('level') . ' = ' . $this->data['level'] . ', ' . $this->db->fieldName('maglevel') . ' = ' . $this->data['maglevel'] . ', ' . $this->db->fieldName('health') . ' = ' . $this->data['health'] . ', ' . $this->db->fieldName('healthmax') . ' = ' . $this->data['healthmax'] . ', ' . $this->db->fieldName('mana') . ' = ' . $this->data['mana'] . ', ' . $this->db->fieldName('manamax') . ' = ' . $this->data['manamax'] . ', ' . $this->db->fieldName('manaspent') . ' = ' . $this->data['manaspent'] . ', ' . $this->db->fieldName('soul') . ' = ' . $this->data['soul'] . ', ' . $this->db->fieldName('lookbody') . ' = ' . $this->data['lookbody'] . ', ' . $this->db->fieldName('lookfeet') . ' = ' . $this->data['lookfeet'] . ', ' . $this->db->fieldName('lookhead') . ' = ' . $this->data['lookhead'] . ', ' . $this->db->fieldName('looklegs') . ' = ' . $this->data['looklegs'] . ', ' . $this->db->fieldName('looktype') . ' = ' . $this->data['looktype'] . $lookaddons . ', ' . $this->db->fieldName('posx') . ' = ' . $this->data['posx'] . ', ' . $this->db->fieldName('posy') . ' = ' . $this->data['posy'] . ', ' . $this->db->fieldName('posz') . ' = ' . $this->data['posz'] . ', ' . $this->db->fieldName('cap') . ' = ' . $this->data['cap'] . ', ' . $this->db->fieldName('lastlogin') . ' = ' . $this->data['lastlogin'] . ', ' . $this->db->fieldName('lastlogout') . ' = ' . $this->data['lastlogout'] . ', ' . $this->db->fieldName('lastip') . ' = ' . $this->db->quote($this->data['lastip']) . ', ' . $this->db->fieldName('save') . ' = ' . (int) $this->data['save'] . ', ' . $this->db->fieldName('conditions') . ' = ' . $this->db->quote($this->data['conditions']) . ', `' . $skull_time . '` = ' . $this->data['skulltime'] . ', `' . $skull_type . '` = ' . (int) $this->data['skull'] . $guild_info . ', ' . $this->db->fieldName('town_id') . ' = ' . $this->data['town_id'] . $loss . $loss_items . ', ' . $this->db->fieldName('balance') . ' = ' . $this->data['balance'] . $blessings . $stamina . $direction . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']); + } + // creates new player + else + { $loss = ''; $loss_data = ''; if($this->db->hasColumn('players', 'loss_experience')) { @@ -459,13 +459,13 @@ class OTS_Player extends OTS_Row_DAO $lookaddons_data = ', ' . $this->data['lookaddons']; } - // INSERT query on database - $this->db->query('INSERT INTO `players` (`name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`' . $lookaddons . ', `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `save`, `conditions`, `' . $skull_time . '`, `' . $skull_type . '`' . $guild_info . ', `town_id`' . $loss . $loss_items . ', `balance`' . $blessings . $stamina . $direction . ', `created`' . $promotion . ', `comment`) VALUES (' . $this->db->quote($this->data['name']) . ', ' . $this->data['account_id'] . ', ' . $this->data['group_id'] . ', ' . $this->data['sex'] . ', ' . $this->data['vocation'] . ', ' . $this->data['experience'] . ', ' . $this->data['level'] . ', ' . $this->data['maglevel'] . ', ' . $this->data['health'] . ', ' . $this->data['healthmax'] . ', ' . $this->data['mana'] . ', ' . $this->data['manamax'] . ', ' . $this->data['manaspent'] . ', ' . $this->data['soul'] . ', ' . $this->data['lookbody'] . ', ' . $this->data['lookfeet'] . ', ' . $this->data['lookhead'] . ', ' . $this->data['looklegs'] . ', ' . $this->data['looktype'] . $lookaddons_data . ', ' . $this->data['posx'] . ', ' . $this->data['posy'] . ', ' . $this->data['posz'] . ', ' . $this->data['cap'] . ', ' . $this->data['lastlogin'] . ', ' . $this->data['lastlogout'] . ', ' . $this->data['lastip'] . ', ' . (int) $this->data['save'] . ', ' . $this->db->quote($this->data['conditions']) . ', ' . $this->data['skulltime'] . ', ' . (int) $this->data['skull'] . $guild_info_data . ', ' . $this->data['town_id'] . $loss_data . $loss_items_data . ', ' . $this->data['balance'] . $blessings_data . $stamina_data . $direction_data . ', ' . time() . $promotion_data . ', "")'); - // ID of new group - $this->data['id'] = $this->db->lastInsertId(); - } + // INSERT query on database + $this->db->query('INSERT INTO `players` (`name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`' . $lookaddons . ', `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `save`, `conditions`, `' . $skull_time . '`, `' . $skull_type . '`' . $guild_info . ', `town_id`' . $loss . $loss_items . ', `balance`' . $blessings . $stamina . $direction . ', `created`' . $promotion . ', `comment`) VALUES (' . $this->db->quote($this->data['name']) . ', ' . $this->data['account_id'] . ', ' . $this->data['group_id'] . ', ' . $this->data['sex'] . ', ' . $this->data['vocation'] . ', ' . $this->data['experience'] . ', ' . $this->data['level'] . ', ' . $this->data['maglevel'] . ', ' . $this->data['health'] . ', ' . $this->data['healthmax'] . ', ' . $this->data['mana'] . ', ' . $this->data['manamax'] . ', ' . $this->data['manaspent'] . ', ' . $this->data['soul'] . ', ' . $this->data['lookbody'] . ', ' . $this->data['lookfeet'] . ', ' . $this->data['lookhead'] . ', ' . $this->data['looklegs'] . ', ' . $this->data['looktype'] . $lookaddons_data . ', ' . $this->data['posx'] . ', ' . $this->data['posy'] . ', ' . $this->data['posz'] . ', ' . $this->data['cap'] . ', ' . $this->data['lastlogin'] . ', ' . $this->data['lastlogout'] . ', ' . $this->data['lastip'] . ', ' . (int) $this->data['save'] . ', ' . $this->db->quote($this->data['conditions']) . ', ' . $this->data['skulltime'] . ', ' . (int) $this->data['skull'] . $guild_info_data . ', ' . $this->data['town_id'] . $loss_data . $loss_items_data . ', ' . $this->data['balance'] . $blessings_data . $stamina_data . $direction_data . ', ' . time() . $promotion_data . ', "")'); + // ID of new group + $this->data['id'] = $this->db->lastInsertId(); + } - // updates skills - doesn't matter if we have just created character - trigger inserts new skills + // updates skills - doesn't matter if we have just created character - trigger inserts new skills if($this->db->hasColumn('players', 'skill_fist')) { // tfs 1.0 $set = ''; @@ -496,7 +496,7 @@ class OTS_Player extends OTS_Row_DAO $this->db->query('UPDATE ' . $this->db->tableName('player_skills') . ' SET ' . $this->db->fieldName('value') . ' = ' . $skill['value'] . ', ' . $this->db->fieldName('count') . ' = ' . $skill['tries'] . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('skillid') . ' = ' . $id); } } - } + } /** * Player ID. @@ -509,43 +509,43 @@ class OTS_Player extends OTS_Row_DAO * @return int Player ID. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getId() - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getId() + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['id']; - } + return $this->data['id']; + } - public function isHidden() - { - if( !isset($this->data['hide']) ) - { - throw new E_OTS_NotLoaded(); - } + public function isHidden() + { + if( !isset($this->data['hide']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['hide'] == 1; - } + return $this->data['hide'] == 1; + } - public function setHidden($hidden) - { - $this->data['hide'] = (int) $hidden; - } + public function setHidden($hidden) + { + $this->data['hide'] = (int) $hidden; + } - public function getMarriage() - { + public function getMarriage() + { if(!$this->db->hasColumn('players', 'marriage')) return ''; - if( !isset($this->data['marriage']) ) - { - throw new E_OTS_NotLoaded(); - } + if( !isset($this->data['marriage']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['marriage']; - } + return $this->data['marriage']; + } /** * Player name. @@ -558,15 +558,15 @@ class OTS_Player extends OTS_Row_DAO * @return string Player's name. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getName() - { - if( !isset($this->data['name']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getName() + { + if( !isset($this->data['name']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['name']; - } + return $this->data['name']; + } /** * Sets players's name. @@ -577,10 +577,10 @@ class OTS_Player extends OTS_Row_DAO * * @param string $name Name. */ - public function setName($name) - { - $this->data['name'] = (string) $name; - } + public function setName($name) + { + $this->data['name'] = (string) $name; + } /** * Returns account of this player. @@ -594,27 +594,27 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function getAccount() - { - if( !isset($this->data['account_id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getAccount() + { + if( !isset($this->data['account_id']) ) + { + throw new E_OTS_NotLoaded(); + } - $account = new OTS_Account(); - $account->load($this->data['account_id']); - return $account; - } + $account = new OTS_Account(); + $account->load($this->data['account_id']); + return $account; + } - public function getAccountId() - { - if( !isset($this->data['account_id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getAccountId() + { + if( !isset($this->data['account_id']) ) + { + throw new E_OTS_NotLoaded(); + } return $this->data['account_id']; - } + } /** * Assigns character to account. * @@ -625,15 +625,15 @@ class OTS_Player extends OTS_Row_DAO * @param OTS_Account $account Owning account. * @throws E_OTS_NotLoaded If passed $account parameter is not loaded. */ - public function setAccount(OTS_Account $account) - { - $this->data['account_id'] = $account->getId(); - } + public function setAccount(OTS_Account $account) + { + $this->data['account_id'] = $account->getId(); + } public function setAccountId($account_id) - { - $this->data['account_id'] = (int)$account_id; - } + { + $this->data['account_id'] = (int)$account_id; + } /** * Returns group of this player. @@ -647,19 +647,19 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function getGroup() - { + public function getGroup() + { //global $config; //if($path == '') // $path = $config['data_path'].'XML/groups.xml'; - if( !isset($this->data['group_id']) ) - { - throw new E_OTS_NotLoaded(); - } + if( !isset($this->data['group_id']) ) + { + throw new E_OTS_NotLoaded(); + } - //$groups = new DOMDocument(); - //$groups->load($path); + //$groups = new DOMDocument(); + //$groups->load($path); global $groups; $tmp = $groups->getGroup($this->data['group_id']); @@ -671,18 +671,18 @@ class OTS_Player extends OTS_Row_DAO /* $_id = $this->data['group_id']; $tmpGroup = new OTS_Group; - foreach($groups->getElementsByTagName('group') as $group) - { + foreach($groups->getElementsByTagName('group') as $group) + { if($group->getAttribute('id') == $_id) { $tmpGroup->load($group); return $tmpGroup; } - }*/ + }*/ // $group = new OTS_Group(); // $group->load($this->data['group_id']); // return $group; - } + } /** * Assigns character to group. @@ -694,15 +694,15 @@ class OTS_Player extends OTS_Row_DAO * @param OTS_Group $group Group to be a member. * @throws E_OTS_NotLoaded If passed $group parameter is not loaded. */ - public function setGroup(OTS_Group $group) - { - $this->data['group_id'] = $group->getId(); - } + public function setGroup(OTS_Group $group) + { + $this->data['group_id'] = $group->getId(); + } - public function setGroupId($group_id) - { - $this->data['group_id'] = $group_id; - } + public function setGroupId($group_id) + { + $this->data['group_id'] = $group_id; + } /** * Player's Premium Account expiration timestamp. @@ -713,15 +713,15 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @deprecated 0.1.5 Use OTS_Account->getPremiumEnd(). */ - public function getPremiumEnd() - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getPremiumEnd() + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->getAccount()->getPremiumEnd(); - } + return $this->getAccount()->getPremiumEnd(); + } /** * Player gender. @@ -734,80 +734,80 @@ class OTS_Player extends OTS_Row_DAO * @return int Player gender. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getSex() - { - if( !isset($this->data['sex']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getSex() + { + if( !isset($this->data['sex']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['sex']; - } + return $this->data['sex']; + } public function isDeleted() - { + { $field = 'deleted'; if($this->db->hasColumn('players', 'deletion')) $field = 'deletion'; - if( !isset($this->data[$field]) ) - { - throw new E_OTS_NotLoaded(); - } + if( !isset($this->data[$field]) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data[$field] > 0; - } + return $this->data[$field] > 0; + } - public function setDeleted($deleted) - { - $this->data['deleted'] = (int) $deleted; - } + public function setDeleted($deleted) + { + $this->data['deleted'] = (int) $deleted; + } - public function isOnline() - { + public function isOnline() + { if($this->db->hasTable('players_online')) // tfs 1.0 { $query = $this->db->query('SELECT `player_id` FROM `players_online` WHERE `player_id` = ' . $this->data['id']); return $query->rowCount() > 0; } - if( !isset($this->data['online']) ) - { - throw new E_OTS_NotLoaded(); - } + if( !isset($this->data['online']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['online'] == 1; - } + return $this->data['online'] == 1; + } - public function getCreated() - { - if( !isset($this->data['created']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getCreated() + { + if( !isset($this->data['created']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['created']; - } + return $this->data['created']; + } - public function setCreated($created) - { - $this->data['created'] = (bool) $created; - } + public function setCreated($created) + { + $this->data['created'] = (bool) $created; + } - public function getComment() - { - if( !isset($this->data['comment']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getComment() + { + if( !isset($this->data['comment']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['comment']; - } + return $this->data['comment']; + } - public function setComment($comment) - { - $this->data['comment'] = (string) $comment; - } + public function setComment($comment) + { + $this->data['comment'] = (string) $comment; + } /** @@ -819,10 +819,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $sex Player gender. */ - public function setSex($sex) - { - $this->data['sex'] = (int) $sex; - } + public function setSex($sex) + { + $this->data['sex'] = (int) $sex; + } /** * Player proffesion. @@ -835,12 +835,12 @@ class OTS_Player extends OTS_Row_DAO * @return int Player proffesion. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getVocation() - { - if( !isset($this->data['vocation']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getVocation() + { + if( !isset($this->data['vocation']) ) + { + throw new E_OTS_NotLoaded(); + } if(isset($this->data['promotion'])) { global $config; @@ -848,19 +848,19 @@ class OTS_Player extends OTS_Row_DAO return ($this->data['vocation'] + ($this->data['promotion'] * $config['vocations_amount'])); } - return $this->data['vocation']; - } + return $this->data['vocation']; + } - public function getPromotion() - { - if( !isset($this->data['promotion']) ) - { - return false; - } + public function getPromotion() + { + if( !isset($this->data['promotion']) ) + { + return false; + } - return $this->data['promotion']; - } + return $this->data['promotion']; + } /** * Sets player proffesion. * @@ -870,15 +870,15 @@ class OTS_Player extends OTS_Row_DAO * * @param int $vocation Player proffesion. */ - public function setVocation($vocation) - { - $this->data['vocation'] = (int) $vocation; - } + public function setVocation($vocation) + { + $this->data['vocation'] = (int) $vocation; + } - public function setPromotion($promotion) - { - $this->data['promotion'] = (int) $promotion; - } + public function setPromotion($promotion) + { + $this->data['promotion'] = (int) $promotion; + } /** * Experience points. * @@ -890,15 +890,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Experience points. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getExperience() - { - if( !isset($this->data['experience']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getExperience() + { + if( !isset($this->data['experience']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['experience']; - } + return $this->data['experience']; + } /** * Sets experience points. @@ -909,10 +909,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $experience Experience points. */ - public function setExperience($experience) - { - $this->data['experience'] = (int) $experience; - } + public function setExperience($experience) + { + $this->data['experience'] = (int) $experience; + } /** * Experience level. @@ -925,15 +925,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Experience level. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getLevel() - { - if( !isset($this->data['level']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLevel() + { + if( !isset($this->data['level']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['level']; - } + return $this->data['level']; + } /** * Sets experience level. @@ -944,10 +944,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $level Experience level. */ - public function setLevel($level) - { - $this->data['level'] = (int) $level; - } + public function setLevel($level) + { + $this->data['level'] = (int) $level; + } /** * Magic level. @@ -960,15 +960,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Magic level. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getMagLevel() - { - if( !isset($this->data['maglevel']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getMagLevel() + { + if( !isset($this->data['maglevel']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['maglevel']; - } + return $this->data['maglevel']; + } /** * Sets magic level. @@ -979,10 +979,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $maglevel Magic level. */ - public function setMagLevel($maglevel) - { - $this->data['maglevel'] = (int) $maglevel; - } + public function setMagLevel($maglevel) + { + $this->data['maglevel'] = (int) $maglevel; + } /** * Current HP. @@ -995,15 +995,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Current HP. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getHealth() - { - if( !isset($this->data['health']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getHealth() + { + if( !isset($this->data['health']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['health']; - } + return $this->data['health']; + } /** * Sets current HP. @@ -1014,10 +1014,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $health Current HP. */ - public function setHealth($health) - { - $this->data['health'] = (int) $health; - } + public function setHealth($health) + { + $this->data['health'] = (int) $health; + } /** * Maximum HP. @@ -1030,15 +1030,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Maximum HP. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getHealthMax() - { - if( !isset($this->data['healthmax']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getHealthMax() + { + if( !isset($this->data['healthmax']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['healthmax']; - } + return $this->data['healthmax']; + } /** * Sets maximum HP. @@ -1049,10 +1049,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $healthmax Maximum HP. */ - public function setHealthMax($healthmax) - { - $this->data['healthmax'] = (int) $healthmax; - } + public function setHealthMax($healthmax) + { + $this->data['healthmax'] = (int) $healthmax; + } /** * Current mana. @@ -1065,15 +1065,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Current mana. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getMana() - { - if( !isset($this->data['mana']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getMana() + { + if( !isset($this->data['mana']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['mana']; - } + return $this->data['mana']; + } /** * Sets current mana. @@ -1084,10 +1084,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $mana Current mana. */ - public function setMana($mana) - { - $this->data['mana'] = (int) $mana; - } + public function setMana($mana) + { + $this->data['mana'] = (int) $mana; + } /** * Maximum mana. @@ -1100,15 +1100,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Maximum mana. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getManaMax() - { - if( !isset($this->data['manamax']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getManaMax() + { + if( !isset($this->data['manamax']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['manamax']; - } + return $this->data['manamax']; + } /** * Sets maximum mana. @@ -1119,10 +1119,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $manamax Maximum mana. */ - public function setManaMax($manamax) - { - $this->data['manamax'] = (int) $manamax; - } + public function setManaMax($manamax) + { + $this->data['manamax'] = (int) $manamax; + } /** * Mana spent. @@ -1135,15 +1135,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Mana spent. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getManaSpent() - { - if( !isset($this->data['manaspent']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getManaSpent() + { + if( !isset($this->data['manaspent']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['manaspent']; - } + return $this->data['manaspent']; + } /** * Sets mana spent. @@ -1154,10 +1154,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $manaspent Mana spent. */ - public function setManaSpent($manaspent) - { - $this->data['manaspent'] = (int) $manaspent; - } + public function setManaSpent($manaspent) + { + $this->data['manaspent'] = (int) $manaspent; + } /** * Soul points. @@ -1170,15 +1170,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Soul points. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getSoul() - { - if( !isset($this->data['soul']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getSoul() + { + if( !isset($this->data['soul']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['soul']; - } + return $this->data['soul']; + } /** * Sets soul points. @@ -1189,10 +1189,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $soul Soul points. */ - public function setSoul($soul) - { - $this->data['soul'] = (int) $soul; - } + public function setSoul($soul) + { + $this->data['soul'] = (int) $soul; + } /** * Looking direction. @@ -1205,15 +1205,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Looking direction. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getDirection() - { - if( !isset($this->data['direction']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getDirection() + { + if( !isset($this->data['direction']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['direction']; - } + return $this->data['direction']; + } /** * Sets looking direction. @@ -1224,10 +1224,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $direction Looking direction. */ - public function setDirection($direction) - { - $this->data['direction'] = (int) $direction; - } + public function setDirection($direction) + { + $this->data['direction'] = (int) $direction; + } public function getOutfit(): string { @@ -1247,15 +1247,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Body color. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getLookBody() - { - if( !isset($this->data['lookbody']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLookBody() + { + if( !isset($this->data['lookbody']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['lookbody']; - } + return $this->data['lookbody']; + } /** * Sets body color. @@ -1266,10 +1266,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $lookbody Body color. */ - public function setLookBody($lookbody) - { - $this->data['lookbody'] = (int) $lookbody; - } + public function setLookBody($lookbody) + { + $this->data['lookbody'] = (int) $lookbody; + } /** * Boots color. @@ -1282,15 +1282,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Boots color. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getLookFeet() - { - if( !isset($this->data['lookfeet']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLookFeet() + { + if( !isset($this->data['lookfeet']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['lookfeet']; - } + return $this->data['lookfeet']; + } /** * Sets boots color. @@ -1301,10 +1301,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $lookfeet Boots color. */ - public function setLookFeet($lookfeet) - { - $this->data['lookfeet'] = (int) $lookfeet; - } + public function setLookFeet($lookfeet) + { + $this->data['lookfeet'] = (int) $lookfeet; + } /** * Hair color. @@ -1317,15 +1317,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Hair color. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getLookHead() - { - if( !isset($this->data['lookhead']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLookHead() + { + if( !isset($this->data['lookhead']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['lookhead']; - } + return $this->data['lookhead']; + } /** * Sets hair color. @@ -1336,10 +1336,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $lookhead Hair color. */ - public function setLookHead($lookhead) - { - $this->data['lookhead'] = (int) $lookhead; - } + public function setLookHead($lookhead) + { + $this->data['lookhead'] = (int) $lookhead; + } /** * Legs color. @@ -1352,15 +1352,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Legs color. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getLookLegs() - { - if( !isset($this->data['looklegs']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLookLegs() + { + if( !isset($this->data['looklegs']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['looklegs']; - } + return $this->data['looklegs']; + } /** * Sets legs color. @@ -1371,10 +1371,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $looklegs Legs color. */ - public function setLookLegs($looklegs) - { - $this->data['looklegs'] = (int) $looklegs; - } + public function setLookLegs($looklegs) + { + $this->data['looklegs'] = (int) $looklegs; + } /** * Outfit. @@ -1387,15 +1387,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Outfit. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getLookType() - { - if( !isset($this->data['looktype']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLookType() + { + if( !isset($this->data['looktype']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['looktype']; - } + return $this->data['looktype']; + } /** * Sets outfit. @@ -1406,10 +1406,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $looktype Outfit. */ - public function setLookType($looktype) - { - $this->data['looktype'] = (int) $looktype; - } + public function setLookType($looktype) + { + $this->data['looktype'] = (int) $looktype; + } /** * Addons. @@ -1422,15 +1422,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Addons. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getLookAddons() - { - if( !isset($this->data['lookaddons']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLookAddons() + { + if( !isset($this->data['lookaddons']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['lookaddons']; - } + return $this->data['lookaddons']; + } /** * Sets addons. @@ -1441,10 +1441,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $lookaddons Addons. */ - public function setLookAddons($lookaddons) - { - $this->data['lookaddons'] = (int) $lookaddons; - } + public function setLookAddons($lookaddons) + { + $this->data['lookaddons'] = (int) $lookaddons; + } /** * X map coordinate. @@ -1457,15 +1457,15 @@ class OTS_Player extends OTS_Row_DAO * @return int X map coordinate. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getPosX() - { - if( !isset($this->data['posx']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getPosX() + { + if( !isset($this->data['posx']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['posx']; - } + return $this->data['posx']; + } /** * Sets X map coordinate. @@ -1476,10 +1476,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $posx X map coordinate. */ - public function setPosX($posx) - { - $this->data['posx'] = (int) $posx; - } + public function setPosX($posx) + { + $this->data['posx'] = (int) $posx; + } /** * Y map coordinate. @@ -1492,15 +1492,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Y map coordinate. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getPosY() - { - if( !isset($this->data['posy']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getPosY() + { + if( !isset($this->data['posy']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['posy']; - } + return $this->data['posy']; + } /** * Sets Y map coordinate. @@ -1511,10 +1511,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $posy Y map coordinate. */ - public function setPosY($posy) - { - $this->data['posy'] = (int) $posy; - } + public function setPosY($posy) + { + $this->data['posy'] = (int) $posy; + } /** * Z map coordinate. @@ -1527,15 +1527,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Z map coordinate. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getPosZ() - { - if( !isset($this->data['posz']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getPosZ() + { + if( !isset($this->data['posz']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['posz']; - } + return $this->data['posz']; + } /** * Sets Z map coordinate. @@ -1546,10 +1546,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $posz Z map coordinate. */ - public function setPosZ($posz) - { - $this->data['posz'] = (int) $posz; - } + public function setPosZ($posz) + { + $this->data['posz'] = (int) $posz; + } /** * Capacity. @@ -1562,15 +1562,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Capacity. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getCap() - { - if( !isset($this->data['cap']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getCap() + { + if( !isset($this->data['cap']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['cap']; - } + return $this->data['cap']; + } /** * Sets capacity. @@ -1581,10 +1581,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $cap Capacity. */ - public function setCap($cap) - { - $this->data['cap'] = (int) $cap; - } + public function setCap($cap) + { + $this->data['cap'] = (int) $cap; + } /** * Last login timestamp. @@ -1597,25 +1597,25 @@ class OTS_Player extends OTS_Row_DAO * @return int Last login timestamp. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getLastLogin() - { - if( !isset($this->data['lastlogin']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLastLogin() + { + if( !isset($this->data['lastlogin']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['lastlogin']; - } + return $this->data['lastlogin']; + } - public function getLastLogout() - { - if( !isset($this->data['lastlogout']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLastLogout() + { + if( !isset($this->data['lastlogout']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['lastlogout']; - } + return $this->data['lastlogout']; + } /** @@ -1627,15 +1627,15 @@ class OTS_Player extends OTS_Row_DAO * * @param int $lastlogin Last login timestamp. */ - public function setLastLogin($lastlogin) - { - $this->data['lastlogin'] = (int) $lastlogin; - } + public function setLastLogin($lastlogin) + { + $this->data['lastlogin'] = (int) $lastlogin; + } - public function setLastLogout($lastlogout) - { - $this->data['lastlogout'] = (int) $lastlogout; - } + public function setLastLogout($lastlogout) + { + $this->data['lastlogout'] = (int) $lastlogout; + } /** * Last login IP. @@ -1648,15 +1648,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Last login IP. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getLastIP() - { - if( !isset($this->data['lastip']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLastIP() + { + if( !isset($this->data['lastip']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['lastip']; - } + return $this->data['lastip']; + } /** * Sets last login IP. @@ -1667,10 +1667,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $lastip Last login IP. */ - public function setLastIP($lastip) - { - $this->data['lastip'] = (int) $lastip; - } + public function setLastIP($lastip) + { + $this->data['lastip'] = (int) $lastip; + } /** * Checks if save flag is set. @@ -1683,15 +1683,15 @@ class OTS_Player extends OTS_Row_DAO * @return bool PACC days. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function isSaveSet() - { - if( !isset($this->data['save']) ) - { - throw new E_OTS_NotLoaded(); - } + public function isSaveSet() + { + if( !isset($this->data['save']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['save']; - } + return $this->data['save']; + } /** * Unsets save flag. @@ -1702,10 +1702,10 @@ class OTS_Player extends OTS_Row_DAO * * @version 0.0.7 */ - public function unsetSave() - { - $this->data['save'] = false; - } + public function unsetSave() + { + $this->data['save'] = false; + } /** * @version 0.0.7 @@ -1714,15 +1714,15 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @deprecated 0.0.7 Save field is back as flag not a counter. */ - public function getSave() - { - if( !isset($this->data['save']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getSave() + { + if( !isset($this->data['save']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['save']; - } + return $this->data['save']; + } /** * Sets save flag. @@ -1734,10 +1734,10 @@ class OTS_Player extends OTS_Row_DAO * @version 0.0.7 * @param int $save Deprecated, unused, optional. */ - public function setSave($save = 1) - { - $this->data['save'] = true; - } + public function setSave($save = 1) + { + $this->data['save'] = true; + } /** * Conditions. @@ -1750,10 +1750,10 @@ class OTS_Player extends OTS_Row_DAO * @return string Conditions binary string. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getConditions() - { - return $this->data['conditions']; - } + public function getConditions() + { + return $this->data['conditions']; + } /** * Sets conditions. @@ -1764,10 +1764,10 @@ class OTS_Player extends OTS_Row_DAO * * @param string $conditions Condition binary string. */ - public function setConditions($conditions) - { - $this->data['conditions'] = $conditions; - } + public function setConditions($conditions) + { + $this->data['conditions'] = $conditions; + } /** * Red skulled time remained. @@ -1780,15 +1780,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Red skulled time remained. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getSkullTime() - { - if( !isset($this->data['skulltime']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getSkullTime() + { + if( !isset($this->data['skulltime']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['skulltime']; - } + return $this->data['skulltime']; + } /** * Sets red skulled time remained. @@ -1799,10 +1799,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $redskulltime Red skulled time remained. */ - public function setSkullTime($skulltime) - { - $this->data['skulltime'] = (int) $skulltime; - } + public function setSkullTime($skulltime) + { + $this->data['skulltime'] = (int) $skulltime; + } /** * Checks if player has red skull. @@ -1815,15 +1815,15 @@ class OTS_Player extends OTS_Row_DAO * @return bool Red skull state. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getSkull() - { - if( !isset($this->data['skull']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getSkull() + { + if( !isset($this->data['skull']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['skull']; - } + return $this->data['skull']; + } /** * Unsets red skull flag. @@ -1832,10 +1832,10 @@ class OTS_Player extends OTS_Row_DAO * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database. *

*/ - public function unsetRedSkull() - { - $this->data['skull'] = false; - } + public function unsetRedSkull() + { + $this->data['skull'] = false; + } /** * Sets red skull flag. @@ -1844,10 +1844,10 @@ class OTS_Player extends OTS_Row_DAO * This method only updates object state. To save changes in database you need to use {@link OTS_Player::save() save() method} to flush changed to database. *

*/ - public function setSkull($value) - { - $this->data['skull'] = $value; - } + public function setSkull($value) + { + $this->data['skull'] = $value; + } /** * Guild nick. @@ -1860,7 +1860,7 @@ class OTS_Player extends OTS_Row_DAO * @return string Guild title. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function loadRank() + public function loadRank() { $table = 'guild_membership'; if($this->db->hasTable('guild_members')) @@ -1879,13 +1879,13 @@ class OTS_Player extends OTS_Row_DAO } } - public function getGuildNick() - { + public function getGuildNick() + { if(!isset($this->data['guildnick']) || !isset($this->data['rank_id'])) $this->loadRank(); return $this->data['guildnick']; - } + } /** * Sets guild nick. @@ -1896,9 +1896,9 @@ class OTS_Player extends OTS_Row_DAO * * @param string $guildnick Name. */ - public function setGuildNick($guildnick) - { - $this->data['guildnick'] = (string) $guildnick; + public function setGuildNick($guildnick) + { + $this->data['guildnick'] = (string) $guildnick; if($this->db->hasTable('guild_members')) $this->db->query('UPDATE `guild_members` SET `nick` = ' . $this->db->quote($this->data['guildnick']) . ' WHERE `player_id` = ' . $this->getId()); else if($this->db->hasTable('guild_membership')) @@ -1932,8 +1932,8 @@ class OTS_Player extends OTS_Row_DAO * @return OTS_GuildRank|null Guild rank (null if not member of any). * @throws PDOException On PDO operation error. */ - public function getRank() - { + public function getRank() + { $rank_id = 0; if($this->db->hasTable('guild_members')) { $query = $this->db->query('SELECT `rank_id` FROM `guild_members` WHERE `player_id`= ' . $this->data['id'] . ' LIMIT 1;'); @@ -1954,20 +1954,20 @@ class OTS_Player extends OTS_Row_DAO $rank_id = (int)$query['rank_id']; } - $guildRank = new OTS_GuildRank(); + $guildRank = new OTS_GuildRank(); if($rank_id !== 0) { $guildRank->load($rank_id); } - return $guildRank; - } + return $guildRank; + } /** * @param int $rank_id Guild rank ID. * @deprecated 0.0.4 Use setRank(). */ - public function setRankId($rank_id, $guild) - { + public function setRankId($rank_id, $guild) + { if( isset($rank_id) && isset($guild)) { if($rank_id == 0) { if($this->db->hasTable('guild_membership')) { @@ -2004,7 +2004,7 @@ class OTS_Player extends OTS_Row_DAO } } } - } + } /** * Assigns guild rank. @@ -2016,13 +2016,13 @@ class OTS_Player extends OTS_Row_DAO * @param OTS_GuildRank|null Guild rank (null to clear assign). * @throws E_OTS_NotLoaded If passed $guildRank parameter is not loaded. */ - public function setRank(OTS_GuildRank $guildRank = null) - { + public function setRank(OTS_GuildRank $guildRank = null) + { if(isset($guildRank)) $this->setRankId($guildRank->getId(), $guildRank->getGuild()->getId()); else $this->setRankId(0, 0); - } + } /** * Residence town's ID. @@ -2035,15 +2035,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Residence town's ID. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getTownId() - { - if( !isset($this->data['town_id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getTownId() + { + if( !isset($this->data['town_id']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['town_id']; - } + return $this->data['town_id']; + } /** * Sets residence town's ID. @@ -2054,10 +2054,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $town_id Residence town's ID. */ - public function setTownId($town_id) - { - $this->data['town_id'] = (int) $town_id; - } + public function setTownId($town_id) + { + $this->data['town_id'] = (int) $town_id; + } /** * Percentage of experience lost after dead. @@ -2070,15 +2070,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Percentage of experience lost after dead. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getLossExperience() - { - if( !isset($this->data['loss_experience']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLossExperience() + { + if( !isset($this->data['loss_experience']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['loss_experience']; - } + return $this->data['loss_experience']; + } /** * Sets percentage of experience lost after dead. @@ -2089,10 +2089,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $loss_experience Percentage of experience lost after dead. */ - public function setLossExperience($loss_experience) - { - $this->data['loss_experience'] = (int) $loss_experience; - } + public function setLossExperience($loss_experience) + { + $this->data['loss_experience'] = (int) $loss_experience; + } /** * Percentage of used mana lost after dead. @@ -2105,15 +2105,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Percentage of used mana lost after dead. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getLossMana() - { - if( !isset($this->data['loss_mana']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLossMana() + { + if( !isset($this->data['loss_mana']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['loss_mana']; - } + return $this->data['loss_mana']; + } /** * Sets percentage of used mana lost after dead. @@ -2124,10 +2124,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $loss_mana Percentage of used mana lost after dead. */ - public function setLossMana($loss_mana) - { - $this->data['loss_mana'] = (int) $loss_mana; - } + public function setLossMana($loss_mana) + { + $this->data['loss_mana'] = (int) $loss_mana; + } /** * Percentage of skills lost after dead. @@ -2140,15 +2140,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Percentage of skills lost after dead. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getLossSkills() - { - if( !isset($this->data['loss_skills']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLossSkills() + { + if( !isset($this->data['loss_skills']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['loss_skills']; - } + return $this->data['loss_skills']; + } /** * Sets percentage of skills lost after dead. @@ -2159,10 +2159,10 @@ class OTS_Player extends OTS_Row_DAO * * @param int $loss_skills Percentage of skills lost after dead. */ - public function setLossSkills($loss_skills) - { - $this->data['loss_skills'] = (int) $loss_skills; - } + public function setLossSkills($loss_skills) + { + $this->data['loss_skills'] = (int) $loss_skills; + } /** * Percentage of items lost after dead. @@ -2172,15 +2172,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Percentage of items lost after dead. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getLossItems() - { - if( !isset($this->data['loss_items']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLossItems() + { + if( !isset($this->data['loss_items']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['loss_items']; - } + return $this->data['loss_items']; + } /** * Sets percentage of items lost after dead. @@ -2189,39 +2189,39 @@ class OTS_Player extends OTS_Row_DAO * @since 0.1.4 * @param int $loss_items Percentage of items lost after dead. */ - public function setLossItems($loss_items) - { - $this->data['loss_items'] = (int) $loss_items; - } + public function setLossItems($loss_items) + { + $this->data['loss_items'] = (int) $loss_items; + } - public function getLossContainers() - { - if( !isset($this->data['loss_containers']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getLossContainers() + { + if( !isset($this->data['loss_containers']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['loss_containers']; - } - public function setLossContainers($loss_containers) - { - $this->data['loss_containers'] = (int) $loss_containers; - } + return $this->data['loss_containers']; + } + public function setLossContainers($loss_containers) + { + $this->data['loss_containers'] = (int) $loss_containers; + } - public function getBlessings() - { - if( !isset($this->data['blessings']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getBlessings() + { + if( !isset($this->data['blessings']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['blessings']; - } + return $this->data['blessings']; + } - public function setBlessings($blessings) - { - $this->data['blessings'] = (int) $blessings; - } + public function setBlessings($blessings) + { + $this->data['blessings'] = (int) $blessings; + } public function countBlessings() { @@ -2253,20 +2253,20 @@ class OTS_Player extends OTS_Row_DAO return $value; } - public function getStamina() - { - if( !isset($this->data['stamina']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getStamina() + { + if( !isset($this->data['stamina']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['stamina']; - } + return $this->data['stamina']; + } - public function setStamina($stamina) - { - $this->data['stamina'] = (int) $stamina; - } + public function setStamina($stamina) + { + $this->data['stamina'] = (int) $stamina; + } /** * Bank balance. * @@ -2275,15 +2275,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Amount of money stored in bank. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getBalance() - { - if( !isset($this->data['balance']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getBalance() + { + if( !isset($this->data['balance']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['balance']; - } + return $this->data['balance']; + } /** * Sets bank balance value. @@ -2296,24 +2296,24 @@ class OTS_Player extends OTS_Row_DAO * @since 0.1.2 * @param int $balance Amount of money to be set in bank. */ - public function setBalance($balance) - { - $this->data['balance'] = (int) $balance; - } + public function setBalance($balance) + { + $this->data['balance'] = (int) $balance; + } - public function getWorldId() - { - if( !isset($this->data['world_id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getWorldId() + { + if( !isset($this->data['world_id']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->data['world_id']; - } - public function setWorldId($worldId) - { - $this->data['world_id'] = (int) $worldId; - } + return $this->data['world_id']; + } + public function setWorldId($worldId) + { + $this->data['world_id'] = (int) $worldId; + } /** * Reads custom field. * @@ -2332,16 +2332,16 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function getCustomField($field) - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getCustomField($field) + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - $value = $this->db->query('SELECT ' . $this->db->fieldName($field) . ' FROM ' . $this->db->tableName('players') . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id'])->fetch(); - return $value[$field]; - } + $value = $this->db->query('SELECT ' . $this->db->fieldName($field) . ' FROM ' . $this->db->tableName('players') . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id'])->fetch(); + return $value[$field]; + } /** * Writes custom field. @@ -2365,21 +2365,21 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function setCustomField($field, $value) - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function setCustomField($field, $value) + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - // quotes value for SQL query - if(!( is_int($value) || is_float($value) )) - { - $value = $this->db->quote($value); - } + // quotes value for SQL query + if(!( is_int($value) || is_float($value) )) + { + $value = $this->db->quote($value); + } - $this->db->query('UPDATE `players` SET `' . $field . '` = ' . $value . ' WHERE `id` = ' . $this->data['id']); - } + $this->db->query('UPDATE `players` SET `' . $field . '` = ' . $value . ' WHERE `id` = ' . $this->data['id']); + } /** * Returns player's skill. @@ -2390,15 +2390,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Skill value. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getSkill($skill) - { - if( !isset($this->skills[$skill]) ) - { - throw new E_OTS_NotLoaded(); - } + public function getSkill($skill) + { + if( !isset($this->skills[$skill]) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->skills[$skill]['value']; - } + return $this->skills[$skill]['value']; + } /** * Sets skill value. @@ -2408,8 +2408,8 @@ class OTS_Player extends OTS_Row_DAO * @param int $skill Skill ID. * @param int $value Skill value. */ - public function setSkill($skill, $value) - { + public function setSkill($skill, $value) + { $skill_ids = array( 'skill_fist' => POT::SKILL_FIST, 'skill_club' => POT::SKILL_CLUB, @@ -2424,7 +2424,7 @@ class OTS_Player extends OTS_Row_DAO else { $this->skills[ (int) $skill_ids[$skill]]['value'] = (int) $value; } - } + } /** * Returns player's skill's tries for next level. @@ -2435,15 +2435,15 @@ class OTS_Player extends OTS_Row_DAO * @return int Skill tries. * @throws E_OTS_NotLoaded If player is not loaded. */ - public function getSkillTries($skill) - { - if( !isset($this->skills[$skill]) ) - { - throw new E_OTS_NotLoaded(); - } + public function getSkillTries($skill) + { + if( !isset($this->skills[$skill]) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->skills[$skill]['tries']; - } + return $this->skills[$skill]['tries']; + } /** * Sets skill's tries for next level. @@ -2453,8 +2453,8 @@ class OTS_Player extends OTS_Row_DAO * @param int $skill Skill ID. * @param int $tries Skill tries. */ - public function setSkillTries($skill, $tries) - { + public function setSkillTries($skill, $tries) + { $skill_ids = array( 'skill_fist' => POT::SKILL_FIST, 'skill_club' => POT::SKILL_CLUB, @@ -2470,7 +2470,7 @@ class OTS_Player extends OTS_Row_DAO else { $this->skills[ (int) $skill_ids[$skill]]['tries'] = (int) $tries; } - } + } /** * Returns value of storage record. @@ -2482,22 +2482,22 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function getStorage($key) - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getStorage($key) + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - $value = $this->db->query('SELECT ' . $this->db->fieldName('value') . ' FROM ' . $this->db->tableName('player_storage') . ' WHERE ' . $this->db->fieldName('key') . ' = ' . (int) $key . ' AND ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'])->fetch(); + $value = $this->db->query('SELECT ' . $this->db->fieldName('value') . ' FROM ' . $this->db->tableName('player_storage') . ' WHERE ' . $this->db->fieldName('key') . ' = ' . (int) $key . ' AND ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'])->fetch(); - if($value === false) - { - return null; - } + if($value === false) + { + return null; + } - return $value['value']; - } + return $value['value']; + } /** * Sets value of storage record. @@ -2509,26 +2509,26 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function setStorage($key, $value) - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function setStorage($key, $value) + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - $current = $this->getStorage($key); + $current = $this->getStorage($key); - // checks if there is any row to be updates - if( isset($current) ) - { - $this->db->query('UPDATE ' . $this->db->tableName('player_storage') . ' SET ' . $this->db->fieldName('value') . ' = ' . (int) $value . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('key') . ' = ' . (int) $key); - } - // inserts new storage record - else - { - $this->db->query('INSERT INTO ' . $this->db->tableName('player_storage') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('key') . ', ' . $this->db->fieldName('value') . ') VALUES (' . $this->data['id'] . ', ' . (int) $key . ', ' . (int) $value . ')'); - } - } + // checks if there is any row to be updates + if( isset($current) ) + { + $this->db->query('UPDATE ' . $this->db->tableName('player_storage') . ' SET ' . $this->db->fieldName('value') . ' = ' . (int) $value . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('key') . ' = ' . (int) $key); + } + // inserts new storage record + else + { + $this->db->query('INSERT INTO ' . $this->db->tableName('player_storage') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('key') . ', ' . $this->db->fieldName('value') . ') VALUES (' . $this->data['id'] . ', ' . (int) $key . ', ' . (int) $value . ')'); + } + } /** * Deletes item with contained items. @@ -2538,17 +2538,17 @@ class OTS_Player extends OTS_Row_DAO * @param int $sid Item unique player's ID. * @throws PDOException On PDO operation error. */ - private function deleteItem($sid) - { - // deletes all sub-items - foreach( $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . $sid)->fetchAll() as $item) - { - $this->deleteItem($item['sid']); - } + private function deleteItem($sid) + { + // deletes all sub-items + foreach( $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . $sid)->fetchAll() as $item) + { + $this->deleteItem($item['sid']); + } - // deletes item - $this->db->query('DELETE FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('sid') . ' = ' . $sid); - } + // deletes item + $this->db->query('DELETE FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('sid') . ' = ' . $sid); + } /** * Returns items tree from given slot. @@ -2565,51 +2565,51 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotAContainer If item which is not of type container contains sub items. * @throws PDOException On PDO operation error. */ - public function getSlot($slot) - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getSlot($slot) + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - // loads current item - $item = $this->db->query('SELECT ' . $this->db->fieldName('itemtype') . ', ' . $this->db->fieldName('sid') . ', ' . $this->db->fieldName('count') . ', ' . $this->db->fieldName('attributes') . ' FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName($slot > POT::SLOT_AMMO ? 'sid' : 'pid') . ' = ' . (int) $slot)->fetch(); + // loads current item + $item = $this->db->query('SELECT ' . $this->db->fieldName('itemtype') . ', ' . $this->db->fieldName('sid') . ', ' . $this->db->fieldName('count') . ', ' . $this->db->fieldName('attributes') . ' FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName($slot > POT::SLOT_AMMO ? 'sid' : 'pid') . ' = ' . (int) $slot)->fetch(); - if( empty($item) ) - { - return null; - } + if( empty($item) ) + { + return null; + } - // checks if there are any items under current one - $items = array(); - foreach( $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . $item['sid'])->fetchAll() as $sub) - { - $items[] = $this->getSlot($sub['sid']); - } + // checks if there are any items under current one + $items = array(); + foreach( $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . $item['sid'])->fetchAll() as $sub) + { + $items[] = $this->getSlot($sub['sid']); + } - // item type - $slot = POT::getInstance()->getItemsList()->getItemType($item['itemtype'])->createItem(); - $slot->setCount($item['count']); - $slot->setAttributes($item['attributes']); + // item type + $slot = POT::getInstance()->getItemsList()->getItemType($item['itemtype'])->createItem(); + $slot->setCount($item['count']); + $slot->setAttributes($item['attributes']); - // checks if current item has any contained items - if( !empty($items) ) - { - // checks if item is realy a container - if(!$slot instanceof OTS_Container) - { - throw new E_OTS_NotAContainer(); - } + // checks if current item has any contained items + if( !empty($items) ) + { + // checks if item is realy a container + if(!$slot instanceof OTS_Container) + { + throw new E_OTS_NotAContainer(); + } - // puts items into container - foreach($items as $sub) - { - $slot->addItem($sub); - } - } + // puts items into container + foreach($items as $sub) + { + $slot->addItem($sub); + } + } - return $slot; - } + return $slot; + } /** * Sets slot content. @@ -2622,56 +2622,56 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function setSlot($slot, OTS_Item $item = null, $pid = 0) - { - static $sid; + public function setSlot($slot, OTS_Item $item = null, $pid = 0) + { + static $sid; - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - // clears current slot - if($slot <= POT::SLOT_AMMO) - { - $id = $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . (int) $slot)->fetch(); - $this->deleteItem( (int) $id['sid']); - } + // clears current slot + if($slot <= POT::SLOT_AMMO) + { + $id = $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . (int) $slot)->fetch(); + $this->deleteItem( (int) $id['sid']); + } - // checks if there is any item to insert - if( isset($item) ) - { - // current maximum sid (over slot sids) - if( !isset($sid) ) - { - $sid = $this->db->query('SELECT MAX(' . $this->db->fieldName('sid') . ') AS `sid` FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'])->fetch(); - $sid = $sid['sid'] > POT::SLOT_AMMO ? $sid['sid'] : POT::SLOT_AMMO; - } + // checks if there is any item to insert + if( isset($item) ) + { + // current maximum sid (over slot sids) + if( !isset($sid) ) + { + $sid = $this->db->query('SELECT MAX(' . $this->db->fieldName('sid') . ') AS `sid` FROM ' . $this->db->tableName('player_items') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'])->fetch(); + $sid = $sid['sid'] > POT::SLOT_AMMO ? $sid['sid'] : POT::SLOT_AMMO; + } - $sid++; + $sid++; - // inserts given item - $this->db->query('INSERT INTO ' . $this->db->tableName('player_items') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('sid') . ', ' . $this->db->fieldName('pid') . ', ' . $this->db->fieldName('itemtype') . ', ' . $this->db->fieldName('count') . ', ' . $this->db->fieldName('attributes') . ') VALUES (' . $this->data['id'] . ', ' . $sid . ', ' . (int) $slot . ', ' . $item->getId() . ', ' . $item->getCount() . ', ' . $this->db->quote( $item->getAttributes() ) . ')'); + // inserts given item + $this->db->query('INSERT INTO ' . $this->db->tableName('player_items') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('sid') . ', ' . $this->db->fieldName('pid') . ', ' . $this->db->fieldName('itemtype') . ', ' . $this->db->fieldName('count') . ', ' . $this->db->fieldName('attributes') . ') VALUES (' . $this->data['id'] . ', ' . $sid . ', ' . (int) $slot . ', ' . $item->getId() . ', ' . $item->getCount() . ', ' . $this->db->quote( $item->getAttributes() ) . ')'); - // checks if this is container - if($item instanceof OTS_Container) - { - $pid = $sid; + // checks if this is container + if($item instanceof OTS_Container) + { + $pid = $sid; - // inserts all contained items - foreach($item as $sub) - { - $this->setSlot($pid, $sub); - } - } - } + // inserts all contained items + foreach($item as $sub) + { + $this->setSlot($pid, $sub); + } + } + } - // clears $sid for next public call - if($slot <= POT::SLOT_AMMO) - { - $sid = null; - } - } + // clears $sid for next public call + if($slot <= POT::SLOT_AMMO) + { + $sid = null; + } + } /** * Deletes depot item with contained items. @@ -2681,17 +2681,17 @@ class OTS_Player extends OTS_Row_DAO * @param int $sid Depot item unique player's ID. * @throws PDOException On PDO operation error. */ - private function deleteDepot($sid) - { - // deletes all sub-items - foreach( $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . $sid)->fetchAll() as $item) - { - $this->deleteDepot($item['sid']); - } + private function deleteDepot($sid) + { + // deletes all sub-items + foreach( $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . $sid)->fetchAll() as $item) + { + $this->deleteDepot($item['sid']); + } - // deletes item - $this->db->query('DELETE FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('sid') . ' = ' . $sid); - } + // deletes item + $this->db->query('DELETE FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('sid') . ' = ' . $sid); + } /** * Returns items tree from given depot. @@ -2708,51 +2708,51 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotAContainer If item which is not of type container contains sub items. * @throws PDOException On PDO operation error. */ - public function getDepot($depot) - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getDepot($depot) + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - // loads current item - $item = $this->db->query('SELECT ' . $this->db->fieldName('itemtype') . ', ' . $this->db->fieldName('sid') . ', ' . $this->db->fieldName('count') . ', ' . $this->db->fieldName('attributes') . ' FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName($depot > POT::DEPOT_SID_FIRST ? 'sid' : 'pid') . ' = ' . (int) $depot)->fetch(); + // loads current item + $item = $this->db->query('SELECT ' . $this->db->fieldName('itemtype') . ', ' . $this->db->fieldName('sid') . ', ' . $this->db->fieldName('count') . ', ' . $this->db->fieldName('attributes') . ' FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName($depot > POT::DEPOT_SID_FIRST ? 'sid' : 'pid') . ' = ' . (int) $depot)->fetch(); - if( empty($item) ) - { - return null; - } + if( empty($item) ) + { + return null; + } - // checks if there are any items under current one - $items = array(); - foreach( $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . $item['sid'])->fetchAll() as $sub) - { - $items[] = $this->getDepot($sub['sid']); - } + // checks if there are any items under current one + $items = array(); + foreach( $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . $item['sid'])->fetchAll() as $sub) + { + $items[] = $this->getDepot($sub['sid']); + } - // item type - $depot = POT::getInstance()->getItemsList()->getItemType($item['itemtype'])->createItem(); - $depot->setCount($item['count']); - $depot->setAttributes($item['attributes']); + // item type + $depot = POT::getInstance()->getItemsList()->getItemType($item['itemtype'])->createItem(); + $depot->setCount($item['count']); + $depot->setAttributes($item['attributes']); - // checks if current item has any contained items - if( !empty($items) ) - { - // checks if item is realy a container - if(!$depot instanceof OTS_Container) - { - throw new E_OTS_NotAContainer(); - } + // checks if current item has any contained items + if( !empty($items) ) + { + // checks if item is realy a container + if(!$depot instanceof OTS_Container) + { + throw new E_OTS_NotAContainer(); + } - // puts items into container - foreach($items as $sub) - { - $depot->addItem($sub); - } - } + // puts items into container + foreach($items as $sub) + { + $depot->addItem($sub); + } + } - return $depot; - } + return $depot; + } /** * Sets depot content. @@ -2766,62 +2766,62 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function setDepot($depot, OTS_Item $item = null, $pid = 0, $depot_id = 0) - { - static $sid; + public function setDepot($depot, OTS_Item $item = null, $pid = 0, $depot_id = 0) + { + static $sid; - // if no depot_id is specified then it is same as depot slot - if($depot_id == 0) - { - $depot_id = $depot; - } + // if no depot_id is specified then it is same as depot slot + if($depot_id == 0) + { + $depot_id = $depot; + } - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - // clears current depot - if($depot <= POT::DEPOT_SID_FIRST) - { - $id = $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . (int) $depot)->fetch(); - $this->deleteDepot( (int) $id['sid']); - } + // clears current depot + if($depot <= POT::DEPOT_SID_FIRST) + { + $id = $this->db->query('SELECT ' . $this->db->fieldName('sid') . ' FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('pid') . ' = ' . (int) $depot)->fetch(); + $this->deleteDepot( (int) $id['sid']); + } - // checks if there is any item to insert - if( isset($item) ) - { - // current maximum sid (over depot sids) - if( !isset($sid) ) - { - $sid = $this->db->query('SELECT MAX(' . $this->db->fieldName('sid') . ') AS `sid` FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'])->fetch(); - $sid = $sid['sid'] > POT::DEPOT_SID_FIRST ? $sid['sid'] : POT::DEPOT_SID_FIRST; - } + // checks if there is any item to insert + if( isset($item) ) + { + // current maximum sid (over depot sids) + if( !isset($sid) ) + { + $sid = $this->db->query('SELECT MAX(' . $this->db->fieldName('sid') . ') AS `sid` FROM ' . $this->db->tableName('player_depotitems') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'])->fetch(); + $sid = $sid['sid'] > POT::DEPOT_SID_FIRST ? $sid['sid'] : POT::DEPOT_SID_FIRST; + } - $sid++; + $sid++; - // inserts given item - $this->db->query('INSERT INTO ' . $this->db->tableName('player_depotitems') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('depot_id') . ', ' . $this->db->fieldName('sid') . ', ' . $this->db->fieldName('pid') . ', ' . $this->db->fieldName('itemtype') . ', ' . $this->db->fieldName('count') . ', ' . $this->db->fieldName('attributes') . ') VALUES (' . $this->data['id'] . ', ' . $depot_id . ', ' . $sid . ', ' . (int) $depot . ', ' . $item->getId() . ', ' . $item->getCount() . ', ' . $this->db->quote( $item->getAttributes() ) . ')'); + // inserts given item + $this->db->query('INSERT INTO ' . $this->db->tableName('player_depotitems') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('depot_id') . ', ' . $this->db->fieldName('sid') . ', ' . $this->db->fieldName('pid') . ', ' . $this->db->fieldName('itemtype') . ', ' . $this->db->fieldName('count') . ', ' . $this->db->fieldName('attributes') . ') VALUES (' . $this->data['id'] . ', ' . $depot_id . ', ' . $sid . ', ' . (int) $depot . ', ' . $item->getId() . ', ' . $item->getCount() . ', ' . $this->db->quote( $item->getAttributes() ) . ')'); - // checks if this is container - if($item instanceof OTS_Container) - { - $pid = $sid; + // checks if this is container + if($item instanceof OTS_Container) + { + $pid = $sid; - // inserts all contained items - foreach($item as $sub) - { - $this->setDepot($pid, $sub, 0, $depot_id); - } - } - } + // inserts all contained items + foreach($item as $sub) + { + $this->setDepot($pid, $sub, 0, $depot_id); + } + } + } - // clears $sid for next public call - if($depot <= POT::DEPOT_SID_FIRST) - { - $sid = null; - } - } + // clears $sid for next public call + if($depot <= POT::DEPOT_SID_FIRST) + { + $sid = null; + } + } /** * @version 0.1.5 @@ -2830,22 +2830,22 @@ class OTS_Player extends OTS_Row_DAO * @throws PDOException On PDO operation error. * @deprecated 0.1.5 Use OTS_PlayerBan class. */ - public function ban($time = 0) - { - // can't ban nothing - if( !$this->isLoaded() ) - { - throw new E_OTS_NotLoaded(); - } + public function ban($time = 0) + { + // can't ban nothing + if( !$this->isLoaded() ) + { + throw new E_OTS_NotLoaded(); + } - // creates ban entry - $ban = new OTS_PlayerBan(); - $ban->setValue($this->data['id']); - $ban->setExpires($time); - $ban->setAdded( time() ); - $ban->activate(); - $ban->save(); - } + // creates ban entry + $ban = new OTS_PlayerBan(); + $ban->setValue($this->data['id']); + $ban->setExpires($time); + $ban->setAdded( time() ); + $ban->activate(); + $ban->save(); + } /** * @version 0.1.5 @@ -2853,19 +2853,19 @@ class OTS_Player extends OTS_Row_DAO * @throws PDOException On PDO operation error. * @deprecated 0.1.5 Use OTS_PlayerBan class. */ - public function unban() - { - // can't unban nothing - if( !$this->isLoaded() ) - { - throw new E_OTS_NotLoaded(); - } + public function unban() + { + // can't unban nothing + if( !$this->isLoaded() ) + { + throw new E_OTS_NotLoaded(); + } - // deletes ban entry - $ban = new OTS_PlayerBan(); - $ban->find($this->data['id']); - $ban->delete(); - } + // deletes ban entry + $ban = new OTS_PlayerBan(); + $ban->find($this->data['id']); + $ban->delete(); + } /** * @version 0.1.5 @@ -2874,41 +2874,41 @@ class OTS_Player extends OTS_Row_DAO * @throws PDOException On PDO operation error. * @deprecated 0.1.5 Use OTS_PlayerBan class. */ - public function isBanned() - { - // nothing can't be banned - if( !$this->isLoaded() ) - { - throw new E_OTS_NotLoaded(); - } + public function isBanned() + { + // nothing can't be banned + if( !$this->isLoaded() ) + { + throw new E_OTS_NotLoaded(); + } if( !isset($this->data['banned']) ) $this->loadBan(); - return ($this->data['banned'] == 1); - } + return ($this->data['banned'] == 1); + } - public function getBanTime() - { - // nothing can't be banned - if( !$this->isLoaded() ) - { - throw new E_OTS_NotLoaded(); - } + public function getBanTime() + { + // nothing can't be banned + if( !$this->isLoaded() ) + { + throw new E_OTS_NotLoaded(); + } if( !isset($this->data['banned_time']) ) $this->loadBan(); - return $this->data['banned_time']; - } + return $this->data['banned_time']; + } - public function loadBan() - { - // nothing can't be banned - if( !$this->isLoaded() ) - { - throw new E_OTS_NotLoaded(); - } + public function loadBan() + { + // nothing can't be banned + if( !$this->isLoaded() ) + { + throw new E_OTS_NotLoaded(); + } $ban = $this->db->query('SELECT ' . $this->db->fieldName('active') . ', ' . $this->db->fieldName('expires') . ' FROM ' . $this->db->tableName('bans') . ' WHERE (' . $this->db->fieldName('type') . ' = 3 OR ' . $this->db->fieldName('type') . ' = 5) AND ' . $this->db->fieldName('active') . ' = 1 AND ' . $this->db->fieldName('value') . ' = ' . $this->data['account_id'] . ' AND (' . $this->db->fieldName('expires') . ' > ' . time() .' OR ' . $this->db->fieldName('expires') . ' = -1)')->fetch(); $this->data['banned'] = $ban['active']; $this->data['banned_time'] = $ban['expires']; - } + } /** * Deletes player. * @@ -2917,19 +2917,19 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function delete() - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function delete() + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - // deletes row from database - $this->db->query('UPDATE ' . $this->db->tableName('players') . ' SET ' . $this->db->fieldName('deleted') . ' = 1 WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']); + // deletes row from database + $this->db->query('UPDATE ' . $this->db->tableName('players') . ' SET ' . $this->db->fieldName('deleted') . ' = 1 WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']); - // resets object handle - unset($this->data['id']); - } + // resets object handle + unset($this->data['id']); + } /** * Player proffesion name. @@ -2943,12 +2943,12 @@ class OTS_Player extends OTS_Row_DAO * @return string Player proffesion name. * @throws E_OTS_NotLoaded If player is not loaded or global vocations list is not loaded. */ - public function getVocationName() - { - if( !isset($this->data['vocation']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getVocationName() + { + if( !isset($this->data['vocation']) ) + { + throw new E_OTS_NotLoaded(); + } global $config; $voc = $this->getVocation(); @@ -2957,8 +2957,8 @@ class OTS_Player extends OTS_Row_DAO } return $config['vocations'][$voc]; - //return POT::getInstance()->getVocationsList()->getVocationName($this->data['vocation']); - } + //return POT::getInstance()->getVocationsList()->getVocationName($this->data['vocation']); + } /** * Player residence town name. @@ -2972,15 +2972,15 @@ class OTS_Player extends OTS_Row_DAO * @return string Player town name. * @throws E_OTS_NotLoaded If player is not loaded or global map is not loaded. */ - public function getTownName() - { - if( !isset($this->data['town_id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getTownName() + { + if( !isset($this->data['town_id']) ) + { + throw new E_OTS_NotLoaded(); + } - return POT::getInstance()->getMap()->getTownName($this->data['town_id']); - } + return POT::getInstance()->getMap()->getTownName($this->data['town_id']); + } /** * Returns house rented by this player. @@ -2995,23 +2995,23 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded or global houses list is not loaded. * @throws PDOException On PDO operation error. */ - public function getHouse() - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getHouse() + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - // SELECT query on database - $house = $this->db->query('SELECT ' . $this->db->fieldName('id') . ' FROM ' . $this->db->tableName('houses') . ' WHERE ' . $this->db->fieldName('owner') . ' = ' . $this->data['id'])->fetch(); + // SELECT query on database + $house = $this->db->query('SELECT ' . $this->db->fieldName('id') . ' FROM ' . $this->db->tableName('houses') . ' WHERE ' . $this->db->fieldName('owner') . ' = ' . $this->data['id'])->fetch(); - if( !empty($house) ) - { - return POT::getInstance()->getHousesList()->getHouse($house['id']); - } + if( !empty($house) ) + { + return POT::getInstance()->getHousesList()->getHouse($house['id']); + } - return null; - } + return null; + } /** * Returns list of VIPs. @@ -3026,29 +3026,29 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function getVIPsList() - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getVIPsList() + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - $list = new OTS_Players_List(); + $list = new OTS_Players_List(); - // foreign table fields identifiers - $field1 = new OTS_SQLField('player_id', 'player_viplist'); - $field2 = new OTS_SQLField('vip_id', 'player_viplist'); + // foreign table fields identifiers + $field1 = new OTS_SQLField('player_id', 'player_viplist'); + $field2 = new OTS_SQLField('vip_id', 'player_viplist'); - // creates filter - $filter = new OTS_SQLFilter(); - $filter->addFilter($field1, $this->data['id']); - $filter->compareField('id', $field2); + // creates filter + $filter = new OTS_SQLFilter(); + $filter->addFilter($field1, $this->data['id']); + $filter->compareField('id', $field2); - // puts filter onto list - $list->setFilter($filter); + // puts filter onto list + $list->setFilter($filter); - return $list; - } + return $list; + } /** * Adds player to VIP list. @@ -3059,15 +3059,15 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function addVIP(OTS_Player $player) - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function addVIP(OTS_Player $player) + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - $this->db->query('INSERT INTO ' . $this->db->tableName('player_viplist') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('vip_id') . ') VALUES (' . $this->data['id'] . ', ' . $player->getId() . ')'); - } + $this->db->query('INSERT INTO ' . $this->db->tableName('player_viplist') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('vip_id') . ') VALUES (' . $this->data['id'] . ', ' . $player->getId() . ')'); + } /** * Checks if given player is a VIP for current one. @@ -3079,15 +3079,15 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function isVIP(OTS_Player $player) - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function isVIP(OTS_Player $player) + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->db->query('SELECT COUNT(' . $this->db->fieldName('vip_id') . ') FROM ' . $this->db->tableName('player_viplist') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('vip_id') . ' = ' . $player->getId() )->fetchColumn() > 0; - } + return $this->db->query('SELECT COUNT(' . $this->db->fieldName('vip_id') . ') FROM ' . $this->db->tableName('player_viplist') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('vip_id') . ' = ' . $player->getId() )->fetchColumn() > 0; + } /** * Deletes player from VIP list. @@ -3098,15 +3098,15 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function deleteVIP(OTS_Player $player) - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function deleteVIP(OTS_Player $player) + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - $this->db->query('DELETE FROM ' . $this->db->tableName('player_viplist') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('vip_id') . ' = ' . $player->getId() ); - } + $this->db->query('DELETE FROM ' . $this->db->tableName('player_viplist') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('vip_id') . ' = ' . $player->getId() ); + } /** * Returns list of known spells. @@ -3121,39 +3121,39 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function getSpellsList() - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function getSpellsList() + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - $spells = array(); - $list = POT::getInstance()->getSpellsList(); + $spells = array(); + $list = POT::getInstance()->getSpellsList(); - // reads all known spells - foreach( $this->db->query('SELECT ' . $this->db->fieldName('name') . ' FROM ' . $this->db->tableName('player_spells') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id']) as $spell) - { - // checks if there is rune, instant or conjure spell with given name + // reads all known spells + foreach( $this->db->query('SELECT ' . $this->db->fieldName('name') . ' FROM ' . $this->db->tableName('player_spells') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id']) as $spell) + { + // checks if there is rune, instant or conjure spell with given name - if( $list->hasRune($spell['name']) ) - { - $spells[] = $list->getRune($spell['name']); - } + if( $list->hasRune($spell['name']) ) + { + $spells[] = $list->getRune($spell['name']); + } - if( $list->hasInstance($spell['name']) ) - { - $spells[] = $list->getInstance($spell['name']); - } + if( $list->hasInstance($spell['name']) ) + { + $spells[] = $list->getInstance($spell['name']); + } - if( $list->hasConjure($spell['name']) ) - { - $spells[] = $list->getConjure($spell['name']); - } - } + if( $list->hasConjure($spell['name']) ) + { + $spells[] = $list->getConjure($spell['name']); + } + } - return $spells; - } + return $spells; + } /** * Checks if player knows given spell. @@ -3165,15 +3165,15 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function hasSpell(OTS_Spell $spell) - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function hasSpell(OTS_Spell $spell) + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - return $this->db->query('SELECT COUNT(' . $this->db->fieldName('name') . ') FROM ' . $this->db->tableName('player_spells') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('name') . ' = ' . $this->db->quote( $spell->getName() ) )->fetchColumn() > 0; - } + return $this->db->query('SELECT COUNT(' . $this->db->fieldName('name') . ') FROM ' . $this->db->tableName('player_spells') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('name') . ' = ' . $this->db->quote( $spell->getName() ) )->fetchColumn() > 0; + } /** * Adds given spell to player's spell book (makes him knowing it). @@ -3184,15 +3184,15 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function addSpell(OTS_Spell $spell) - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function addSpell(OTS_Spell $spell) + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - $this->db->query('INSERT INTO ' . $this->db->tableName('player_spells') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('name') . ') VALUES (' . $this->data['id'] . ', ' . $this->db->quote( $spell->getName() ) . ')'); - } + $this->db->query('INSERT INTO ' . $this->db->tableName('player_spells') . ' (' . $this->db->fieldName('player_id') . ', ' . $this->db->fieldName('name') . ') VALUES (' . $this->data['id'] . ', ' . $this->db->quote( $spell->getName() ) . ')'); + } /** * Removes given spell from player's spell book. @@ -3203,15 +3203,15 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded If player is not loaded. * @throws PDOException On PDO operation error. */ - public function deleteSpell(OTS_Spell $spell) - { - if( !isset($this->data['id']) ) - { - throw new E_OTS_NotLoaded(); - } + public function deleteSpell(OTS_Spell $spell) + { + if( !isset($this->data['id']) ) + { + throw new E_OTS_NotLoaded(); + } - $this->db->query('DELETE FROM ' . $this->db->tableName('player_spells') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('name') . ' = ' . $this->db->quote( $spell->getName() ) ); - } + $this->db->query('DELETE FROM ' . $this->db->tableName('player_spells') . ' WHERE ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'] . ' AND ' . $this->db->fieldName('name') . ' = ' . $this->db->quote( $spell->getName() ) ); + } public static function getPercentLevel($count, $nextLevelCount) { @@ -3232,168 +3232,168 @@ class OTS_Player extends OTS_Row_DAO * @throws OutOfBoundsException For non-supported properties. * @throws PDOException On PDO operation error. */ - public function __get($name) - { - switch($name) - { - case 'id': - return $this->getId(); + public function __get($name) + { + switch($name) + { + case 'id': + return $this->getId(); - case 'name': - return $this->getName(); + case 'name': + return $this->getName(); - case 'account': - return $this->getAccount(); + case 'account': + return $this->getAccount(); - case 'group': - return $this->getGroup(); + case 'group': + return $this->getGroup(); - case 'sex': - return $this->getSex(); + case 'sex': + return $this->getSex(); - case 'vocation': - return $this->getVocation(); + case 'vocation': + return $this->getVocation(); - case 'experience': - return $this->getExperience(); + case 'experience': + return $this->getExperience(); - case 'level': - return $this->getLevel(); + case 'level': + return $this->getLevel(); - case 'magLevel': - return $this->getMagLevel(); + case 'magLevel': + return $this->getMagLevel(); - case 'health': - return $this->getHealth(); + case 'health': + return $this->getHealth(); - case 'healthMax': - return $this->getHealthMax(); + case 'healthMax': + return $this->getHealthMax(); - case 'mana': - return $this->getMana(); + case 'mana': + return $this->getMana(); - case 'manaMax': - return $this->getManaMax(); + case 'manaMax': + return $this->getManaMax(); - case 'manaSpent': - return $this->getManaSpent(); + case 'manaSpent': + return $this->getManaSpent(); - case 'soul': - return $this->getSoul(); + case 'soul': + return $this->getSoul(); - case 'direction': - return $this->getDirection(); + case 'direction': + return $this->getDirection(); - case 'lookBody': - return $this->getLookBody(); + case 'lookBody': + return $this->getLookBody(); - case 'lookFeet': - return $this->getLookFeet(); + case 'lookFeet': + return $this->getLookFeet(); - case 'lookHead': - return $this->getLookHead(); + case 'lookHead': + return $this->getLookHead(); - case 'lookLegs': - return $this->getLookLegs(); + case 'lookLegs': + return $this->getLookLegs(); - case 'lookType': - return $this->getLookType(); + case 'lookType': + return $this->getLookType(); - case 'lookAddons': - return $this->getLookAddons(); + case 'lookAddons': + return $this->getLookAddons(); - case 'posX': - return $this->getPosX(); + case 'posX': + return $this->getPosX(); - case 'posY': - return $this->getPosY(); + case 'posY': + return $this->getPosY(); - case 'posZ': - return $this->getPosZ(); + case 'posZ': + return $this->getPosZ(); - case 'cap': - return $this->getCap(); + case 'cap': + return $this->getCap(); - case 'lastLogin': - return $this->getLastLogin(); + case 'lastLogin': + return $this->getLastLogin(); - case 'lastLogout': - return $this->getLastLogout(); + case 'lastLogout': + return $this->getLastLogout(); - case 'lastIP': - return $this->getLastIP(); + case 'lastIP': + return $this->getLastIP(); - case 'save': - return $this->isSaveSet(); + case 'save': + return $this->isSaveSet(); - case 'conditions': - return $this->getConditions(); + case 'conditions': + return $this->getConditions(); - case 'skullTime': - return $this->getRedSkullTime(); + case 'skullTime': + return $this->getRedSkullTime(); - case 'skull': - return $this->getSkull(); + case 'skull': + return $this->getSkull(); - case 'guildNick': - return $this->getGuildNick(); + case 'guildNick': + return $this->getGuildNick(); - case 'rank': - return $this->getRank(); + case 'rank': + return $this->getRank(); - case 'townId': - return $this->getTownId(); + case 'townId': + return $this->getTownId(); - case 'townName': - return $this->getTownName(); + case 'townName': + return $this->getTownName(); - case 'house': - return $this->getHouse(); + case 'house': + return $this->getHouse(); - case 'lossExperience': - return $this->getLossExperience(); + case 'lossExperience': + return $this->getLossExperience(); - case 'lossMana': - return $this->getLossMana(); + case 'lossMana': + return $this->getLossMana(); - case 'lossSkills': - return $this->getLossSkills(); + case 'lossSkills': + return $this->getLossSkills(); - case 'lossItems': - return $this->getLossItems(); + case 'lossItems': + return $this->getLossItems(); - case 'lossContainers': - return $this->getLossContainers(); + case 'lossContainers': + return $this->getLossContainers(); - case 'balance': - return $this->getBalance(); + case 'balance': + return $this->getBalance(); - case 'loaded': - return $this->isLoaded(); + case 'loaded': + return $this->isLoaded(); - case 'banned': - return $this->isBanned(); + case 'banned': + return $this->isBanned(); - case 'online': - return $this->isOnline(); + case 'online': + return $this->isOnline(); - case 'worldId': - return $this->getWorldId(); + case 'worldId': + return $this->getWorldId(); - case 'vipsList': - return $this->getVIPsList(); + case 'vipsList': + return $this->getVIPsList(); - case 'vocationName': - return $this->getVocationName(); + case 'vocationName': + return $this->getVocationName(); - case 'spellsList': - return $this->getSpellsList(); + case 'spellsList': + return $this->getSpellsList(); - default: - throw new OutOfBoundsException(); - } - } + default: + throw new OutOfBoundsException(); + } + } /** * Magic PHP5 method. @@ -3405,203 +3405,203 @@ class OTS_Player extends OTS_Row_DAO * @throws E_OTS_NotLoaded When passing object value which represents not-initialised instance. * @throws OutOfBoundsException For non-supported properties. */ - public function __set($name, $value) - { - switch($name) - { - case 'name': - $this->setName($value); - break; + public function __set($name, $value) + { + switch($name) + { + case 'name': + $this->setName($value); + break; - case 'account': - $this->setAccount($value); - break; + case 'account': + $this->setAccount($value); + break; - case 'group': - $this->setGroup($value); - break; + case 'group': + $this->setGroup($value); + break; - case 'sex': - $this->setSex($value); - break; + case 'sex': + $this->setSex($value); + break; - case 'vocation': - $this->setVocation($value); - break; + case 'vocation': + $this->setVocation($value); + break; - case 'experience': - $this->setExperience($value); - break; + case 'experience': + $this->setExperience($value); + break; - case 'level': - $this->setLevel($value); - break; + case 'level': + $this->setLevel($value); + break; - case 'magLevel': - $this->setMagLevel($value); - break; + case 'magLevel': + $this->setMagLevel($value); + break; - case 'health': - $this->setHealth($value); - break; + case 'health': + $this->setHealth($value); + break; - case 'healthMax': - $this->setHealthMax($value); - break; + case 'healthMax': + $this->setHealthMax($value); + break; - case 'mana': - $this->setMana($value); - break; + case 'mana': + $this->setMana($value); + break; - case 'manaMax': - $this->setManaMax($value); - break; + case 'manaMax': + $this->setManaMax($value); + break; - case 'manaSpent': - $this->setManaSpent($value); - break; + case 'manaSpent': + $this->setManaSpent($value); + break; - case 'soul': - $this->setSoul($value); - break; + case 'soul': + $this->setSoul($value); + break; - case 'direction': - $this->setDirection($value); - break; + case 'direction': + $this->setDirection($value); + break; - case 'lookBody': - $this->setLookBody($value); - break; + case 'lookBody': + $this->setLookBody($value); + break; - case 'lookFeet': - $this->setLookFeet($value); - break; + case 'lookFeet': + $this->setLookFeet($value); + break; - case 'lookHead': - $this->setLookHead($value); - break; + case 'lookHead': + $this->setLookHead($value); + break; - case 'lookLegs': - $this->setLookLegs($value); - break; + case 'lookLegs': + $this->setLookLegs($value); + break; - case 'lookType': - $this->setLookType($value); - break; + case 'lookType': + $this->setLookType($value); + break; - case 'lookAddons': - $this->setLookAddons($value); - break; + case 'lookAddons': + $this->setLookAddons($value); + break; - case 'posX': - $this->setPosX($value); - break; + case 'posX': + $this->setPosX($value); + break; - case 'posY': - $this->setPosY($value); - break; + case 'posY': + $this->setPosY($value); + break; - case 'posZ': - $this->setPosZ($value); - break; + case 'posZ': + $this->setPosZ($value); + break; - case 'cap': - $this->setCap($value); - break; + case 'cap': + $this->setCap($value); + break; - case 'lastLogin': - $this->setLastLogin($value); - break; + case 'lastLogin': + $this->setLastLogin($value); + break; - case 'lastLogout': - $this->setLastLogout($value); - break; + case 'lastLogout': + $this->setLastLogout($value); + break; - case 'lastIP': - $this->setLastIP($value); - break; + case 'lastIP': + $this->setLastIP($value); + break; - case 'conditions': - $this->setConditions($value); - break; + case 'conditions': + $this->setConditions($value); + break; - case 'skull': - $this->setSkull($value); - break; + case 'skull': + $this->setSkull($value); + break; - case 'skullTime': - $this->setSkullTime($value); - break; + case 'skullTime': + $this->setSkullTime($value); + break; - case 'guildNick': - $this->setGuildNick($value); - break; + case 'guildNick': + $this->setGuildNick($value); + break; - case 'rank': - $this->setRank($value); - break; + case 'rank': + $this->setRank($value); + break; - case 'townId': - $this->setTownId($value); - break; + case 'townId': + $this->setTownId($value); + break; - case 'lossExperience': - $this->setLossExperience($value); - break; + case 'lossExperience': + $this->setLossExperience($value); + break; - case 'lossMana': - $this->setLossMana($value); - break; + case 'lossMana': + $this->setLossMana($value); + break; - case 'lossSkills': - $this->setLossSkills($value); - break; + case 'lossSkills': + $this->setLossSkills($value); + break; - case 'lossItems': - $this->setLossItems($value); - break; + case 'lossItems': + $this->setLossItems($value); + break; - case 'balance': - $this->setBalance($value); - break; + case 'balance': + $this->setBalance($value); + break; - case 'skull': - if($value) - { - $this->setRedSkull(); - } - else - { - $this->unsetRedSkull(); - } - break; + case 'skull': + if($value) + { + $this->setRedSkull(); + } + else + { + $this->unsetRedSkull(); + } + break; - case 'save': - if($value) - { - $this->setSave(); - } - else - { - $this->unsetSave(); - } - break; + case 'save': + if($value) + { + $this->setSave(); + } + else + { + $this->unsetSave(); + } + break; - case 'banned': - if($value) - { - $this->ban(); - } - else - { - $this->unban(); - } - break; + case 'banned': + if($value) + { + $this->ban(); + } + else + { + $this->unban(); + } + break; - default: - throw new OutOfBoundsException(); - } - } + default: + throw new OutOfBoundsException(); + } + } /** * Returns string representation of object. @@ -3614,18 +3614,18 @@ class OTS_Player extends OTS_Row_DAO * @since 0.1.0 * @return string String representation of object. */ - public function __toString() - { - $ots = POT::getInstance(); + public function __toString() + { + $ots = POT::getInstance(); - // checks if display driver is loaded - if( $ots->isDisplayDriverLoaded() ) - { - return $ots->getDisplayDriver()->displayPlayer($this); - } + // checks if display driver is loaded + if( $ots->isDisplayDriverLoaded() ) + { + return $ots->getDisplayDriver()->displayPlayer($this); + } - return $this->getName(); - } + return $this->getName(); + } } /**#@-*/ From 10dd818b139d5e1bb1ca9ec81edfb083ba9316b4 Mon Sep 17 00:00:00 2001 From: slawkens Date: Fri, 17 Jan 2025 22:49:40 +0100 Subject: [PATCH 32/79] Optimize $player->isOnline() function --- system/libs/pot/OTS_Player.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/system/libs/pot/OTS_Player.php b/system/libs/pot/OTS_Player.php index d0b6a831..5c1cbf87 100644 --- a/system/libs/pot/OTS_Player.php +++ b/system/libs/pot/OTS_Player.php @@ -108,6 +108,8 @@ class OTS_Player extends OTS_Row_DAO POT::SKILL_SHIELD => array('value' => 0, 'tries' => 0), POT::SKILL_FISH => array('value' => 0, 'tries' => 0) ); + + private static array $playersOnline; /** * Magic PHP5 method. * @@ -765,10 +767,18 @@ class OTS_Player extends OTS_Row_DAO public function isOnline() { - if($this->db->hasTable('players_online')) // tfs 1.0 - { - $query = $this->db->query('SELECT `player_id` FROM `players_online` WHERE `player_id` = ' . $this->data['id']); - return $query->rowCount() > 0; + if($this->db->hasTable('players_online')) {// tfs 1.0 + if (!isset(self::$playersOnline)) { + self::$playersOnline = []; + + $query = $this->db->query('SELECT `player_id` FROM `players_online`'); + + foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $item) { + self::$playersOnline[$item['player_id']] = true; + } + } + + return isset(self::$playersOnline[$this->data['id']]); } if( !isset($this->data['online']) ) From 89be68731e954dbf22f76a9fd730a0f6c5ec0ac6 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 18 Jan 2025 00:11:18 +0100 Subject: [PATCH 33/79] Update CHANGELOG.md --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 523a119c..9141ff2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -140,7 +140,6 @@ Minimum PHP version for this release is 8.1. * support for login and create account only by email (configurable) * with no need for account name * Google ReCAPTCHA v3 support (available as plugin) -* automatically load towns names from .OTBM file * support for Account Number * suggest account number option * many new functions, hooks and configurables From b7de8b32eb66c740dd4105ca28c2e808ce077b10 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 18 Jan 2025 11:05:15 +0100 Subject: [PATCH 34/79] Revert "Fix menus like char-bazaar/auctions-history etc." This reverts commit dd47423157e007a36cea60fd248191a278fef891. --- templates/tibiacom/index.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/tibiacom/index.php b/templates/tibiacom/index.php index a03ff3e3..a1900538 100644 --- a/templates/tibiacom/index.php +++ b/templates/tibiacom/index.php @@ -42,6 +42,8 @@ if(isset($config['boxes'])) } else if ($exp[0] === 'news' && $exp[1] === 'archive') { $tmp = 'news_archive'; } + else + $tmp = $exp[0]; } } } From 3fb2675b5af3a4eeb30d210df7afe3f0a2e4ae3f Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 18 Jan 2025 11:11:35 +0100 Subject: [PATCH 35/79] Fix tibiacom menus --- templates/tibiacom/index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/tibiacom/index.php b/templates/tibiacom/index.php index a1900538..04b40952 100644 --- a/templates/tibiacom/index.php +++ b/templates/tibiacom/index.php @@ -42,8 +42,9 @@ if(isset($config['boxes'])) } else if ($exp[0] === 'news' && $exp[1] === 'archive') { $tmp = 'news_archive'; } - else + else if (in_array($exp[0], ['characters', 'highscores', 'guilds'])) { $tmp = $exp[0]; + } } } } From e85ce193bedbec17e9072d084e07d70e9b7c7dae Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 18 Jan 2025 11:18:21 +0100 Subject: [PATCH 36/79] Add forum to the list --- templates/tibiacom/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/tibiacom/index.php b/templates/tibiacom/index.php index 04b40952..4e640159 100644 --- a/templates/tibiacom/index.php +++ b/templates/tibiacom/index.php @@ -42,7 +42,7 @@ if(isset($config['boxes'])) } else if ($exp[0] === 'news' && $exp[1] === 'archive') { $tmp = 'news_archive'; } - else if (in_array($exp[0], ['characters', 'highscores', 'guilds'])) { + else if (in_array($exp[0], ['characters', 'highscores', 'guilds', 'forum'])) { $tmp = $exp[0]; } } From c5d5bb80671db135e6b503f53684771c7272e05d Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 18 Jan 2025 16:18:47 +0100 Subject: [PATCH 37/79] Adjust mailer settings to latest gmail --- system/settings.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/system/settings.php b/system/settings.php index 0d447c0f..5f899961 100644 --- a/system/settings.php +++ b/system/settings.php @@ -509,7 +509,7 @@ Sent by MyAAC,
'smtp_port' => [ 'name' => 'SMTP Host', 'type' => 'number', - 'desc' => '25 (default) / 465 (ssl, GMail) / 587 (tls, Microsoft Outlook)', + 'desc' => '25 (default) / 587 (tls - GMail, Microsoft Outlook)', 'default' => 25, 'show_if' => [ 'mail_enabled', '=', 'true' @@ -536,7 +536,8 @@ Sent by MyAAC,
'smtp_pass' => [ 'name' => 'SMTP Password', 'type' => 'password', - 'desc' => 'Here your email password to authenticate with SMTP', + 'desc' => 'Here your email password to authenticate with SMTP.' . PHP_EOL + . 'For GMail use generated App password - https://myaccount.google.com/apppasswords.', 'default' => '', 'show_if' => [ 'mail_enabled', '=', 'true' @@ -546,7 +547,8 @@ Sent by MyAAC,
'name' => 'SMTP Security', 'type' => 'options', 'options' => ['None', 'SSL', 'TLS'], - 'desc' => 'What kind of encryption to use on the SMTP connection', + 'desc' => 'What kind of encryption to use on the SMTP connection.' . PHP_EOL + . '(Gmail, Outlook - tls).', 'default' => 0, 'show_if' => [ 'mail_enabled', '=', 'true' From cbe0d187b4d4206222c6a1ccba03e2eba7f97fd7 Mon Sep 17 00:00:00 2001 From: slawkens Date: Mon, 20 Jan 2025 16:31:54 +0100 Subject: [PATCH 38/79] Formatting and types hint --- system/functions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/functions.php b/system/functions.php index 89f45676..7a26b7ec 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1057,14 +1057,14 @@ function get_browser_real_ip() { return '0'; } -function setSession($key, $data) { +function setSession($key, $data): void { $_SESSION[setting('core.session_prefix') . $key] = $data; } function getSession($key) { $key = setting('core.session_prefix') . $key; - return isset($_SESSION[$key]) ? $_SESSION[$key] : false; + return $_SESSION[$key] ?? false; } -function unsetSession($key) { +function unsetSession($key): void { unset($_SESSION[setting('core.session_prefix') . $key]); } From da43b32ff00e2a7cb9fb78722fa12759d71e0d58 Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 21 Jan 2025 20:43:59 +0100 Subject: [PATCH 39/79] Nothing important, code refactor --- plugins/account-create-hint.json | 2 +- plugins/account-create-hint/hint.php | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/account-create-hint.json b/plugins/account-create-hint.json index 87734108..3bf20037 100644 --- a/plugins/account-create-hint.json +++ b/plugins/account-create-hint.json @@ -1,6 +1,6 @@ { "name": "create-account-hint", - "description": "This plugin display text 'To play on Forgotten you need an account. All you have to do to create your new account is to enter an account name, password, country and your email address. Also you have to agree to the terms presented below. If you have done so, your account name will be shown on the following page and your account password will be sent to your email address along with further instructions. If you do not receive the email with your password, please check your spam filter.' on the create account page. Be careful when uninstalling this!", + "description": "This plugin display text 'To play on Forgotten you need an account. All you have to do to create your new account is to enter an account name, password, country and your email address. Also you have to agree to the terms presented below. If you have done so, your account name will be shown on the following page and your account password will be sent to your email address along with further instructions. If you do not receive the email with your password, please check your spam filter.' on the create account page.", "version": "1.0", "author": "slawkens", "contact": "slawkens@gmail.com", diff --git a/plugins/account-create-hint/hint.php b/plugins/account-create-hint/hint.php index b7ff8a7a..d1eab9ad 100644 --- a/plugins/account-create-hint/hint.php +++ b/plugins/account-create-hint/hint.php @@ -9,7 +9,4 @@ */ defined('MYAAC') or die('Direct access not allowed!'); -global $twig_loader; -$twig_loader->prependPath(BASE . 'plugins/account-create-hint'); - -$twig->display('hint.html.twig'); +$twig->display('account-create-hint/hint.html.twig'); From 669c447fca8643ce56d9ef8c1374ec647c780998 Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 21 Jan 2025 21:45:28 +0100 Subject: [PATCH 40/79] Fix hook ACCOUNT_LOGIN_BEFORE_ACCOUNT location --- system/templates/account.login.html.twig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/system/templates/account.login.html.twig b/system/templates/account.login.html.twig index c1b4afcc..fe52d7f9 100644 --- a/system/templates/account.login.html.twig +++ b/system/templates/account.login.html.twig @@ -24,21 +24,28 @@ Please enter your account {{ account|lower }} and your password.
- {{ hook('HOOK_ACCOUNT_LOGIN_BEFORE_PASSWORD') }} + + {{ hook('HOOK_ACCOUNT_LOGIN_BEFORE_ACCOUNT') }} + + {{ hook('HOOK_ACCOUNT_LOGIN_AFTER_ACCOUNT') }} + {{ hook('HOOK_ACCOUNT_LOGIN_BEFORE_PASSWORD') }} + + {{ hook('HOOK_ACCOUNT_LOGIN_AFTER_PASSWORD') }} +
{{ account_login_by }}:
Password:
From a45ceab83a74bee2b89cdb72baceda75e577e3cf Mon Sep 17 00:00:00 2001 From: slawkens Date: Wed, 22 Jan 2025 21:44:58 +0100 Subject: [PATCH 41/79] Make players.comment and guilds.description VARCHAR --- common.php | 2 +- install/includes/schema.sql | 2 +- install/tools/5-database.php | 14 ++++++++++++-- system/migrations/43.php | 20 ++++++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 system/migrations/43.php diff --git a/common.php b/common.php index 0f675753..66489235 100644 --- a/common.php +++ b/common.php @@ -27,7 +27,7 @@ if (version_compare(phpversion(), '8.1', '<')) die('PHP version 8.1 or higher is const MYAAC = true; const MYAAC_VERSION = '1.0.1'; -const DATABASE_VERSION = 42; +const DATABASE_VERSION = 43; const TABLE_PREFIX = 'myaac_'; define('START_TIME', microtime(true)); define('MYAAC_OS', stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : (strtoupper(PHP_OS) === 'DARWIN' ? 'MAC' : 'LINUX')); diff --git a/install/includes/schema.sql b/install/includes/schema.sql index 91853e07..21409c00 100644 --- a/install/includes/schema.sql +++ b/install/includes/schema.sql @@ -1,4 +1,4 @@ -SET @myaac_database_version = 42; +SET @myaac_database_version = 43; CREATE TABLE `myaac_account_actions` ( diff --git a/install/tools/5-database.php b/install/tools/5-database.php index ff0bcbbb..395492ee 100644 --- a/install/tools/5-database.php +++ b/install/tools/5-database.php @@ -156,9 +156,14 @@ if ($db->hasTable('guilds')) { } if (!$db->hasColumn('guilds', 'description')) { - if (query("ALTER TABLE `guilds` ADD `description` TEXT NOT NULL;")) + if (query("ALTER TABLE `guilds` ADD `description` VARCHAR(5000) NOT NULL DEFAULT '';")) success($locale['step_database_adding_field'] . ' guilds.description...'); } + else { + if (query("ALTER TABLE `guilds` MODIFY `description` VARCHAR(5000) NOT NULL DEFAULT '';")) { + success($locale['step_database_modifying_field'] . ' guilds.description...'); + } + } if ($db->hasColumn('guilds', 'logo_gfx_name')) { if (query("ALTER TABLE `guilds` CHANGE `logo_gfx_name` `logo_name` VARCHAR( 255 ) NOT NULL DEFAULT 'default.gif';")) { @@ -197,9 +202,14 @@ if ($db->hasTable('players')) { } if (!$db->hasColumn('players', 'comment')) { - if (query("ALTER TABLE `players` ADD `comment` TEXT NOT NULL;")) + if (query("ALTER TABLE `players` ADD `comment` VARCHAR(5000) NOT NULL DEFAULT '';")) success($locale['step_database_adding_field'] . ' players.comment...'); } + else { + if (query("ALTER TABLE `players` MODIFY `comment` VARCHAR(5000) NOT NULL DEFAULT '';")) { + success($locale['step_database_modifying_field'] . ' players.comment...'); + } + } if ($db->hasColumn('players', 'rank_id')) { if (query("ALTER TABLE players MODIFY `rank_id` INT(11) NOT NULL DEFAULT 0;")) diff --git a/system/migrations/43.php b/system/migrations/43.php new file mode 100644 index 00000000..2601f265 --- /dev/null +++ b/system/migrations/43.php @@ -0,0 +1,20 @@ +query("UPDATE guilds set description = '' WHERE description is NULL;"); // prevent truncate error when column is NULL + $db->modifyColumn('guilds', 'description', "VARCHAR(5000) NOT NULL DEFAULT ''"); + + $db->query("UPDATE players set comment = '' WHERE comment is NULL;"); + $db->modifyColumn('players', 'comment', "VARCHAR(5000) NOT NULL DEFAULT ''"); +}; + +$down = function () use ($db) { + $db->modifyColumn('guilds', 'description', "TEXT NOT NULL"); + $db->modifyColumn('players', 'comment', "TEXT NOT NULL"); +}; + From 07012f786b1114cb6ab2f064f82c645b136a375a Mon Sep 17 00:00:00 2001 From: slawkens Date: Wed, 22 Jan 2025 21:45:07 +0100 Subject: [PATCH 42/79] Ignore lua/ folder --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 39712f98..b198856f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ Thumbs.db # /.htaccess +lua # composer composer.phar @@ -75,6 +76,3 @@ landing # system system/functions_custom.php - -# others/rest -system/pages/downloads.php From 4d749b881582f64b5a46196dbbb5ee8097127f03 Mon Sep 17 00:00:00 2001 From: slawkens Date: Fri, 24 Jan 2025 21:42:52 +0100 Subject: [PATCH 43/79] Fix error in CLI, where BASE_URL is not defined --- system/init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/init.php b/system/init.php index 7bf9f1de..8c7e56fc 100644 --- a/system/init.php +++ b/system/init.php @@ -139,7 +139,7 @@ require_once SYSTEM . 'database.php'; // verify myaac tables exists in database if(!defined('MYAAC_INSTALL') && !$db->hasTable('myaac_account_actions')) { - throw new RuntimeException('Seems that the table myaac_account_actions of MyAAC doesn\'t exist in the database. This is a fatal error. You can try to reinstall MyAAC by visiting ' . BASE_URL . 'install'); + throw new RuntimeException('Seems that the table myaac_account_actions of MyAAC doesn\'t exist in the database. This is a fatal error. You can try to reinstall MyAAC by visiting ' . (IS_CLI ? 'http://your-ip.com/' : BASE_URL) . 'install'); } // execute migrations From ea753278a052973959de6842d7d64b7a22ca8ac7 Mon Sep 17 00:00:00 2001 From: slawkens Date: Mon, 27 Jan 2025 22:15:00 +0100 Subject: [PATCH 44/79] Secure direct access to template.php --- install/template/template.php | 1 + 1 file changed, 1 insertion(+) diff --git a/install/template/template.php b/install/template/template.php index 1e1829a6..aadaae23 100644 --- a/install/template/template.php +++ b/install/template/template.php @@ -1,3 +1,4 @@ + From 9ab25abcdf6be3768dd9235c11b7e080c13377dd Mon Sep 17 00:00:00 2001 From: slawkens Date: Mon, 27 Jan 2025 22:30:18 +0100 Subject: [PATCH 45/79] Release v1.1 --- CHANGELOG.md | 14 ++++++++++++++ common.php | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9141ff2f..74906354 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [1.1 - 27.01.2025] + +### Changed +* adjust mailer settings descriptions to latest gmail (https://github.com/slawkens/myaac/commit/c5d5bb80671db135e6b503f53684771c7272e05d) +* optimize $player->isOnline() function, thanks @gesior (https://github.com/slawkens/myaac/commit/10dd818b139d5e1bb1ca9ec81edfb083ba9316b4) +* make players.comment and guilds.description VARCHAR (https://github.com/slawkens/myaac/commit/a45ceab83a74bee2b89cdb72baceda75e577e3cf) +* add lua/ folder to .gitignore (https://github.com/slawkens/myaac/commit/07012f786b1114cb6ab2f064f82c645b136a375a) + +### Fixed +* general fixes in the tibiacom template menus, better support for custom menus +* make functions_custom.php optional +* error in CLI, where BASE_URL is not defined (https://github.com/slawkens/myaac/commit/4d749b881582f64b5a46196dbbb5ee8097127f03) +* hook ACCOUNT_LOGIN_BEFORE_ACCOUNT location (https://github.com/slawkens/myaac/commit/669c447fca8643ce56d9ef8c1374ec647c780998) + ## [1.0.1 - 14.01.2025] ### Fixed diff --git a/common.php b/common.php index 66489235..5c5aeeb2 100644 --- a/common.php +++ b/common.php @@ -26,7 +26,7 @@ if (version_compare(phpversion(), '8.1', '<')) die('PHP version 8.1 or higher is required.'); const MYAAC = true; -const MYAAC_VERSION = '1.0.1'; +const MYAAC_VERSION = '1.1'; const DATABASE_VERSION = 43; const TABLE_PREFIX = 'myaac_'; define('START_TIME', microtime(true)); From 19b290feb70e9805795d72749c8e76658e7940d3 Mon Sep 17 00:00:00 2001 From: slawkens Date: Mon, 27 Jan 2025 22:48:32 +0100 Subject: [PATCH 46/79] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74906354..497e042a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ ### Fixed * general fixes in the tibiacom template menus, better support for custom menus -* make functions_custom.php optional +* make functions_custom.php optional (https://github.com/slawkens/myaac/commit/dc2b5afd9980984e2b259c9fc99f2ade46f70a5a) * error in CLI, where BASE_URL is not defined (https://github.com/slawkens/myaac/commit/4d749b881582f64b5a46196dbbb5ee8097127f03) * hook ACCOUNT_LOGIN_BEFORE_ACCOUNT location (https://github.com/slawkens/myaac/commit/669c447fca8643ce56d9ef8c1374ec647c780998) From 34321613d6428794b0dc7ff48e27025b843b8613 Mon Sep 17 00:00:00 2001 From: slawkens Date: Mon, 27 Jan 2025 22:57:40 +0100 Subject: [PATCH 47/79] Start v1.1.1 --- common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.php b/common.php index 5c5aeeb2..2aa09d28 100644 --- a/common.php +++ b/common.php @@ -26,7 +26,7 @@ if (version_compare(phpversion(), '8.1', '<')) die('PHP version 8.1 or higher is required.'); const MYAAC = true; -const MYAAC_VERSION = '1.1'; +const MYAAC_VERSION = '1.1.1-dev'; const DATABASE_VERSION = 43; const TABLE_PREFIX = 'myaac_'; define('START_TIME', microtime(true)); From a1ed20959199232e3509b1b8136f6558238183e7 Mon Sep 17 00:00:00 2001 From: slawkens Date: Mon, 27 Jan 2025 22:58:32 +0100 Subject: [PATCH 48/79] Update README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dc0bbff6..8fab33a5 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,12 @@ Official website: https://my-aac.org [![OpenTibia Discord](https://img.shields.io/discord/288399552581468162)](https://discord.gg/2J39Wus) [![Closed Issues](https://img.shields.io/github/issues-closed-raw/slawkens/myaac)](https://github.com/slawkens/myaac/issues?q=is%3Aissue+is%3Aclosed) -| Version | Status | Branch | Requirements | -|:--------|:-----------------------|:--------|:---------------| -| **1.x** | **Active development** | develop | **PHP >= 8.1** | -| 0.9.x | Not developed anymore | 0.9 | PHP >= 7.2.5 | -| 0.8.x | Active support | master | PHP >= 7.2.5 | -| 0.7.x | End Of Life | 0.7 | PHP >= 5.3.3 | +| Version | Status | Branch | Requirements | +|:--------|:-----------------------|:-------|:---------------| +| **1.x** | **Active development** | master | **PHP >= 8.1** | +| 0.9.x | Not developed anymore | 0.9 | PHP >= 7.2.5 | +| 0.8.x | Active support | 0.8 | PHP >= 7.2.5 | +| 0.7.x | End Of Life | 0.7 | PHP >= 5.3.3 | ### Requirements From d2a4748a5957a41d89800650138c547c5d4acc6d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 20:00:58 +0100 Subject: [PATCH 49/79] Bump twig/twig from 3.18.0 to 3.19.0 (#284) Bumps [twig/twig](https://github.com/twigphp/Twig) from 3.18.0 to 3.19.0. - [Changelog](https://github.com/twigphp/Twig/blob/3.x/CHANGELOG) - [Commits](https://github.com/twigphp/Twig/compare/v3.18.0...v3.19.0) --- updated-dependencies: - dependency-name: twig/twig dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.lock b/composer.lock index ea98d5b5..3a484492 100644 --- a/composer.lock +++ b/composer.lock @@ -2637,16 +2637,16 @@ }, { "name": "twig/twig", - "version": "v3.18.0", + "version": "v3.19.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "acffa88cc2b40dbe42eaf3a5025d6c0d4600cc50" + "reference": "d4f8c2b86374f08efc859323dbcd95c590f7124e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/acffa88cc2b40dbe42eaf3a5025d6c0d4600cc50", - "reference": "acffa88cc2b40dbe42eaf3a5025d6c0d4600cc50", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/d4f8c2b86374f08efc859323dbcd95c590f7124e", + "reference": "d4f8c2b86374f08efc859323dbcd95c590f7124e", "shasum": "" }, "require": { @@ -2701,7 +2701,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.18.0" + "source": "https://github.com/twigphp/Twig/tree/v3.19.0" }, "funding": [ { @@ -2713,7 +2713,7 @@ "type": "tidelift" } ], - "time": "2024-12-29T10:51:50+00:00" + "time": "2025-01-29T07:06:14+00:00" }, { "name": "voku/portable-ascii", @@ -2910,7 +2910,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -2921,6 +2921,6 @@ "ext-xml": "*", "ext-dom": "*" }, - "platform-dev": {}, - "plugin-api-version": "2.6.0" + "platform-dev": [], + "plugin-api-version": "2.3.0" } From ea51ad27c38be88d86514cb979bb394fcfbef1f0 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 1 Feb 2025 00:35:22 +0100 Subject: [PATCH 50/79] Fix online status + vocation for TFS 0.x --- system/functions.php | 4 ---- system/pages/highscores.php | 4 ---- system/src/Models/Player.php | 18 ++++++++++++------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/system/functions.php b/system/functions.php index 7a26b7ec..d25dc5ae 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1107,10 +1107,6 @@ function getTopPlayers($limit = 5, $skill = 'level') { $columns[] = 'lookaddons'; } - if ($db->hasColumn('players', 'online')) { - $columns[] = 'online'; - } - return Player::query() ->select($columns) ->withOnlineStatus() diff --git a/system/pages/highscores.php b/system/pages/highscores.php index d8057595..269c8ce4 100644 --- a/system/pages/highscores.php +++ b/system/pages/highscores.php @@ -234,10 +234,6 @@ foreach($highscores as $id => &$player) $player['experience'] = number_format($player['experience']); } - if(!$settingHighscoresVocation) { - unset($player['vocation']); - } - $player['link'] = getPlayerLink($player['name'], false); $player['flag'] = getFlagImage($player['country']); if($settingHighscoresOutfit) { diff --git a/system/src/Models/Player.php b/system/src/Models/Player.php index 6faf5df3..77fe4504 100644 --- a/system/src/Models/Player.php +++ b/system/src/Models/Player.php @@ -49,8 +49,8 @@ class Player extends Model { public function getVocationNameAttribute() { $vocation = $this->vocation; - if (isset($this->promotion)) { - $vocation *= $this->promotion; + if (isset($this->promotion) && $this->promotion > 0) { + $vocation += ($this->promotion * setting('core.vocations_amount')); } return config('vocations')[$vocation] ?? 'Unknown'; @@ -80,11 +80,17 @@ class Player extends Model { $query->where($column, 0); } - public function scopeWithOnlineStatus($query) { + public function scopeWithOnlineStatus($query) + { global $db; - $query->when($db->hasTable('players_online'), function ($query) { - $query->with('onlineTable'); - }); + if ($db->hasColumn('players', 'online')) { + $query->addSelect('online'); + } + else { + $query->when($db->hasTable('players_online'), function ($query) { + $query->with('onlineTable'); + }); + } } public function getOutfitUrlAttribute() { From de468a8dcd56e704eb160e157847aa373ca9ee71 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 2 Feb 2025 14:22:57 +0100 Subject: [PATCH 51/79] Fixed need to click on button second time --- system/templates/admin-bar.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/templates/admin-bar.html.twig b/system/templates/admin-bar.html.twig index b14eb84e..5d215610 100644 --- a/system/templates/admin-bar.html.twig +++ b/system/templates/admin-bar.html.twig @@ -110,7 +110,7 @@ html { margin-top: 32px !important; }
{{ csrf() }} - Clear Cache + Clear Cache
From b46ddb43d03ef7e5fc34e555e92e856bdc905691 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 2 Feb 2025 16:16:59 +0100 Subject: [PATCH 52/79] Twig session(key) function + reworked session functions to accept multi-array like in Laravel Important: getSession returns NULL now instead of false if session value not found --- CHANGELOG.md | 5 +++++ system/functions.php | 27 +++++++++++++++++++++++---- system/login.php | 4 ++-- system/template.php | 2 +- system/twig.php | 5 +++++ 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 497e042a..a90861f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [master - 02.02.2025] + +### Added +* Twig session(key) function + reworked session functions to accept multi-array like in Laravel + ## [1.1 - 27.01.2025] ### Changed diff --git a/system/functions.php b/system/functions.php index d25dc5ae..77b33415 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1057,17 +1057,36 @@ function get_browser_real_ip() { return '0'; } -function setSession($key, $data): void { - $_SESSION[setting('core.session_prefix') . $key] = $data; +function setSession($key, $value = null): void { + if (!is_array($key)) { + $key = [$key => $value]; + } + + foreach ($key as $arrayKey => $arrayValue) { + if (is_null($arrayValue)) { + unsetSession($arrayKey); + } + else { + $_SESSION[setting('core.session_prefix') . $arrayKey] = $arrayValue; + } + } } function getSession($key) { - $key = setting('core.session_prefix') . $key; - return $_SESSION[$key] ?? false; + return $_SESSION[setting('core.session_prefix') . $key] ?? null; } function unsetSession($key): void { unset($_SESSION[setting('core.session_prefix') . $key]); } +function session($key): mixed { + if (is_array($key)) { + setSession($key); + return null; + } + + return getSession($key); +} + function csrf(bool $return = false): string { return CsrfToken::create($return); } diff --git a/system/login.php b/system/login.php index e018c043..42a96111 100644 --- a/system/login.php +++ b/system/login.php @@ -14,12 +14,12 @@ $account_logged = new OTS_Account(); // stay-logged with sessions $current_session = getSession('account'); -if($current_session !== false) +if($current_session) { $account_logged->load($current_session); if($account_logged->isLoaded() && $account_logged->getPassword() == getSession('password') //&& (!isset($_SESSION['admin']) || admin()) - && (getSession('remember_me') !== false || getSession('last_visit') > time() - 15 * 60)) { // login for 15 minutes if "remember me" is not used + && (getSession('remember_me') || getSession('last_visit') > time() - 15 * 60)) { // login for 15 minutes if "remember me" is not used $logged = true; } else { diff --git a/system/template.php b/system/template.php index 62d3e29b..0434dbac 100644 --- a/system/template.php +++ b/system/template.php @@ -41,7 +41,7 @@ if(setting('core.template_allow_change')) } else { $template_session = getSession('template'); - if ($template_session !== false) { + if ($template_session) { if (!preg_match("/[^A-z0-9_\-]/", $template_session)) { $template_name = $template_session; } diff --git a/system/twig.php b/system/twig.php index 1268f292..fc3125fe 100644 --- a/system/twig.php +++ b/system/twig.php @@ -140,6 +140,11 @@ $function = new TwigFunction('csrfToken', function () { }); $twig->addFunction($function); +$function = new TwigFunction('session', function ($key) { + return session($key); +}); +$twig->addFunction($function); + $filter = new TwigFilter('urlencode', function ($s) { return urlencode($s); }); From a73fb1003ee3f812cf182d1834d65f08e6f60d1f Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 2 Feb 2025 16:17:24 +0100 Subject: [PATCH 53/79] Fix HOOK_STARTUP location --- index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 9d30339f..0a42deed 100644 --- a/index.php +++ b/index.php @@ -76,6 +76,8 @@ require_once SYSTEM . 'status.php'; $twig->addGlobal('config', $config); $twig->addGlobal('status', $status); +$hooks->trigger(HOOK_STARTUP); + // backward support for gesior if(setting('core.backward_support')) { define('INITIALIZED', true); @@ -117,8 +119,6 @@ if(setting('core.backward_support')) { require_once SYSTEM . 'router.php'; -$hooks->trigger(HOOK_STARTUP); - // anonymous usage statistics // sent only when user agrees if(setting('core.anonymous_usage_statistics')) { From 19686725dc810f63a07f049f82c66cf336d90ca6 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 2 Feb 2025 16:17:49 +0100 Subject: [PATCH 54/79] Add HOOK_INIT, executed just after $hooks are loaded --- system/init.php | 1 + system/src/global.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/system/init.php b/system/init.php index 8c7e56fc..ba2990db 100644 --- a/system/init.php +++ b/system/init.php @@ -50,6 +50,7 @@ $cache = Cache::getInstance(); global $hooks; $hooks = new Hooks(); $hooks->load(); +$hooks->trigger(HOOK_INIT); // twig require_once SYSTEM . 'twig.php'; diff --git a/system/src/global.php b/system/src/global.php index d5c54fd8..61b887b5 100644 --- a/system/src/global.php +++ b/system/src/global.php @@ -5,6 +5,7 @@ const SKILL_BALANCE = -2; $i = 0; +define('HOOK_INIT', ++$i); define('HOOK_STARTUP', ++$i); define('HOOK_BEFORE_PAGE', ++$i); define('HOOK_AFTER_PAGE', ++$i); @@ -96,7 +97,7 @@ define('HOOK_CACHE_CLEAR', ++$i); define('HOOK_INSTALL_FINISH', ++$i); define('HOOK_INSTALL_FINISH_END', ++$i); -const HOOK_FIRST = HOOK_STARTUP; +const HOOK_FIRST = HOOK_INIT; define('HOOK_LAST', $i); function is_sub_dir($path = NULL, $parent_folder = BASE): bool|string From 4fda4f643b60a151179e5dd4f04912fb2618d98f Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 2 Feb 2025 21:55:16 +0100 Subject: [PATCH 55/79] feat: Settings: password input with hide/show options --- system/settings.php | 2 +- system/src/Settings.php | 8 ++++++++ system/templates/admin.settings.html.twig | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/system/settings.php b/system/settings.php index 5f899961..f4f3fedf 100644 --- a/system/settings.php +++ b/system/settings.php @@ -348,7 +348,7 @@ return [ ], 'database_password' => [ 'name' => 'Database Password', - 'type' => 'text', + 'type' => 'password', 'default' => '', 'show_if' => [ 'database_overwrite', '=', 'true' diff --git a/system/src/Settings.php b/system/src/Settings.php index 0749396a..a02ff43c 100644 --- a/system/src/Settings.php +++ b/system/src/Settings.php @@ -247,7 +247,15 @@ class Settings implements \ArrayAccess $min = $max = $step = ''; } + if ($setting['type'] === 'password') { + echo '
'; + } + echo ''; + + if ($setting['type'] === 'password') { + echo '
'; + } } else if($setting['type'] === 'textarea') { diff --git a/system/templates/admin.settings.html.twig b/system/templates/admin.settings.html.twig index 89a38a95..e0f5d94b 100644 --- a/system/templates/admin.settings.html.twig +++ b/system/templates/admin.settings.html.twig @@ -109,3 +109,26 @@ }); }); + From 28fef952f857b79d64bc7495ffa5e1999e68e192 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 2 Feb 2025 22:04:37 +0100 Subject: [PATCH 56/79] feat: Settings: enable Save button only if changes has been made --- system/templates/admin.settings.html.twig | 29 ++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/system/templates/admin.settings.html.twig b/system/templates/admin.settings.html.twig index e0f5d94b..7982780d 100644 --- a/system/templates/admin.settings.html.twig +++ b/system/templates/admin.settings.html.twig @@ -80,7 +80,26 @@ } }); - $('#settings').submit(function(e) { + const noChangesText = "No changes has been made"; + + $('form') + .each(function(){ + $(this).data('serialized', $(this).serialize()) + }) + .on('change input', function(){ + const disable = $(this).serialize() === $(this).data('serialized'); + $(this) + .find('input:submit, button:submit') + .prop('disabled', disable) + .prop('title', disable ? noChangesText : '') + ; + }) + .find('input:submit, button:submit') + .prop('disabled', true) + .prop('title', noChangesText) + ; + + $('#settings').on('submit', function(e) { e.preventDefault(); $.ajax({ @@ -94,6 +113,13 @@ duration: 3000, escapeMarkup: false, }).showToast(); + + let $settings = $('#settings'); + $settings.data('serialized', $settings.serialize()); + $settings + .find('input:submit, button:submit') + .prop('disabled', true) + .prop('title', noChangesText); }, error : function(response) { Toastify({ @@ -109,6 +135,7 @@ }); }); +