dedicated server api update (reverted from commit 77a53b282c
)
This commit is contained in:
@ -19,12 +19,6 @@ class Base64
|
||||
{
|
||||
$this->scalar = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function __toString()
|
||||
{
|
||||
return $this->scalar;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -8,3 +8,5 @@
|
||||
namespace Maniaplanet\DedicatedServer\Xmlrpc;
|
||||
|
||||
class Exception extends \Exception {}
|
||||
|
||||
?>
|
||||
|
@ -57,3 +57,5 @@ class MapNotCompatibleOrCompleteException extends FaultException{}
|
||||
class LadderModeUnknownException extends FaultException{}
|
||||
class PlayerAlreadyIgnoredException extends FaultException{}
|
||||
class PlayerNotIgnoredException extends FaultException{}
|
||||
|
||||
?>
|
||||
|
@ -17,6 +17,7 @@ class GbxRemote
|
||||
|
||||
private $socket;
|
||||
private $timeouts = array(
|
||||
'open' => 5,
|
||||
'read' => 5000,
|
||||
'write' => 5000
|
||||
);
|
||||
@ -28,12 +29,13 @@ class GbxRemote
|
||||
/**
|
||||
* @param string $host
|
||||
* @param int $port
|
||||
* @param int $timeout Timeout when opening connection
|
||||
* @param int[string] $timeouts Override default timeouts for 'open' (in s), 'read' (in ms) and 'write' (in ms) socket operations
|
||||
*/
|
||||
function __construct($host, $port, $timeout = 5)
|
||||
function __construct($host, $port, $timeouts = array())
|
||||
{
|
||||
$this->requestHandle = (int) 0x80000000;
|
||||
$this->connect($host, $port, $timeout);
|
||||
$this->timeouts = array_merge($this->timeouts, $timeouts);
|
||||
$this->connect($host, $port);
|
||||
}
|
||||
|
||||
function __destruct()
|
||||
@ -43,10 +45,10 @@ class GbxRemote
|
||||
|
||||
/**
|
||||
* Change timeouts
|
||||
* @param int $read read timeout (in ms), 0 to leave unchanged
|
||||
* @param int $write write timeout (in ms), 0 to leave unchanged
|
||||
* @param int $read read timeout (in ms), null or 0 to leave unchanged
|
||||
* @param int $write write timeout (in ms), null or 0 to leave unchanged
|
||||
*/
|
||||
function setTimeouts($read=0, $write=0)
|
||||
function setTimeouts($read=null, $write=null)
|
||||
{
|
||||
if($read)
|
||||
$this->timeouts['read'] = $read;
|
||||
@ -66,12 +68,12 @@ class GbxRemote
|
||||
/**
|
||||
* @param string $host
|
||||
* @param int $port
|
||||
* @param int $timeout
|
||||
* @throws TransportException
|
||||
*/
|
||||
private function connect($host, $port, $timeout)
|
||||
private function connect($host, $port)
|
||||
{
|
||||
$this->socket = @fsockopen($host, $port, $errno, $errstr, $timeout);
|
||||
$this->socket = @fsockopen($host, $port, $errno, $errstr, $this->timeouts['open']);
|
||||
|
||||
if(!$this->socket)
|
||||
throw new TransportException('Cannot open socket', TransportException::NOT_INITIALIZED);
|
||||
|
||||
@ -112,13 +114,12 @@ class GbxRemote
|
||||
|
||||
if(strlen($xml) > self::MAX_REQUEST_SIZE-8)
|
||||
{
|
||||
if($method != 'system.multicall' || count($args[0]) < 2)
|
||||
if($method != 'system.multicall' || count($args) < 2)
|
||||
throw new MessageException('Request too large', MessageException::REQUEST_TOO_LARGE);
|
||||
|
||||
$mid = count($args[0]) >> 1;
|
||||
$res1 = $this->query('system.multicall', array(array_slice($args[0], 0, $mid)));
|
||||
$res2 = $this->query('system.multicall', array(array_slice($args[0], $mid)));
|
||||
return array_merge($res1, $res2);
|
||||
$mid = count($args) >> 1;
|
||||
$this->query('system.multicall', array_slice($args, 0, $mid));
|
||||
$this->query('system.multicall', array_slice($args, $mid));
|
||||
}
|
||||
|
||||
$this->writeMessage($xml);
|
||||
@ -150,7 +151,7 @@ class GbxRemote
|
||||
$call = array_shift($this->multicallBuffer);
|
||||
return $this->query($call['methodName'], $call['params']);
|
||||
default:
|
||||
$result = $this->query('system.multicall', array($this->multicallBuffer));
|
||||
$result = $this->query('system.multicall', $this->multicallBuffer);
|
||||
$this->multicallBuffer = array();
|
||||
return $result;
|
||||
}
|
||||
@ -184,9 +185,9 @@ class GbxRemote
|
||||
*/
|
||||
private function flush($waitResponse=false)
|
||||
{
|
||||
$r = array($this->socket);
|
||||
$w = null;
|
||||
$e = null;
|
||||
$r=array($this->socket);
|
||||
$w=null;
|
||||
$e=null;
|
||||
$n = @stream_select($r, $w, $e, 0);
|
||||
while($waitResponse || $n > 0)
|
||||
{
|
||||
@ -204,8 +205,12 @@ class GbxRemote
|
||||
$this->callbacksBuffer[] = $value;
|
||||
}
|
||||
|
||||
if(!$waitResponse)
|
||||
if(!$waitResponse){
|
||||
$r=array($this->socket);
|
||||
$w=null;
|
||||
$e=null;
|
||||
$n = @stream_select($r, $w, $e, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -305,3 +310,5 @@ class MessageException extends Exception
|
||||
const REQUEST_TOO_LARGE = 1;
|
||||
const RESPONSE_TOO_LARGE = 2;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -22,12 +22,9 @@ if(extension_loaded('xmlrpc'))
|
||||
* @param mixed[] $args
|
||||
* @return string
|
||||
*/
|
||||
static function encode($method, $args, $escape=true)
|
||||
static function encode($method, $args)
|
||||
{
|
||||
$opts = self::$options;
|
||||
if(!$escape)
|
||||
$opts['escaping'] = array();
|
||||
return xmlrpc_encode_request($method, $args, $opts);
|
||||
return xmlrpc_encode_request($method, $args, self::$options);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,7 +40,7 @@ if(extension_loaded('xmlrpc'))
|
||||
|
||||
if($method === null)
|
||||
{
|
||||
if(is_array($value) && xmlrpc_is_fault($value))
|
||||
if(is_array($value) && @xmlrpc_is_fault($value))
|
||||
return array('fault', $value);
|
||||
return array('response', $value);
|
||||
}
|
||||
@ -62,80 +59,55 @@ else
|
||||
* @param mixed[] $args
|
||||
* @return string
|
||||
*/
|
||||
static function encode($method, $args, $escape=true)
|
||||
static function encode($method, $args)
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="utf-8"?><methodCall><methodName>'.self::escape($method, $escape).'</methodName>';
|
||||
if(!$args)
|
||||
return $xml.'<params/></methodCall>';
|
||||
|
||||
$xml .= '<params>';
|
||||
$xml = '<?xml version="1.0" encoding="utf-8"?><methodCall><methodName><![CDATA['.$method.']]></methodName><params>';
|
||||
foreach($args as $arg)
|
||||
$xml .= '<param><value>'.self::encodeValue($arg, $escape).'</value></param>';
|
||||
return $xml.'</params></methodCall>';
|
||||
$xml .= '<param><value>'.self::encodeValue($arg).'</value></param>';
|
||||
$xml .= '</params></methodCall>';
|
||||
return $xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $v
|
||||
* @return string
|
||||
*/
|
||||
private static function encodeValue($v, $escape=true)
|
||||
private static function encodeValue($v)
|
||||
{
|
||||
switch(gettype($v))
|
||||
{
|
||||
case 'boolean':
|
||||
return '<boolean>'.self::escape((int) $v, $escape).'</boolean>';
|
||||
return '<boolean><![CDATA['.((int) $v).']]></boolean>';
|
||||
case 'integer':
|
||||
return '<int>'.self::escape($v, $escape).'</int>';
|
||||
return '<int><![CDATA['.$v.']]></int>';
|
||||
case 'double':
|
||||
return '<double>'.self::escape($v, $escape).'</double>';
|
||||
return '<double><![CDATA['.$v.']]></double>';
|
||||
case 'string':
|
||||
case 'NULL':
|
||||
if(!$v)
|
||||
return '<string/>';
|
||||
return '<string>'.self::escape($v, $escape).'</string>';
|
||||
return '<string><![CDATA['.$v.']]></string>';
|
||||
case 'object':
|
||||
if($v instanceof Base64)
|
||||
{
|
||||
if(!$v->scalar)
|
||||
return '<base64/>';
|
||||
return '<base64>'.self::escape(base64_encode($v->scalar), $escape).'</base64>';
|
||||
}
|
||||
return '<base64><![CDATA['.base64_encode($v->scalar).']]></base64>';
|
||||
if($v instanceof \DateTime)
|
||||
return '<dateTime.iso8601>'.self::escape($v->format(self::DATE_FORMAT), $escape).'</dateTime.iso8601>';
|
||||
return '<dateTime.iso8601><![CDATA['.$v->format(self::DATE_FORMAT).']]></dateTime.iso8601>';
|
||||
$v = get_object_vars($v);
|
||||
// fallthrough
|
||||
// fallthrough
|
||||
case 'array':
|
||||
$return = '';
|
||||
// empty array case
|
||||
if(!$v)
|
||||
return '<array><data/></array>';
|
||||
// pure array case
|
||||
if(array_keys($v) === range(0, count($v) - 1))
|
||||
{
|
||||
foreach($v as $item)
|
||||
$return .= '<value>'.self::encodeValue($item, $escape).'</value>';
|
||||
$return .= '<value>'.self::encodeValue($item).'</value>';
|
||||
return '<array><data>'.$return.'</data></array>';
|
||||
}
|
||||
// else it's a struct
|
||||
foreach($v as $name => $value)
|
||||
$return .= '<member><name>'.self::escape($name, $escape).'</name><value>'.self::encodeValue($value, $escape).'</value></member>';
|
||||
$return .= '<member><name><![CDATA['.$name.']]></name><value>'.self::encodeValue($value).'</value></member>';
|
||||
return '<struct>'.$return.'</struct>';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $str
|
||||
* @param bool $escape
|
||||
* @return string
|
||||
*/
|
||||
private static function escape($str, $escape=true)
|
||||
{
|
||||
if($escape)
|
||||
return '<![CDATA['.$str.']]>';
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @return mixed
|
||||
@ -170,7 +142,7 @@ else
|
||||
switch($elt->getName())
|
||||
{
|
||||
case 'boolean':
|
||||
return (bool) (int) $elt;
|
||||
return (bool) $elt;
|
||||
case 'i4':
|
||||
case 'int':
|
||||
return (int) $elt;
|
||||
@ -198,3 +170,5 @@ else
|
||||
}
|
||||
|
||||
class ParseException extends Exception {}
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user