Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Load Composer and register Requests
- require 'vendor/autoload.php';
- Requests::register_autoloader();
- // Global Variables
- date_default_timezone_set('EST');
- $censusServerURL = 'http://census.soe.com/s:danofthedeep/get/ps2ps4';
- $characterIDListURL = 'http://the-swarm.net/stats-work/characterIDs.list';
- $populationJSONURL = 'http://the-swarm.net/stats-work/populationInfo.json';
- $onlineStatusCount = 0;
- $onlineStatusBuffer = "";
- $onlineStatusBufferBot = array();
- $_q = ""; // Temporary Query for Single Character Stat
- $characterNames = array();
- $characterIDs = array();
- $psnIDs = array();
- $population = array(array(), array(), array()); //{VS, TR, NC}
- $charactersArray = array();
- class Character {
- public $name, $br, $certs, $character_id, $daily_ribbon, $faction_id, $head_id, $profile_id, $times, $title_id, $score, $kills, $deaths, $assists, $online;
- public function __construct($name, $br, $certs, $character_id, $daily_ribbon, $faction_id, $head_id, $profile_id, $times, $title_id, $score=0, $kills=0, $deaths=0, $assists=0, $online=0)
- {
- $this->name = $name;
- $this->br = $br;
- $this->certs = $certs;
- $this->character_id = $character_id;
- $this->daily_ribbon = $daily_ribbon;
- $this->faction_id = $faction_id;
- $this->head_id = $head_id;
- $this->profile_id = $profile_id;
- $this->times = $times;
- $this->title_id = $title_id;
- $this->score = $score;
- $this->kills = $kills;
- $this->deaths = $deaths;
- $this->assists = $assists;
- $this->online = $online;
- }
- }
- // Support Functions
- function updateStatus($x)
- { // Support Function for Online Status Module
- if ($x['online_status'] == '1000') {
- $GLOBALS['onlineStatusCount']++;
- $idx = array_search($x['character_id'], $GLOBALS['characterIDs']);
- $GLOBALS['onlineStatusBuffer'] .= "<tr style='border: 1px solid #1d4698; background-color: #173676'><td>".$GLOBALS['characterNames'][$idx] . "</td><td>" . $GLOBALS['psnIDs'][$idx] . '</td></tr>';
- }
- }
- function updateStatusBot($x) {
- if ($x['online_status'] == '1000') {
- $GLOBALS['onlineStatusCount']++;
- $idx = array_search($x['character_id'], $GLOBALS['characterIDs']);
- $GLOBALS['onlineStatusBuffer'] .= $GLOBALS['characterNames'][$idx] . " (" . $GLOBALS['psnIDs'][$idx] . ")|||";
- }
- }
- function characterIDs()
- {
- $characterIDArray = unserialize(Requests::get($GLOBALS['characterIDListURL'])->body);
- $GLOBALS['characterNames'] = array_map(function ($x) {
- return $x[0];
- }, $characterIDArray);
- $GLOBALS['characterIDs'] = array_map(function ($x) {
- return $x[1];
- }, $characterIDArray);
- $GLOBALS['psnIDs'] = array_map(function ($x) {
- return $x[2];
- }, $characterIDArray);
- }
- function population($x)
- {
- if ($x['online_status'] == "1000") {
- $factionID = intval($x['faction_id']) - 1;
- $GLOBALS['population'][$factionID][] = 1;
- }
- }
- // Query Handler
- $queryRaw = ($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : "cmd=default";
- parse_str($queryRaw, $query);
- switch ($query['cmd']) {
- case 'world':
- $targetPage = 'world';
- break;
- case 'character_id':
- $targetPage = 'character_id';
- break;
- case 'character_id_json':
- $target_page = 'character_id_json';
- break;
- case 'online_status_module':
- $targetPage = 'online_status_module';
- break;
- case 'online_status_bot':
- $targetPage = 'online_status_bot';
- break;
- case 'population':
- $targetPage = 'population';
- break;
- case 'character_stat':
- $targetPage = 'character_stat';
- break;
- case 'stat_page':
- $targetPage = 'stat_page';
- break;
- case 'default':
- $targetPage = 'default';
- break;
- }
- if ($targetPage == 'world') { // World Status
- $censusRequest = "" . $censusServerURL . "/world";
- $censusResponse = Requests::get($censusRequest);
- $censusResponse = json_decode($censusResponse->body);
- $worldState = $censusResponse->world_list[0]->state;
- if ($worldState == 'online') {
- echo 'Genudine is <span style="color:green;">Online</span> <img src="http://the-swarm.net/images/avenger_blue/misc/subscribed_40b.png"/></span>';
- } else if ($worldState == 'locked') {
- echo 'Genudine is <span style="color:red;">Locked</span>';
- }
- } else if ($targetPage == 'character_id') { // Character ID, Single Character
- if ($query['name']) {
- $censusRequest = $censusServerURL . "/character/?name.first_lower=" . strtolower($query['name']) . "&c:show=character_id";
- $censusResponse = Requests::get($censusRequest);
- $censusResponse = json_decode($censusResponse->body);
- echo serialize(array($query['name'], $censusResponse->character_list[0]->character_id));
- }
- } else if ($targetPage == 'character_id_json') { // Character ID, Single Character
- if ($query['name']) {
- $censusRequest = $censusServerURL . "/character/?name.first_lower=" . strtolower($query['name']) . "&c:show=character_id";
- $censusResponse = Requests::get($censusRequest);
- $censusResponse = json_decode($censusResponse->body);
- echo json_encode(array($query['name'], $censusResponse->character_list[0]->character_id));
- }
- } else if ($targetPage == 'online_status_module') { // vBulletin Module Display for Online Status
- $censusRequest = "" . $censusServerURL . "/world";
- $censusResponse = Requests::get($censusRequest);
- $censusResponse = json_decode($censusResponse->body);
- $worldState = $censusResponse->world_list[0]->state;
- if ($worldState == 'online') {
- characterIDs();
- $onlineStatusRaw = json_decode(Requests::get($censusServerURL . '/characters_online_status?character_id=' . join(',', $characterIDs))->body, true);
- $onlineStatusUpdated = array_map("updateStatus", $onlineStatusRaw['characters_online_status_list']);
- //echo $onlineStatusBuffer;
- echo '<table style="width: 100%;"><thead><tr><th style="text-align:center!important;">In-Game</th><th style="text-align:center!important;">PSN ID</th></tr></thead><tbody style="padding-top: 5px;">' . $onlineStatusBuffer . '</tbody><tfoot><tr><td style="padding-top: 5px;"colspan="2">Total Members In-Game: ' . $onlineStatusCount . '</td></tr></tfoot></table>';
- } else {
- echo "";
- }
- } else if ($targetPage == 'online_status_bot') { // vBulletin Module Display for Online Status
- $censusRequest = "" . $censusServerURL . "/world";
- $censusResponse = Requests::get($censusRequest);
- $censusResponse = json_decode($censusResponse->body);
- $worldState = $censusResponse->world_list[0]->state;
- if ($worldState == 'online') {
- characterIDs();
- $onlineStatusRaw = json_decode(Requests::get($censusServerURL . '/characters_online_status?character_id=' . join(',', $characterIDs))->body, true);
- $onlineStatusUpdated = array_map("updateStatusBot", $onlineStatusRaw['characters_online_status_list']);
- //echo $onlineStatusBuffer;
- echo $onlineStatusBuffer . "|||Total: " . $onlineStatusCount;
- } else {
- echo "";
- }
- } else if ($targetPage == 'character_stat') {
- if ($query['name']) {
- $censusRequest = $censusServerURL . "/character/?name.first_lower=" . strtolower($query['name']) . "&c:show=character_id";
- $censusResponse = Requests::get($censusRequest);
- $censusResponse = json_decode($censusResponse->body);
- $_q = $censusResponse->character_list[0]->character_id;
- }
- if ($_q || $query['id']) {
- if ($query['id']) { $_q = $query['id']; }
- $censusRequest = $censusServerURL . '/character?character_id=' . $_q;
- $censusResponse = json_decode(Requests::get($censusRequest)->body);
- $_cMain = $censusResponse->character_list[0];
- $censusRequest = $censusServerURL . '/characters_stat_history?character_id=' . $_q . '&stat_name=assist_count,deaths,kills,score&c:show=character_id,stat_name,all_time&c:limit=100&c:sort=character_id:-1';
- $censusResponse = json_decode(Requests::get($censusRequest)->body);
- $_cStats = $censusResponse->characters_stat_history_list;
- $censusRequest = $censusServerURL . '/characters_online_status?character_id=' . $_q;
- $censusResponse = json_decode(Requests::get($censusRequest)->body);
- $_oStatus = (intval($censusResponse->characters_online_status_list[0]->online_status) == 0) ? "Offline" : "Online";
- $hours = floor($_cMain->times->minutes_played / 60);
- $minutes = $_cMain->times->minutes_played % 60;
- $_KDS = array(0,0,0);
- foreach ($_cStats as $_stat) {
- if ($_stat->stat_name == 'kills') {$_KDS[0] = $_stat->all_time;}
- if ($_stat->stat_name == 'deaths') {$_KDS[1] = $_stat->all_time;}
- if ($_stat->stat_name == 'score') {$_KDS[2] = $_stat->all_time;}
- }
- //$_im = imagecreatetruecolor(450, 125);
- $_im = imagecreatefromjpeg('./signature.jpg');
- $_imBackColor = imagecolorallocate($_im, 11, 26, 57);
- $_imTextColor = imagecolorallocate($_im, 249, 168, 1);
- imagestring($_im, 3, 15, 15, $_cMain->name->first . ': BR'. $_cMain->battle_rank->value . ' (' . $_cMain->battle_rank->percent_to_next . '%->) Score: '. $_KDS[2].' SPM: '.round(intval($_KDS[2])/intval($_cMain->times->minutes_played)) , $_imTextColor);
- imagestring($_im, 3, 65, 30, 'Kills: '.$_KDS[0]. ' Deaths: '. $_KDS[1] . ' Certs: '.$_cMain->certs->available_points.'/'.$_cMain->certs->spent_points, $_imTextColor);
- imagestring($_im, 3, 70, 45, 'Minutes Played: '.$hours.'h '.$minutes.'m ', $_imTextColor);
- imagestring($_im, 3, 70, 60, 'Last Login: '.$_cMain->times->last_login_date.' Total Logins: '.$_cMain->times->login_count, $_imTextColor);
- imagestring($_im, 3, 85, 75, 'Online Status: '. $_oStatus, $_imTextColor);
- header('Content-Type: image/jpeg');
- imagejpeg($_im);
- imagedestroy($_im);
- }
- } else if ($targetPage == 'population') {
- $_pI = json_decode(Requests::get($populationJSONURL)->body);
- echo "<h1 style='font-size: 14pt;'><div style='text-align: center;'><img style='position:relative; top: 7.5px;' src='http://the-swarm.net/stats-work/images/93.png' />". $_pI->vs_pop . " <img style='position:relative; top: 7.5px;' src='http://the-swarm.net/stats-work/images/11.png' /> ". $_pI->nc_pop . "<img style='position:relative; top: 7.5px;' src='http://the-swarm.net/stats-work/images/17.png' />" .$_pI->tr_pop. "</div></h1><br/>";
- echo "<div style='text-align:center;'>Total Server Population: " . $_pI->total_pop. "</div><br/>";
- echo "<div style='text-align:center;'><span style='font-size: 8pt'>Last Updated: ".date("D d M Y h:i A", $_pI->timestamp)."</span></div><br/><br/>";
- } else if ($targetPage == 'stat_page') {
- characterIDs();
- $_cIDs = preg_replace('/,,/',',',join(',', $characterIDs));
- $censusRequest = $censusServerURL . '/character/?character_id=' . $_cIDs;
- $censusResponse = json_decode(Requests::get($censusRequest)->body,true);
- $_cMain = $censusResponse['character_list'];
- $censusRequest = $censusServerURL . '/characters_stat_history?character_id=' . $_cIDs . '&stat_name=assist_count,deaths,kills,score&c:show=character_id,stat_name,all_time&c:limit=100&c:sort=character_id:-1';
- $censusResponse = json_decode(Requests::get($censusRequest)->body,true);
- $_cStats = $censusResponse['characters_stat_history_list'];
- $censusRequest = $censusServerURL . '/characters_online_status/?character_id=' . $_cIDs;
- $censusResponse = json_decode(Requests::get($censusRequest)->body,true);
- $_cOnlineStatus = $censusResponse['characters_stat_history_list'];
- foreach ($_cMain as $_mI) {
- $newGuy = New Character($_mI['name']['first'],$_mI['battle_rank'],$_mI['certs'],$_mI['character_id'],$_mI['daily_ribbon'],$_mI['faction_id'],$_mI['head_id'],$_mI['profile_id'],$_mI['times'], $_mI['title_id']);
- $charactersArray[]=$newGuy;
- }
- asort($charactersArray);
- echo '<html><head><title>the [s]warm - outfit [s]tats</title><script type="text/javascript" src="jquery-1.11.2.min.js"></script><script type="text/javascript" src="jquery.tablesorter.min.js"></script><script type="text/javascript">$(document).ready(function() {$("#outfitStats").tablesorter({dateFormat: "pt",sortList: [[0,0]]});});</script><style type="text/css" media="screen">body { background-color:#0b1a39; color:#f9a801; font-family:"Lucida Console",Monaco,monospace; font-size:9pt;} tr.char { border: 1px solid #1d4698; background-color: #173676; width: 775px; padding-top: 10px; padding-bottom: 10px; padding-left: 10px;} td { padding: 5px;}</style></head><body>';
- echo "<table id='outfitStats' class='tablesorter'><thead><tr><th>Name</th><th>BR</th><th>PTN</th><th>Certs</th><th>DR</th><th>Last Login</th><th>MP</th></tr></thead><tbody>";
- foreach ($charactersArray as $ch) {
- echo "<tr class='char'><td>".$ch->name."</td><td style='text-align: center;'>".$ch->br['value']."</td><td style='text-align: center;'>".$ch->br['percent_to_next']."%</td><td style='text-align: center;'>".$ch->certs['available_points']."/".$ch->certs['earned_points']."</td><td style='text-align: center;'>".$ch->daily_ribbon['count']."</td><td style='text-align: center;'>".$ch->times['last_login_date']."</td><td style='text-align: center;'>".$ch->times['minutes_played']."</td></tr>";
- }
- echo "</tbody></table></body>";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement