Guest User

Untitled

a guest
Aug 24th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. #!/usr/local/bin/php -q
  2. <?php
  3. // Created: Slig
  4. // Updated: Xymph
  5. require('GbxRemote.inc.php');
  6.  
  7. $ip = '127.0.0.1';
  8. $port = 5000;
  9. $user = 'SuperAdmin';
  10. $pass = 'SuperAdmin';
  11.  
  12. $multicall = array();
  13. $isDedicated = true;
  14.  
  15. $client = new IXR_Client_Gbx;
  16.  
  17. if (!$client->InitWithIp($ip, $port)) {
  18. die('An error occurred - '.$client->getErrorCode().':'.$client->getErrorMessage());
  19. }
  20. print "Init ok, authenticate...\n";
  21. if (!$client->query('Authenticate', $user, $pass)) {
  22. Error($client->getErrorMessage(), $client->getErrorCode());
  23. print 'login failed ! Error '.$client->getErrorCode().': '.$client->getErrorMessage()."\n";
  24. }
  25.  
  26. function addCall() {
  27. global $multicall, $isDedicated;
  28. $args = func_get_args();
  29. $methodName = array_shift($args);
  30. // if ingame serrver, replace ChatSendServerMessage with ChatSend
  31. if (!$isDedicated && ($methodName == 'ChatSendServerMessage'))
  32. $methodName = 'ChatSend';
  33. // forbid to ChatSendXX an empty message
  34. if (strncmp($methodName, 'ChatSend', 8) == 0) {
  35. if (!isset($args[0]) || (strlen(trim($args[0])) == 0)) {
  36. console('Tried to send an empty string: ' . $args[0]);
  37. return -1;
  38. }
  39. }
  40. $call = array('methodName' => $methodName, 'params' => $args);
  41. $index = count($multicall);
  42. $multicall[] = $call;
  43. return $index;
  44. }
  45.  
  46. function showIt($key, $val, $indent) {
  47. if (is_array($val)) {
  48. print $indent.'*'.$key." :\n";
  49. foreach ($val as $key2 => $val2) {
  50. showIt($key2, $val2, ' '.$indent);
  51. }
  52. } else {
  53. print $indent.$key.' = '.$val."\n";
  54. }
  55. }
  56.  
  57. function gettime() {
  58. return floor(microtime(true)*1000);
  59. }
  60.  
  61. $tstart = gettime();
  62.  
  63. $multicall = array();
  64. addCall('EnableCallbacks', true);
  65. addCall('GetStatus');
  66. addCall('SetApiVersion', '2011-10-06');
  67. addCall('GetVersion');
  68. if ($client->query('system.multicall', $multicall)) {
  69. $res = $client->getCBResponses();
  70. showIt('CallBacks', $res, '');
  71. $res = $client->getResponse();
  72. showIt('Results', $res, '');
  73. $version = $res[2][0]['Version'];
  74. } else {
  75. print 'Can\'t do/get '.$method.' ! Error '.$client->getErrorCode().': '.$client->getErrorMessage()."\n";
  76. }
  77. echo "\n\n";
  78.  
  79. $oldcode = -1;
  80. while (true) {
  81. $read = array($client->socket);
  82. $nb = @stream_select($read, $write = NULL, $except = NULL, 0, 1000000);
  83. if ($nb === false) {
  84. echo 'Error, wait 5s then retry...';
  85. usleep(5000000);
  86. continue;
  87. } elseif ($nb > 0) {
  88. $client->readCB(0);
  89. $res = $client->getCBResponses();
  90. showIt('**CallBacks', $res, '');
  91. foreach ($res as $r) {
  92. foreach ($res as $r) {
  93. if ($r[0] == 'TrackMania.BeginChallenge' && $version >= '3.1.0') {
  94. $tstart = gettime();
  95. echo "\n";
  96. } elseif ($r[0] == 'TrackMania.BeginRace' && $version < '3.1.0') {
  97. $tstart = gettime();
  98. echo "\n";
  99. }
  100. if ($r[0] == 'TrackMania.PlayerInfoChanged') {
  101. echo sprintf('%7.3f', (gettime()-$tstart)/1000).': '.$r[0]."()\n";
  102. showIt('SPlayerInfo', $r[1][0],' ');
  103. } elseif ($r[0] == 'TrackMania.BeginRace') {
  104. echo sprintf('%7.3f', (gettime()-$tstart)/1000).': '.$r[0]."()\n";
  105. showIt('SChallengeInfo', $r[1][0],' ');
  106. } elseif ($r[0] == 'TrackMania.EndRace') {
  107. echo sprintf('%7.3f', (gettime()-$tstart)/1000).': '.$r[0]."()\n";
  108. showIt('SChallengeInfo', $r[1][1],' ');
  109. showIt('SPlayerRanking', $r[1][0],' ');
  110. } elseif ($r[0] == 'TrackMania.BeginChallenge') {
  111. echo sprintf('%7.3f', (gettime()-$tstart)/1000).': '.$r[0]."()\n";
  112. showIt('SChallengeInfo', $r[1][0],' ');
  113. showIt('WarmUp', $r[1][1],' ');
  114. showIt('MatchContinuation', $r[1][2],' ');
  115. } elseif ($r[0] == 'TrackMania.EndChallenge') {
  116. echo sprintf('%7.3f', (gettime()-$tstart)/1000).': '.$r[0]."()\n";
  117. showIt('SChallengeInfo', $r[1][1],' ');
  118. showIt('SPlayerRanking', $r[1][0],' ');
  119. showIt('WasWarmUp', $r[1][2],' ');
  120. showIt('MatchContinuesOnNextChallenge', $r[1][3],' ');
  121. showIt('RestartChallenge', $r[1][4],' ');
  122. } elseif ($r[0] == 'TrackMania.RulesScriptCallback') {
  123. echo sprintf('%7.3f', (gettime()-$tstart)/1000).': '.$r[0]."()\n";
  124. showIt('Param1', $r[1][0],' ');
  125. showIt('Param2', $r[1][1],' ');
  126. } else {
  127. echo sprintf('%7.3f', (gettime()-$tstart)/1000).': '.$r[0].'('.(isset($r[1]) ? (is_array($r[1])? @implode(', ', $r[1]) : '') : '').")\n";
  128. }
  129. }
  130. }
  131. }
  132. }
  133.  
  134. $client->Terminate();
  135. ?>
Add Comment
Please, Sign In to add comment