diff --git a/.gitignore b/.gitignore index 069bcd1..aa2c50d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/scripts .gitignore -docker-compose.yml -/.tmp \ No newline at end of file +/.tmp +.env +.env-mysql \ No newline at end of file diff --git a/TODO.md b/TODO.md deleted file mode 100644 index 9e7a106..0000000 --- a/TODO.md +++ /dev/null @@ -1,2 +0,0 @@ -# TODO's - - test runs diff --git a/entrypoint-tmserver.sh b/entrypoint-tmserver.sh deleted file mode 100755 index 1c25a2c..0000000 --- a/entrypoint-tmserver.sh +++ /dev/null @@ -1,135 +0,0 @@ -#!/bin/bash -# - -set -e - -if [[ "$(id -u)" = "0" ]]; then - chown -R trackmania /opt/tmserver - exec su-exec trackmania "$0" -fi - -# Change dir to /opt/tmserver -cd /opt/tmserver - -# Evaluate all the available environment variables -if [[ -z "${SERVER_LOGIN}" ]]; then - echo "Server account login is missing. Server cannot start." - echo "Please set environment variable SERVER_LOGIN." - exit 9 -fi -if [[ -z "${SERVER_LOGIN_PASSWORD}" ]]; then - echo "Server account password is missing. Server cannot start." - echo "Please set environment variable SERVER_LOGIN_PASSWORD." - exit 9 -fi -if [[ -z "${SERVER_PORT}" ]]; then - echo "No server port was set. Defaulting to port 2350" - export SERVER_PORT="2350" -fi -if [[ -z "${SERVER_P2P_PORT}" ]]; then - echo "No server peer2peer port was set. Defaulting to port 3450" - export SERVER_P2P_PORT="3450" -fi -if [[ -z "${SERVER_SA_PASSWORD}" ]]; then - echo "No SuperAdmin password was set. Generating a random one. You can change it afterwards but it's also not that important" - echo "Might aswell leave it as randomly generated" - export SERVER_SA_PASSWORD=$(pwgen -s 12) - echo "SuperAdmin password: ${SERVER_SA_PASSWORD}" - echo "Please write this down or pipe the docker logs to a file." -fi -if [[ -z "${SERVER_ADM_PASSWORD}" ]]; then - echo "No Admin password was set. Generating a random one. You can change it afterwards but it's also not that important" - echo "Might aswell leave it as randomly generated" - export SERVER_ADM_PASSWORD=$(pwgen -s 12) - echo "Admin password: ${SERVER_ADM_PASSWORD}" - echo "Please write this down or pipe the docker logs to a file." -fi -if [[ -z "${SERVER_NAME}" ]]; then - echo "No server name was set. Defaulting to 'Trackmania Server'" - export SERVER_NAME="Trackmania Server" -fi -if [[ -z "${SERVER_COMMENT}" ]]; then - echo "No server description was set. Defaulting to 'This is a Trackmania Server'" - export SERVER_COMMENT="This is a Trackmania Server" -fi - -if [[ -z "${GAMEMODE}" ]]; then - echo "No gamemode was specified. Defaulting to TimeAttack." - export GAMEMODE="1" -fi - -if [[ -z "${CHATTIME}" ]]; then - echo "No chat timeout was specified. Defaulting to 10000 ms." - export CHATTIME="10000" -fi - -if [[ -z "${FINISHTIMEOUT}" ]]; then - echo "No finish timeout was specified. Defaulting to adaptive mode." - export FINISHTIMEOUT="1" -fi - -if [[ -z "${DISABLERESPAWN}" ]]; then - echo "Respawns were not specified. Defaulting to enabled." - export DISABLERESPAWN="0" -fi - -if [[ -z "${ROUNDS_POINTSLIMIT}" ]]; then - echo "No points limit was specified for rounds mode. Defaulting to 30." - export ROUNDS_POINTSLIMIT="30" -fi - -if [[ -z "${TIMEATTACK_LIMIT}" ]]; then - echo "No time limit was specified for time attack mode. Defaulting to 180000 ms." - export TIMEATTACK_LIMIT="180000" -fi - -if [[ -z "${TEAM_POINTSLIMIT}" ]]; then - echo "No points limit was specified for team mode. Defaulting to 50." - export TEAM_POINTSLIMIT="50" -fi - -if [[ -z "${TEAM_MAXPOINTS}" ]]; then - echo "No number of maximum points per round was specified for team mode. Defaulting to 6." - export TEAM_MAXPOINTS="6" -fi - -if [[ -z "${LAPS_NBLAPS}" ]]; then - echo "No number of laps was specified for laps mode. Defaulting to 5." - export LAPS_NBLAPS="5" -fi - -if [[ -z "${LAPS_TIMELIMIT}" ]]; then - echo "No time limit was specified for laps mode. Defaulting to no limit." - export LAPS_TIMELIMIT="0" -fi - - -echo "Evaluation over" -echo "Checking for custom playlist" - - CUSTOM_PLAYLIST='playlist/playlist.txt' - TEMPLATE_FILE='GameData/Tracks/MatchSettings/_playlist.txt' - TEMPLATE_FILE_TEMP='GameData/Tracks/MatchSettings/_playlist.txt.tmp' - PLAYLIST_FILE_TEMP='GameData/Tracks/MatchSettings/playlist.txt.tmp' - cp $TEMPLATE_FILE $PLAYLIST_FILE_TEMP -if [[ -f 'playlist/playlist.txt' ]]; then - count=1 - while read l; do - xmlstarlet ed -s /playlist -t elem -n challenge $PLAYLIST_FILE_TEMP > $TEMPLATE_FILE_TEMP - xmlstarlet ed -s "/playlist/challenge[${count}]" -t elem -n file -v "${l}" $TEMPLATE_FILE_TEMP > $PLAYLIST_FILE_TEMP - count=$((count+1)) - done < $CUSTOM_PLAYLIST -else - xmlstarlet ed -s /playlist -t elem -n challenge $PLAYLIST_FILE_TEMP > $TEMPLATE_FILE_TEMP - xmlstarlet ed -s "playlist/challenge[1]" -t elem -n file -v "Challenges/Nadeo/A01-Race.Challenge.Gbx" $TEMPLATE_FILE_TEMP > $PLAYLIST_FILE_TEMP -fi - -echo "Evaluating custom playlist over" -echo "Substition in config files" - -#Trackmania Files - -envsubst < GameData/Config/_config.txt > GameData/Config/config.txt -envsubst < $PLAYLIST_FILE_TEMP > GameData/Tracks/MatchSettings/playlist.txt - -exec "./TrackmaniaServer" "/nodaemon" "/internet" "/game_settings=MatchSettings/playlist.txt" "/dedicated_cfg=config.txt" diff --git a/tmserver/GameData/Config/_config.txt b/tmserver/GameData/Config/_config.txt deleted file mode 100644 index c07c46c..0000000 --- a/tmserver/GameData/Config/_config.txt +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - SuperAdmin - $SERVER_SA_PASSWORD - - - Admin - $SERVER_ADM_PASSWORD - - - User - User - - - - - $SERVER_LOGIN - $SERVER_LOGIN_PASSWORD - - - - - $SERVER_NAME - $SERVER_COMMENT - 0 - - 32 - $SERVER_PASSWORD - - 32 - - - forced - 0 - 50000 - - True - True - - 60000 - 0.5 - - - - - - True - False - False - - - 0 - - False - - - - 512 - 8192 - - - $SERVER_PORT - $SERVER_P2P_PORT - 0 - - - - 600 - - 5000 - True - - - - - - stadium - - False - - - - - - False - - - - diff --git a/tmserver/GameData/Tracks/MatchSettings/_playlist.txt b/tmserver/GameData/Tracks/MatchSettings/_playlist.txt deleted file mode 100644 index ade1d73..0000000 --- a/tmserver/GameData/Tracks/MatchSettings/_playlist.txt +++ /dev/null @@ -1,39 +0,0 @@ - - - - $GAMEMODE - $CHATTIME - $FINISHTIMEOUT - 0 - $DISABLERESPAWN - 0 - $ROUNDS_POINTSLIMIT - 0 - 0 - 5 - $TEAM_POINTSLIMIT - $TEAM_MAXPOINTS - 0 - 5 - $TIMEATTACK_LIMIT - 0 - $LAPS_NBLAPS - $LAPS_TIMELIMIT - 100 - 5 - 3 - 2 - - - - 1 - 1 - 0 - 0 - 7 - 0 - 0 - - - 0 - diff --git a/tmserver/RemoteControlExamples/PhpRemote/GbxRemote.bem.php b/tmserver/RemoteControlExamples/PhpRemote/GbxRemote.bem.php deleted file mode 100644 index cb590b4..0000000 --- a/tmserver/RemoteControlExamples/PhpRemote/GbxRemote.bem.php +++ /dev/null @@ -1,867 +0,0 @@ - htmlspecialchars) - Site: http://scripts.incutio.com/xmlrpc/ - Manual: http://scripts.incutio.com/xmlrpc/manual.php - Made available under the Artistic License: http://www.opensource.org/licenses/artistic-license.php - - Modified to support protocol 'GbxRemote 2' ('GbxRemote 1') - This version is for BigEndian machines. For LittleEndian (e.g. Intel PC) - machines use the original GbxRemote.inc.php instead. - - Release 2007-09-22 - Slig: - Modified to support >256KB received data (and now >2MB data produce a specific error message) - Modified readCB() to wait the initial timeout only before first read packet - Modified readCB() to return true if there is data to get with getCBResponses() - Modified to support amd64 (for $recvhandle) - Modified IXR_ClientMulticall_Gbx->addCall() to fit Aseco 0.6.1 - Added IXR_Client_Gbx->bytes_sent & bytes_received counters - Fix for a changed feature since php5.1.1 about reference parameter assignment (was used in stream_select) - Workaround for stream_select return value bug with amd64 - - Release 2008-01-20 - Slig / Xymph / Assembler Maniac: - Workaround for fread delay bug in some cases - Added resetError method (by Xymph) - Some comments and strings code cleanup (by Xymph) - Fix stream_set_timeout($this->socket,...) (thx to CavalierDeVache) - Added a default timeout value to function readCB($timeout) - Changed calls with timeout on a stream to use microseconds instead of seconds (by AM) - Removed IXR_Client_Gbx->bytes_sent & bytes_received counters - not used (by AM) - - Release 2008-02-05 - Slig: - Changed some socket read/write timeouts back to seconds to avoid 'transport error' - Changed max data received from 2MB to 4MB - - Release 2008-05-20 - Xymph: - Prevented unpack() warnings in query method when the connection dies - Changed resetError method to assign 'false' for correct isError method - Tweaked some 'transport error' messages - - Release 2009-04-08 - Gou1: - Added method IXR_Client_Gbx::queryIgnoreResult() - Added methods IXR_Client_Gbx::sendRequest() & IXR_Client_Gbx::getResult() - IXR_Client_Gbx::queryIgnoreResult checks if the request is larger than 512KB to avoid errors - If larger than 512KB and method is system.multicall, try to divide the request into - two separate requests with two separate IXR_Client_Gbx::queryIgnoreResult() calls - - Release 2009-06-03 - Xymph: - Suppress possible repetitive CRT warning at stream_select -*/ - -if (!defined('LF')) { - define('LF', "\n"); -} - -class IXR_Value { - public $data; - public $type; - - function IXR_Value ($data, $type = false) { - $this->data = $data; - if (!$type) { - $type = $this->calculateType(); - } - $this->type = $type; - if ($type == 'struct') { - // Turn all the values in the array into new IXR_Value objects - foreach ($this->data as $key => $value) { - $this->data[$key] = new IXR_Value($value); - } - } - if ($type == 'array') { - for ($i = 0, $j = count($this->data); $i < $j; $i++) { - $this->data[$i] = new IXR_Value($this->data[$i]); - } - } - } - - function calculateType() { - if ($this->data === true || $this->data === false) { - return 'boolean'; - } - if (is_integer($this->data)) { - return 'int'; - } - if (is_double($this->data)) { - return 'double'; - } - // Deal with IXR object types base64 and date - if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { - return 'date'; - } - if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { - return 'base64'; - } - // If it is a normal PHP object convert it into a struct - if (is_object($this->data)) { - $this->data = get_object_vars($this->data); - return 'struct'; - } - if (!is_array($this->data)) { - return 'string'; - } - // We have an array - is it an array or a struct? - if ($this->isStruct($this->data)) { - return 'struct'; - } else { - return 'array'; - } - } - - function getXml() { - // Return XML for this value - switch ($this->type) { - case 'boolean': - return '' . ($this->data ? '1' : '0') . ''; - break; - case 'int': - return '' . $this->data . ''; - break; - case 'double': - return '' . $this->data . ''; - break; - case 'string': - return '' . htmlspecialchars($this->data) . ''; - break; - case 'array': - $return = '' . LF; - foreach ($this->data as $item) { - $return .= ' ' . $item->getXml() . '' . LF; - } - $return .= ''; - return $return; - break; - case 'struct': - $return = '' . LF; - foreach ($this->data as $name => $value) { - $return .= ' ' . $name . ''; - $return .= $value->getXml() . '' . LF; - } - $return .= ''; - return $return; - break; - case 'date': - case 'base64': - return $this->data->getXml(); - break; - } - return false; - } - - function isStruct($array) { - // Nasty function to check if an array is a struct or not - $expected = 0; - foreach ($array as $key => $value) { - if ((string)$key != (string)$expected) { - return true; - } - $expected++; - } - return false; - } -} - - -class IXR_Message { - public $message; - public $messageType; // methodCall / methodResponse / fault - public $faultCode; - public $faultString; - public $methodName; - public $params; - // Current variable stacks - protected $_arraystructs = array(); // Stack to keep track of the current array/struct - protected $_arraystructstypes = array(); // Stack to keep track of whether things are structs or array - protected $_currentStructName = array(); // A stack as well - protected $_param; - protected $_value; - protected $_currentTag; - protected $_currentTagContents; - // The XML parser - protected $_parser; - - function IXR_Message ($message) { - $this->message = $message; - } - - function parse() { - // first remove the XML declaration - $this->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $this->message); - if (trim($this->message) == '') { - return false; - } - $this->_parser = xml_parser_create(); - // Set XML parser to take the case of tags into account - xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); - // Set XML parser callback functions - xml_set_object($this->_parser, $this); - xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); - xml_set_character_data_handler($this->_parser, 'cdata'); - if (!xml_parse($this->_parser, $this->message)) { - /* die(sprintf('GbxRemote XML error: %s at line %d', - xml_error_string(xml_get_error_code($this->_parser)), - xml_get_current_line_number($this->_parser))); */ - return false; - } - xml_parser_free($this->_parser); - // Grab the error messages, if any - if ($this->messageType == 'fault') { - $this->faultCode = $this->params[0]['faultCode']; - $this->faultString = $this->params[0]['faultString']; - } - return true; - } - - function tag_open($parser, $tag, $attr) { - $this->currentTag = $tag; - switch ($tag) { - case 'methodCall': - case 'methodResponse': - case 'fault': - $this->messageType = $tag; - break; - // Deal with stacks of arrays and structs - case 'data': // data is to all intents and purposes more interesting than array - $this->_arraystructstypes[] = 'array'; - $this->_arraystructs[] = array(); - break; - case 'struct': - $this->_arraystructstypes[] = 'struct'; - $this->_arraystructs[] = array(); - break; - } - } - - function cdata($parser, $cdata) { - $this->_currentTagContents .= $cdata; - } - - function tag_close($parser, $tag) { - $valueFlag = false; - switch ($tag) { - case 'int': - case 'i4': - $value = (int)trim($this->_currentTagContents); - $this->_currentTagContents = ''; - $valueFlag = true; - break; - case 'double': - $value = (double)trim($this->_currentTagContents); - $this->_currentTagContents = ''; - $valueFlag = true; - break; - case 'string': - $value = (string)trim($this->_currentTagContents); - $this->_currentTagContents = ''; - $valueFlag = true; - break; - case 'dateTime.iso8601': - $value = new IXR_Date(trim($this->_currentTagContents)); - // $value = $iso->getTimestamp(); - $this->_currentTagContents = ''; - $valueFlag = true; - break; - case 'value': - // If no type is indicated, the type is string - if (trim($this->_currentTagContents) != '') { - $value = (string)$this->_currentTagContents; - $this->_currentTagContents = ''; - $valueFlag = true; - } - break; - case 'boolean': - $value = (boolean)trim($this->_currentTagContents); - $this->_currentTagContents = ''; - $valueFlag = true; - break; - case 'base64': - $value = base64_decode($this->_currentTagContents); - $this->_currentTagContents = ''; - $valueFlag = true; - break; - // Deal with stacks of arrays and structs - case 'data': - case 'struct': - $value = array_pop($this->_arraystructs); - array_pop($this->_arraystructstypes); - $valueFlag = true; - break; - case 'member': - array_pop($this->_currentStructName); - break; - case 'name': - $this->_currentStructName[] = trim($this->_currentTagContents); - $this->_currentTagContents = ''; - break; - case 'methodName': - $this->methodName = trim($this->_currentTagContents); - $this->_currentTagContents = ''; - break; - } - - if ($valueFlag) { - /* - if (!is_array($value) && !is_object($value)) { - $value = trim($value); - } - */ - if (count($this->_arraystructs) > 0) { - // Add value to struct or array - if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { - // Add to struct - $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; - } else { - // Add to array - $this->_arraystructs[count($this->_arraystructs)-1][] = $value; - } - } else { - // Just add as a paramater - $this->params[] = $value; - } - } - } -} - - -class IXR_Request { - public $method; - public $args; - public $xml; - - function IXR_Request($method, $args) { - $this->method = $method; - $this->args = $args; - $this->xml = '' . $this->method . ''; - foreach ($this->args as $arg) { - $this->xml .= ''; - $v = new IXR_Value($arg); - $this->xml .= $v->getXml(); - $this->xml .= '' . LF; - } - $this->xml .= ''; - } - - function getLength() { - return strlen($this->xml); - } - - function getXml() { - return $this->xml; - } -} - - -class IXR_Error { - public $code; - public $message; - - function IXR_Error($code, $message) { - $this->code = $code; - $this->message = $message; - } - - function getXml() { - $xml = << - - - - - faultCode - {$this->code} - - - faultString - {$this->message} - - - - - -EOD; - return $xml; - } -} - - -class IXR_Date { - public $year; - public $month; - public $day; - public $hour; - public $minute; - public $second; - - function IXR_Date($time) { - // $time can be a PHP timestamp or an ISO one - if (is_numeric($time)) { - $this->parseTimestamp($time); - } else { - $this->parseIso($time); - } - } - - function parseTimestamp($timestamp) { - $this->year = date('Y', $timestamp); - $this->month = date('Y', $timestamp); - $this->day = date('Y', $timestamp); - $this->hour = date('H', $timestamp); - $this->minute = date('i', $timestamp); - $this->second = date('s', $timestamp); - } - - function parseIso($iso) { - $this->year = substr($iso, 0, 4); - $this->month = substr($iso, 4, 2); - $this->day = substr($iso, 6, 2); - $this->hour = substr($iso, 9, 2); - $this->minute = substr($iso, 12, 2); - $this->second = substr($iso, 15, 2); - } - - function getIso() { - return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second; - } - - function getXml() { - return ''.$this->getIso().''; - } - - function getTimestamp() { - return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); - } -} - - -class IXR_Base64 { - public $data; - - function IXR_Base64($data) { - $this->data = $data; - } - - function getXml() { - return ''.base64_encode($this->data).''; - } -} - - -////////////////////////////////////////////////////////// -// Nadeo modifications // -// (many thanks to slig for adding callback support) // -////////////////////////////////////////////////////////// -class IXR_Client_Gbx { - public $socket; - public $message = false; - public $cb_message = array(); - public $reqhandle; - public $protocol = 0; - // Storage place for an error message - public $error = false; - - function bigEndianTest() { - list($endiantest) = array_values(unpack('L1L', pack('V', 1))); - if ($endiantest == 1) { - echo "Machine reports itself as LittleEndian, float handling will work correctly with unpack\r\n"; - echo "Use original GbxRemote.inc.php instead of GbxRemote.bem.php\r\n"; - die('App Terminated'); - return false; - } - return true; - } // bigEndianTest - - function IXR_Client_Gbx() { - $this->socket = false; - $this->reqhandle = 0x80000000; - } - - function InitWithIp($ip, $port) { - - if (!$this->bigEndianTest()) { - $this->error = new IXR_Error(-32999, 'endian error - script doesn\'t match machine type'); - return false; - } - - // open connection - $this->socket = @fsockopen($ip, $port, $errno, $errstr); - if (!$this->socket) { - $this->error = new IXR_Error(-32300, "transport error - could not open socket (error: $errno, $errstr)"); - return false; - } - // handshake - $array_result = big_endian_unpack('Vsize', fread($this->socket, 4)); - $size = $array_result['size']; - if ($size > 64) { - $this->error = new IXR_Error(-32300, 'transport error - wrong lowlevel protocol header'); - return false; - } - $handshake = fread($this->socket, $size); - if ($handshake == 'GBXRemote 1') { - $this->protocol = 1; - } else if ($handshake == 'GBXRemote 2') { - $this->protocol = 2; - } else { - $this->error = new IXR_Error(-32300, 'transport error - wrong lowlevel protocol version'); - return false; - } - return true; - } - - function Init($port) { - return $this->InitWithIp('localhost', $port); - } - - function Terminate() { - if ($this->socket) { - fclose($this->socket); - $this->socket = false; - } - } - - protected function sendRequest(IXR_Request $request) { - $xml = $request->getXml(); - - @stream_set_timeout($this->socket, 20); // timeout 20 s (to write the request) - // send request - $this->reqhandle++; - if ($this->protocol == 1) { - $bytes = pack('Va*', strlen($xml), $xml); - } else { - $bytes = pack('VVa*', strlen($xml), $this->reqhandle, $xml); - } - - $bytes_to_write = strlen($bytes); - while ($bytes_to_write > 0) { - $r = fwrite($this->socket, $bytes); - if ($r === false || $r == 0) { - // connection interrupted - return false; // or die? - } - - $bytes_to_write -= $r; - if ($bytes_to_write == 0) - break; - - $bytes = substr($bytes, $r); - } - - return true; - } - - protected function getResult() { - $contents = ''; - $contents_length = 0; - do { - $size = 0; - $recvhandle = 0; - @stream_set_timeout($this->socket, 20); // timeout 20 s (to read the reply header) - // Get result - if ($this->protocol == 1) { - $contents = fread($this->socket, 4); - if (strlen($contents) == 0) { - $this->error = new IXR_Error(-32700, 'transport error - connection interrupted!'); - return false; - } - $array_result = big_endian_unpack('Vsize', $contents); - $size = $array_result['size']; - $recvhandle = $this->reqhandle; - } else { - $contents = fread($this->socket, 8); - if (strlen($contents) == 0) { - $this->error = new IXR_Error(-32700, 'transport error - connection interrupted!'); - return false; - } - $array_result = big_endian_unpack('Vsize/Vhandle', $contents); - $size = $array_result['size']; - $recvhandle = $array_result['handle']; - // -- amd64 support -- - $bits = sprintf('%b', $recvhandle); - if (strlen($bits) == 64) { - $recvhandle = bindec(substr($bits, 32)); - } - } - - if ($recvhandle == 0 || $size == 0) { - $this->error = new IXR_Error(-32700, 'transport error - connection interrupted!'); - return false; - } - if ($size > 4096*1024) { - $this->error = new IXR_Error(-32700, "transport error - answer too big ($size)"); - return false; - } - - $contents = ''; - $contents_length = 0; - @stream_set_timeout($this->socket, 0, 10000); // timeout 10 ms (for successive reads until end) - while ($contents_length < $size) { - $contents .= fread($this->socket, $size-$contents_length); - $contents_length = strlen($contents); - } - - if (($recvhandle & 0x80000000) == 0) { - // this is a callback, not our answer! handle= $recvhandle, xml-rpc= $contents - // just add it to the message list for the user to read - $new_cb_message = new IXR_Message($contents); - if ($new_cb_message->parse() && $new_cb_message->messageType != 'fault') { - array_push($this->cb_message, array($new_cb_message->methodName, $new_cb_message->params)); - } - } - } while ((int)$recvhandle != (int)$this->reqhandle); - - $this->message = new IXR_Message($contents); - if (!$this->message->parse()) { - // XML error - $this->error = new IXR_Error(-32700, 'parse error. not well formed'); - return false; - } - // Is the message a fault? - if ($this->message->messageType == 'fault') { - $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); - return false; - } - // Message must be OK - return true; - } - - - function query() { - $args = func_get_args(); - $method = array_shift($args); - - if (!$this->socket || $this->protocol == 0) { - $this->error = new IXR_Error(-32300, 'transport error - Client not initialized'); - return false; - } - - $request = new IXR_Request($method, $args); - - // Check if request is larger than 512 Kbytes - if ($request->getLength() > 512*1024-8) { - $this->error = new IXR_Error(-32700, 'transport error - request too large!'); - return false; - } - - // Send request - $ok = $this->sendRequest($request); - if (!$ok) { - $this->error = new IXR_Error(-32700, 'transport error - connection interrupted'); - return false; - } - - // Get result - return $this->getResult(); - } - - // Non-blocking query method: doesn't read the response - function queryIgnoreResult() { - $args = func_get_args(); - $method = array_shift($args); - - if (!$this->socket || $this->protocol == 0) { - $this->error = new IXR_Error(-32300, 'transport error - Client not initialized'); - return false; - } - - $request = new IXR_Request($method, $args); - - // Check if the request is greater than 512 Kbytes to avoid errors - // If the method is system.multicall, make two calls (possibly recursively) - if ($request->getLength() > 512*1024-8) { - if ($method = 'system.multicall' && isset($args[0])) { - $count = count($args[0]); - // If count is 1, query cannot be reduced - if ($count < 2) { - $this->error = new IXR_Error(-32700, 'transport error - request too large!'); - return false; - } - $length = floor($count/2); - - $args1 = array_slice($args[0], 0, $length); - $args2 = array_slice($args[0], $length, ($count-$length)); - - $res1 = $this->queryIgnoreResult('system.multicall', $args1); - $res2 = $this->queryIgnoreResult('system.multicall', $args2); - return ($res1 && $res2); - } - // If the method is not a multicall, just stop - else { - $this->error = new IXR_Error(-32700, 'transport error - request too large!'); - return false; - } - } - - // Send request - $ok = $this->sendRequest($request); - if (!$ok) { - $this->error = new IXR_Error(-32700, 'transport error - connection interrupted'); - return false; - } - } - - function readCB($timeout = 2000) { // timeout 2 ms - if (!$this->socket || $this->protocol == 0) { - $this->error = new IXR_Error(-32300, 'transport error - Client not initialized'); - return false; - } - if ($this->protocol == 1) - return false; - - $something_received = count($this->cb_message)>0; - $contents = ''; - $contents_length = 0; - - @stream_set_timeout($this->socket, 0, 10000); // timeout 10 ms (to read available data) - // (assignment in arguments is forbidden since php 5.1.1) - $read = array($this->socket); - $write = NULL; - $except = NULL; - $nb = @stream_select($read, $write, $except, 0, $timeout); - // workaround for stream_select bug with amd64 - if ($nb !== false) - $nb = count($read); - - while ($nb !== false && $nb > 0) { - $timeout = 0; // we don't want to wait for the full time again, just flush the available data - - $size = 0; - $recvhandle = 0; - // Get result - $contents = fread($this->socket, 8); - if (strlen($contents) == 0) { - $this->error = new IXR_Error(-32700, 'transport error - connection interrupted!'); - return false; - } - $array_result = big_endian_unpack('Vsize/Vhandle', $contents); - $size = $array_result['size']; - $recvhandle = $array_result['handle']; - - if ($recvhandle == 0 || $size == 0) { - $this->error = new IXR_Error(-32700, 'transport error - connection interrupted!'); - return false; - } - if ($size > 4096*1024) { - $this->error = new IXR_Error(-32700, "transport error - answer too big ($size)"); - return false; - } - - $contents = ''; - $contents_length = 0; - while ($contents_length < $size) { - $contents .= fread($this->socket, $size-$contents_length); - $contents_length = strlen($contents); - } - - if (($recvhandle & 0x80000000) == 0) { - // this is a callback. handle= $recvhandle, xml-rpc= $contents - //echo 'CALLBACK('.$contents_length.')[ '.$contents.' ]' . LF; - $new_cb_message = new IXR_Message($contents); - if ($new_cb_message->parse() && $new_cb_message->messageType != 'fault') { - array_push($this->cb_message, array($new_cb_message->methodName, $new_cb_message->params)); - } - $something_received = true; - } - - // (assignment in arguments is forbidden since php 5.1.1) - $read = array($this->socket); - $write = NULL; - $except = NULL; - $nb = @stream_select($read, $write, $except, 0, $timeout); - // workaround for stream_select bug with amd64 - if ($nb !== false) - $nb = count($read); - } - return $something_received; - } - - function getResponse() { - // methodResponses can only have one param - return that - return $this->message->params[0]; - } - - function getCBResponses() { - // (look at the end of basic.php for an example) - $messages = $this->cb_message; - $this->cb_message = array(); - return $messages; - } - - function isError() { - return is_object($this->error); - } - - function resetError() { - $this->error = false; - } - - function getErrorCode() { - return $this->error->code; - } - - function getErrorMessage() { - return $this->error->message; - } -} - - -class IXR_ClientMulticall_Gbx extends IXR_Client_Gbx { - public $calls = array(); - - function addCall($methodName, $args) { - $struct = array('methodName' => $methodName, 'params' => $args); - $this->calls[] = $struct; - - return (count($this->calls) - 1); - } - - function multiquery($ignoreResult = false) { - // Prepare multicall, then call the parent::query() (or queryIgnoreResult) method - if ($ignoreResult) { - $result = parent::queryIgnoreResult('system.multicall', $this->calls); - } else { - $result = parent::query('system.multicall', $this->calls); - } - $this->calls = array(); // reset for next calls - return $result; - } -} - -/** - * The following code is a workaround for php's unpack function which - * does not have the capability of unpacking double precision floats - * that were packed in the opposite byte order of the current machine. - */ -function big_endian_unpack($format, $data) { - $ar = unpack($format, $data); - $vals = array_values($ar); - $f = explode('/', $format); - $i = 0; - foreach ($f as $f_k => $f_v) { - $repeater = intval(substr($f_v, 1)); - if ($repeater == 0) - $repeater = 1; - if ($f_v{1} == '*') { - $repeater = count($ar) - $i; - } - if ($f_v{0} != 'd') { - $i += $repeater; - continue; - } - $j = $i + $repeater; - for ($a = $i; $a < $j; ++$a) { - $p = pack('d', $vals[$i]); - $p = strrev($p); - list($vals[$i]) = array_values(unpack('d1d', $p)); - ++$i; - } - } - $a = 0; - foreach ($ar as $ar_k => $ar_v) { - $ar[$ar_k] = $vals[$a]; - ++$a; - } - return $ar; -} -?> diff --git a/tmserver/RemoteControlExamples/PhpRemote/GbxRemote.inc.php b/tmserver/RemoteControlExamples/PhpRemote/GbxRemote.inc.php deleted file mode 100644 index f53e966..0000000 --- a/tmserver/RemoteControlExamples/PhpRemote/GbxRemote.inc.php +++ /dev/null @@ -1,830 +0,0 @@ - htmlspecialchars) - Site: http://scripts.incutio.com/xmlrpc/ - Manual: http://scripts.incutio.com/xmlrpc/manual.php - Made available under the Artistic License: http://www.opensource.org/licenses/artistic-license.php - - Modified to support protocol 'GbxRemote 2' ('GbxRemote 1') - This version is for LittleEndian (e.g. Intel PC) machines. - For BigEndian machines use GbxRemote.bem.php as GbxRemote.inc.php instead. - - Release 2007-09-22 - Slig: - Modified to support >256KB received data (and now >2MB data produce a specific error message) - Modified readCB() to wait the initial timeout only before first read packet - Modified readCB() to return true if there is data to get with getCBResponses() - Modified to support amd64 (for $recvhandle) - Modified IXR_ClientMulticall_Gbx->addCall() to fit Aseco 0.6.1 - Added IXR_Client_Gbx->bytes_sent & bytes_received counters - Fix for a changed feature since php5.1.1 about reference parameter assignment (was used in stream_select) - Workaround for stream_select return value bug with amd64 - - Release 2008-01-20 - Slig / Xymph / Assembler Maniac: - Workaround for fread delay bug in some cases - Added resetError method (by Xymph) - Some comments and strings code cleanup (by Xymph) - Fix stream_set_timeout($this->socket,...) (thx to CavalierDeVache) - Added a default timeout value to function readCB($timeout) - Changed calls with timeout on a stream to use microseconds instead of seconds (by AM) - Removed IXR_Client_Gbx->bytes_sent & bytes_received counters - not used (by AM) - - Release 2008-02-05 - Slig: - Changed some socket read/write timeouts back to seconds to avoid 'transport error' - Changed max data received from 2MB to 4MB - - Release 2008-05-20 - Xymph: - Prevented unpack() warnings in query method when the connection dies - Changed resetError method to assign 'false' for correct isError method - Tweaked some 'transport error' messages - - Release 2009-04-08 - Gou1: - Added method IXR_Client_Gbx::queryIgnoreResult() - Added methods IXR_Client_Gbx::sendRequest() & IXR_Client_Gbx::getResult() - IXR_Client_Gbx::queryIgnoreResult checks if the request is larger than 512KB to avoid errors - If larger than 512KB and method is system.multicall, try to divide the request into - two separate requests with two separate IXR_Client_Gbx::queryIgnoreResult() calls - - Release 2009-06-03 - Xymph: - Suppress possible repetitive CRT warning at stream_select -*/ - -if (!defined('LF')) { - define('LF', "\n"); -} - -class IXR_Value { - public $data; - public $type; - - function IXR_Value ($data, $type = false) { - $this->data = $data; - if (!$type) { - $type = $this->calculateType(); - } - $this->type = $type; - if ($type == 'struct') { - // Turn all the values in the array into new IXR_Value objects - foreach ($this->data as $key => $value) { - $this->data[$key] = new IXR_Value($value); - } - } - if ($type == 'array') { - for ($i = 0, $j = count($this->data); $i < $j; $i++) { - $this->data[$i] = new IXR_Value($this->data[$i]); - } - } - } - - function calculateType() { - if ($this->data === true || $this->data === false) { - return 'boolean'; - } - if (is_integer($this->data)) { - return 'int'; - } - if (is_double($this->data)) { - return 'double'; - } - // Deal with IXR object types base64 and date - if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { - return 'date'; - } - if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { - return 'base64'; - } - // If it is a normal PHP object convert it into a struct - if (is_object($this->data)) { - $this->data = get_object_vars($this->data); - return 'struct'; - } - if (!is_array($this->data)) { - return 'string'; - } - // We have an array - is it an array or a struct? - if ($this->isStruct($this->data)) { - return 'struct'; - } else { - return 'array'; - } - } - - function getXml() { - // Return XML for this value - switch ($this->type) { - case 'boolean': - return '' . ($this->data ? '1' : '0') . ''; - break; - case 'int': - return '' . $this->data . ''; - break; - case 'double': - return '' . $this->data . ''; - break; - case 'string': - return '' . htmlspecialchars($this->data) . ''; - break; - case 'array': - $return = '' . LF; - foreach ($this->data as $item) { - $return .= ' ' . $item->getXml() . '' . LF; - } - $return .= ''; - return $return; - break; - case 'struct': - $return = '' . LF; - foreach ($this->data as $name => $value) { - $return .= ' ' . $name . ''; - $return .= $value->getXml() . '' . LF; - } - $return .= ''; - return $return; - break; - case 'date': - case 'base64': - return $this->data->getXml(); - break; - } - return false; - } - - function isStruct($array) { - // Nasty function to check if an array is a struct or not - $expected = 0; - foreach ($array as $key => $value) { - if ((string)$key != (string)$expected) { - return true; - } - $expected++; - } - return false; - } -} - - -class IXR_Message { - public $message; - public $messageType; // methodCall / methodResponse / fault - public $faultCode; - public $faultString; - public $methodName; - public $params; - // Current variable stacks - protected $_arraystructs = array(); // Stack to keep track of the current array/struct - protected $_arraystructstypes = array(); // Stack to keep track of whether things are structs or array - protected $_currentStructName = array(); // A stack as well - protected $_param; - protected $_value; - protected $_currentTag; - protected $_currentTagContents; - // The XML parser - protected $_parser; - - function IXR_Message ($message) { - $this->message = $message; - } - - function parse() { - // first remove the XML declaration - $this->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $this->message); - if (trim($this->message) == '') { - return false; - } - $this->_parser = xml_parser_create(); - // Set XML parser to take the case of tags into account - xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); - // Set XML parser callback functions - xml_set_object($this->_parser, $this); - xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); - xml_set_character_data_handler($this->_parser, 'cdata'); - if (!xml_parse($this->_parser, $this->message)) { - /* die(sprintf('GbxRemote XML error: %s at line %d', - xml_error_string(xml_get_error_code($this->_parser)), - xml_get_current_line_number($this->_parser))); */ - return false; - } - xml_parser_free($this->_parser); - // Grab the error messages, if any - if ($this->messageType == 'fault') { - $this->faultCode = $this->params[0]['faultCode']; - $this->faultString = $this->params[0]['faultString']; - } - return true; - } - - function tag_open($parser, $tag, $attr) { - $this->currentTag = $tag; - switch ($tag) { - case 'methodCall': - case 'methodResponse': - case 'fault': - $this->messageType = $tag; - break; - // Deal with stacks of arrays and structs - case 'data': // data is to all intents and purposes more interesting than array - $this->_arraystructstypes[] = 'array'; - $this->_arraystructs[] = array(); - break; - case 'struct': - $this->_arraystructstypes[] = 'struct'; - $this->_arraystructs[] = array(); - break; - } - } - - function cdata($parser, $cdata) { - $this->_currentTagContents .= $cdata; - } - - function tag_close($parser, $tag) { - $valueFlag = false; - switch ($tag) { - case 'int': - case 'i4': - $value = (int)trim($this->_currentTagContents); - $this->_currentTagContents = ''; - $valueFlag = true; - break; - case 'double': - $value = (double)trim($this->_currentTagContents); - $this->_currentTagContents = ''; - $valueFlag = true; - break; - case 'string': - $value = (string)trim($this->_currentTagContents); - $this->_currentTagContents = ''; - $valueFlag = true; - break; - case 'dateTime.iso8601': - $value = new IXR_Date(trim($this->_currentTagContents)); - // $value = $iso->getTimestamp(); - $this->_currentTagContents = ''; - $valueFlag = true; - break; - case 'value': - // If no type is indicated, the type is string - if (trim($this->_currentTagContents) != '') { - $value = (string)$this->_currentTagContents; - $this->_currentTagContents = ''; - $valueFlag = true; - } - break; - case 'boolean': - $value = (boolean)trim($this->_currentTagContents); - $this->_currentTagContents = ''; - $valueFlag = true; - break; - case 'base64': - $value = base64_decode($this->_currentTagContents); - $this->_currentTagContents = ''; - $valueFlag = true; - break; - // Deal with stacks of arrays and structs - case 'data': - case 'struct': - $value = array_pop($this->_arraystructs); - array_pop($this->_arraystructstypes); - $valueFlag = true; - break; - case 'member': - array_pop($this->_currentStructName); - break; - case 'name': - $this->_currentStructName[] = trim($this->_currentTagContents); - $this->_currentTagContents = ''; - break; - case 'methodName': - $this->methodName = trim($this->_currentTagContents); - $this->_currentTagContents = ''; - break; - } - - if ($valueFlag) { - /* - if (!is_array($value) && !is_object($value)) { - $value = trim($value); - } - */ - if (count($this->_arraystructs) > 0) { - // Add value to struct or array - if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { - // Add to struct - $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; - } else { - // Add to array - $this->_arraystructs[count($this->_arraystructs)-1][] = $value; - } - } else { - // Just add as a paramater - $this->params[] = $value; - } - } - } -} - - -class IXR_Request { - public $method; - public $args; - public $xml; - - function IXR_Request($method, $args) { - $this->method = $method; - $this->args = $args; - $this->xml = '' . $this->method . ''; - foreach ($this->args as $arg) { - $this->xml .= ''; - $v = new IXR_Value($arg); - $this->xml .= $v->getXml(); - $this->xml .= '' . LF; - } - $this->xml .= ''; - } - - function getLength() { - return strlen($this->xml); - } - - function getXml() { - return $this->xml; - } -} - - -class IXR_Error { - public $code; - public $message; - - function IXR_Error($code, $message) { - $this->code = $code; - $this->message = $message; - } - - function getXml() { - $xml = << - - - - - faultCode - {$this->code} - - - faultString - {$this->message} - - - - - -EOD; - return $xml; - } -} - - -class IXR_Date { - public $year; - public $month; - public $day; - public $hour; - public $minute; - public $second; - - function IXR_Date($time) { - // $time can be a PHP timestamp or an ISO one - if (is_numeric($time)) { - $this->parseTimestamp($time); - } else { - $this->parseIso($time); - } - } - - function parseTimestamp($timestamp) { - $this->year = date('Y', $timestamp); - $this->month = date('Y', $timestamp); - $this->day = date('Y', $timestamp); - $this->hour = date('H', $timestamp); - $this->minute = date('i', $timestamp); - $this->second = date('s', $timestamp); - } - - function parseIso($iso) { - $this->year = substr($iso, 0, 4); - $this->month = substr($iso, 4, 2); - $this->day = substr($iso, 6, 2); - $this->hour = substr($iso, 9, 2); - $this->minute = substr($iso, 12, 2); - $this->second = substr($iso, 15, 2); - } - - function getIso() { - return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second; - } - - function getXml() { - return ''.$this->getIso().''; - } - - function getTimestamp() { - return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); - } -} - - -class IXR_Base64 { - public $data; - - function IXR_Base64($data) { - $this->data = $data; - } - - function getXml() { - return ''.base64_encode($this->data).''; - } -} - - -////////////////////////////////////////////////////////// -// Nadeo modifications // -// (many thanks to slig for adding callback support) // -////////////////////////////////////////////////////////// -class IXR_Client_Gbx { - public $socket; - public $message = false; - public $cb_message = array(); - public $reqhandle; - public $protocol = 0; - // Storage place for an error message - public $error = false; - - function bigEndianTest() { - list($endiantest) = array_values(unpack('L1L', pack('V', 1))); - if ($endiantest != 1) { - echo "Machine reports itself as BigEndian, float handling must be altered\r\n"; - echo "Overwrite GbxRemote.inc.php with GbxRemote.bem.php\r\n"; - die('App Terminated'); - return false; - } - return true; - } // bigEndianTest - - function IXR_Client_Gbx() { - $this->socket = false; - $this->reqhandle = 0x80000000; - } - - function InitWithIp($ip, $port) { - - if (!$this->bigEndianTest()) { - $this->error = new IXR_Error(-32999, 'endian error - script doesn\'t match machine type'); - return false; - } - - // open connection - $this->socket = @fsockopen($ip, $port, $errno, $errstr); - if (!$this->socket) { - $this->error = new IXR_Error(-32300, "transport error - could not open socket (error: $errno, $errstr)"); - return false; - } - // handshake - $array_result = unpack('Vsize', fread($this->socket, 4)); - $size = $array_result['size']; - if ($size > 64) { - $this->error = new IXR_Error(-32300, 'transport error - wrong lowlevel protocol header'); - return false; - } - $handshake = fread($this->socket, $size); - if ($handshake == 'GBXRemote 1') { - $this->protocol = 1; - } else if ($handshake == 'GBXRemote 2') { - $this->protocol = 2; - } else { - $this->error = new IXR_Error(-32300, 'transport error - wrong lowlevel protocol version'); - return false; - } - return true; - } - - function Init($port) { - return $this->InitWithIp('localhost', $port); - } - - function Terminate() { - if ($this->socket) { - fclose($this->socket); - $this->socket = false; - } - } - - protected function sendRequest(IXR_Request $request) { - $xml = $request->getXml(); - - @stream_set_timeout($this->socket, 20); // timeout 20 s (to write the request) - // send request - $this->reqhandle++; - if ($this->protocol == 1) { - $bytes = pack('Va*', strlen($xml), $xml); - } else { - $bytes = pack('VVa*', strlen($xml), $this->reqhandle, $xml); - } - - $bytes_to_write = strlen($bytes); - while ($bytes_to_write > 0) { - $r = fwrite($this->socket, $bytes); - if ($r === false || $r == 0) { - // connection interrupted - return false; // or die? - } - - $bytes_to_write -= $r; - if ($bytes_to_write == 0) - break; - - $bytes = substr($bytes, $r); - } - - return true; - } - - protected function getResult() { - $contents = ''; - $contents_length = 0; - do { - $size = 0; - $recvhandle = 0; - @stream_set_timeout($this->socket, 20); // timeout 20 s (to read the reply header) - // Get result - if ($this->protocol == 1) { - $contents = fread($this->socket, 4); - if (strlen($contents) == 0) { - $this->error = new IXR_Error(-32700, 'transport error - connection interrupted!'); - return false; - } - $array_result = unpack('Vsize', $contents); - $size = $array_result['size']; - $recvhandle = $this->reqhandle; - } else { - $contents = fread($this->socket, 8); - if (strlen($contents) == 0) { - $this->error = new IXR_Error(-32700, 'transport error - connection interrupted!'); - return false; - } - $array_result = unpack('Vsize/Vhandle', $contents); - $size = $array_result['size']; - $recvhandle = $array_result['handle']; - // -- amd64 support -- - $bits = sprintf('%b', $recvhandle); - if (strlen($bits) == 64) { - $recvhandle = bindec(substr($bits, 32)); - } - } - - if ($recvhandle == 0 || $size == 0) { - $this->error = new IXR_Error(-32700, 'transport error - connection interrupted!'); - return false; - } - if ($size > 4096*1024) { - $this->error = new IXR_Error(-32700, "transport error - answer too big ($size)"); - return false; - } - - $contents = ''; - $contents_length = 0; - @stream_set_timeout($this->socket, 0, 10000); // timeout 10 ms (for successive reads until end) - while ($contents_length < $size) { - $contents .= fread($this->socket, $size-$contents_length); - $contents_length = strlen($contents); - } - - if (($recvhandle & 0x80000000) == 0) { - // this is a callback, not our answer! handle= $recvhandle, xml-rpc= $contents - // just add it to the message list for the user to read - $new_cb_message = new IXR_Message($contents); - if ($new_cb_message->parse() && $new_cb_message->messageType != 'fault') { - array_push($this->cb_message, array($new_cb_message->methodName, $new_cb_message->params)); - } - } - } while ((int)$recvhandle != (int)$this->reqhandle); - - $this->message = new IXR_Message($contents); - if (!$this->message->parse()) { - // XML error - $this->error = new IXR_Error(-32700, 'parse error. not well formed'); - return false; - } - // Is the message a fault? - if ($this->message->messageType == 'fault') { - $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); - return false; - } - // Message must be OK - return true; - } - - - function query() { - $args = func_get_args(); - $method = array_shift($args); - - if (!$this->socket || $this->protocol == 0) { - $this->error = new IXR_Error(-32300, 'transport error - Client not initialized'); - return false; - } - - $request = new IXR_Request($method, $args); - - // Check if request is larger than 512 Kbytes - if ($request->getLength() > 512*1024-8) { - $this->error = new IXR_Error(-32700, 'transport error - request too large!'); - return false; - } - - // Send request - $ok = $this->sendRequest($request); - if (!$ok) { - $this->error = new IXR_Error(-32700, 'transport error - connection interrupted'); - return false; - } - - // Get result - return $this->getResult(); - } - - // Non-blocking query method: doesn't read the response - function queryIgnoreResult() { - $args = func_get_args(); - $method = array_shift($args); - - if (!$this->socket || $this->protocol == 0) { - $this->error = new IXR_Error(-32300, 'transport error - Client not initialized'); - return false; - } - - $request = new IXR_Request($method, $args); - - // Check if the request is greater than 512 Kbytes to avoid errors - // If the method is system.multicall, make two calls (possibly recursively) - if ($request->getLength() > 512*1024-8) { - if ($method = 'system.multicall' && isset($args[0])) { - $count = count($args[0]); - // If count is 1, query cannot be reduced - if ($count < 2) { - $this->error = new IXR_Error(-32700, 'transport error - request too large!'); - return false; - } - $length = floor($count/2); - - $args1 = array_slice($args[0], 0, $length); - $args2 = array_slice($args[0], $length, ($count-$length)); - - $res1 = $this->queryIgnoreResult('system.multicall', $args1); - $res2 = $this->queryIgnoreResult('system.multicall', $args2); - return ($res1 && $res2); - } - // If the method is not a multicall, just stop - else { - $this->error = new IXR_Error(-32700, 'transport error - request too large!'); - return false; - } - } - - // Send request - $ok = $this->sendRequest($request); - if (!$ok) { - $this->error = new IXR_Error(-32700, 'transport error - connection interrupted'); - return false; - } - } - - function readCB($timeout = 2000) { // timeout 2 ms - if (!$this->socket || $this->protocol == 0) { - $this->error = new IXR_Error(-32300, 'transport error - Client not initialized'); - return false; - } - if ($this->protocol == 1) - return false; - - $something_received = count($this->cb_message)>0; - $contents = ''; - $contents_length = 0; - - @stream_set_timeout($this->socket, 0, 10000); // timeout 10 ms (to read available data) - // (assignment in arguments is forbidden since php 5.1.1) - $read = array($this->socket); - $write = NULL; - $except = NULL; - $nb = @stream_select($read, $write, $except, 0, $timeout); - // workaround for stream_select bug with amd64 - if ($nb !== false) - $nb = count($read); - - while ($nb !== false && $nb > 0) { - $timeout = 0; // we don't want to wait for the full time again, just flush the available data - - $size = 0; - $recvhandle = 0; - // Get result - $contents = fread($this->socket, 8); - if (strlen($contents) == 0) { - $this->error = new IXR_Error(-32700, 'transport error - connection interrupted!'); - return false; - } - $array_result = unpack('Vsize/Vhandle', $contents); - $size = $array_result['size']; - $recvhandle = $array_result['handle']; - - if ($recvhandle == 0 || $size == 0) { - $this->error = new IXR_Error(-32700, 'transport error - connection interrupted!'); - return false; - } - if ($size > 4096*1024) { - $this->error = new IXR_Error(-32700, "transport error - answer too big ($size)"); - return false; - } - - $contents = ''; - $contents_length = 0; - while ($contents_length < $size) { - $contents .= fread($this->socket, $size-$contents_length); - $contents_length = strlen($contents); - } - - if (($recvhandle & 0x80000000) == 0) { - // this is a callback. handle= $recvhandle, xml-rpc= $contents - //echo 'CALLBACK('.$contents_length.')[ '.$contents.' ]' . LF; - $new_cb_message = new IXR_Message($contents); - if ($new_cb_message->parse() && $new_cb_message->messageType != 'fault') { - array_push($this->cb_message, array($new_cb_message->methodName, $new_cb_message->params)); - } - $something_received = true; - } - - // (assignment in arguments is forbidden since php 5.1.1) - $read = array($this->socket); - $write = NULL; - $except = NULL; - $nb = @stream_select($read, $write, $except, 0, $timeout); - // workaround for stream_select bug with amd64 - if ($nb !== false) - $nb = count($read); - } - return $something_received; - } - - function getResponse() { - // methodResponses can only have one param - return that - return $this->message->params[0]; - } - - function getCBResponses() { - // (look at the end of basic.php for an example) - $messages = $this->cb_message; - $this->cb_message = array(); - return $messages; - } - - function isError() { - return is_object($this->error); - } - - function resetError() { - $this->error = false; - } - - function getErrorCode() { - return $this->error->code; - } - - function getErrorMessage() { - return $this->error->message; - } -} - - -class IXR_ClientMulticall_Gbx extends IXR_Client_Gbx { - public $calls = array(); - - function addCall($methodName, $args) { - $struct = array('methodName' => $methodName, 'params' => $args); - $this->calls[] = $struct; - - return (count($this->calls) - 1); - } - - function multiquery($ignoreResult = false) { - // Prepare multicall, then call the parent::query() (or queryIgnoreResult) method - if ($ignoreResult) { - $result = parent::queryIgnoreResult('system.multicall', $this->calls); - } else { - $result = parent::query('system.multicall', $this->calls); - } - $this->calls = array(); // reset for next calls - return $result; - } -} -?> diff --git a/tmserver/RemoteControlExamples/PhpRemote/ListMethods.php b/tmserver/RemoteControlExamples/PhpRemote/ListMethods.php deleted file mode 100644 index 6bda308..0000000 --- a/tmserver/RemoteControlExamples/PhpRemote/ListMethods.php +++ /dev/null @@ -1,68 +0,0 @@ -\n"; -echo "\n\n"; -echo "\tTrackmania methods\n"; -echo "\n\n"; - -echo "

