Ejemplo n.º 1
0
 /**
  * fetch info from Armory
  *
  * @return integer
  */
 public function Armory_getmember()
 {
     global $phpEx, $phpbb_root_path, $user;
     $game = new \bbdkp\controller\games\Game();
     $game->game_id = $this->game_id;
     $game->Get();
     if ($this->game_id != 'wow') {
         $this->member_portrait_url = '';
         $this->deactivate_reason = '';
         return -1;
     }
     if ($game->getArmoryEnabled() == 0) {
         return -1;
     }
     //Initialising the class
     if (!class_exists('\\bbdkp\\controller\\wowapi\\BattleNet')) {
         require $phpbb_root_path . 'includes/bbdkp/controller/wowapi/BattleNet.' . $phpEx;
     }
     /**
      * available extra fields :
      * 'guild','stats','talents','items','reputation','titles','professions','appearance',
      * 'companions','mounts','pets','achievements','progression','pvp','quests'
      */
     $api = new \bbdkp\controller\wowapi\BattleNet('character', $this->member_region, $game->getApikey(), $game->getApilocale(), $game->getPrivkey());
     $params = array('guild', 'titles', 'talents');
     $data = $api->Character->getCharacter($this->member_name, $this->member_realm, $params);
     unset($api);
     // if $data == false then there is no character data, so
     if (!isset($data) || !isset($data['response'])) {
         $this->armoryresult = 'KO';
         $log_action = array('header' => 'L_ERROR_ARMORY_DOWN', 'L_UPDATED_BY' => $user->data['username'], 'L_GUILD' => $this->name . '-' . $this->realm);
         $this->log_insert(array('log_type' => $log_action['header'], 'log_action' => $log_action, 'log_result' => 'L_ERROR'));
         return -1;
     }
     $data = $data['response'];
     //if we get error code
     if (isset($data['code'])) {
         if ($data['code'] == '403') {
             // even if we have active API account, it may be that Blizzard account is inactive
             $this->armoryresult = 'KO';
             $log_action = array('header' => 'L_ERROR_BATTLENET_ACCOUNT_INACTIVE', 'L_UPDATED_BY' => $user->data['username'], 'L_GUILD' => $this->name . '-' . $this->realm);
             $this->log_insert(array('log_type' => $log_action['header'], 'log_action' => $log_action, 'log_result' => 'L_ERROR'));
             return -1;
         }
     }
     if (isset($data['reason'])) {
         //not found in armory
         $this->member_status = 0;
         $this->deactivate_reason = 'DEACTIVATED_BY_API';
         return -1;
     }
     $this->member_level = isset($data['level']) ? $data['level'] : $this->member_level;
     $this->member_race_id = isset($data['race']) ? $data['race'] : $this->member_race_id;
     $this->member_class_id = isset($data['class']) ? $data['class'] : $this->member_class_id;
     /*
      * select the build
      */
     $buildid = 0;
     if (isset($data['talents'][0]) && isset($data['talents'][1])) {
         if (isset($data['talents'][0]['selected'])) {
             $buildid = 0;
         } elseif (isset($data['talents'][1]['selected'])) {
             $buildid = 1;
         }
     } elseif (isset($data['talents'][0])) {
         $buildid = 0;
     } elseif (isset($data['talents'][1])) {
         $buildid = 1;
     }
     $conversion_array = array('DPS' => 0, 'HEALING' => 1, 'TANK' => 2);
     $role = isset($data['talents'][$buildid]['spec']['role']) ? $data['talents'][$buildid]['spec']['role'] : 'DPS';
     if (isset($role) && in_array($role, $conversion_array)) {
         $this->member_role = $conversion_array[$role];
     }
     $this->member_gender_id = isset($data['gender']) ? $data['gender'] : $this->member_gender_id;
     $this->member_achiev = isset($data['achievementPoints']) ? $data['achievementPoints'] : $this->member_achiev;
     if (isset($data['name'])) {
         $this->member_armory_url = sprintf('http://%s.battle.net/wow/en/', $this->member_region) . 'character/' . $this->member_realm . '/' . $data['name'] . '/simple';
     }
     if (isset($data['thumbnail'])) {
         $this->member_portrait_url = sprintf('http://%s.battle.net/static-render/%s/', $this->member_region, $this->member_region) . $data['thumbnail'];
     }
     if (isset($data['realm'])) {
         $this->member_realm = $data['realm'];
     }
     if (isset($data['guild'])) {
         $found = false;
         foreach ($this->guildlist as $guild) {
             if (strtolower($guild['name']) == strtolower($data['guild']['name'])) {
                 $this->member_guild_id = $guild['id'];
                 $this->member_guild_name = $guild['name'];
                 $found = true;
                 break;
             }
         }
         if ($found == false) {
             $this->member_guild_id = 0;
             $this->member_rank_id = 99;
         }
     } else {
         $this->member_guild_id = 0;
         $this->member_rank_id = 99;
     }
     if (isset($data['titles'])) {
         foreach ($data['titles'] as $key => $title) {
             if (isset($title['selected'])) {
                 $this->member_title = $title['name'];
                 break;
             }
         }
     }
     //if the last logged-in date is > 3 months ago then disable the account
     if (isset($data['lastModified'])) {
         $latest = $data['lastModified'];
         $diff = \round(\abs(\time() - $latest / 1000) / 60 / 60 / 24, 2);
         if ($diff > 90 && $this->member_status == 1) {
             $this->member_status = 0;
             $this->deactivate_reason = 'DEACTIVATED_BY_API';
         }
         if ($diff < 90 && $this->member_status == 0 && $this->deactivate_reason == 'DEACTIVATED_BY_API') {
             $this->member_status = 1;
             $this->deactivate_reason = '';
         }
     }
     return 1;
 }
