public function Get_Player_Loadout($db_id) { $web_prefs = PlayerAPIController::Get_Player_Webprefs($db_id); if ($web_prefs['show_loadout'] != 1) { return Response::json(array('status' => 'error', 'error' => 'Player is not allowing loadout viewing.')); } else { if (Cache::has($this->class_name . "_" . $db_id . "_Loadout")) { //pull from cache $loadout = Cache::get($this->class_name . "_" . $db_id . "_Loadout"); } else { $loadout = Loadout::where('db_id', '=', $db_id)->first(array('entry')); if (!$loadout) { return Response::json(array('status' => 'error', 'error' => 'Player does not an loadout database entry.')); } else { $loadout = gzuncompress($loadout['entry']); $loadout = json_decode($loadout, true); //clean out the player db_id for ($i = 0; $i < count($loadout); $i++) { unset($loadout[$i]->Player_ID); } } } return json_encode($loadout); } }
public function get_single_battleframe($name = NULL, $frame_name = NULL) { //searching by name, null name = no buenos if ($name == NULL || $frame_name == NULL) { return Response::error('404'); } else { $input_name = urldecode($name); } $valid_frame_name = array('assault', 'firecat', 'tigerclaw', 'biotech', 'recluse', 'dragonfly', 'dreadnaught', 'rhino', 'mammoth', 'engineer', 'electron', 'bastion', 'recon', 'raptor', 'nighthawk', 'arsenal'); if (!in_array($frame_name, $valid_frame_name)) { return Response::error('404'); } //Look up the player, latest to account for deletes with the same name $player = Player::where('name', '=', $input_name)->order_by('created_at', 'DESC')->first(); //no player found, why not search? if (!$player) { return Response::error('404'); } //escape for output in title $playerName = htmlentities($player->name); //Player website preferences $web_prefs = WebsitePref::where('db_id', '=', $player->db_id)->first(); if (isset($web_prefs->attributes)) { $web_prefs = $web_prefs->attributes; } //loadouts /* Mappings: $loadout->Gear[$i] = Currently equipped items array $loadout->Gear[$i]->slot_index $loadout->Gear[$i]->info->durability->pool $loadout->Gear[$i]->info->durability->current $loadout->Gear[$i]->info->attribute_modifiers[$k] = array of custom attributes for this item $loadout->Gear[$i]->info->quality = The quality of the crafted item $loadout->Gear[$i]->info->creator_guid = the creators unique player ID $loadout->Gear[$i]->info->item_sdb_id = The root item this was crafted from $loadout->Weapons[$i] = Currently equiped weapons array $loadout->Weapons[$i]->info->durability->pool $loadout->Weapons[$i]->info->durability->current $loadout->Weapons[$i]->info->attribute_modifiers[$k] $loadout->Weapons[$i]->info->quality $loadout->Weapons[$i]->info->creator_guid $loadout->Weapons[$i]->info->item_sdb_id $loadout->Weapons[$i]->allocated_power $loadout->Weapons[$i]->slot_index = Weapon slot, 0 is main hand, 1 is alt weapon */ /* Attribute modifiers mapping: 5 = Jet Energy Recharge 6 = health 7 = health regen 12 = Run Speed 29 = weapon splash radius 35 = Energy (for jetting) 37 = Jump Height 950 = Max durability pool 951 = Mass (unmodified - YOU MUST take the abs of this to get it to display correctly!) 952 = Power (unmodified - YOU MUST take the abs of this to get it to display correctly!) 953 = CPU (unmodified - YOU MUST take the abs of this to get it to display correctly!) 956 = clip size 954 = damage per round 977 = Damage 978 = Debuff Duration 1121= Air Sprint Defaults for weapons are set in the "hstats" table. */ if (isset($web_prefs['show_loadout'])) { if ($web_prefs['show_loadout'] == 1) { $loadout = Loadout::where('db_id', '=', $player->db_id)->first(); } else { $loadout = null; } } else { $loadout = Loadout::where('db_id', '=', $player->db_id)->first(); } if ($loadout) { //Lets play the cache game, where all the stuff is stored locally and the points don't matter! $loadout = unserialize($loadout->entry); //VERSION 0.6 CHECKING (Array = Good, Object = BAD!) if (gettype($loadout) == "object") { //This is from version 0.6, we can no longer use this data. $loadout = null; } $cache_key_loadouts = $player->db_id . "_loadouts"; $loadout_md5 = md5(serialize($loadout)); if (Cache::Get($cache_key_loadouts . '_md5') != $loadout_md5 && $loadout != null) { //Oh I am playing the game, the one that will take me to my end. //Make sure this isnt a terrible send if (isset($loadout[0]->Gear)) { for ($k = 0; $k < count($loadout); $k++) { if ($loadout[$k]->Chassis_ID == 77733 || $loadout[$k]->Chassis_ID == 82394 || $loadout[$k]->Chassis_ID == 31334) { //ignore the training frame } else { //Break each loadout into its own cache Cache::forever($cache_key_loadouts . '_' . $loadout[$k]->Chassis_ID, $loadout[$k]); } } //Cache the loadout md5 so we can call it again later Cache::forever($cache_key_loadouts . '_md5', $loadout_md5); //and finally set loadout=1 so we know to display equipped gear data $loadout = 1; } } } //progress (feat. obama) if (isset($web_prefs['show_progress'])) { if ($web_prefs['show_progress'] == 1) { $progress = Progress::where('db_id', '=', $player->db_id)->order_by('updated_at', 'DESC')->first(); } else { $progress = null; } } else { $progress = Progress::where('db_id', '=', $player->db_id)->order_by('updated_at', 'DESC')->first(); } /* Mappings: $progress->xp[$i].sdb_id = ItemTypeId for chassis $progress->xp[$i].name = battle frame name $progress->xp[$i].lifetime_xp = amount of xp gained overall $progress->xp[$i].current_xp = currently allocated XP (WARNING: key may not exist!) $progress->chassis_id = current chassis ID, use this to identify what battleframe the player was last using $progress->unlocks.array() = certificate array for currently equipped chassis */ if ($progress) { //Progression graph builder $player_progresses_cache_key = $player->db_id . "_graph"; $player_id = $player->db_id; $frame_progress_javascript = array(); if (Cache::has($player_progresses_cache_key)) { //pull from cache $frame_progress_javascript = Cache::get($player_progresses_cache_key); } else { //don't cache the query, that wont help us; cache the javascript output for highcharts instead. $player_progresses = DB::query('SELECT DISTINCT(`db_id`),`entry`,unix_timestamp(`updated_at`) AS `updated_at` FROM `progresses` WHERE db_id= ' . $player_id . ' AND `created_at` > DATE_SUB(CURDATE(), INTERVAL 7 DAY) GROUP BY `created_at` ORDER BY `updated_at` ASC LIMIT 7'); //check chassis_id exists if (!empty($player_progresses)) { $check_chassis = unserialize($player_progresses[0]->entry); } else { $check_chassis = ""; $check_chassis_id = false; } if (!isset($check_chassis->chassis_id)) { $check_chassis_id = false; } else { $check_chassis_id = true; } if ($player_progresses && $check_chassis_id) { $frame_progress = array(); for ($i = 0; $i < count($player_progresses); $i++) { $day_progress = unserialize($player_progresses[$i]->entry); unset($day_progress->unlocks); foreach ($day_progress->xp as $key => $value) { if ($value->sdb_id == 77733 || $value->sdb_id == 82394 || $value->sdb_id == 31334) { //ignore training frame } else { $frame_progress[$value->name][$player_progresses[$i]->updated_at] = $value->lifetime_xp; } } } //Make it json datas $frame_progress_javascript = array(); foreach ($frame_progress as $battle_frame_name => $value) { $xp_data_string = "["; foreach ($value as $day => $xp_amt) { $xp_data_string .= "[" . $day * 1000 . "," . $xp_amt . "],"; $frame_progress_javascript[$battle_frame_name] = rtrim($xp_data_string, ",") . "]"; } } } else { $frame_progress_javascript = null; $progress = false; } //build cache Cache::put($player_progresses_cache_key, $frame_progress_javascript, 30); } } else { $frame_progress_javascript = null; $progress = false; } //Frames & Unlocks if ($progress) { $progress = unserialize($progress->entry); $cache_key_progress = $player->db_id . "_progress"; if (Cache::Get($cache_key_progress) != $progress) { if (isset($progress->xp)) { $battle_frame_id_list = array(); for ($i = 0; $i < count($progress->xp); $i++) { $battle_frame_id_list[$i] = $progress->xp[$i]->sdb_id; } $battle_frame_images = hWebIcon::where(function ($query) use($battle_frame_id_list) { $query->where('version', '=', Base_Controller::getVersionDate()); $query->where_in('itemTypeId', $battle_frame_id_list); })->get(); //set some cache Cache::forever($cache_key_progress . "_battleframe_images", $battle_frame_images); } else { $battle_frame_images = null; } if (isset($web_prefs['show_unlocks'])) { $show_unlocks = $web_prefs['show_unlocks']; } else { //Assume show unlocks is 1 $show_unlocks = 1; } if (isset($progress->unlocks) && $show_unlocks == 1) { //VERSION 0.6 CHECK (Array = BAD, Object = Good!) if (gettype($progress->unlocks) == "array") { //NOPE. $battle_frame_unlocks = null; } else { if (gettype($progress->unlocks) == "object") { //Looks like 0.7+ to me! //Create a cache for each frame unlock set foreach ($progress->unlocks as $chassis_id => $cert_array) { if ($chassis_id == 77733 || $chassis_id == 82394 || ($chassis_id = 31334)) { //ignore training frame } else { Cache::forever($cache_key_progress . "_" . $chassis_id, $cert_array); } } } } } //Cache the progress variable so we can do a quick compare on a later load Cache::forever($cache_key_progress, $progress); } else { //Assign cache values to local variable names. $battle_frame_images = Cache::Get($cache_key_progress . "_battleframe_images"); $progress = Cache::Get($cache_key_progress); } } else { $battle_frame_unlocks = null; } return View::make('player.single_battleframe')->with('title', 'Player Profile for ' . $playerName)->with(compact('player'))->with(compact('frame_name'))->with(compact('loadout'))->with(compact('battle_frame_unlocks'))->with(compact('progress'))->with(compact('frame_progress_javascript'))->with(compact('battle_frame_images'))->with(compact('web_prefs')); }