Available methods:

\n"; - -$client = new IXR_Client_Gbx; - -if (!$client->Init(5000)) { - die('An error occurred - ' . $client->getErrorCode() . ':' . $client->getErrorMessage()); -} - -if (!$client->query('system.listMethods')) { - die('An error occurred - ' . $client->getErrorCode() . ':' . $client->getErrorMessage()); -} -$methods = $client->getResponse(); - -print ''; - -$client->Terminate(); - -echo "\n\n\n"; - -flush(); - -?> diff --git a/tmserver/RemoteControlExamples/PhpRemote/SpectatorUi.php b/tmserver/RemoteControlExamples/PhpRemote/SpectatorUi.php deleted file mode 100644 index f070383..0000000 --- a/tmserver/RemoteControlExamples/PhpRemote/SpectatorUi.php +++ /dev/null @@ -1,264 +0,0 @@ -#!/usr/bin/php - -InitWithIp($Ip, $Port)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } - - DoQuerry("Authenticate", $AuthLogin, $AuthPassword); - DoQuerry("EnableCallbacks", True); -} - -function DoQuerry($querry /*...*/) -{ - global $client; - $args = func_get_args(); - if (!call_user_func_array(array($client, 'query'), $args)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - exit(1); - } - return $client->getResponse(); -} - -function TryQuerry($querry /*...*/) -{ - global $client; - $args = func_get_args(); - if (!call_user_func_array(array($client, 'query'), $args)) { - print ("Warning: '$querry' -> " . "[".$client->getErrorCode()."] ".$client->getErrorMessage()); - return False; - } - return $client->getResponse(); -} - -function XMLEscapeString( $String ) -{ - return htmlspecialchars( $String, ENT_NOQUOTES ) ; -} - - -function MwTimeToString($MwTime) -{ - if ($MwTime == -1) { - return "???"; - } else { - $minutes = floor($MwTime/(1000*60)); - $seconds = floor(($MwTime-$minutes*60*1000)/1000); - $millisec = floor(($MwTime - $minutes*60*1000 - $seconds*1000)/10); - return $minutes.":".$seconds.".".$millisec; - } -} - -// UI construction: -$ActionChangeSpec = 1*1000; - -function MakePlayerFrame($PlayerRanking, $CurTarget, $GameInfos, &$posx, &$posy) -{ - global $ActionChangeSpec; - - $NickName = XMLEscapeString($PlayerRanking['NickName']); - $Rank = $PlayerRanking['Rank']; - $Score = $PlayerRanking['Score']; - $Time = MwTimeToString($PlayerRanking["BestTime"]); - $PlayerUId = $PlayerRanking['PlayerId']; - - $Action = $ActionChangeSpec + $PlayerUId; - - $Frame = ""; - $Frame .= ""; - $Frame .= ""; - $Frame .= ""; - - if ($GameInfos["GameMode"] == 5) { // Cup Mode - $Limit = $GameInfos["CupPointsLimit"]; - if ($Score == $Limit) { - $Frame .= ""; - } else if ($Score > $Limit) { - $Frame .= ""; - } else { - $Frame .= ""; - } - - } else if ($GameInfos["GameMode"] == 0) { // Rounds - $Frame .= ""; - - } else if ($GameInfos["GameMode"] == 1) { // TimeAttack - $Frame .= ""; - - } else { - // mode not supported. - } - - if ($PlayerUId == $CurTarget) { - $Frame .= ""; - } - - $Frame .= ""; - - $posy -= 10; - return $Frame; -} - -function BuildUiForSpectator($Login, $Target, $Rankings, $GameInfos) -{ - $Page = ''; - - // rankings and scores. - $Page .= ''; - $posx=-63; - $posy=37; - foreach ($Rankings as $Ranking) { - if ($Ranking['Rank'] == 0) - break; // there aren't 5 players in the top 5, so cut up earlier. - $Page .= MakePlayerFrame($Ranking, $Target, $GameInfos, $posx, $posy); - } - $Page .= ''; - - // customui - $Page .= 'i'; - - $Page .= ''; - - return $Page; -} - -// SpectatorManager -$SpectatorManager_Status = array(); -$SpectatorManager_GlobalDirty = False; -function SpectatorManager_Add($Login) -{ - global $SpectatorManager_Status, $SpectatorManager_GlobalDirty; - $SpectatorManager_GlobalDirty = True; - $SpectatorManager_Status[$Login]= - array( "uptodate" => False, - "page" => "", - "target" => "" ); -} - -function SpectatorManager_Remove($Login) -{ - global $SpectatorManager_Status, $SpectatorManager_GlobalDirty; - unset($SpectatorManager_Status[$Login]); -} - -function SpectatorManager_SetDirtyAll() -{ - global $SpectatorManager_Status, $SpectatorManager_GlobalDirty; - $SpectatorManager_GlobalDirty = True; - foreach($SpectatorManager_Status as $s) { - $s["uptodate"] = False; - } -} - -function SpectatorManager_Update() -{ - global $SpectatorManager_Status, $SpectatorManager_GlobalDirty; - - if (!$SpectatorManager_GlobalDirty) - return; - $SpectatorManager_GlobalDirty = False; - - $GameInfos = DoQuerry('GetCurrentGameInfo', 1); - $Rankings = DoQuerry('GetCurrentRanking', 5, 0); - - foreach($SpectatorManager_Status as $Login => $s) { - if ($s["uptodate"]) - continue; - $NewPage = BuildUiForSpectator($Login, $s["target"], $Rankings, $GameInfos); - if ($s["page"] != $NewPage) { - $s["page"] = $NewPage; - DoQuerry('SendDisplayManialinkPageToLogin', $Login, $NewPage, 0, False); - } - $s["uptodate"] = True; - } -} - -// Callbacks -function OnManialinkPageAnswer($PlayerUId, $Login, $Answer) -{ - global $SpectatorManager_Status, $SpectatorManager_GlobalDirty; - global $ActionChangeSpec; - $Argument = $Answer%1000; - $Action = $Answer - $Argument ; - - if ($Action == $ActionChangeSpec) { - $SpectatorManager_Status[$Login]["target"] = $Argument; - $SpectatorManager_Status[$Login]["uptodate"] = False; - $SpectatorManager_GlobalDirty = True; - TryQuerry('ForceSpectatorTargetId', $PlayerUId, $Argument, 0); - } -} - -function OnPlayerInfoChanged($PlayerInfo) -{ - return; -} - -// ------------------------------------------------------ -// -- (1) Server Adress here!--------------------------------- -// ------------------------------------------------------ -ConnectToServer("localhost", 5000, "Admin", "Admin"); - -// register already connected specs. -$PlayerList = DoQuerry("GetPlayerList", 250, 0, 1); -foreach ($PlayerList as $Player) { - $Login = $Player["Login"]; - $IsPureSpec = ($Player["SpectatorStatus"]/100)%10 != 0; - if ($IsPureSpec) - SpectatorManager_Add($Login); -} - - -while (true) { - // FIXME - Sleep(1); - $client->readCB(5*1000*1000); - - $calls = $client->getCBResponses(); - if (!empty($calls)) { - foreach ($calls as $call) { - switch($call[0]){ - case 'TrackMania.BeginRace': - case 'TrackMania.EndRace': - case 'TrackMania.EndRound': - SpectatorManager_SetDirtyAll(); - break; - - case 'TrackMania.PlayerManialinkPageAnswer': - OnManialinkPageAnswer($call[1][0], $call[1][1], $call[1][2]); - break; - - case 'TrackMania.PlayerConnect': - if ($call[1][1]) // is spectator - SpectatorManager_Add($call[1][0]); - break; - - case 'TrackMania.PlayerDisconnect': - SpectatorManager_Remove($call[1][0]); - break; - case 'TrackMania.PlayerInfoChanged': - OnPlayerInfoChanged($call[1][0]); - break; - } - } - } - SpectatorManager_Update(); - flush(); -} - -$client->Terminate(); - -?> - diff --git a/tmserver/RemoteControlExamples/PhpRemote/basic.php b/tmserver/RemoteControlExamples/PhpRemote/basic.php deleted file mode 100644 index 65bbf11..0000000 --- a/tmserver/RemoteControlExamples/PhpRemote/basic.php +++ /dev/null @@ -1,986 +0,0 @@ -".$Char.""; - $i++; - if ($i>100) { - break; - } - } - return $string; -} - -// Read a styled string -function ReadNextChar(&$_Str, &$_Style) { - - $Char = current($_Str); - next($_Str); - - if ($Char == '\r') { // skip \r - return ReadNextChar($_Str, $_Style); - } - if ($Char != '$') { // detect markup start sequence '$' - return $Char; - } - - $Char = current($_Str); - next($_Str); - if ($Char === FALSE) { - return 0; - } - $MarkupCode = $Char; - - switch ($MarkupCode) { - // color - case '0': case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': case 'a': case 'b': - case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': - case 'C': case 'D': case 'E': case 'F': - { - $RGB = NULL; - for ($Count = 0; $Count < 3; $Count ++) { - if ($Count > 0) { - $Char = current($_Str); - next($_Str); - if ($Char === FALSE) { - return 0; - } - } - $RGB .= $Char.$Char; - } - $_Style .= "color:#".$RGB.";"; - } - break; - - // no color - case 'G': case 'g': - $_Style .= "color:;"; - break; - - // Shodowed / Embossed - case 'S': case 's': - break; - - // Italic - case 'I': case 'i': - $_Style .= "font-style:italic;"; - break; - - // Wide - case 'W': case 'w': - $_Style .= "letter-spacing:1px;"; - break; - - // Narrow - case 'N': case 'n': - $_Style .= "letter-spacing:-1px;"; - break; - - // Medium - case 'M': case 'm': - $_Style .= "letter-spacing:0px;"; - break; - - // underlined - case 'U': case 'u': - $_Style .= "text-decoration:underline;"; - break; - - // reset all - case 'Z': case 'z': - $_Style = ""; - break; - - // escaped char. - case '$': case '[': - return $MarkupCode; - - default: - // eat silently the character... - break; - }; - - return ReadNextChar($_Str, $_Style); // tail recursion. -} - -function catchError($errno, $errstr, $errfile, $errline){ - echo("

