/** * Loads character data * @param string $name * @param int $realm_id * @param boolean $full = true * @param boolean $initialBuild = true * @return boolean **/ public static function LoadCharacter($name, $realm_id, $full = true, $initialBuild = true) { // Data checks if (!is_string($name) || $name == null) { WoW_Log::WriteError('%s : name must be a string (%s given.)!', __METHOD__, gettype($name)); return 1; } if (!$realm_id || $realm_id == 0) { WoW_Log::WriteError('%s : realm ID must be > 0!', __METHOD__); return 1; } if (!isset(WoWConfig::$Realms[$realm_id])) { WoW_Log::WriteError('%s : unable to find realm with ID #%d. Check your configs.', __METHOD__, $realm_id); return 1; } // Connect to characters DB DB::ConnectToDB(DB_CHARACTERS, $realm_id, true, false); // Check connection if (!DB::Characters()->TestLink()) { // Message about failed connection will appear from database handler class. return 1; } self::$m_dbHash = DB::Characters()->GetDatabaseInfo('hash'); // BINARY. self::$name = mb_convert_case($name, MB_CASE_TITLE, "UTF-8"); // If $full == true, we need to check `armory_character_stats` table. // Load character fields. if (!self::LoadCharacterFieldsFromDB()) { return 1; } // Some checks before script will load `data` field. if (!self::IsCharacterFitsRequirements()) { return 2; } // Set Realm's variables self::$realmID = $realm_id; self::$realmName = WoWConfig::$Realms[$realm_id]['name']; self::$m_server = WoWConfig::$Realms[$realm_id]['type']; // Convert equipmentCache field from string to array. self::HandleEquipmentCacheInfo(); if ($full) { if (!self::IsCharacterDataAvailable()) { WoW_Log::WriteError('%s : data for character %s was not found in `armory_character_stats` table! Please, make sure that you have patched core and updated characters DB with provided SQL update.', __METHOD__, self::$name); return false; } // Data exists, load it. self::$data = DB::Characters()->selectCell("SELECT `data` FROM `armory_character_stats` WHERE `guid`=%d LIMIT 1", self::$guid); // Convert string to array self::HandleDataField(); // Last update date self::$last_update = DB::Characters()->selectCell("SELECT `save_date` FROM `armory_character_stats` WHERE `guid` = %d LIMIT 1", self::$guid); // Class/race names/keys self::$class_name = WoW_Locale::GetString('character_class_' . self::$class, self::$gender); self::$race_name = WoW_Locale::GetString('character_race_' . self::$race, self::$gender); self::$class_key = Data_Classes::$classes[self::$class]['key']; self::$race_key = Data_Races::$races[self::$race]['key']; WoW_Achievements::Initialize(); // Load Inventory self::LoadInventory(true); self::CalculateAverageItemLevel(); // Load Professions self::LoadProfessions(); // Load Feeds self::LoadFeed(); self::HandleFeed(); } // Load title data if (self::$chosenTitle > 0) { self::HandleChosenTitleInfo(); } // Set power type self::SetPowerType(); // Finish if ($initialBuild) { WoW_Log::WriteLog('%s : character %s (GUID: %d) was loaded without problems.', __METHOD__, self::$name, self::$guid); } return 3; }