Ejemplo n.º 2
0
 /**
  * get api info
  *
  * @param $params
  * @return bool
  */
 public function GetApiInfo($params)
 {
     global $user;
     $data = 0;
     if ($this->game_id != 'wow') {
         return false;
     }
     if ($this->guildid == "0") {
         return false;
     }
     $game = new \bbdkp\controller\games\Game();
     $game->game_id = $this->game_id;
     $game->Get();
     //is both game and guild armory-enabled and has api key and locale ?
     if ($game->getArmoryEnabled() == 1 && $this->armory_enabled == 1 && trim($game->getApikey()) != '' && trim($game->getApilocale()) != '') {
         //available extra fields : 'members', 'achievements','news'
         $api = new \bbdkp\controller\wowapi\BattleNet('guild', $this->region, $game->getApikey(), $game->getApilocale(), $game->getPrivkey());
         $data = $api->Guild->getGuild($this->name, $this->realm, $params);
         $data = $data['response'];
         unset($api);
         if (!isset($data)) {
             $this->armoryresult = 'KO';
             $log_action = array('header' => 'L_ERROR_ARMORY_DOWN', 'L_UPDATED_BY' => $user->data['username'], 'L_GUILD' => $this->name . '-' . $this->realm);
             $this->log_insert(array('log_type' => $log_action['header'], 'log_action' => $log_action, 'log_result' => 'L_ERROR'));
             return false;
         }
         //if we get error code
         if (isset($data['code'])) {
             if ($data['code'] == '403') {
                 // even if we have active API account, it may be that Blizzard account is inactive
                 $this->armoryresult = 'KO';
                 $log_action = array('header' => 'L_ERROR_BATTLENET_ACCOUNT_INACTIVE', 'L_UPDATED_BY' => $user->data['username'], 'L_GUILD' => $this->name . '-' . $this->realm);
                 $this->log_insert(array('log_type' => $log_action['header'], 'log_action' => $log_action, 'log_result' => 'L_ERROR'));
                 return false;
             }
         }
         $this->armoryresult = 'OK';
     } else {
         $this->armoryresult = 'KO';
     }
     return $data;
 }
Ejemplo n.º 3
0
 /**
  * list the ranks for this guild
  * @param $updateguild
  */
 private function BuildTemplateEditGuildRanks($updateguild)
 {
     global $phpEx, $template, $db, $phpbb_admin_path, $user;
     // everything from rank 90 is readonly
     $listranks = new \bbdkp\controller\guilds\Ranks($updateguild->guildid);
     $listranks->game_id = $updateguild->game_id;
     $result = $listranks->listranks();
     while ($row = $db->sql_fetchrow($result)) {
         $prefix = $row['rank_prefix'];
         $suffix = $row['rank_suffix'];
         $template->assign_block_vars('ranks_row', array('RANK_ID' => $row['rank_id'], 'RANK_NAME' => $row['rank_name'], 'RANK_PREFIX' => $prefix, 'RANK_SUFFIX' => $suffix, 'HIDE_CHECKED' => $row['rank_hide'] == 1 ? 'checked="checked"' : '', 'S_READONLY' => $row['rank_id'] >= 90 ? true : false, 'U_DELETE_RANK' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_guild&amp;mode=editguild&amp;deleterank=1&amp;ranktodelete=" . $row['rank_id'] . "&amp;" . URI_GUILD . "=" . $updateguild->guildid)));
     }
     $db->sql_freeresult($result);
     $game = new \bbdkp\controller\games\Game();
     $game->game_id = $updateguild->game_id;
     $game->Get();
     $template->assign_vars(array('S_GUILDLESS' => $updateguild->guildid == 0 ? true : false, 'F_ENABLGAMEEARMORY' => $game->getArmoryEnabled(), 'F_ENABLEARMORY' => $updateguild->armory_enabled, 'GAME_ID' => $updateguild->game_id, 'GUILDID' => $updateguild->guildid, 'GUILD_NAME' => $updateguild->name, 'U_ADD_RANK' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_guild&amp;mode=editguild&amp;addrank=1&amp;guild=" . $updateguild->guildid), 'L_TITLE' => $this->url_id < 0 ? $user->lang['ACP_ADDGUILD'] : $user->lang['ACP_EDITGUILD'], 'L_EXPLAIN' => $this->url_id < 0 ? $user->lang['ACP_ADDGUILD_EXPLAIN'] : $user->lang['ACP_EDITGUILD_EXPLAIN'], 'L_ADD_GUILD_TITLE' => $this->url_id < 0 ? $user->lang['ADD_GUILD'] : $user->lang['EDIT_GUILD'], 'MSG_NAME_EMPTY' => $user->lang['FV_REQUIRED_NAME'], 'EMBLEM' => $updateguild->emblempath, 'EMBLEMFILE' => basename($updateguild->emblempath), 'S_ADD' => $this->url_id < 0 ? true : false, 'U_EDIT_GUILD' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_guild&amp;mode=editguild&amp;action=editguild&amp;" . URI_GUILD . '=' . $updateguild->guildid), 'U_EDIT_GUILDRANKS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_guild&amp;mode=editguild&amp;action=guildranks&amp;" . URI_GUILD . '=' . $updateguild->guildid), 'U_EDIT_GUILDRECRUITMENT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_guild&amp;mode=editguild&amp;action=guildrecruitment&amp;" . URI_GUILD . '=' . $updateguild->guildid)));
     $form_key = 'editguildranks';
     add_form_key($form_key);
     $this->page_title = $user->lang['ACP_EDITGUILD'];
 }