$errstr (line:$errline)

"); -} -set_error_handler('catchError'); - -function MwTimeToString($MwTime) -{ - if ($MwTime == -1) { - return "???"; - } else { - $minutes = floor($MwTime/(1000*60)); - return $minutes.":".floor(($MwTime-$minutes*60*1000)/1000); - } -} - -function ParseArgument(&$ArgumentValue, $ArgumentName, $DefaultValue) -{ - if (array_key_exists($ArgumentName, $_POST)) { - $ArgumentValue = $_POST[$ArgumentName]; - } else if (array_key_exists($ArgumentName, $_GET)) { - $ArgumentValue = $_GET[$ArgumentName]; - } else { - $ArgumentValue = $DefaultValue; - } -} - -// parse the arguments. -ParseArgument( $AuthLogin, 'authLogin', "SuperAdmin" ); -ParseArgument( $AuthPassword, 'authPassword', "SuperAdmin" ); -ParseArgument( $OldAuthLogin, 'oldAuthLogin', $AuthLogin ); -ParseArgument( $OldAuthPassword, 'oldAuthPassword', $AuthPassword ); -ParseArgument( $port, 'port', 5000 ); -ParseArgument( $MSLogin, 'mslogin', "" ); -ParseArgument( $MSPassword, 'mspassword', "" ); - -if (array_key_exists('action', $_POST)) { - $Action = $_POST['action']; -/*} else if (array_key_exists('action', $_GET)) - $Action = $_GET['action'];*/ -} else { - $Action=""; -} - - -echo "

- Trackmania Forever dedicated server -

"; - - -// ---------------------------------------------------------------- -// connect -// ---------------------------------------------------------------- -$client = new IXR_Client_Gbx; -if (!$client->Init($port)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); -} - -if (!$client->query("Authenticate", $AuthLogin, $AuthPassword)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - - $AuthLogin = $OldAuthLogin; - $AuthPassword = $OldAuthPassword; -} -else -{ - $OldAuthLogin = $AuthLogin; - $OldAuthPassword = $AuthPassword; -} - -// ---------------------------------------------------------------- -// do the job. -// ---------------------------------------------------------------- -$SimpleActions = array('RestartChallenge', 'NextChallenge', 'StopServer', 'QuitGame', 'CleanBanList'); -if (in_array($Action, $SimpleActions)) { - if (!$client->query($Action)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } - -} else if ($Action == 'SetServerOptions') { - $IsP2PUpload = array_key_exists('IsP2PUpload', $_POST); - $IsP2PDownload = array_key_exists('IsP2PDownload', $_POST); - $AutoSaveReplays = array_key_exists('AutoSaveReplays', $_POST); - $AutoSaveValidationReplays = array_key_exists('AutoSaveValidationReplays', $_POST); - $AllowChallengeDownload = array_key_exists('AllowChallengeDownload', $_POST); - $struct = array( 'Name' => $_POST['ServerName'], - 'Comment' => $_POST['ServerComment'], - 'Password' => $_POST['ServerPassword'], - 'PasswordForSpectator' => $_POST['SpectatorPassword'], - 'NextMaxPlayers' => $_POST['NextMaxPlayers']+0, - 'NextMaxSpectators' => $_POST['NextMaxSpectators']+0, - 'IsP2PUpload' => $IsP2PUpload, - 'IsP2PDownload' => $IsP2PDownload, - 'NextLadderMode' => $_POST['NextLadderMode']+0, - 'NextVehicleNetQuality' => $_POST['NextVehicleNetQuality']+0, - 'NextCallVoteTimeOut' => $_POST['NextCallVoteTimeOut']+0, - 'CallVoteRatio' => $_POST['CallVoteRatio']+0, - 'RefereePassword' => $_POST['RefereePassword'], - 'RefereeMode' => $_POST['RefereeMode']+0, - 'AllowChallengeDownload' => $AllowChallengeDownload, - 'AutoSaveValidationReplays' => $AutoSaveValidationReplays, - 'AutoSaveReplays' => $AutoSaveReplays); - if (!$client->query('SetServerOptions', $struct)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } - -} else if ($Action == 'StartServerInternet' || $Action == 'StartServerLan') { - $struct = array( 'Login' => $_POST['Login'], - 'Password' => $_POST['Password']); - if (!$client->query($Action, $struct)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } - -} else if ($Action == 'RemoveChallenge' || $Action == 'AddChallenge' || $Action == 'ChooseNextChallenge') { - if (!$client->query($Action, urldecode($_POST['ChallengeFileName']))) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } - -} else if ($Action == 'Kick' || $Action == 'Ban' || $Action == 'UnBan' || $Action == 'AddGuest' || $Action == 'RemoveGuest' || $Action == 'BlackList' || $Action == 'UnBlackList') { - if (!$client->query($Action, urldecode($_POST['PlayerLogin']))) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } - -} else if ($Action == 'SaveMatchSettings' || $Action == 'LoadMatchSettings' || $Action == 'AppendPlaylistFromMatchSettings') { - if (!$client->query($Action, urldecode($_POST['MatchSettingsFileName']))) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } -} else if ($Action == 'LoadGuestList' || $Action == 'SaveGuestList' ) { - if (!$client->query($Action, urldecode($_POST['GuestListFileName']))) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } -} else if ($Action == 'LoadBlackList' || $Action == 'SaveBlackList' ) { - if (!$client->query($Action, urldecode($_POST['BlackListFileName']))) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } -} else if ($Action == 'SetGameInfos') { - $NextRoundsUseNewRules = array_key_exists('NextRoundsUseNewRules', $_POST); - $NextTeamUseNewRules = array_key_exists('NextTeamUseNewRules', $_POST); - $NextDisableRespawn = array_key_exists('NextDisableRespawn', $_POST); - $struct = array( 'GameMode' => $_POST['NextGameMode']+0, - 'ChatTime' => $_POST['NextChatTime']+0, - 'FinishTimeout' => $_POST['NextFinishTimeout']+0, - 'RoundsPointsLimit' => $_POST['NextRoundsPointsLimit']+0, - 'RoundsForcedLaps' => $_POST['NextRoundsForcedLaps']+0, - 'RoundsUseNewRules' => $NextRoundsUseNewRules, - 'RoundsPointsLimitNewRules' => $_POST['NextRoundsPointsLimitNewRules']+0, - 'TimeAttackLimit' => $_POST['NextTimeAttackLimit']+0, - 'TimeAttackSynchStartPeriod' => $_POST['NextTimeAttackSynchStartPeriod']+0, - 'TeamPointsLimit' => $_POST['NextTeamPointsLimit']+0, - 'TeamMaxPoints' => $_POST['NextTeamMaxPoints']+0, - 'TeamUseNewRules' => $NextTeamUseNewRules, - 'TeamPointsLimitNewRules' => $_POST['NextTeamPointsLimitNewRules']+0, - 'CupPointsLimit' => $_POST['NextCupPointsLimit']+0, - 'CupRoundsPerChallenge' => $_POST['NextCupRoundsPerChallenge']+0, - 'CupNbWinners' => $_POST['NextCupNbWinners']+0, - 'CupWarmUpDuration' => $_POST['NextCupWarmUpDuration']+0, - 'DisableRespawn' => False, - 'ForceShowAllOpponents' => False, - 'LapsNbLaps' => $_POST['NextLapsNbLaps']+0, - 'LapsTimeLimit' => $_POST['NextLapsTimeLimit']+0, - 'AllWarmUpDuration' => 0); - if (!$client->query('SetGameInfos', $struct)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } -} else if ($Action == 'ChangeAuthPassword') { - if (!$client->query('ChangeAuthPassword', $_POST['newLogin'], $_POST['newPassword'])) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } - else if( $AuthLogin==$_POST['newLogin'] ) - { - $AuthLogin = $_POST['newLogin']; - $AuthPassword = $_POST['newLogin']; - $OldAuthLogin = $AuthLogin; - $OldAuthPassword = $AuthPassword; - } -} else if( ($Action == 'ChatSend') || ($Action == 'ChatSendServerMessage') ){ - if (!$client->query($Action, urldecode($_POST['ChatText']))) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } -} else if($Action == 'SendDisplayManialinkPage'){ - $AutoHide = array_key_exists('AutoHide', $_POST); - if (!$client->query($Action, $_POST['Maniacode'], $_POST['TimeOut']+0, $AutoHide)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } -} else if($Action == 'SendDisplayServerMessageToLogin'){ - $AutoHide = array_key_exists('AutoHide', $_POST); - if (!$client->query($Action, $_POST['Login'], $_POST['Maniacode'],$_POST['TimeOut']+0, $AutoHide)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } -} else if($Action == 'SendHideManialinkPage'){ - if (!$client->query($Action)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } -} else if($Action == 'SendHideManialinkPageToLogin'){ - if (!$client->query($Action, $_POST['Login'])) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } -} - -// ---------------------------------------------------------------- -// connection info -// ---------------------------------------------------------------- -echo "\n

Connection Status:

\n"; - -if (!$client->query('GetVersion')) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); -} -else -{ - $AuthSuperAdmin = $AuthLogin=="SuperAdmin" ? "selected" : ""; - $AuthAdmin = $AuthLogin=="Admin" ? "selected" : ""; - $AuthUser = $AuthLogin=="User" ? "selected" : ""; - - echo << - - -
Permission Level: - -
Password: -
- - - - - -END; - - if( $AuthLogin=="SuperAdmin" ) - { - echo << - - -
Set new Password: - for - -
- - - - - -END; - } - - $Version = $client->getResponse(); - echo "Connected to " . $Version['Name']. " - " . $Version['Version'] . "
"; -} - - -// ---------------------------------------------------------------- -// status info -// ---------------------------------------------------------------- -echo "\n

Server Status:

\n"; - -if (!$client->query('GetStatus')) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); -} -else -{ - $Status = $client->getResponse(); - - echo "Status: ".$Status['Name']; - echo << - - - - - -END; - - if ($Status['Code'] == 1) { - // ---------------------------------------------------------------- - // start server - // ---------------------------------------------------------------- - echo << - - - -
Master Server Login:
Master Server Password:
- - - - - - -END; - - echo << - - - - - -END; - - } else if ( ($Status['Code'] == 3) || ($Status['Code'] == 4) || ($Status['Code'] == 5) ) { - if (!$client->query('GetCurrentChallengeInfo')) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } - else - { - $CurrentChallengeInfo = $client->getResponse(); - echo "Current challenge : " . $CurrentChallengeInfo['UId'] . " - " . styledString($CurrentChallengeInfo['Name']) . " - " . $CurrentChallengeInfo['Author'] . "
"; - } - - // ---------------------------------------------------------------- - // in game actions - // ---------------------------------------------------------------- - if( $Status['Code'] == 4 ) - { - echo << - - - - - - - - - -END; - } - else - { - echo "
"; - } - - echo "Players:
"; - - if (!$client->query('GetPlayerList', 50, 0)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } - else - { - $PlayerList = $client->getResponse(); - echo ''; - foreach ($PlayerList as $player) { - $PlayerLogin = $player['Login']; - $PlayerName = styledString($player['NickName']); - $PlayerRanking = $player['LadderRanking']; - - $PlayerIsSpectator = ($player['IsSpectator']!=0) ? "Spectator" : "Player"; - $PlayerIsInOfficialMode = ($player['IsInOfficialMode']!=0) ? "Official" : "Not Official"; - - $PlayerTeamId = $player['TeamId']; - if( $PlayerTeamId == -1) - $PlayerTeam = "No Team"; - else if( $PlayerTeamId == 0) - $PlayerTeam = "Blue Team"; - else - $PlayerTeam = "Red Team"; - - echo << - - -END; - } - echo "
$PlayerLogin$PlayerName$PlayerTeam$PlayerIsSpectator$PlayerIsInOfficialMode$PlayerRanking

"; - } - - echo << - - - - - - - -END; - $AutoHide = False; - echo << - - - - - - -
Maniacode:
TimeOut:
Login:
AutoHide:
- - - - - - - - -END; - - echo "Ranking:
"; - - if (!$client->query('GetCurrentRanking', 50, 0)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } - else - { - $CurrentRanking = $client->getResponse(); - echo ''; - foreach ($CurrentRanking as $Ranking) { - $PlayerLogin = $Ranking['Login']; - $PlayerName = styledString($Ranking['NickName']); - $PlayerRank = $Ranking['Rank']; - $PlayerBestTime = $Ranking['BestTime']; - $PlayerScore = $Ranking['Score']; - $PlayerNbrLaps = $Ranking['NbrLapsFinished']; - $PlayerLadderScore = $Ranking['LadderScore']; - echo << -END; - } - echo "
$PlayerLogin$PlayerName$PlayerRank$PlayerBestTime$PlayerScore$PlayerNbrLaps$PlayerLadderScore

"; - } - - } else if ($Status['Code'] == 2) { - echo "server busy..

"; - } - - echo "GuestList:
"; - - if (!$client->query('GetGuestList', 50, 0)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } - else - { - $GuestList = $client->getResponse(); - echo ''; - foreach ($GuestList as $player) { - $PlayerLogin=$player['Login']; - echo << - -END; - } - echo "
$PlayerLogin
- - - - - -
"; - - echo << - - - - - - -END; - - echo << -
- - - - - - -END; - - } - - echo "BlackList:
"; - - if (!$client->query('GetBlackList', 50, 0)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } - else - { - $BlackList = $client->getResponse(); - echo ''; - foreach ($BlackList as $player) { - $PlayerLogin=$player['Login']; - echo << - -END; - } - echo "
$PlayerLogin
- - - - - -
"; - - echo <<
- - - - - -
-END; - - echo << -
- - - - - - -END; - - } - echo "BanList:
"; - - if (!$client->query('GetBanList', 50, 0)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); - } - else - { - $BanList = $client->getResponse(); - echo ''; - foreach ($BanList as $player) { - $PlayerLogin=$player['Login']; - echo << - -END; - } - echo "
$PlayerLogin
- - - - - -
"; - - echo << - - - - - - -END; - } -} - - -// ---------------------------------------------------------------- -// Server options -// ---------------------------------------------------------------- -echo "\n

Server options:

\n"; - -if (!$client->query('GetServerOptions', 1)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); -} -else -{ - $ServerOptions = $client->getResponse(); - $repGetServerName = $ServerOptions['Name']; - $repServerComment = $ServerOptions['Comment']; - $repServerPassword = $ServerOptions['Password']; - $repPasswordForSpectator = $ServerOptions['PasswordForSpectator']; - $repRefereePassword = $ServerOptions['RefereePassword']; - $repRefereeMode = $ServerOptions['RefereeMode']; - $repCurrentMaxPlayer = $ServerOptions['CurrentMaxPlayers']; - $repNextMaxPlayer = $ServerOptions['NextMaxPlayers']; - $repCurrentMaxSpectator = $ServerOptions['CurrentMaxSpectators']; - $repNextMaxSpectator = $ServerOptions['NextMaxSpectators']; - $repP2PUpload = ($ServerOptions['IsP2PUpload']!=0) ? "checked" : " "; - $repP2PDownload = ($ServerOptions['IsP2PDownload']!=0) ? "checked" : " "; - $repCurrentLadderMode = $ServerOptions['CurrentLadderMode']; - $repNextLadderMode = $ServerOptions['NextLadderMode']; - $repCurrentVehicleNetQuality = $ServerOptions['CurrentVehicleNetQuality']; - $repNextVehicleNetQuality = $ServerOptions['NextVehicleNetQuality']; - $repCurrentCallVoteTimeOut = $ServerOptions['CurrentCallVoteTimeOut']; - $repNextCallVoteTimeOut = $ServerOptions['NextCallVoteTimeOut']; - $repCallVoteRatio = $ServerOptions['CallVoteRatio']; - $repAllowChallengeDownload = ($ServerOptions['AllowChallengeDownload']!=0) ? "checked" : " "; - $repAutoSaveReplays = ($ServerOptions['AutoSaveReplays']!=0) ? "checked" : " "; - $repAutoSaveValidationReplays = ($ServerOptions['AutoSaveValidationReplays']!=0) ? "checked" : " "; - - if( $repCurrentLadderMode==0 ) - $CurrentLadderMode = "Inactive"; - else if( $repCurrentLadderMode==1 ) - $CurrentLadderMode = "Forced"; - else - $CurrentLadderMode = "Undefined"; - - if( $repNextLadderMode==0 ) - { - $NextLadderModeInactive = "selected"; - $NextLadderModeForced = ""; - } - { - $NextLadderModeInactive = ""; - $NextLadderModeForced = "selected"; - } - - if( $repCurrentVehicleNetQuality==0 ) - $CurrentVehicleNetQuality = "Fast"; - else if( $repCurrentVehicleNetQuality==1 ) - $CurrentVehicleNetQuality = "High"; - else - $CurrentLadderMode = "Undefined"; - - if( $repNextVehicleNetQuality==1 ) - { - $NextVehicleNetQualityFast = ""; - $NextVehicleNetQualityHigh = "selected"; - } - else - { - $NextVehicleNetQualityFast = "selected"; - $NextVehicleNetQualityHigh = ""; - } - - echo << - - - - - - - - - - - - - - - - - -
Name:
Comment:
Password:
PasswordForSpectator:
RefereePassword:
MaxPlayer:
Next Value:
MaxSpectator:
Next Value:
P2PUpload:
P2PDownload:
LadderMode:
Next Value: - -
VehicleNetQuality:
Next Value: - -
CallVoteTimeOut:
Next Value:
CallVoteRatio:
AllowChallengeDownload:
AutoSaveReplays:
AutoSaveValidationReplays:
- - - - - - -END; -} - - -// ---------------------------------------------------------------- -// Game infos -// ---------------------------------------------------------------- -echo "\n

Game infos:

\n"; - -if (!$client->query('GetGameInfos', 1)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); -} -else -{ - $GameInfos = $client->getResponse(); - - $CurrentGameInfo = $GameInfos['CurrentGameInfos']; - $NextGameInfo = $GameInfos['NextGameInfos']; - - $ChatTime = $CurrentGameInfo['ChatTime']; - $NbChallenge = $CurrentGameInfo['NbChallenge']; - if( $CurrentGameInfo['GameMode']==0 ) - $GameMode = "Rounds"; - else if( $CurrentGameInfo['GameMode']==1 ) - $GameMode = "TimeAttack"; - else if( $CurrentGameInfo['GameMode']==2 ) - $GameMode = "Team"; - else if( $CurrentGameInfo['GameMode']==3 ) - $GameMode = "Laps"; - else if( $CurrentGameInfo['GameMode']==4 ) - $GameMode = "Stunts"; - else if( $CurrentGameInfo['GameMode']==5 ) - $GameMode = "Cup"; - else - $GameMode = "Undefined"; - $RoundsPointsLimit = $CurrentGameInfo['RoundsPointsLimit']; - $RoundsPointsLimitNewRules = $CurrentGameInfo['RoundsPointsLimitNewRules']; - $RoundsUseNewRules = ($CurrentGameInfo['RoundsUseNewRules']!=0) ? "True" : "False"; - $RoundsForcedLaps = $CurrentGameInfo['RoundsForcedLaps']; - $FinishTimeout = $CurrentGameInfo['FinishTimeout']; - $TimeAttackLimit = $CurrentGameInfo['TimeAttackLimit']; - $TimeAttackSynchStartPeriod = $CurrentGameInfo['TimeAttackSynchStartPeriod']; - $TeamPointsLimit = $CurrentGameInfo['TeamPointsLimit']; - $TeamPointsLimitNewRules = $CurrentGameInfo['TeamPointsLimitNewRules']; - $TeamMaxPoints = $CurrentGameInfo['TeamMaxPoints']; - $TeamUseNewRules = ($CurrentGameInfo['TeamUseNewRules']!=0) ? "True" : "False"; - $CupPointsLimit = $CurrentGameInfo['CupPointsLimit']; - $CupRoundsPerChallenge = $CurrentGameInfo['CupRoundsPerChallenge']; - $CupNbWinners = $CurrentGameInfo['CupNbWinners']; - $CupWarmUpDuration = $CurrentGameInfo['CupWarmUpDuration']; - $LapsNbLaps = $CurrentGameInfo['LapsNbLaps']; - $LapsTimeLimit = $CurrentGameInfo['LapsTimeLimit']; - $NextChatTime = $NextGameInfo['ChatTime']; - $NextGameMode0 = $NextGameInfo['GameMode']==0 ? "selected" : ""; - $NextGameMode1 = $NextGameInfo['GameMode']==1 ? "selected" : ""; - $NextGameMode2 = $NextGameInfo['GameMode']==2 ? "selected" : ""; - $NextGameMode3 = $NextGameInfo['GameMode']==3 ? "selected" : ""; - $NextGameMode4 = $NextGameInfo['GameMode']==4 ? "selected" : ""; - $NextGameMode5 = $NextGameInfo['GameMode']==5 ? "selected" : ""; - $NextRoundsPointsLimit = $NextGameInfo['RoundsPointsLimit']; - $NextRoundsPointsLimitNewRules = $NextGameInfo['RoundsPointsLimitNewRules']; - $NextRoundsUseNewRules = ($NextGameInfo['RoundsUseNewRules']!=0) ? "checked" : " "; - $NextRoundsForcedLaps = $NextGameInfo['RoundsForcedLaps']; - $NextFinishTimeout = $NextGameInfo['FinishTimeout']; - $NextTimeAttackLimit = $NextGameInfo['TimeAttackLimit']; - $NextTimeAttackSynchStartPeriod = $NextGameInfo['TimeAttackSynchStartPeriod']; - $NextTeamPointsLimit = $NextGameInfo['TeamPointsLimit']; - $NextTeamPointsLimitNewRules = $NextGameInfo['TeamPointsLimitNewRules']; - $NextTeamMaxPoints = $NextGameInfo['TeamMaxPoints']; - $NextTeamUseNewRules = ($NextGameInfo['TeamUseNewRules']!=0) ? "checked" : " "; - $NextCupPointsLimit = $NextGameInfo['CupPointsLimit']; - $NextCupRoundsPerChallenge = $NextGameInfo['CupRoundsPerChallenge']; - $NextCupNbWinners = $NextGameInfo['CupNbWinners']; - $NextCupWarmUpDuration = $NextGameInfo['CupWarmUpDuration']; - $NextLapsNbLaps = $NextGameInfo['LapsNbLaps']; - $NextLapsTimeLimit = $NextGameInfo['LapsTimeLimit']; - - echo << - - - - - - - - - - - - - - - - - - - - - - -
CurrentNext
Mode: - -
ChatTime:
NbChallenge:
RoundsPointsLimit:
RoundsPointsLimitNewRules:
RoundsUseNewRules:
RoundsForcedLaps:
FinishTimeout:
TimeAttackLimit:
TimeAttackSynchStartPeriod:
TeamPointsLimit:
TeamPointsLimitNewRules:
TeamMaxPoints:
TeamUseNewRules:
CupPointsLimit:
CupRoundsPerChallenge:
CupNbWinners:
CupWarmUpDuration:
LapsNbLaps:
LapsTimeLimit:
- - - - - -END; -} - - -// ---------------------------------------------------------------- -// challenges -// ---------------------------------------------------------------- -// debug -echo "\n

