From 85d7580e1c56b3561a7f83b678c40f16d869b4ba Mon Sep 17 00:00:00 2001 From: Filo Date: Fri, 12 Nov 2010 22:06:33 +0800 Subject: [PATCH] [415] Replace `armory_` cases to `ARMORYDBPREFIX_` from old SQL queries --- includes/classes/class.characters.php | 14 ++--- includes/classes/class.search.php | 2 +- includes/classes/class.utils.php | 78 ++++++++++++++++++++++----- includes/revision_nr.php | 2 +- 4 files changed, 75 insertions(+), 21 deletions(-) diff --git a/includes/classes/class.characters.php b/includes/classes/class.characters.php index a5035760a..6ec1d34be 100644 --- a/includes/classes/class.characters.php +++ b/includes/classes/class.characters.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 411 + * @revision 415 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -394,11 +394,11 @@ public function BuildCharacter($name, $realmId = 1, $full = true, $initialBuild // Get race and class strings $race_class = $this->armory->aDB->selectRow(" SELECT - `armory_races`.`name_%s` AS `race`, - `armory_classes`.`name_%s` AS `class` - FROM `ARMORYDBPREFIX_races` AS `armory_races` - LEFT JOIN `armory_classes` AS `armory_classes` ON `armory_classes`.`id`=%d - WHERE `armory_races`.`id`=%d", $this->armory->GetLocale(), $this->armory->GetLocale(), $player_data['class'], $player_data['race']); + `ARMORYDBPREFIX_races`.`name_%s` AS `race`, + `ARMORYDBPREFIX_classes`.`name_%s` AS `class` + FROM `ARMORYDBPREFIX_races` AS `ARMORYDBPREFIX_races` + LEFT JOIN `ARMORYDBPREFIX_classes` AS `ARMORYDBPREFIX_classes` ON `ARMORYDBPREFIX_classes`.`id`=%d + WHERE `ARMORYDBPREFIX_races`.`id`=%d", $this->armory->GetLocale(), $this->armory->GetLocale(), $player_data['class'], $player_data['race']); if(!$race_class) { $this->armory->Log()->writeError('%s : unable to find class/race text strings for player %d (name: %s, race: %d, class: %d)', __METHOD__, $player_data['guid'], $player_data['name'], $player_data['race'], $player_data['class']); unset($player_data); @@ -839,7 +839,7 @@ public function GetCharacterEquip($slot) { } switch($slot) { case 'head': - return $this->equipmentCache[0]; + return $this->equipmentCache[0]; break; case 'neck': return $this->equipmentCache[2]; diff --git a/includes/classes/class.search.php b/includes/classes/class.search.php index 2db715e91..27f0c2c39 100644 --- a/includes/classes/class.search.php +++ b/includes/classes/class.search.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 403 + * @revision 415 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * diff --git a/includes/classes/class.utils.php b/includes/classes/class.utils.php index eb00db6c6..49c34b835 100644 --- a/includes/classes/class.utils.php +++ b/includes/classes/class.utils.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 413 + * @revision 415 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -322,14 +322,14 @@ public function GetActiveCharacter() { } return $this->armory->aDB->selectRow(" SELECT - `armory_login_characters`.`guid`, - `armory_login_characters`.`name`, - `armory_login_characters`.`race`, - `armory_login_characters`.`realm_id`, - `armory_realm_data`.`name` AS `realmName` - FROM `ARMORYDBPREFIX_login_characters` AS `armory_login_characters` - LEFT JOIN `armory_realm_data` AS `armory_realm_data` ON `armory_realm_data`.`id`=`armory_login_characters`.`realm_id` - WHERE `armory_login_characters`.`account`=%d AND `armory_login_characters`.`selected`=1 LIMIT 1 + `ARMORYDBPREFIX_login_characters`.`guid`, + `ARMORYDBPREFIX_login_characters`.`name`, + `ARMORYDBPREFIX_login_characters`.`race`, + `ARMORYDBPREFIX_login_characters`.`realm_id`, + `ARMORYDBPREFIX_realm_data`.`name` AS `realmName` + FROM `ARMORYDBPREFIX_login_characters` AS `ARMORYDBPREFIX_login_characters` + LEFT JOIN `ARMORYDBPREFIX_realm_data` AS `ARMORYDBPREFIX_realm_data` ON `ARMORYDBPREFIX_realm_data`.`id`=`ARMORYDBPREFIX_login_characters`.`realm_id` + WHERE `ARMORYDBPREFIX_login_characters`.`account`=%d AND `ARMORYDBPREFIX_login_characters`.`selected`=1 LIMIT 1 ", $_SESSION['accountId']); } @@ -450,7 +450,7 @@ public function AddBookmark($name, $realmName) { return false; } $char_data['realmUrl'] = sprintf('r=%s&cn=%s', urlencode($realmName), urlencode($name)); - $this->armory->aDB->query("INSERT IGNORE INTO `armory_bookmarks` VALUES (%d, '%s', %d, %d, '%s', '%s')", $_SESSION['accountId'], $char_data['name'], $char_data['classId'], $char_data['level'], $realmName, $char_data['realmUrl']); + $this->armory->aDB->query("INSERT IGNORE INTO `ARMORYDBPREFIX_bookmarks` VALUES (%d, '%s', %d, %d, '%s', '%s')", $_SESSION['accountId'], $char_data['name'], $char_data['classId'], $char_data['level'], $realmName, $char_data['realmUrl']); return true; } @@ -686,7 +686,7 @@ public function GetRealmFirsts() { 1419, 1420, 1421, 1422, 1423, 1424, 1425, 1426, 1427, 1463, 3259, 456, 1400, 1402, 3117, 4078, 4576 ) - ORDER BY `character_achievement`.`date` DESC"); // 3.3.3a IDs + ORDER BY `character_achievement`.`date` DESC"); // 4.0.3 IDs if(!$achievements_data) { $this->armory->Log()->writeLog('%s : unable to get data from DB for achievement firsts (theres no completed achievement firsts?)', __METHOD__); return false; @@ -1416,7 +1416,7 @@ public function CheckConfigRealmData() { foreach($this->armory->realmData as $myRealm) { $tmpData = $this->armory->aDB->selectRow("SELECT `id`, `name`, `type` FROM `ARMORYDBPREFIX_realm_data` WHERE `name`='%s' LIMIT 1", $myRealm['name']); if((!$tmpData || !is_array($tmpData)) || ($tmpData['id'] != $myRealm['id'] || $tmpData['name'] != $myRealm['name'] || $tmpData['type'] == UNK_SERVER)) { - $replace = $this->armory->aDB->query("REPLACE INTO `armory_realm_data` (`id`, `name`, `type`) VALUES (%d, '%s', %d)", $myRealm['id'], $myRealm['name'], self::GetServerTypeByString($myRealm['type'])); + $replace = $this->armory->aDB->query("REPLACE INTO `ARMORYDBPREFIX_realm_data` (`id`, `name`, `type`) VALUES (%d, '%s', %d)", $myRealm['id'], $myRealm['name'], self::GetServerTypeByString($myRealm['type'])); if($replace) { $this->armory->Log()->writeLog('%s : realm data for realm "%s" was successfully added to `armory_realm_data` table.', __METHOD__, $myRealm['name']); } @@ -1829,5 +1829,59 @@ public function GetAllowableWeaponTypesForClass($class, $search = false) { } return $allowable_weapon_types; } + + public function CreateNewSession() { + if(isset($_SESSION['armory_sid']) && $this->IsCorrectSession()) { + return true; + } + // Create new + $session_id = $this->GetNextSessionId(); + $session_hash = md5($_SERVER['REMOTE_ADDR'] . ':' . $session_id); + $login_timestamp = time(); + $is_admin = $this->IsUserAdmin(); + // Add + $this->armory->aDB->query("INSERT INTO `ARMORYDBPREFIX_session` (`sid`, `shash`, `ip`, `logintstamp`, `active`, `is_admin`) VALUES ('%s', '%s', %d, 1, %d)", $session_id, $session_hash, $_SERVER['REMOTE_ADDR'], $login_timestamp, (int) $is_admin); + $_SESSION['armory_shash'] = $session_hash; + $_SESSION['armory_sid'] = $session_id; + } + + public function UpdateSession() { + if(isset($_SESSION['armory_sid']) && $this->IsCorrectSession()) { + return $this->armory->aDB->query("UPDATE `ARMORYDBPREFIX_session` SET `active` = 1 WHERE `sid` = %d", $_SESSION['armory_sid']); + } + return true; + } + + public function GetSessionsCount() { + // Drop old sessions before calculations + $this->armory->aDB->query("DELETE FROM `ARMORYDBPREFIX_session` WHERE `logintstamp` >= %d", ((60 * 15) + time())); + return $this->armory->aDB->selectCell("SELECT COUNT(*) FROM `ARMORYDBPREFIX_session` WHERE `active` = %d AND `is_admin` = 0", 1); + } + + public function GetNextSessionId() { + return $this->armory->aDB->selectCell("SELECT MAX(`sid`) FROM `ARMORYDBPREFIX_session`") + 1; + } + + public function IsCorrectSession() { + if(!isset($_SESSION['armory_sid']) && !isset($_SESSION['armory_shash'])) { + return false; + } + return (bool) $this->armory->aDB->selectCell("SELECT `active` FROM `ARMORYDBPREFIX_session` WHERE `sid` = %d AND `shash` = '%s' AND `ip` = '%s'", $_SESSION['armory_sid'], $_SESSION['armory_shash'], $_SERVER['REMOTE_ADDR']); + } + + private function IsUserAdmin() { + if(!isset($_SESSION['accountId'])) { + return false; + } + $gmLevel = $this->armory->rDB->selectCell("SELECT `gmlevel` FROM `account` WHERE `id` = %d LIMIT 1", $_SESSION['accountId']); + if(!$gmLevel) { + // trinity? + $gmLevel = $this->armory->rDB->selectCell("SELECT `gmlevel` FROM `account_access` WHERE `id` = %d LIMIT 1", $_SESSION['accountId']); + } + if($gmLevel >= 1) { + return true; + } + return false; + } } ?> \ No newline at end of file diff --git a/includes/revision_nr.php b/includes/revision_nr.php index feb682c85..56263aecf 100644 --- a/includes/revision_nr.php +++ b/includes/revision_nr.php @@ -1,5 +1,5 @@ \ No newline at end of file