From f6ccadf8fddc5705c0c0d4f993f959a129703943 Mon Sep 17 00:00:00 2001 From: Shadez Date: Thu, 20 Jan 2011 23:50:43 +0800 Subject: [PATCH] [463] Added configuration option to disable characters loading from banned accounts. Do not forget to update your config file from configuration.php.default. Also, move character requirements checks to separate method. --- includes/classes/class.characters.php | 79 +++++++++++++--------- includes/classes/configuration.php.default | 10 ++- includes/revision_nr.php | 4 +- 3 files changed, 56 insertions(+), 37 deletions(-) diff --git a/includes/classes/class.characters.php b/includes/classes/class.characters.php index 4eacdf771..7f7ac0caf 100644 --- a/includes/classes/class.characters.php +++ b/includes/classes/class.characters.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release 4.50 - * @revision 462 + * @revision 463 * @copyright (c) 2009-2011 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -299,6 +299,49 @@ public function SetOptions($options) { return true; } + private function IsCharacterFitsRequirements(&$player_data) { + $gmLevel = 0; + // Disable next SQL error + Armory::$rDB->SkipNextError(); + if($this->m_server == SERVER_TRINITY) { + $gmLevel = Armory::$rDB->selectCell("SELECT `gmlevel` FROM `account_access` WHERE `id`=%d AND `RealmID` IN (-1, %d)", $player_data['account'], Armory::$connectionData['id']); + } + elseif($this->m_server == SERVER_MANGOS) { + $gmLevel = Armory::$rDB->selectCell("SELECT `gmlevel` FROM `account` WHERE `id`=%d LIMIT 1", $player_data['account']); + } + $allowed = ($gmLevel <= Armory::$armoryconfig['minGmLevelToShow']) ? true : false; + if(!$allowed) { + Armory::Log()->writeLog('%s : unable to display character %s (GUID: %d): GM level restriction!', __METHOD__, $player_data['name'], $player_data['guid']); + return false; + } + if($player_data['level'] < Armory::$armoryconfig['minlevel']) { + Armory::Log()->writeLog('%s : unable to load character %s (GUID: %d): level restriction.', __METHOD__, $player_data['name'], $player_data['guid']); + return false; + } + if(Armory::$armoryconfig['skipBanned'] && Armory::$rDB->selectCell("SELECT 1 FROM `account_banned` WHERE `id` = %d AND `active` = 1", $player_data['account'])) { + Armory::Log()->writeLog('%s : unable to load character %s (GUID: %d) from banned account %d.', __METHOD__, $player_data['name'], $player_data['guid'], $player_data['account']); + return false; + } + // Class/race/faction checks + if($player_data['class'] >= MAX_CLASSES) { + // Unknown class + Armory::Log()->writeError('%s : character %s (GUID: %d) has wrong data in DB: classID %d was not found. Unable to continue.', __METHOD__, $player_data['name'], $player_data['guid'], $player_data['class']); + return false; + } + elseif($player_data['race'] >= MAX_RACES) { + // Unknown race + Armory::Log()->writeError('%s : character %s (GUID: %d) has wrong data in DB: raceID %d was not found. Unable to continue.', __METHOD__, $player_data['name'], $player_data['guid'], $player_data['race']); + return false; + } + $this->faction = Utils::GetFactionId($player_data['race']); + if($this->faction === false) { + // Unknown faction + Armory::Log()->writeError('%s : character %s (GUID: %d) has wrong data in DB: factionID %d was not found (raceID: %d).', __METHOD__, $player_data['name'], $player_data['guid'], $this->faction, $player_data['race']); + return false; + } + return true; + } + /** * Init character, load data from DB, checks for requirements, etc. * @category Characters class @@ -397,39 +440,9 @@ public function BuildCharacter($name, $realmId = 1, $full = true, $initialBuild $this->HandleCharacterData(); } // Can we display this character? - $gmLevel = false; - Armory::$rDB->SkipNextError(); - if($this->m_server == SERVER_TRINITY) { - $gmLevel = Armory::$rDB->selectCell("SELECT `gmlevel` FROM `account_access` WHERE `id`=%d AND `RealmID` IN (-1, %d)", $player_data['account'], Armory::$connectionData['id']); - } - elseif($this->m_server == SERVER_MANGOS) { - $gmLevel = Armory::$rDB->selectCell("SELECT `gmlevel` FROM `account` WHERE `id`=%d LIMIT 1", $player_data['account']); - } - $allowed = ($gmLevel <= Armory::$armoryconfig['minGmLevelToShow']) ? true : false; - if(!$allowed || $player_data['level'] < Armory::$armoryconfig['minlevel']) { - Armory::Log()->writeLog('%s : Player %d (%s) can not be displayed (GM level restriction or has low level (%d level))!', __METHOD__, $player_data['guid'], $player_data['name'], $player_data['level']); - unset($player_data); - return false; - } - // Class/race/faction checks - if($player_data['class'] >= MAX_CLASSES) { - // Unknown class - Armory::Log()->writeError('%s : Player %d (%s) has wrong data in DB: classID %d was not found.', __METHOD__, $player_data['guid'], $player_data['name'], $player_data['class']); - unset($player_data); - return false; - } - elseif($player_data['race'] >= MAX_RACES) { - // Unknown race - Armory::Log()->writeError('%s : Player %d (%s) has wrong data in DB: raceID %d was not found.', __METHOD__, $player_data['guid'], $player_data['name'], $player_data['race']); - unset($player_data); - return false; - } - $this->faction = Utils::GetFactionId($player_data['race']); - if($this->faction === false) { - // Unknown faction - Armory::Log()->writeError('%s : Player %d (%s) has wrong data in DB: factionID %d was not found (raceID: %d).', __METHOD__, $player_data['guid'], $player_data['name'], $this->faction, $player_data['class']); - unset($player_data); + if(!$this->IsCharacterFitsRequirements($player_data)) { return false; + // Debug message will be added from Characters::IsCharacterFitsRequirements() } foreach($player_data as $pData_key => $pData_value) { if(is_string($pData_key)) { diff --git a/includes/classes/configuration.php.default b/includes/classes/configuration.php.default index b13355606..52ef38cce 100644 --- a/includes/classes/configuration.php.default +++ b/includes/classes/configuration.php.default @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release 4.50 - * @revision 456 + * @revision 463 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -100,6 +100,11 @@ $ArmoryConfig['mysql']['charset_realmd'] = 'UTF8'; # 1 (Everyone except Administrators and GMs will be displayed in Armory) # 0 (Only players will be displayed in Armory) # +# skipBanned +# Disable characters loading from banned accounts? +# Default: false (Recommended) +# true +# # defaultLocale # Site default locale # Default: en_gb (UK English) @@ -141,11 +146,12 @@ $ArmoryConfig['settings']['cache_lifetime'] = 86400; $ArmoryConfig['settings']['db_prefix'] = 'armory'; $ArmoryConfig['settings']['minlevel'] = 10; $ArmoryConfig['settings']['minGmLevelToShow'] = 3; +$ArmoryConfig['settings']['skipBanned'] = false; $ArmoryConfig['settings']['defaultLocale'] = 'en_gb'; $ArmoryConfig['settings']['maintenance'] = false; $ArmoryConfig['settings']['useDebug'] = true; $ArmoryConfig['settings']['logLevel'] = 2; -$ArmoryConfig['settings']['configVersion'] = '1801201101'; +$ArmoryConfig['settings']['configVersion'] = '2001201101'; $ArmoryConfig['settings']['checkVersionType'] = 'show'; ############################################################################################## diff --git a/includes/revision_nr.php b/includes/revision_nr.php index ac1a3e3a3..e87c38675 100644 --- a/includes/revision_nr.php +++ b/includes/revision_nr.php @@ -1,5 +1,5 @@ \ No newline at end of file