Advertisement
Guest User

stats-work snapshot 01 march danoftheeep

a guest
Mar 1st, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.48 KB | None | 0 0
  1. <?php
  2. // Load Composer and register Requests
  3. require 'vendor/autoload.php';
  4. Requests::register_autoloader();
  5.  
  6. // Global Variables
  7. date_default_timezone_set('EST');
  8.  
  9. $censusServerURL = 'http://census.soe.com/s:danofthedeep/get/ps2ps4';
  10. $characterIDListURL = 'http://the-swarm.net/stats-work/characterIDs.list';
  11. $populationJSONURL = 'http://the-swarm.net/stats-work/populationInfo.json';
  12. $onlineStatusCount = 0;
  13. $onlineStatusBuffer = "";
  14. $onlineStatusBufferBot = array();
  15. $_q = ""; // Temporary Query for Single Character Stat
  16. $characterNames = array();
  17. $characterIDs = array();
  18. $psnIDs = array();
  19. $population = array(array(), array(), array()); //{VS, TR, NC}
  20. $charactersArray = array();
  21.  
  22.  
  23. class Character {
  24.     public $name, $br, $certs, $character_id, $daily_ribbon, $faction_id, $head_id, $profile_id, $times, $title_id, $score, $kills, $deaths, $assists, $online;
  25.     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)
  26.     {
  27.         $this->name = $name;
  28.         $this->br = $br;
  29.         $this->certs = $certs;
  30.         $this->character_id = $character_id;
  31.         $this->daily_ribbon = $daily_ribbon;
  32.         $this->faction_id = $faction_id;
  33.         $this->head_id = $head_id;
  34.         $this->profile_id = $profile_id;
  35.         $this->times = $times;
  36.         $this->title_id = $title_id;
  37.         $this->score = $score;
  38.         $this->kills = $kills;
  39.         $this->deaths = $deaths;
  40.         $this->assists = $assists;
  41.         $this->online = $online;
  42.     }
  43. }
  44.  
  45. // Support Functions
  46. function updateStatus($x)
  47. {    // Support Function for Online Status Module
  48.     if ($x['online_status'] == '1000') {
  49.         $GLOBALS['onlineStatusCount']++;
  50.         $idx = array_search($x['character_id'], $GLOBALS['characterIDs']);
  51.         $GLOBALS['onlineStatusBuffer'] .= "<tr style='border: 1px solid #1d4698; background-color: #173676'><td>".$GLOBALS['characterNames'][$idx] . "</td><td>" . $GLOBALS['psnIDs'][$idx] . '</td></tr>';
  52.     }
  53. }
  54.  
  55. function updateStatusBot($x) {
  56.     if ($x['online_status'] == '1000') {
  57.         $GLOBALS['onlineStatusCount']++;
  58.         $idx = array_search($x['character_id'], $GLOBALS['characterIDs']);
  59.         $GLOBALS['onlineStatusBuffer'] .= $GLOBALS['characterNames'][$idx] . " (" . $GLOBALS['psnIDs'][$idx] . ")|||";
  60.     }
  61. }
  62. function characterIDs()
  63. {
  64.     $characterIDArray = unserialize(Requests::get($GLOBALS['characterIDListURL'])->body);
  65.     $GLOBALS['characterNames'] = array_map(function ($x) {
  66.         return $x[0];
  67.     }, $characterIDArray);
  68.     $GLOBALS['characterIDs'] = array_map(function ($x) {
  69.         return $x[1];
  70.     }, $characterIDArray);
  71.     $GLOBALS['psnIDs'] = array_map(function ($x) {
  72.         return $x[2];
  73.     }, $characterIDArray);
  74. }
  75.  
  76. function population($x)
  77. {
  78.     if ($x['online_status'] == "1000") {
  79.         $factionID = intval($x['faction_id']) - 1;
  80.         $GLOBALS['population'][$factionID][] = 1;
  81.     }
  82. }
  83.  
  84.  
  85. // Query Handler
  86. $queryRaw = ($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : "cmd=default";
  87. parse_str($queryRaw, $query);
  88.  
  89. switch ($query['cmd']) {
  90.     case 'world':
  91.         $targetPage = 'world';
  92.         break;
  93.     case 'character_id':
  94.         $targetPage = 'character_id';
  95.         break;
  96.     case 'character_id_json':
  97.         $target_page = 'character_id_json';
  98.         break;
  99.     case 'online_status_module':
  100.         $targetPage = 'online_status_module';
  101.         break;
  102.     case 'online_status_bot':
  103.         $targetPage = 'online_status_bot';
  104.         break;
  105.     case 'population':
  106.         $targetPage = 'population';
  107.         break;
  108.     case 'character_stat':
  109.         $targetPage = 'character_stat';
  110.         break;
  111.     case 'stat_page':
  112.         $targetPage = 'stat_page';
  113.         break;
  114.     case 'default':
  115.         $targetPage = 'default';
  116.         break;
  117. }
  118.  
  119. if ($targetPage == 'world') { // World Status
  120.     $censusRequest = "" . $censusServerURL . "/world";
  121.     $censusResponse = Requests::get($censusRequest);
  122.     $censusResponse = json_decode($censusResponse->body);
  123.     $worldState = $censusResponse->world_list[0]->state;
  124.     if ($worldState == 'online') {
  125.         echo 'Genudine is <span style="color:green;">Online</span> <img src="http://the-swarm.net/images/avenger_blue/misc/subscribed_40b.png"/></span>';
  126.     } else if ($worldState == 'locked') {
  127.         echo 'Genudine is <span style="color:red;">Locked</span>';
  128.     }
  129. } else if ($targetPage == 'character_id') { // Character ID, Single Character
  130.     if ($query['name']) {
  131.         $censusRequest = $censusServerURL . "/character/?name.first_lower=" . strtolower($query['name']) . "&c:show=character_id";
  132.         $censusResponse = Requests::get($censusRequest);
  133.         $censusResponse = json_decode($censusResponse->body);
  134.         echo serialize(array($query['name'], $censusResponse->character_list[0]->character_id));
  135.     }
  136. } else if ($targetPage == 'character_id_json') { // Character ID, Single Character
  137.     if ($query['name']) {
  138.         $censusRequest = $censusServerURL . "/character/?name.first_lower=" . strtolower($query['name']) . "&c:show=character_id";
  139.         $censusResponse = Requests::get($censusRequest);
  140.         $censusResponse = json_decode($censusResponse->body);
  141.         echo json_encode(array($query['name'], $censusResponse->character_list[0]->character_id));
  142.     }
  143. } else if ($targetPage == 'online_status_module') { // vBulletin Module Display for Online Status
  144.     $censusRequest = "" . $censusServerURL . "/world";
  145.     $censusResponse = Requests::get($censusRequest);
  146.     $censusResponse = json_decode($censusResponse->body);
  147.     $worldState = $censusResponse->world_list[0]->state;
  148.     if ($worldState == 'online') {
  149.         characterIDs();
  150.         $onlineStatusRaw = json_decode(Requests::get($censusServerURL . '/characters_online_status?character_id=' . join(',', $characterIDs))->body, true);
  151.         $onlineStatusUpdated = array_map("updateStatus", $onlineStatusRaw['characters_online_status_list']);
  152.         //echo $onlineStatusBuffer;
  153.         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>';
  154.     } else {
  155.         echo "";
  156.     }
  157. } else if ($targetPage == 'online_status_bot') { // vBulletin Module Display for Online Status
  158.     $censusRequest = "" . $censusServerURL . "/world";
  159.     $censusResponse = Requests::get($censusRequest);
  160.     $censusResponse = json_decode($censusResponse->body);
  161.     $worldState = $censusResponse->world_list[0]->state;
  162.     if ($worldState == 'online') {
  163.         characterIDs();
  164.         $onlineStatusRaw = json_decode(Requests::get($censusServerURL . '/characters_online_status?character_id=' . join(',', $characterIDs))->body, true);
  165.         $onlineStatusUpdated = array_map("updateStatusBot", $onlineStatusRaw['characters_online_status_list']);
  166.         //echo $onlineStatusBuffer;
  167.         echo $onlineStatusBuffer . "|||Total: " . $onlineStatusCount;
  168.     } else {
  169.         echo "";
  170.     }
  171. } else if ($targetPage == 'character_stat') {
  172.     if ($query['name']) {
  173.         $censusRequest = $censusServerURL . "/character/?name.first_lower=" . strtolower($query['name']) . "&c:show=character_id";
  174.         $censusResponse = Requests::get($censusRequest);
  175.         $censusResponse = json_decode($censusResponse->body);
  176.         $_q = $censusResponse->character_list[0]->character_id;
  177.     }
  178.     if ($_q || $query['id']) {
  179.         if ($query['id']) { $_q = $query['id']; }
  180.         $censusRequest = $censusServerURL . '/character?character_id=' . $_q;
  181.         $censusResponse = json_decode(Requests::get($censusRequest)->body);
  182.         $_cMain = $censusResponse->character_list[0];
  183.         $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';
  184.         $censusResponse = json_decode(Requests::get($censusRequest)->body);
  185.         $_cStats = $censusResponse->characters_stat_history_list;
  186.         $censusRequest = $censusServerURL . '/characters_online_status?character_id=' . $_q;
  187.         $censusResponse = json_decode(Requests::get($censusRequest)->body);
  188.         $_oStatus = (intval($censusResponse->characters_online_status_list[0]->online_status) == 0) ? "Offline" : "Online";
  189.         $hours = floor($_cMain->times->minutes_played / 60);
  190.         $minutes = $_cMain->times->minutes_played % 60;
  191.         $_KDS = array(0,0,0);
  192.         foreach ($_cStats as $_stat) {
  193.             if ($_stat->stat_name == 'kills') {$_KDS[0] = $_stat->all_time;}
  194.             if ($_stat->stat_name == 'deaths') {$_KDS[1] = $_stat->all_time;}
  195.             if ($_stat->stat_name == 'score') {$_KDS[2] = $_stat->all_time;}
  196.         }
  197.         //$_im = imagecreatetruecolor(450, 125);
  198.         $_im = imagecreatefromjpeg('./signature.jpg');
  199.         $_imBackColor = imagecolorallocate($_im, 11, 26, 57);
  200.         $_imTextColor = imagecolorallocate($_im, 249, 168, 1);
  201.         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);
  202.         imagestring($_im, 3, 65, 30, 'Kills: '.$_KDS[0]. ' Deaths: '. $_KDS[1] . ' Certs: '.$_cMain->certs->available_points.'/'.$_cMain->certs->spent_points, $_imTextColor);
  203.         imagestring($_im, 3, 70, 45, 'Minutes Played: '.$hours.'h '.$minutes.'m ', $_imTextColor);
  204.         imagestring($_im, 3, 70, 60, 'Last Login: '.$_cMain->times->last_login_date.' Total Logins: '.$_cMain->times->login_count, $_imTextColor);
  205.         imagestring($_im, 3, 85, 75, 'Online Status: '. $_oStatus, $_imTextColor);
  206.         header('Content-Type: image/jpeg');
  207.         imagejpeg($_im);
  208.         imagedestroy($_im);
  209.     }
  210. } else if ($targetPage == 'population') {
  211.     $_pI = json_decode(Requests::get($populationJSONURL)->body);
  212.     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/>";
  213.     echo "<div style='text-align:center;'>Total Server Population: " . $_pI->total_pop. "</div><br/>";
  214.     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/>";
  215. } else if ($targetPage == 'stat_page') {
  216.     characterIDs();
  217.     $_cIDs = preg_replace('/,,/',',',join(',', $characterIDs));
  218.     $censusRequest = $censusServerURL . '/character/?character_id=' . $_cIDs;
  219.     $censusResponse = json_decode(Requests::get($censusRequest)->body,true);
  220.     $_cMain = $censusResponse['character_list'];
  221.     $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';
  222.     $censusResponse = json_decode(Requests::get($censusRequest)->body,true);
  223.     $_cStats = $censusResponse['characters_stat_history_list'];
  224.     $censusRequest = $censusServerURL . '/characters_online_status/?character_id=' . $_cIDs;
  225.     $censusResponse = json_decode(Requests::get($censusRequest)->body,true);
  226.     $_cOnlineStatus = $censusResponse['characters_stat_history_list'];
  227.     foreach ($_cMain as $_mI) {
  228.         $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']);
  229.         $charactersArray[]=$newGuy;
  230.     }
  231.     asort($charactersArray);
  232.     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>';
  233.     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>";
  234.     foreach ($charactersArray as $ch) {
  235.         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>";
  236.     }
  237.     echo "</tbody></table></body>";
  238. }
  239. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement