Guest User

ya nasral

a guest
Jan 4th, 2015
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2. $devKey = '2BD1AA14D090F3EC860C750FDB0CBA77';
  3. $accountID = 32436608;
  4. $url = 'https://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/V001/?key=' . $devKey;
  5.  
  6. $matches = array();
  7. $lastMatchID = 0;
  8.  
  9. $ch = curl_init();
  10. $options = array(
  11.     CURLOPT_RETURNTRANSFER => 1,
  12.     CURLOPT_SSL_VERIFYPEER => 0,
  13.     CURLOPT_SSL_VERIFYHOST => 0
  14. );
  15. curl_setopt_array($ch, $options);
  16.  
  17. for ($i = 1; $i <= 10; $i++) {
  18.     curl_setopt($ch, CURLOPT_URL, $url . '&account_id=' . $accountID . '&start_at_match_id=' . $lastMatchID . '&matches_requested=51');
  19.     $response = json_decode(curl_exec($ch), TRUE);
  20.  
  21.     $matches = array_merge($matches, $response['result']['matches']);
  22.  
  23.     $lastMatchKey = count($matches) - 1;
  24.     $lastMatchID = $matches[$lastMatchKey]['match_id'];
  25.  
  26.     if ($i < 10) {
  27.         unset($matches[$lastMatchKey]);
  28.     }
  29. }
  30.  
  31. function checkIfRanked($match) {
  32.     $lobbyType = $match['lobby_type'];
  33.  
  34.     if ($lobbyType == 7) {
  35.         return TRUE;
  36.     } else {
  37.         return FALSE;
  38.     }
  39. }
  40.  
  41. function checkIfFullStack($match) {
  42.     $players = $match['players'];
  43.     $ourIDs = array(32436608, 89759793, 111340921, 141605683, 192150916);
  44.     $counter = 0;
  45.  
  46.     for ($i = 0; $i <= 9; $i++) {
  47.         $playerID = $players[$i]['account_id'];
  48.  
  49.         if (in_array($playerID, $ourIDs)) {
  50.             $counter++;
  51.         }
  52.     }
  53.  
  54.     if ($counter == 5) {
  55.         return TRUE;
  56.     } else {
  57.         return FALSE;
  58.     }
  59. }
  60.  
  61. foreach ($matches as $key => &$value) {
  62.     if (!checkIfRanked($value) || !checkIfFullStack($value)) {
  63.         unset($matches[$key]);
  64.     }
  65. }
  66.  
  67. $allIDs = array();
  68.  
  69. foreach (array_values($matches) as $value) {
  70.     $allIDs[] = $value['match_id'];
  71. }
  72.  
  73. $url = 'https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/?key=' . $devKey;
  74. $matchesDetailed = array();
  75.  
  76. foreach ($allIDs as $value) {
  77.     curl_setopt($ch, CURLOPT_URL, $url . '&match_id=' . $value);
  78.     $response = json_decode(curl_exec($ch), TRUE);
  79.  
  80.     $matchesDetailed[] = $response['result'];
  81. }
  82.  
  83. curl_close($ch);
  84.  
  85. print "<pre>";
  86. print_r($matchesDetailed);
  87. print "</pre>";
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment