Skip to content

Commit

Permalink
[410] Internal database handler is required for Achievements class (a…
Browse files Browse the repository at this point in the history
…chievement comparison between characters on different realms becomes bugged without it)
  • Loading branch information
Shadez committed Oct 24, 2010
1 parent 45c397e commit 8bcbeec
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
25 changes: 14 additions & 11 deletions includes/classes/class.achievements.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package World of Warcraft Armory
* @version Release Candidate 1
* @revision 392
* @revision 410
* @copyright (c) 2009-2010 Shadez
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
Expand Down Expand Up @@ -58,6 +58,8 @@
**/
private $m_count;

private $db = null;

/**
* Assign $armory variable
**/
Expand All @@ -76,7 +78,8 @@ public function Achievements($armory) {
* @param bool $check = true
* @return bool
**/
public function InitAchievements($player_guid, $check = true) {
public function InitAchievements($player_guid, $db, $check = true) {
$this->db = $db;
if($player_guid <= 0) {
$this->armory->Log()->writeError('%s : wrong player guid (%d), ignore.', __METHOD__, $player_guid);
return false;
Expand All @@ -86,7 +89,7 @@ public function InitAchievements($player_guid, $check = true) {
$this->achId = 0;
$this->m_count = 0;
$this->pts = 0;
if($check == true && !$this->armory->cDB->selectCell("SELECT 1 FROM `characters` WHERE `guid`=%d LIMIT 1", $player_guid)) {
if($check == true && !$this->db->selectCell("SELECT 1 FROM `characters` WHERE `guid`=%d LIMIT 1", $player_guid)) {
$this->armory->Log()->writeError('%s : player with guid %d was not found in `characters` table!', __METHOD__, $player_guid);
return false;
}
Expand Down Expand Up @@ -127,7 +130,7 @@ public function CalculateAchievementPoints() {
$this->armory->Log()->writeError('%s : player guid not defined', __METHOD__);
return false;
}
$achievement_ids = $this->armory->cDB->select("SELECT `achievement` FROM `character_achievement` WHERE `guid`=%d", $this->guid);
$achievement_ids = $this->db->select("SELECT `achievement` FROM `character_achievement` WHERE `guid`=%d", $this->guid);
if(!$achievement_ids) {
$this->armory->Log()->writeError('%s : unable to find any completed achievement for player %d', __METHOD__, $this->guid);
return false;
Expand All @@ -151,7 +154,7 @@ public function CountCharacterAchievements() {
$this->armory->Log()->writeError('%s : player guid not defined', __METHOD__);
return false;
}
$this->m_count = $this->armory->cDB->selectCell("SELECT COUNT(`achievement`) FROM `character_achievement` WHERE `guid`=%d", $this->guid);
$this->m_count = $this->db->selectCell("SELECT COUNT(`achievement`) FROM `character_achievement` WHERE `guid`=%d", $this->guid);
return $this->m_count;
}

Expand Down Expand Up @@ -231,7 +234,7 @@ public function GetSummaryAchievementData($category) {
$a_ids[] = $_tId['id'];
}
}
$achievement_ids = $this->armory->cDB->select("SELECT `achievement` FROM `character_achievement` WHERE `guid`=%d AND `achievement` IN (%s)", $this->guid, $a_ids);
$achievement_ids = $this->db->select("SELECT `achievement` FROM `character_achievement` WHERE `guid`=%d AND `achievement` IN (%s)", $this->guid, $a_ids);
if(!$achievement_ids) {
$achievement_data['earned'] = 0;
$achievement_data['points'] = 0;
Expand Down Expand Up @@ -268,7 +271,7 @@ public function GetLastAchievements() {
$this->armory->Log()->writeError('%s : player guid not defined', __METHOD__);
return false;
}
$achievements = $this->armory->cDB->select("SELECT `achievement`, `date` FROM `character_achievement` WHERE `guid`=%d ORDER BY `date` DESC LIMIT 5", $this->guid);
$achievements = $this->db->select("SELECT `achievement`, `date` FROM `character_achievement` WHERE `guid`=%d ORDER BY `date` DESC LIMIT 5", $this->guid);
if(!$achievements) {
$this->armory->Log()->writeError('%s : unable to get data from character_achievement (player %d does not have achievements?)', __METHOD__, $this->guid);
return false;
Expand All @@ -295,7 +298,7 @@ public function GetAchievementDate($achId = 0) {
$this->armory->Log()->writeError('%s : not enough data for calculation (guid: %d, achId: %d).', __METHOD__, $this->guid, $achId);
return false;
}
$achievement_date = $this->armory->cDB->selectCell("SELECT `date` FROM `character_achievement` WHERE `achievement`=%d AND `guid`=%d LIMIT 1", $achId, $this->guid);
$achievement_date = $this->db->selectCell("SELECT `date` FROM `character_achievement` WHERE `achievement`=%d AND `guid`=%d LIMIT 1", $achId, $this->guid);
if(!$achievement_date) {
$this->armory->Log()->writeError('%s : unable to find completion date for achievement %d, player %d', __METHOD__, $achId, $this->guid);
return false;
Expand Down Expand Up @@ -400,7 +403,7 @@ public function IsAchievementCompleted($achId) {
$this->armory->Log()->writeError('%s : achievement %d not exists', __METHOD__, $achId);
return false;
}
return $this->armory->cDB->selectCell("SELECT 1 FROM `character_achievement` WHERE `guid`=%d AND `achievement`=%d", $this->guid, $achId);
return $this->db->selectCell("SELECT 1 FROM `character_achievement` WHERE `guid`=%d AND `achievement`=%d", $this->guid, $achId);
}

/**
Expand Down Expand Up @@ -572,7 +575,7 @@ private function GetCriteriaData($criteria_id) {
$this->armory->Log()->writeError('%s : player guid not defined', __METHOD__);
return false;
}
return $this->armory->cDB->selectRow("SELECT * FROM `character_achievement_progress` WHERE `guid`=%d AND `criteria`=%d", $this->guid, $criteria_id);
return $this->db->selectRow("SELECT * FROM `character_achievement_progress` WHERE `guid`=%d AND `criteria`=%d", $this->guid, $criteria_id);
}

/**
Expand Down Expand Up @@ -641,7 +644,7 @@ private function GetCriteriaValue() {
}
$tmp_criteria_value = '--';
foreach($criteria_ids as $criteria) {
$tmp_criteria_value = $this->armory->cDB->selectCell("SELECT `counter` FROM `character_achievement_progress` WHERE `guid`=%d AND `criteria`=%d LIMIT 1", $this->guid, $criteria['id']);
$tmp_criteria_value = $this->db->selectCell("SELECT `counter` FROM `character_achievement_progress` WHERE `guid`=%d AND `criteria`=%d LIMIT 1", $this->guid, $criteria['id']);
if(!$tmp_criteria_value) {
continue;
}
Expand Down
27 changes: 13 additions & 14 deletions includes/classes/class.characters.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package World of Warcraft Armory
* @version Release Candidate 1
* @revision 406
* @revision 410
* @copyright (c) 2009-2010 Shadez
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
Expand Down Expand Up @@ -352,38 +352,35 @@ public function BuildCharacter($name, $realmId = 1, $full = true, $initialBuild
}
// Is character allowed to be displayed in Armory?
$gmLevel = false;
if($this->armory->currentRealmInfo['type'] == 'trinity') {
if($this->m_server == SERVER_TRINITY) {
$gmLevel = $this->armory->rDB->selectCell("SELECT `gmlevel` FROM `account_access` WHERE `id`=%d AND `RealmID` IN (-1, %d)", $player_data['account'], $this->armory->connectionData['id']);
}
elseif($this->armory->currentRealmInfo['type'] == 'mangos') {
$gmLevel = $gmLevel_mangos = $this->armory->rDB->selectCell("SELECT `gmlevel` FROM `account` WHERE `id`=%d LIMIT 1", $player_data['account']);
}
if(!$gmLevel) {
$gmLevel = 0;
elseif($this->m_server == SERVER_MANGOS) {
$gmLevel = $this->armory->rDB->selectCell("SELECT `gmlevel` FROM `account` WHERE `id`=%d LIMIT 1", $player_data['account']);
}
$allowed = ($gmLevel <= $this->armory->armoryconfig['minGmLevelToShow']) ? true : false;
if(!$allowed || $player_data['level'] < $this->armory->armoryconfig['minlevel']) {
$this->armory->Log()->writeLog('%s: Player %d (%s) is not allowed to be displayed in Armory (GM level restriction)!', __METHOD__, $player_data['guid'], $player_data['name']);
$this->armory->Log()->writeLog('%s : Player %d (%s) is not allowed to be displayed in Armory (GM level restriction or have low level)!', __METHOD__, $player_data['guid'], $player_data['name']);
unset($player_data);
return false;
}
// Class/race/faction checks
if($player_data['class'] >= MAX_CLASSES) {
// Unknown class
$this->armory->Log()->writeError('%s: Player %d (%s) have incorrect data in DB: class %d not found.', __METHOD__, $player_data['guid'], $player_data['name'], $player_data['class']);
$this->armory->Log()->writeError('%s : Player %d (%s) have wrong data in DB: class %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
$this->armory->Log()->writeError('%s: Player %d (%s) have incorrect data in DB: race %d not found.', __METHOD__, $player_data['guid'], $player_data['name'], $player_data['race']);
$this->armory->Log()->writeError('%s : Player %d (%s) have wrong data in DB: race %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
$this->armory->Log()->writeError('%s : player %d (%s) have incorrect faction in DB: faction %d not found (race: %d).', __METHOD__, $player_data['guid'], $player_data['name'], $this->faction, $player_data['class']);
$this->armory->Log()->writeError('%s : Player %d (%s) have wrong faction in DB: faction %d was not found (race: %d).', __METHOD__, $player_data['guid'], $player_data['name'], $this->faction, $player_data['class']);
unset($player_data);
return false;
}
Expand Down Expand Up @@ -424,7 +421,7 @@ public function BuildCharacter($name, $realmId = 1, $full = true, $initialBuild
// Initialize achievement manager
if(defined('load_achievements_class') && class_exists('Achievements')) {
$this->m_achievementMgr = new Achievements($this->armory);
$this->m_achievementMgr->InitAchievements($this->guid, true);
$this->m_achievementMgr->InitAchievements($this->guid, $this->db, true);
}
// Everything correct
if($initialBuild == true) {
Expand All @@ -441,7 +438,7 @@ public function BuildCharacter($name, $realmId = 1, $full = true, $initialBuild
**/
private function HandleEquipmentCacheData() {
if(!$this->equipmentCache) {
$this->armory->Log()->writeError('%s : %s::$equipmentCache have `false` value, unable to generate array. Character items would not be shown.', __METHOD__, __METHOD__);
$this->armory->Log()->writeError('%s : %s::$equipmentCache have NULL value, unable to generate array. Character items would not be shown.', __METHOD__, __METHOD__);
return false;
}
$itemscache = explode(' ', $this->equipmentCache);
Expand Down Expand Up @@ -723,7 +720,7 @@ public function GetMoney() {
public function GetAchievementMgr() {
if(!is_object($this->m_achievementMgr)) {
$this->m_achievementMgr = new Achievements($this->armory);
$this->m_achievementMgr->InitAchievements($this->GetGUID(), true);
$this->m_achievementMgr->InitAchievements($this->GetGUID(), $this->db, true);
}
return $this->m_achievementMgr;
}
Expand Down Expand Up @@ -1097,6 +1094,8 @@ public function CalculateCharacterTalents() {
}
}
$talent_data = array('points' => $talent_points);
//print_r($talent_data);
//die;
return $talent_data;
}

Expand Down
6 changes: 3 additions & 3 deletions includes/classes/class.utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package World of Warcraft Armory
* @version Release Candidate 1
* @revision 403
* @revision 410
* @copyright (c) 2009-2010 Shadez
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
Expand Down Expand Up @@ -1392,15 +1392,15 @@ public function IsAchievementsComparison($returnFirstRealmName = false) {
$countR = count($realms);
$countC = count($chars);
if($countC == 1 && $countR == 1) {
// 1 Character, there's nothing to do.
// Only one character, there's nothing to do.
return false;
}
$totalCount = 0;
if($countC == $countR) {
$totalCount = $countC;
}
else {
$this->armory->Log()->writeError('%s : realm and characters count are not equal (realms: %d, chars: %d)!', __METHOD__, $countR, $countC);
$this->armory->Log()->writeError('%s : realms and characters counters are not equal (realms: %d, chars: %d, total: %d)!', __METHOD__, $countR, $countC, $totalCount);
return false;
}
$data = array();
Expand Down
2 changes: 1 addition & 1 deletion includes/revision_nr.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
define('ARMORY_REVISION', 409);
define('ARMORY_REVISION', 410);
define('DB_VERSION', 'armory_r398');
define('CONFIG_VERSION', '0708201001');
?>

0 comments on commit 8bcbeec

Please sign in to comment.