Challenges:

\n"; - -if (!$client->query('GetChallengeList', 50, 0)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); -} -else -{ - $ChallengeList = $client->getResponse(); - echo ''; - foreach ($ChallengeList as $challenge) { - $ChallengeUId = $challenge['UId']; - $ChallengeAuthor = $challenge['Author']; - $ChallengeName = styledString($challenge['Name']); - $FileName = $challenge['FileName']; - $FileNameUrl = urlencode($FileName); - $Environnement = $challenge['Environnement']; - $GoldTime = MwTimeToString($challenge['GoldTime']); - $CopperPrice = $challenge['CopperPrice']; - echo << - - - -END; - } - echo "
$ChallengeName
$ChallengeUId
$FileName$Environnement
$ChallengeAuthor
$GoldTime$CopperPrice
"; -} - -echo <<
- - - - - -
-END; - -echo << -
- - - - - - - -END; - -/* -// uncomment to test the callbacks.. - -echo "

callbacks:


"; -if (!$client->query('EnableCallbacks', true)) { - trigger_error("[".$client->getErrorCode()."] ".$client->getErrorMessage()); -} -flush(); -while (true) { - $client->readCB(5); - - $calls = $client->getCBResponses(); - if (!empty($calls)) { - foreach ($calls as $call) { - echo "call: ".$call[0]."
"; - } - } else { - echo "no calls...
"; - } - flush(); -} -*/ - -$client->Terminate(); - -?> diff --git a/tmserver/bin/.xaseco_restart_pott.sh.swp b/tmserver/bin/.xaseco_restart_pott.sh.swp deleted file mode 100644 index 53dcb7b..0000000 Binary files a/tmserver/bin/.xaseco_restart_pott.sh.swp and /dev/null differ diff --git a/tmserver/bin/delete_cache.sh b/tmserver/bin/delete_cache.sh deleted file mode 100755 index dcdc80a..0000000 --- a/tmserver/bin/delete_cache.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -cd $TMDIR/GameData/Cache/ -find . -type f -exec rm {} \;