QuantumEternity

RankData

Oct 17th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.83 KB | None | 0 0
  1. <?php
  2. /*
  3.  * This file is subject to the terms and conditions defined in
  4.  * file 'LICENSE.txt', which is part of this source code package.
  5.  */
  6.  
  7.  
  8.     $user = ''; // default
  9.     $plat = 'steam'; // default
  10.     $type = 'ranked'; // default (alt: 'extra', 'stats')
  11.     $mmr = 'show'; // default (alt: 'hide')
  12.        
  13.     $rankData = array(
  14.         'name' => '',
  15.         'ranked' => array(
  16.             '1v1' => array(0, 100), // rankNumber, MMR
  17.             '2v2' => array(0, 100), // rankNumber, MMR
  18.             '3v3' => array(0, 100), // rankNumber, MMR
  19.             'Tournament' => array(0, 100), // rankNumber, MMR
  20.         ),
  21.         'extra' => array(
  22.             'Hoops' => array(0, 100), // rankNumber, MMR
  23.             'Rumble' => array(0, 100), // rankNumber, MMR
  24.             'Dropshot' => array(0, 100), // rankNumber, MMR
  25.             'Snowday' => array(0, 100), // rankNumber, MMR
  26.         ),
  27.         'stats' => array(
  28.             'SeasonReward' => array(0, 0), // Level, Wins
  29.             'Wins' => 0,
  30.             'Goals' => 0,
  31.             'Saves' => 0,
  32.             'Assists' => 0,
  33.             'Shots' => 0,
  34.             'MVPs' => 0,
  35.             'GoalShotRatio' => 0.0
  36.         )
  37.   );
  38.    
  39.     function hasPlaylist($name, $data){
  40.         for ($i = 0 ; $i < count($data) ; $i++){
  41.             if (isset($data[$i]['metadata'])){
  42.                 if ($data[$i]['metadata']['name'] == $name){
  43.                     return $i;
  44.                 }
  45.             }
  46.         }
  47.         return -1;
  48.     }
  49.  
  50.     if (!empty($_GET['user'])) { // is user parameter given
  51.         $user = str_replace(array(' ', '%20'), array('-', '-') , strtolower($_GET['user'])); // set user the value of given parameter in lower case and replace spaces with hyphen
  52.     }
  53.     if (!empty($_GET['plat'])) { // is plat parameter given
  54.         $plat = strtolower($_GET['plat']); // set plat the value of given parameter in lower case
  55.     }
  56.     if (!empty($_GET['type'])) { // is type parameter given
  57.         $type = strtolower($_GET['type']); // set type the value of given parameter in lower case
  58.     }
  59.     if (!empty($_GET['mmr'])) { // is type parameter given
  60.         $mmr = strtolower($_GET['mmr']); // set type the value of given parameter in lower case
  61.     }
  62.  
  63.  
  64.     // valid arguments
  65.     $platforms = array('psn'=>1, 'steam'=>1, 'xbox'=>1);
  66.     $types = array('ranked'=>1, 'extra'=>1, 'stats'=>1);
  67.     $mmrVisibility = array('show'=>1, 'hide'=>1);
  68.  
  69.  
  70.     // no username or too long username
  71.     if (($user=='') || (strlen($user)>32)) {
  72.         $error = array(
  73.             'message' => 'No/Invalid username given',
  74.             'code' => '0'
  75.     );
  76.         die(json_encode($error));
  77.     }
  78.  
  79.     // validate platform
  80.     if (!isset($platforms[$plat])) {
  81.         $error = array(
  82.             'message' => $plat.' is an invalid platform on rocketleague.tracker.network',
  83.             'code' => '0'
  84.     );
  85.         die(json_encode($error));
  86.     }
  87.  
  88.     if (!isset($types[$type])) {
  89.         $error = array(
  90.             'message' => '$type must be blank, "ranked", "extra", or "stats"',
  91.             'code' => '0'
  92.     );
  93.         die(json_encode($error));
  94.     }
  95.  
  96.     if (!isset($mmrVisibility[$mmr])) {
  97.         $error = array(
  98.             'message' => '$mmr must be blank, "show", or "hide"',
  99.             'code' => '0'
  100.     );
  101.         die(json_encode($error));
  102.     }
  103.  
  104.   $RL_tracker = @file_get_contents('https://rocketleague.tracker.network/rocket-league/profile/'.$plat.'/'.$user.'/overview'); // get html code
  105.  
  106.     preg_match_all("/\"segments\":(.+?),\"availableSegments\"/is", $RL_tracker, $first); // first = json of stats and rank data
  107.     preg_match_all("/\"platformUserHandle\":\"(.+?)\",\"platformUserIdentifier\"/is", $RL_tracker, $name); // fetch name
  108.  
  109.     $rankData['name'] = isset($name[1][0]) ? html_entity_decode($name[1][0], ENT_QUOTES | ENT_XML1, 'UTF-8') : $user; // set name
  110.  
  111.     if (count($first[0])==0) { // checking for existing data (if not, no ranks given)
  112.         $error = array(
  113.             'message' => $user.' ('.$plat.') has no data on rocketleague.tracker.network yet.',
  114.             'code' => 0
  115.     );
  116.         die(json_encode($error));
  117.     }
  118.  
  119.     $data = json_decode($first[1][0], true); // decode to php array
  120.     // or use the array $data instead of $rankData, ofc it has lots more info.
  121.     // var_dump($data);
  122.  
  123.     $rankData['stats']['SeasonReward'] = array($data[0]['stats']['seasonRewardLevel']['value'], $data[0]['stats']['seasonRewardWins']['value']);
  124.     $rankData['stats']['Wins'] = $data[0]['stats']['wins']['value'];
  125.     $rankData['stats']['Goals'] = $data[0]['stats']['goals']['value'];
  126.     $rankData['stats']['MVPs'] = $data[0]['stats']['mVPs']['value'];
  127.     $rankData['stats']['Saves'] = $data[0]['stats']['saves']['value'];
  128.     $rankData['stats']['Assists'] = $data[0]['stats']['assists']['value'];
  129.     $rankData['stats']['Shots'] = $data[0]['stats']['shots']['value'];
  130.     $rankData['stats']['GoalShotRatio'] = $data[0]['stats']['goalShotRatio']['value'];
  131.  
  132.     // shortened playlist names / associations
  133.     $rankedPlaylists = array('Ranked Duel 1v1'=>'1v1', 'Ranked Doubles 2v2'=>'2v2', 'Ranked Standard 3v3'=>'3v3', 'Tournament Matches' => 'Tournament');
  134.     $extraPlaylists = array('Hoops', 'Rumble', 'Dropshot', 'Snowday');
  135.  
  136.     if(count($data) > 1 ) { // not sure if consistent yet, maybe needs some revamp
  137.         foreach ($rankedPlaylists as $key => $value) {
  138.             $id = hasPlaylist($key, $data);
  139.  
  140.             if($id != -1){
  141.                 $rankData['ranked'][$value] = array($data[$id]['stats']['tier']['value'], $data[$id]['stats']['rating']['value']);
  142.             }
  143.         }
  144.         foreach ($extraPlaylists as $value) {
  145.             $id = hasPlaylist($key, $data);
  146.  
  147.             if($id != -1){
  148.                 $rankData['extra'][$value] = array($data[$id]['stats']['tier']['value'], $data[$id]['stats']['rating']['value']);
  149.             }
  150.         }
  151.     }
  152.    
  153.    
  154.     $rewardLevels = array('Unranked', 'Bronze', 'Silver', 'Gold', 'Platinum', 'Diamond', 'Champion', 'Grand Champion', 'Supersonic Legend'); // array of all possible reward levels (bottom up)
  155.  
  156.     $rankNames = array('Unranked', 'Bronze I', 'Bronze II', 'Bronze III', 'Silver I', 'Silver II', 'Silver III', 'Gold I', 'Gold II', 'Gold III', 'Platinum I', 'Platinum II', 'Platinum III', 'Diamond I', 'Diamond II', 'Diamond III', 'Champion I', 'Champion II', 'Champion III', 'Grand Champion I', 'Grand Champion II', 'Grand Champion III', 'Supersonic Legend'); // array of all possible rank names (bottom up)
  157.  
  158.     echo json_encode($rankData);
  159.  
  160. ?>
Add Comment
Please, Sign In to add comment