Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/php -q
- <?php
- // Created: Slig
- // Updated: Xymph
- require('GbxRemote.inc.php');
- $ip = '127.0.0.1';
- $port = 5000;
- $user = 'SuperAdmin';
- $pass = 'SuperAdmin';
- $multicall = array();
- $isDedicated = true;
- $client = new IXR_Client_Gbx;
- if (!$client->InitWithIp($ip, $port)) {
- die('An error occurred - '.$client->getErrorCode().':'.$client->getErrorMessage());
- }
- print "Init ok, authenticate...\n";
- if (!$client->query('Authenticate', $user, $pass)) {
- Error($client->getErrorMessage(), $client->getErrorCode());
- print 'login failed ! Error '.$client->getErrorCode().': '.$client->getErrorMessage()."\n";
- }
- function addCall() {
- global $multicall, $isDedicated;
- $args = func_get_args();
- $methodName = array_shift($args);
- // if ingame serrver, replace ChatSendServerMessage with ChatSend
- if (!$isDedicated && ($methodName == 'ChatSendServerMessage'))
- $methodName = 'ChatSend';
- // forbid to ChatSendXX an empty message
- if (strncmp($methodName, 'ChatSend', 8) == 0) {
- if (!isset($args[0]) || (strlen(trim($args[0])) == 0)) {
- console('Tried to send an empty string: ' . $args[0]);
- return -1;
- }
- }
- $call = array('methodName' => $methodName, 'params' => $args);
- $index = count($multicall);
- $multicall[] = $call;
- return $index;
- }
- function showIt($key, $val, $indent) {
- if (is_array($val)) {
- print $indent.'*'.$key." :\n";
- foreach ($val as $key2 => $val2) {
- showIt($key2, $val2, ' '.$indent);
- }
- } else {
- print $indent.$key.' = '.$val."\n";
- }
- }
- function gettime() {
- return floor(microtime(true)*1000);
- }
- $tstart = gettime();
- $multicall = array();
- addCall('EnableCallbacks', true);
- addCall('GetStatus');
- addCall('SetApiVersion', '2011-10-06');
- addCall('GetVersion');
- if ($client->query('system.multicall', $multicall)) {
- $res = $client->getCBResponses();
- showIt('CallBacks', $res, '');
- $res = $client->getResponse();
- showIt('Results', $res, '');
- $version = $res[2][0]['Version'];
- } else {
- print 'Can\'t do/get '.$method.' ! Error '.$client->getErrorCode().': '.$client->getErrorMessage()."\n";
- }
- echo "\n\n";
- $oldcode = -1;
- while (true) {
- $read = array($client->socket);
- $nb = @stream_select($read, $write = NULL, $except = NULL, 0, 1000000);
- if ($nb === false) {
- echo 'Error, wait 5s then retry...';
- usleep(5000000);
- continue;
- } elseif ($nb > 0) {
- $client->readCB(0);
- $res = $client->getCBResponses();
- showIt('**CallBacks', $res, '');
- foreach ($res as $r) {
- foreach ($res as $r) {
- if ($r[0] == 'TrackMania.BeginChallenge' && $version >= '3.1.0') {
- $tstart = gettime();
- echo "\n";
- } elseif ($r[0] == 'TrackMania.BeginRace' && $version < '3.1.0') {
- $tstart = gettime();
- echo "\n";
- }
- if ($r[0] == 'TrackMania.PlayerInfoChanged') {
- echo sprintf('%7.3f', (gettime()-$tstart)/1000).': '.$r[0]."()\n";
- showIt('SPlayerInfo', $r[1][0],' ');
- } elseif ($r[0] == 'TrackMania.BeginRace') {
- echo sprintf('%7.3f', (gettime()-$tstart)/1000).': '.$r[0]."()\n";
- showIt('SChallengeInfo', $r[1][0],' ');
- } elseif ($r[0] == 'TrackMania.EndRace') {
- echo sprintf('%7.3f', (gettime()-$tstart)/1000).': '.$r[0]."()\n";
- showIt('SChallengeInfo', $r[1][1],' ');
- showIt('SPlayerRanking', $r[1][0],' ');
- } elseif ($r[0] == 'TrackMania.BeginChallenge') {
- echo sprintf('%7.3f', (gettime()-$tstart)/1000).': '.$r[0]."()\n";
- showIt('SChallengeInfo', $r[1][0],' ');
- showIt('WarmUp', $r[1][1],' ');
- showIt('MatchContinuation', $r[1][2],' ');
- } elseif ($r[0] == 'TrackMania.EndChallenge') {
- echo sprintf('%7.3f', (gettime()-$tstart)/1000).': '.$r[0]."()\n";
- showIt('SChallengeInfo', $r[1][1],' ');
- showIt('SPlayerRanking', $r[1][0],' ');
- showIt('WasWarmUp', $r[1][2],' ');
- showIt('MatchContinuesOnNextChallenge', $r[1][3],' ');
- showIt('RestartChallenge', $r[1][4],' ');
- } elseif ($r[0] == 'TrackMania.RulesScriptCallback') {
- echo sprintf('%7.3f', (gettime()-$tstart)/1000).': '.$r[0]."()\n";
- showIt('Param1', $r[1][0],' ');
- showIt('Param2', $r[1][1],' ');
- } else {
- echo sprintf('%7.3f', (gettime()-$tstart)/1000).': '.$r[0].'('.(isset($r[1]) ? (is_array($r[1])? @implode(', ', $r[1]) : '') : '').")\n";
- }
- }
- }
- }
- }
- $client->Terminate();
- ?>
Add Comment
Please, Sign In to add comment