Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. <?php
  2. header('Content-Type: application/json');
  3. $start = microtime(true);
  4.  
  5. $countries = array ( 'Albania' => '55', 'Argentina' => '24', 'Australia' => '35', 'Austria' => '48', 'Bangladesh' => '59', 'Belarus' => '52', 'Belgium' => '40', 'Bosnia-and-Herzegovina' => '13', 'Brazil' => '23', 'Bulgaria' => '10', 'Cambodia' => '119', 'Canada' => '27', 'Chile' => '45', 'China' => '28', 'Colombia' => '46', 'Croatia' => '12', 'Czech-Republic' => '51', 'Estonia' => '53', 'Finland' => '37', 'France' => '4', 'Germany' => '3', 'Greece' => '14', 'Hungary' => '8', 'India' => '34', 'Indonesia' => '29', 'Iran' => '30', 'Ireland' => '38', 'Israel' => '33', 'Italy' => '7', 'Japan' => '58', 'Latvia' => '20', 'Lithuania' => '19', 'Malaysia' => '42', 'Mexico' => '25', 'Montenegro' => '47', 'Netherlands' => '36', 'New-Zealand' => '139', 'Norway' => '43', 'Pakistan' => '41', 'Peru' => '44', 'Philippines' => '54', 'Poland' => '1', 'Portugal' => '18', 'Republic-of-Macedonia' => '15', 'Romania' => '9', 'Russia' => '2', 'Serbia' => '11', 'Slovenia' => '21', 'South-Korea' => '31', 'Spain' => '5', 'Sweden' => '17', 'Switzerland' => '39', 'Taiwan' => '32', 'Thailand' => '63', 'Turkey' => '22', 'Ukraine' => '16', 'United-Kingdom' => '6', 'USA' => '26', 'Vietnam' => '60');
  6.  
  7. $server = $_GET['server'];
  8. $server = 'primera';
  9.  
  10. $pob_profil = file_get_contents('http://vei.cba.pl/*************');
  11.  
  12. $matches = array();
  13. preg_match("'JSESSIONID=(.*?);'si",$pob_profil,$matches);
  14. $cookie = 'JSESSIONID=' . urlencode(''.$matches[1].'') . '; Expires=' . urlencode('Tue, 26-Oct-2014 17:21:59');
  15.  
  16. if ($_GET['round'] != null)
  17. {
  18. $ch = curl_init('http://'.$server.'.e-sim.org/battle.html?id='.$_GET['id'].'&round='.$_GET['round'].'');
  19. }
  20. else
  21. {
  22. $ch = curl_init('http://'.$server.'.e-sim.org/battle.html?id='.$_GET['id'].'');
  23. }
  24.  
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  26. curl_setopt ($ch, CURLOPT_COOKIE, $cookie);
  27. curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
  28. $content = curl_exec($ch);
  29. curl_close($ch);
  30.  
  31. if( strpos($content,'No battle id') !== false )
  32. {
  33. $end = microtime(true);
  34. $time = number_format(($end - $start), 2);
  35. $result = json_encode(array('error' => 'No battle id', 'load' => $time));
  36. }
  37. elseif ( strpos($content,'No such battle round') !== false )
  38. {
  39. $end = microtime(true);
  40. $time = number_format(($end - $start), 2);
  41. $result = json_encode(array('error' => 'No such battle round', 'load' => $time));
  42.  
  43. }elseif (strpos($content,'No such battle') !== false)
  44. {
  45. $end = microtime(true);
  46. $time = number_format(($end - $start), 2);
  47. $result = json_encode(array('error' => 'No such battle', 'load' => $time));
  48. }
  49. else
  50. {
  51.  
  52.  
  53. preg_match('/<a\s+class="fightFont"\s+href="region\.html\?id=(.*?)">(.*?)<\/a>/',$content,$regionArray);
  54. preg_match_all('/<div class="fightFlag flags-big (.*?)"><\/div>/',$content,$defenderArray);
  55.  
  56. preg_match('/<span class="fightFont" style="font-size:1.6em">Round (.*?)<\/span>/',$content,$roundArray);
  57. preg_match('/<b>This round was won by:<\/b>\s+<br \/>\s+ <div class="fightFlag flags-medium (.*?)">/',$content,$roundWonBy);
  58.  
  59.  
  60. $regionId = $regionArray[1];
  61. $regionName = $regionArray[2];
  62. $round = $roundArray[1];
  63.  
  64. usleep(200000);
  65. $esimApiContent = json_decode(file_get_contents('http://primera.e-sim.org/apiFights.html?battleId='.$_GET['id'].'&roundId='.$round));
  66.  
  67. $lastHitTime = $esimApiContent[0]->{'time'};
  68.  
  69. $roundStatus = 'open';
  70. if (strpos($content,'This round was won by') !== false) {
  71. $roundStatus = 'closed';
  72. }
  73.  
  74.  
  75. $attacker = $defenderArray[1][1];
  76. $attackerScore = str_replace(',',"",$attackerScoreArray[1]);
  77. $attackerBar = $attackerStatArray[1];
  78.  
  79. $type = 'Direct War';
  80. if (strpos($content,'Resistance war started by') !== false) {
  81. $type = 'Resistance War';
  82. }
  83.  
  84. $end = microtime(true);
  85. $time = number_format(($end - $start), 2);
  86.  
  87. $result = json_encode(array('type' => $type,'region' => array('id' => $regionId, 'name' => $regionName), 'round' => $round, 'roundStatus' => $roundStatus, 'roundWonBy' => $roundWonBy[1], 'roundWonById' => $countries[$roundWonBy[1]], 'lastHitTime' => $lastHitTime, 'load' => $time));
  88.  
  89.  
  90.  
  91. }
  92.  
  93. print_r($result);
  94.  
  95. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement