Exemplo n.º 1
0
 /**
  * Count all arena teams (by type) in all available realms.
  * @category Arenateams class
  * @access   public
  * @param    int $type
  * @return   int
  **/
 public function CountArenaTeams($type)
 {
     $summary = 0;
     foreach ($this->armory->realmData as $realm_info) {
         $db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], $this->armory->Log());
         $current_count = $db->selectCell("SELECT COUNT(`arenateamid`) FROM `arena_team` WHERE `type`=%d", $type);
         $summary = $summary + $current_count;
     }
     return $summary;
 }
Exemplo n.º 2
0
 public function PerformCharactersSearch($num = false)
 {
     if (!$this->searchQuery) {
         $this->armory->Log()->writeLog('%s : searchQuery not defined', __METHOD__);
         return false;
     }
     $currentTimeStamp = time();
     $results = array();
     // Full results
     $current_realm = array();
     $count_results = 0;
     // All realms results
     $count_results_currrent_realm = 0;
     // Current realm results
     $db = null;
     // Temporary handler
     $countRealmData = count($this->armory->realmData);
     if ($num == true) {
         foreach ($this->armory->realmData as $realm_info) {
             $count_results_currrent_realm = 0;
             $db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], $this->armory->Log());
             $characters_data[] = $db->select("SELECT `guid`, `level`, `account` FROM `characters` WHERE `name`='%s' AND `level` >= %d LIMIT 200", $this->searchQuery, $this->armory->armoryconfig['minlevel']);
         }
         for ($ii = 0; $ii < $countRealmData; $ii++) {
             $count_result_chars = count($characters_data[$ii]);
             for ($i = 0; $i < $count_result_chars; $i++) {
                 if (isset($characters_data[$ii][$i]) && self::IsCharacterAllowedForSearch($characters_data[$ii][$i]['guid'], $characters_data[$ii][$i]['level'], $characters_data[$ii][$i]['account'])) {
                     $count_results++;
                 }
             }
         }
         return $count_results;
     }
     $accounts_cache = array();
     // For relevance calculation
     foreach ($this->armory->realmData as $realm_info) {
         $db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], $this->armory->Log());
         if (!$db) {
             continue;
         }
         $current_realm = $db->select("SELECT `guid`, `name`, `class` AS `classId`, `gender` AS `genderId`, `race` AS `raceId`, `level`, `account` FROM `characters` WHERE `name` = '%s'", $this->searchQuery);
         if (!$current_realm) {
             continue;
         }
         $count_current_realm = count($current_realm);
         foreach ($current_realm as $realm) {
             if (!self::IsCharacterAllowedForSearch($realm['guid'], $realm['level'], $realm['account'])) {
                 continue;
             }
             if ($realm['guildId'] = $db->selectCell("SELECT `guildid` FROM `guild_member` WHERE `guid`=%d", $realm['guid'])) {
                 $realm['guild'] = $db->selectCell("SELECT `name` FROM `guild` WHERE `guildid`=%d", $realm['guildId']);
                 $realm['guildUrl'] = sprintf('r=%s&gn=%s', urlencode($realm_info['name']), urlencode($realm['guild']));
             }
             $realm['url'] = sprintf('r=%s&cn=%s', urlencode($realm_info['name']), urlencode($realm['name']));
             $realm['battleGroup'] = $this->armory->armoryconfig['defaultBGName'];
             $realm['battleGroupId'] = 1;
             $realm['class'] = $this->armory->aDB->selectCell("SELECT `name_%s` FROM `ARMORYDBPREFIX_classes` WHERE `id`=%d", $this->armory->GetLocale(), $realm['classId']);
             $realm['race'] = $this->armory->aDB->selectCell("SELECT `name_%s` FROM `ARMORYDBPREFIX_races` WHERE `id`=%d", $this->armory->GetLocale(), $realm['raceId']);
             $realm['realm'] = $realm_info['name'];
             $realm['factionId'] = Utils::GetFactionId($realm['raceId']);
             $realm['searchRank'] = 1;
             //???
             /* Calculate relevance */
             $realm['relevance'] = 100;
             // Relevance by last login date will check `realmd`.`account`.`last_login` timestamp
             // First of all - check character level
             $temp_value = $realm['level'];
             if ($temp_value > 70 && $temp_value < PLAYER_MAX_LEVEL) {
                 $realm['relevance'] -= 20;
             } elseif ($temp_value > 60 && $temp_value < 70) {
                 $realm['relevance'] -= 25;
             } elseif ($temp_value > 50 && $temp_value < 60) {
                 $realm['relevance'] -= 30;
             } elseif ($temp_value > 40 && $temp_value < 50) {
                 $realm['relevance'] -= 35;
             } elseif ($temp_value > 30 && $temp_value < 40) {
                 $realm['relevance'] -= 40;
             } elseif ($temp_value > 20 && $temp_value < 30) {
                 $realm['relevance'] -= 45;
             } elseif ($temp_value < 20) {
                 $realm['relevance'] -= 50;
                 // characters with level < 20 have 50% relevance and other reasons can't change this value
                 unset($realm['account'], $realm['guid']);
                 $results[] = $realm;
                 continue;
             }
             // Check last login date. If it's more than 2 days, decrease relevance by 4 for every day
             if (!isset($accounts_cache[$realm['account']])) {
                 $lastLogin = $this->armory->rDB->selectCell("SELECT `last_login` FROM `account` WHERE `id`=%d", $realm['account']);
                 $accounts_cache[$realm['account']] = $lastLogin;
             } else {
                 $lastLogin = $accounts_cache[$realm['account']];
             }
             $lastLoginTimestamp = strtotime($lastLogin);
             $diff = $currentTimeStamp - $lastLoginTimestamp;
             if ($lastLogin && $diff > 0) {
                 // 1 day is 86400 seconds
                 $totalDays = round($diff / 86400);
                 if ($totalDays > 2) {
                     $decreaseRelevanceByLogin = $totalDays * 4;
                     $realm['relevance'] -= $decreaseRelevanceByLogin;
                 }
             }
             // Relevance for characters can't be less than 50
             if ($realm['relevance'] < 50) {
                 $realm['relevance'] = 50;
             }
             // Relevance can't be more than 100
             if ($realm['relevance'] > 100) {
                 $realm['relevance'] = 100;
             }
             unset($realm['account'], $realm['guid']);
             $results[] = $realm;
         }
     }
     if ($results) {
         return $results;
     }
     return false;
 }
Exemplo n.º 3
0
if (isset($_GET)) {
    $totalCharsCount = $utils->CountSelectedCharacters();
    $utils->DropAllSelectedCharacters(true);
    for ($i = 1; $i < MAX_SELECTED_CHARACTERS_COUNT + 1; $i++) {
        if (isset($_GET['cn' . $i]) && isset($_GET['r' . $i])) {
            $realmName = urldecode($_GET['r' . $i]);
            $realm_id = $utils->GetRealmIdByName($realmName);
            if (!$realm_id) {
                $armory->Log()->writeLog('character-select-submit : realm %s not found in database!', $realmName);
                continue;
            } elseif (!isset($armory->realmData[$realm_id])) {
                $armory->Log()->writeLog('character-select-submit : connection data to realm %s (ID: %d) not found!', $realmName, $realm_id);
                continue;
            }
            $realm_info = $armory->realmData[$realm_id];
            $db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], $armory->Log());
            if (!$db) {
                // Error message will appear in ArmoryDatabaseHandler::ArmoryDatabaseHandler();
                continue;
            }
            $char_data = $db->selectRow("SELECT `guid`, `name`, `class`, `race`, `gender`, `level`, `account` FROM `characters` WHERE `name`='%s' AND `account`=%d LIMIT 1", $utils->escape($_GET['cn' . $i]), $_SESSION['accountId']);
            if (!$char_data) {
                $armory->Log()->writeLog('character-select-submit : unable to get character data from DB (name: %s, accountId: %d)', $_GET['cn' . $i], $_SESSION['accountId']);
                continue;
            }
            $char_data['realm_id'] = $realm_id;
            if (isset($_GET['cn1']) && $i == 1) {
                $char_data['selected'] = 1;
            } else {
                $char_data['selected'] = $i;
            }
Exemplo n.º 4
0
 /**
  * Creates new bookmark
  * @category Utils class
  * @access   public
  * @param    string $name
  * @param    string $realmName
  * @return   bool
  **/
 public function AddBookmark($name, $realmName)
 {
     if (!isset($_SESSION['accountId'])) {
         return false;
     }
     if ($this->GetBookmarksCount() >= 60) {
         // Unable to store more than 60 bookmarks for single account
         return false;
     }
     $realm_id = Armory::FindRealm($realmName);
     if (!$realm) {
         return false;
     } elseif (!isset(Armory::$realmData[$realm_id])) {
         return false;
     }
     $realm_info = Armory::$realmData[$realm_id];
     $db = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters']);
     if (!$db) {
         return false;
     }
     $char_data = $db->selectRow("SELECT `name`, `class` AS `classId`, `level` FROM `characters` WHERE `name`='%s' LIMIT 1", $name);
     if (!$char_data) {
         return false;
     }
     $char_data['realmUrl'] = sprintf('r=%s&cn=%s', urlencode($realmName), urlencode($name));
     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;
 }
Exemplo n.º 5
0
 /**
  * Returns realm type for provided $realm_id.
  * Warning: if detection fails, realm with provided ID will be deleted from allowed realms!
  * @category Utils class
  * @access   public
  * @param    int $realm_id
  * @return   mixed
  **/
 public function GetRealmType($realm_id)
 {
     if (!isset($this->armory->realmData[$realm_id]) || !isset($this->armory->realmData[$realm_id]['name_world'])) {
         $this->armory->Log()->writeError('%s : unable to detect realm type: world database config not found', __METHOD__);
         return false;
     }
     $realm_info = $this->armory->realmData[$realm_id];
     $db = new ArmoryDatabaseHandler($realm_info['host_world'], $realm_info['user_world'], $realm_info['pass_world'], $realm_info['name_world'], $realm_info['charset_world'], $this->armory->Log());
     if (!$db->TestLink()) {
         $this->armory->Log()->writeError('%s : unable to connect to MySQL database ("%s":"%s":"%s":"%s")', __METHOD__, $realm_info['host_world'], str_replace(substr($realm_info['user_world'], 2, 3), '***', $realm_info['user_world']), str_replace(substr($realm_info['pass_world'], 2, 3), '***', $realm_info['pass_world']), $realm_info['name_world']);
         return false;
     }
     if ($tmp = $db->selectCell("SELECT 1 FROM `mangos_string` LIMIT 1")) {
         return 'mangos';
     } elseif ($tmp = $db->selectCell("SELECT 1 FROM `trinity_string` LIMIT 1")) {
         return 'trinity';
     }
     $this->armory->Log()->writeError('%s : unable to detect realm type, realm info with ID #%d was removed from allowed realms', __METHOD__, $realm_id);
     unset($realm_id, $realm_info, $this->armory->realmData[$realm_id], $db);
     return false;
 }