From bde438f665e15b0314b539665860159cc8b63f99 Mon Sep 17 00:00:00 2001 From: kremsy Date: Thu, 8 May 2014 19:38:15 +0200 Subject: [PATCH] dedicated server api update --- .../DedicatedServer/Connection.php | 3875 ++++++++--------- .../Structures/AbstractStructure.php | 18 +- .../DedicatedServer/Structures/Bill.php | 7 +- .../DedicatedServer/Structures/Command.php | 14 +- .../DedicatedServer/Structures/GameInfos.php | 26 +- .../DedicatedServer/Structures/LobbyInfo.php | 7 +- .../DedicatedServer/Structures/Map.php | 19 +- .../DedicatedServer/Structures/Mod.php | 10 +- .../DedicatedServer/Structures/Music.php | 8 +- .../Structures/NetworkStats.php | 14 +- .../DedicatedServer/Structures/Player.php | 86 +- .../DedicatedServer/Structures/ScriptInfo.php | 21 +- .../Structures/ScriptSettings.php | 10 +- .../Structures/ServerOptions.php | 34 +- .../DedicatedServer/Structures/Skin.php | 19 +- .../DedicatedServer/Structures/Status.php | 5 +- .../Structures/SystemInfos.php | 12 +- .../DedicatedServer/Structures/Team.php | 10 +- .../DedicatedServer/Structures/Version.php | 8 +- .../DedicatedServer/Structures/Vote.php | 28 +- .../DedicatedServer/Structures/VoteRatio.php | 34 +- .../DedicatedServer/Xmlrpc/Base64.php | 10 +- .../DedicatedServer/Xmlrpc/Exception.php | 2 - .../DedicatedServer/Xmlrpc/FaultException.php | 2 - .../DedicatedServer/Xmlrpc/GbxRemote.php | 45 +- .../DedicatedServer/Xmlrpc/Request.php | 68 +- 26 files changed, 2035 insertions(+), 2357 deletions(-) diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Connection.php b/application/core/Libs/Maniaplanet/DedicatedServer/Connection.php index f1f208d7..cedb102e 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Connection.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Connection.php @@ -13,42 +13,56 @@ namespace Maniaplanet\DedicatedServer; */ class Connection { - /** - * @var Connection[] - */ - static protected $instances = array(); + const API_2011_08_01 = '2011-08-01'; + const API_2011_10_06 = '2011-10-06'; + const API_2012_06_19 = '2012-06-19'; + const API_2013_04_16 = '2013-04-16'; - /** - * XML-RPC client instance - * @var Xmlrpc\GbxRemote - */ + /** @var Connection[] */ + protected static $instances = array(); + /** @var int[] */ + private static $levels = array( + null => -1, + 'User' => 0, + 'Admin' => 1, + 'SuperAdmin' => 2 + ); + + /** @var Xmlrpc\GbxRemote */ protected $xmlrpcClient; + /** @var string */ + protected $user; /** * @param string $host * @param int $port - * @param int $timeout (in ms) + * @param int $timeout (in s) * @param string $user * @param string $password + * @param string $apiVersion * @return Connection */ - static function factory($host = '127.0.0.1', $port = 5000, $timeout = 50, $user = 'SuperAdmin', $password = 'SuperAdmin') + static function factory($host='127.0.0.1', $port=5000, $timeout=5, $user='SuperAdmin', $password='SuperAdmin', $apiVersion=self::API_2013_04_16) { $key = $host.':'.$port; if(!isset(self::$instances[$key])) - { - self::$instances[$key] = new self($host, $port, $timeout, $user, $password); - } + self::$instances[$key] = new self($host, $port, $timeout); + self::$instances[$key]->authenticate($user, $password); + self::$instances[$key]->setApiVersion($apiVersion); + return self::$instances[$key]; } /** - * @param string $host + * @param Connection|string $hostOrConnection * @param int $port */ - static function delete($host, $port) + static function delete($hostOrConnection, $port=null) { - $key = $host.':'.$port; + if($hostOrConnection instanceof Connection) + $key = array_search($hostOrConnection, self::$instances); + else + $key = $hostOrConnection.':'.$port; if(isset(self::$instances[$key])) { self::$instances[$key]->terminate(); @@ -58,8 +72,8 @@ class Connection /** * Change client timeouts - * @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 + * @param int $read read timeout (in ms), 0 to leave unchanged + * @param int $write write timeout (in ms), 0 to leave unchanged */ function setTimeouts($read=null, $write=null) { @@ -78,14 +92,10 @@ class Connection * @param string $host * @param int $port * @param int $timeout - * @param string $user - * @param string $password */ - protected function __construct($host, $port, $timeout, $user, $password) + protected function __construct($host, $port, $timeout) { - $this->xmlrpcClient = new Xmlrpc\GbxRemote($host, $port, array('open' => $timeout)); - $this->authenticate($user, $password); - $this->setApiVersion('2013-04-16'); + $this->xmlrpcClient = new Xmlrpc\GbxRemote($host, $port, $timeout); } /** @@ -98,9 +108,8 @@ class Connection } /** - * - * Read a Call back on the DedicatedServer and call the method if handle - * @param array $methods if empty, every methods will be called on call back, otherwise only the method declared inside. The metho name must be the name of the interface's method + * Return pending callbacks + * @return mixed[] */ function executeCallbacks() { @@ -109,62 +118,68 @@ class Connection /** * Execute the calls in queue and return the result - * TODO Prendre en compte les retours du mutliQuery (via un handler ?) + * @return mixed */ function executeMulticall() { - $this->xmlrpcClient->multiquery(); + return $this->xmlrpcClient->multiquery(); } /** - * Add a call in queur. It will be executed by the next Call from the user to executemulticall + * Add a call in queue. It will be executed by the next Call from the user to executeMulticall * @param string $methodName - * @param string $authLevel - * @param array $params + * @param mixed[] $params + * @param bool $multicall True to queue the request or false to execute it immediately + * @return mixed */ - protected function execute($methodName, $params = array(), $multicall = false) + protected function execute($methodName, $params=array(), $multicall=false) { if($multicall) - { $this->xmlrpcClient->addCall($methodName, $params); - } else - { return $this->xmlrpcClient->query($methodName, $params); - } } /** - * Given the name of a method, return an array of legal signatures. - * Each signature is an array of strings. - * The first item of each signature is the return type, and any others items are parameter types. - * @param string $methodName - * @return array - */ - function methodSignature($methodName) - { - return $this->execute('system.methodSignature', array($methodName)); - } - - /** - * Change the password for the specified login/user. - * @param string $username + * Allow user authentication by specifying a login and a password, to gain access to the set of functionalities corresponding to this authorization level. + * @param string $user * @param string $password * @return bool * @throws InvalidArgumentException */ - function changeAuthPassword($username, $password) + function authenticate($user, $password) { - if(!is_string($password)) - { - throw new InvalidArgumentException('password = '.print_r($password, true)); - } - if($username != 'User' && $username != 'Admin' && $username != 'SuperAdmin') - { - throw new InvalidArgumentException('username = '.print_r($username, true)); - } + if(!is_string($user) || !isset(self::$levels[$user])) + throw new InvalidArgumentException('user = '.print_r($user, true)); + if(self::$levels[$this->user] >= self::$levels[$user]) + return true; - return $this->execute(ucfirst(__FUNCTION__), array($username, $password), false); + if(!is_string($password)) + throw new InvalidArgumentException('password = '.print_r($password, true)); + + $res = $this->execute(ucfirst(__FUNCTION__), array($user, $password)); + if($res) + $this->user = $user; + return $res; + } + + /** + * Change the password for the specified login/user. + * Only available to SuperAdmin. + * @param string $user + * @param string $password + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function changeAuthPassword($user, $password, $multicall=false) + { + if(!is_string($user) || !isset(self::$levels[$user])) + throw new InvalidArgumentException('user = '.print_r($user, true)); + if(!is_string($password)) + throw new InvalidArgumentException('password = '.print_r($password, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($user, $password), $multicall); } /** @@ -172,10 +187,14 @@ class Connection * @param bool $enable * @param bool $multicall * @return bool + * @throws InvalidArgumentException */ - function enableCallbacks($enable, $multicall = false) + function enableCallbacks($enable, $multicall=false) { - return $this->execute(ucfirst(__FUNCTION__), array((bool) $enable), $multicall); + if(!is_bool($enable)) + throw new InvalidArgumentException('enable = '.print_r($enable, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($enable), $multicall); } /** @@ -183,230 +202,163 @@ class Connection * @param string $version * @param bool $multicall * @return bool + * @throws InvalidArgumentException */ - function setApiVersion($version, $multicall = false) + function setApiVersion($version, $multicall=false) { - return $this->execute(ucfirst(__FUNCTION__), array((string) $version), $multicall); + if(!is_string($version)) + throw new InvalidArgumentException('version = '.print_r($version, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($version), $multicall); } /** - * Returns a struct with the Name, Version, Build and ApiVersion of the application remotely controled. + * Returns a struct with the Name, TitleId, Version, Build and ApiVersion of the application remotely controlled. * @return Structures\Version - * @throws InvalidArgumentException */ function getVersion() { - $result = $this->execute(ucfirst(__FUNCTION__)); - return Structures\Version::fromArray($result); - } - - function authenticate($username, $password) - { - return $this->execute(ucfirst(__FUNCTION__), array($username, $password), false); + return Structures\Version::fromArray($this->execute(ucfirst(__FUNCTION__))); } /** - * Call a vote for a cmd. The command is a XML string corresponding to an XmlRpc request. - * You can additionally specifiy specific parameters for this vote: a ratio, a time out - * and who is voting. Special timeout values: a timeout of '0' means default, '1' means - * indefinite; a ratio of '-1' means default; Voters values: '0' means only active players, - * '1' means any player, '2' is for everybody, pure spectators included. - * @param Structures\Vote $vote - * @param double $ratio -1 means default, else ration should be between 0 and 1 - * @param int $timeout time to vote in millisecondes, '0' means default - * @param int $voters Voters values: '0' means only active players, '1' means any player, '2' is for everybody, pure spectators included + * Returns the current status of the server. + * @return Structures\Status + */ + function getStatus() + { + return Structures\Status::fromArray($this->execute(ucfirst(__FUNCTION__))); + } + + /** + * Quit the application. + * Only available to SuperAdmin. * @param bool $multicall - * @throws InvalidArgumentException + * @return bool */ - function callVote(Structures\Vote $vote, $ratio = 0.5, $timeout = 0, $voters = 1, $multicall = false) - { - if(is_null($vote)) - { - throw new InvalidArgumentException('vote must be set'); - } - if(!is_float($ratio)) - { - throw new InvalidArgumentException('ratio = '.print_r($ratio, true)); - } - if(!is_int($timeout)) - { - throw new InvalidArgumentException('timeout = '.print_r($timeout, true)); - } - if(!is_int($voters)) - { - throw new InvalidArgumentException('voters = '.print_r($voters, true)); - } - if(!is_array($vote->cmdParam)) - { - throw new InvalidArgumentException('vote->cmdParam = '.print_r($vote->cmdParam, true)); - } - - $tmpCmd = Xmlrpc\Request::encode($vote->cmdName, $vote->cmdName); - - return $this->execute(ucfirst(__FUNCTION__).'Ex', array($tmpCmd, $ratio, $timeout, $voters), $multicall); - } - - /** - * Call a vote to kick a player. - * You can additionally specifiy specific parameters for this vote: a ratio, a time out - * and who is voting. Special timeout values: a timeout of '0' means default, '1' means - * indefinite; a ratio of '-1' means default; Voters values: '0' means only active players, - * '1' means any player, '2' is for everybody, pure spectators included. - * @param Structures\Player|string $player Structures\Player or string - * @param double $ratio -1 means default, else ration should be between 0 and 1 - * @param int $timeout time to vote in millisecondes, '0' means default - * @param int $voters Voters values: '0' means only active players, '1' means any player, '2' is for everybody, pure spectators included - * @param bool $multicall - * @throws InvalidArgumentException - */ - function callVoteKick($player, $ratio = 0.5, $timeout = 0, $voters = 1, $multicall = false) - { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } - if(!is_float($ratio)) - { - throw new InvalidArgumentException('ratio = '.print_r($ratio, true)); - } - if(!is_int($timeout)) - { - throw new InvalidArgumentException('timeout = '.print_r($timeout, true)); - } - if(!is_int($voters)) - { - throw new InvalidArgumentException('voters = '.print_r($voters, true)); - } - - $tmpCmd = Xmlrpc\Request::encode('Kick', array($login)); - - return $this->execute('CallVoteEx', array($tmpCmd, $ratio, $timeout, $voters), $multicall); - } - - /** - * Call a vote to ban a player. - * You can additionally specifiy specific parameters for this vote: a ratio, a time out - * and who is voting. Special timeout values: a timeout of '0' means default, '1' means - * indefinite; a ratio of '-1' means default; Voters values: '0' means only active players, - * '1' means any player, '2' is for everybody, pure spectators included. - * @param Structures\Player|string $player - * @param double $ratio -1 means default, else ration should be between 0 and 1 - * @param int $timeout time to vote in millisecondes, '0' means default - * @param int $voters Voters values: '0' means only active players, '1' means any player, '2' is for everybody, pure spectators included - * @param bool $multicall - * @throws InvalidArgumentException - */ - function callVoteBan($player, $ratio = 0.6, $timeout = 0, $voters = 1, $multicall = false) - { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } - if(!is_float($ratio)) - { - throw new InvalidArgumentException('ratio = '.print_r($ratio, true)); - } - if(!is_int($timeout)) - { - throw new InvalidArgumentException('timeout = '.print_r($timeout, true)); - } - if(!is_int($voters)) - { - throw new InvalidArgumentException('voters = '.print_r($voters, true)); - } - - $tmpCmd = Xmlrpc\Request::encode('Ban', array($login)); - - return $this->execute('CallVoteEx', array($tmpCmd, $ratio, $timeout, $voters), $multicall); - } - - /** - * Call a vote to restart the current Map. - * You can additionally specifiy specific parameters for this vote: a ratio, a time out - * and who is voting. Special timeout values: a timeout of '0' means default, '1' means - * indefinite; a ratio of '-1' means default; Voters values: '0' means only active players, - * '1' means any player, '2' is for everybody, pure spectators included. - * @param double $ratio -1 means default, else ration should be between 0 and 1 - * @param int $timeout time to vote in millisecondes, '0' means default - * @param int $voters Voters values: '0' means only active players, '1' means any player, '2' is for everybody, pure spectators included - * @param bool $multicall - * @throws InvalidArgumentException - */ - function callVoteRestartMap($ratio = 0.5, $timeout = 0, $voters = 1, $multicall = false) - { - if(!is_float($ratio)) - { - throw new InvalidArgumentException('ratio = '.print_r($ratio, true)); - } - if(!is_int($timeout)) - { - throw new InvalidArgumentException('timeout = '.print_r($timeout, true)); - } - if(!is_int($voters)) - { - throw new InvalidArgumentException('voters = '.print_r($voters, true)); - } - - $tmpCmd = Xmlrpc\Request::encode('RestartMap', array()); - - return $this->execute('CallVoteEx', array($tmpCmd, $ratio, $timeout, $voters), $multicall); - } - - /** - * Call a vote to go to the next Map. - * You can additionally specifiy specific parameters for this vote: a ratio, a time out - * and who is voting. Special timeout values: a timeout of '0' means default, '1' means - * indefinite; a ratio of '-1' means default; Voters values: '0' means only active players, - * '1' means any player, '2' is for everybody, pure spectators included. - * @param double $ratio -1 means default, else ration should be between 0 and 1 - * @param int $timeout time to vote in millisecondes, '0' means default - * @param int $voters Voters values: '0' means only active players, '1' means any player, '2' is for everybody, pure spectators included - * @param bool $multicall - * @throws InvalidArgumentException - */ - function callVoteNextMap($ratio = 0.5, $timeout = 0, $voters = 1, $multicall = false) - { - if(!is_float($ratio)) - { - throw new InvalidArgumentException('ratio = '.print_r($ratio, true)); - } - if(!is_int($timeout)) - { - throw new InvalidArgumentException('timeout = '.print_r($timeout, true)); - } - if(!is_int($voters)) - { - throw new InvalidArgumentException('voters = '.print_r($voters, true)); - } - - $tmpCmd = Xmlrpc\Request::encode('NextMap', array()); - - return $this->execute('CallVoteEx', array($tmpCmd, $ratio, $timeout, $voters), $multicall); - } - - /** - * Used internaly by game. - * @param bool $multicall - * @return bool - */ - protected function internalCallVote($multicall = false) + function quitGame($multicall=false) { return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); } + /** + * Call a vote for a command. + * You can additionally supply specific parameters for this vote: a ratio, a time out and who is voting. + * Only available to Admin. + * @param Structures\Vote $vote + * @param float $ratio In range [0,1] or -1 for default ratio + * @param int $timeout In milliseconds, 0 for default timeout, 1 for indefinite + * @param int $voters 0: active players, 1: any player, 2: everybody including pure spectators + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function callVote($vote, $ratio=-1., $timeout=0, $voters=1, $multicall=false) + { + if(!($vote instanceof Structures\Vote && $vote->isValid())) + throw new InvalidArgumentException('vote = '.print_r($vote, true)); + if(!Structures\VoteRatio::isRatio($ratio)) + throw new InvalidArgumentException('ratio = '.print_r($ratio, true)); + if(!is_int($timeout)) + throw new InvalidArgumentException('timeout = '.print_r($timeout, true)); + if(!is_int($voters) || $voters < 0 || $voters > 2) + throw new InvalidArgumentException('voters = '.print_r($voters, true)); + + $xml = Xmlrpc\Request::encode($vote->cmdName, $vote->cmdParam, false); + return $this->execute(ucfirst(__FUNCTION__).'Ex', array($xml, $ratio, $timeout, $voters), $multicall); + } + + /** + * Call a vote to kick a player. + * You can additionally supply specific parameters for this vote: a ratio, a time out and who is voting. + * Only available to Admin. + * @param mixed $player A player object or a login + * @param float $ratio In range [0,1] or -1 for default ratio + * @param int $timeout In milliseconds, 0 for default timeout, 1 for indefinite + * @param int $voters 0: active players, 1: any player, 2: everybody including pure spectators + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function callVoteKick($player, $ratio=0.5, $timeout=0, $voters=1, $multicall=false) + { + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + + $vote = new Structures\Vote(Structures\VoteRatio::COMMAND_KICK, array($login)); + return $this->callVote($vote, $ratio, $timeout, $voters, $multicall); + } + + /** + * Call a vote to ban a player. + * You can additionally supply specific parameters for this vote: a ratio, a time out and who is voting. + * Only available to Admin. + * @param mixed $player A player object or a login + * @param float $ratio In range [0,1] or -1 for default ratio + * @param int $timeout In milliseconds, 0 for default timeout, 1 for indefinite + * @param int $voters 0: active players, 1: any player, 2: everybody including pure spectators + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function callVoteBan($player, $ratio=0.6, $timeout=0, $voters=1, $multicall=false) + { + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + + $vote = new Structures\Vote(Structures\VoteRatio::COMMAND_BAN, array($login)); + return $this->callVote($vote, $ratio, $timeout, $voters, $multicall); + } + + /** + * Call a vote to restart the current map. + * You can additionally supply specific parameters for this vote: a ratio, a time out and who is voting. + * Only available to Admin. + * @param float $ratio In range [0,1] or -1 for default ratio + * @param int $timeout In milliseconds, 0 for default timeout, 1 for indefinite + * @param int $voters 0: active players, 1: any player, 2: everybody including pure spectators + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function callVoteRestartMap($ratio=0.5, $timeout=0, $voters=1, $multicall=false) + { + $vote = new Structures\Vote(Structures\VoteRatio::COMMAND_RESTART_MAP); + return $this->callVote($vote, $ratio, $timeout, $voters, $multicall); + } + + /** + * Call a vote to go to the next map. + * You can additionally supply specific parameters for this vote: a ratio, a time out and who is voting. + * Only available to Admin. + * @param float $ratio In range [0,1] or -1 for default ratio + * @param int $timeout In milliseconds, 0 for default timeout, 1 for indefinite + * @param int $voters 0: active players, 1: any player, 2: everybody including pure spectators + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function callVoteNextMap($ratio=0.5, $timeout=0, $voters=1, $multicall=false) + { + $vote = new Structures\Vote(Structures\VoteRatio::COMMAND_NEXT_MAP); + return $this->callVote($vote, $ratio, $timeout, $voters, $multicall); + } + /** * Cancel the current vote. + * Only available to Admin. * @param bool $multicall * @return bool */ - function cancelVote($multicall = false) + function cancelVote($multicall=false) { return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); } /** * Returns the vote currently in progress. - * The returned structure is { CallerLogin, CmdName, CmdParam }. * @return Structures\Vote */ function getCurrentCallVote() @@ -415,27 +367,24 @@ class Connection } /** - * Set a new timeout for waiting for votes. A zero value disables callvote. - * Requires a map restart to be taken into account - * @param int $timeout time to vote in millisecondes, '0' disables callvote + * Set a new timeout for waiting for votes. + * Only available to Admin. + * @param int $timeout In milliseconds, 0 to disable votes * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setCallVoteTimeOut($timeout, $multicall = false) + function setCallVoteTimeOut($timeout, $multicall=false) { if(!is_int($timeout)) - { throw new InvalidArgumentException('timeout = '.print_r($timeout, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($timeout), $multicall); } /** * Get the current and next timeout for waiting for votes. - * The struct returned contains two fields 'CurrentValue' and 'NextValue'. - * @return array + * @return int[] {int CurrentValue, int NextValue} */ function getCallVoteTimeOut() { @@ -444,236 +393,149 @@ class Connection /** * Set a new default ratio for passing a vote. - * Must lie between 0 and 1. - * @param double $ratio + * Only available to Admin. + * @param float $ratio In range [0,1] or -1 to disable votes * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setCallVoteRatio($ratio, $multicall = false) + function setCallVoteRatio($ratio, $multicall=false) { - if($ratio !== -1. && !(is_float($ratio) && $ratio >= 0 && $ratio <= 1)) - { + if(!Structures\VoteRatio::isRatio($ratio)) throw new InvalidArgumentException('ratio = '.print_r($ratio, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($ratio), $multicall); } /** * Get the current default ratio for passing a vote. - * This value lies between 0 and 1. - * @return double + * @param bool $multicall + * @return float */ function getCallVoteRatio() { return $this->execute(ucfirst(__FUNCTION__)); } - /** - * Set new ratios for passing specific votes. - * The parameter is an array of associative arrays - * {string votecommand, double ratio}, ratio is in [0,1] or -1. for vote disabled. - * @example setCallVoteRatios(array(array('Command' => 'Kick', 'Ratio' => -1. )); - * @param array $ratios - * @param bool $multicall - * @return bool - * @throws InvalidArgumentException - */ - function setCallVoteRatios(array $ratios, $multicall = false) - { - return $this->setCallVoteRatiosEx(true, $ratios, $multicall); - } - - /** - * Get the current ratios for passing votes. - * @return array - */ - function getCallVoteRatios() - { - return $this->execute(ucfirst(__FUNCTION__)); - } - /** * Set the ratios list for passing specific votes, extended version with parameters matching. - * The parameters, a boolean ReplaceAll (or else, only modify specified ratios, leaving the previous ones unmodified) - * and an array of structs {string Command, string Param, double Ratio}, - * ratio is in [0,1] or -1 for vote disabled. - * Param is matched against the vote parameters to make more specific ratios, leave empty to match all votes for the command. * Only available to Admin. - * @param bool $replaceAll - * @param array[array[]]|Structures\VoteRatio[] $ratios + * @param Structures\VoteRatio[] $ratios + * @param bool $replaceAll True to override the whole ratios list or false to modify only specified ratios * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setCallVoteRatiosEx($replaceAll, array $ratios, $multicall = false) + function setCallVoteRatios($ratios, $replaceAll=true, $multicall=false) { if(!is_array($ratios)) - { throw new InvalidArgumentException('ratios = '.print_r($ratios, true)); - } - - foreach($ratios as $i => $ratio) + foreach($ratios as $i => &$ratio) { - if($ratio instanceof Structures\VoteRatio) - { - $ratios[$i] = $ratio->toArray(); - } - else - { - if(!is_array($ratio) && !array_key_exists('Command', $ratio) && !array_key_exists('Ratio', $ratio)) - { - throw new InvalidArgumentException('ratios['.$i.'] = '.print_r($ratio, true)); - } - if(!is_string($ratio['Command'])) - { - throw new InvalidArgumentException('ratios['.$i.'][Command] = '.print_r($ratios['Command'], true)); - } - if($ratio['Ratio'] !== -1. && !(is_float($ratio['Ratio']) && $ratio['Ratio'] >= 0 && $ratio['Ratio'] <= 1)) - { - throw new InvalidArgumentException('ratios['.$i.'][Ratio] = '.print_r($ratio['Ratio'], true)); - } - if(array_key_exists('Param', $ratio) && !is_string($ratio['Param'])) - { - throw new InvalidArgumentException('ratios['.$i.'][Param] = '.print_r($ratio['Param'], true)); - } - elseif(!array_key_exists('Param', $ratio)) - { - $ratio['Param'] = ''; - $ratios[$i] = $ratio; - } - } + if(!($ratio instanceof Structures\VoteRatio && $ratio->isValid())) + throw new InvalidArgumentException('ratios['.$i.'] = '.print_r($ratios, true)); + $ratio = $ratio->toArray(); } + if(!is_bool($replaceAll)) + throw new InvalidArgumentException('replaceAll = '.print_r($replaceAll, true)); - return $this->execute(ucfirst(__FUNCTION__), array($replaceAll, $ratios), $multicall); + return $this->execute(ucfirst(__FUNCTION__).'Ex', array($replaceAll, $ratios), $multicall); + } + + /** + * @deprecated + * @see setCallVoteRatios() + */ + function setCallVoteRatiosEx($replaceAll, $ratios, $multicall=false) + { + return $this->setCallVoteRatios($ratios, $replaceAll, $multicall); } /** * Get the current ratios for passing votes, extended version with parameters matching. + * @param bool $multicall * @return Structures\VoteRatio[] */ + function getCallVoteRatios() + { + return Structures\VoteRatio::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__).'Ex')); + } + + /** + * @deprecated + * @see getCallVoteRatios() + */ function getCallVoteRatiosEx() { - return Structures\VoteRatio::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__))); + return $this->getCallVoteRatios(); } /** - * Send a localised text message to specied clients. - * The parameter is an array of structures {Lang='??', Text='...'}. - * If no matching language is found, the last text in the array is used. - * @param array $messages - * @param Structures\Player|string|mixed[] $receiver Structures\Player(s) who will receive the message, put null to send the message to everyone + * @deprecated + * @see chatSend() + */ + function chatSendServerMessage($message, $recipient=null, $multicall=false) + { + return $this->chatSend($message, $recipient, true, $multicall); + } + + /** + * @deprecated + * @see chatSend() + */ + function chatSendServerMessageToLanguage($messages, $recipient=null, $multicall=false) + { + return $this->chatSend($messages, $recipient, true, $multicall); + } + + /** + * Send a text message, possibly localised to a specific login or to everyone. + * Only available to Admin. + * @param string|string[][] $message Single string or array of structures {Lang='xx', Text='...'}: + * if no matching language is found, the last text in the array is used + * @param mixed $recipient Login, player object or array; null for all + * @param bool $isServerMessage False to include server login * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function chatSendServerMessageToLanguage(array $messages, $receiver = null, $multicall = false) + function chatSend($message, $recipient=null, $isServerMessage=false, $multicall=false) { - if(!is_array($messages)) - { - throw new InvalidArgumentException('messages = '.print_r($messages, true)); - } - if(is_null($receiver)) - { - $receiverString = ''; - } - else if(!($receiverString = $this->getLogins($receiver))) - { - throw new InvalidArgumentException('receiver = '.print_r($receiver, true)); - } + $logins = $this->getLogins($recipient, true); + if($logins === false) + throw new InvalidArgumentException('recipient = '.print_r($recipient, true)); - return $this->execute(ucfirst(__FUNCTION__), array($messages, $receiverString), $multicall); + $method = ucfirst(__FUNCTION__); + if(!is_bool($isServerMessage)) + throw new InvalidArgumentException('isServerMessage = '.print_r($isServerMessage, true)); + if($isServerMessage) + $method .= 'ServerMessage'; + + if(is_string($message)) + { + if($logins === '') + return $this->execute($method, array($message), $multicall); + return $this->execute($method.'ToLogin', array($message, $logins), $multicall); + } + if(is_array($message)) + return $this->execute($method.'ToLanguage', array($message, $logins), $multicall); + // else + throw new InvalidArgumentException('message = '.print_r($message, true)); } /** - * Send a text message without the server login to everyone if players is null. - * Players can be a Structures\Player object or an array of Structures\Player - * @param string $message - * @param Structures\Player|string|mixed[] $receiver Structures\Player(s) who will receive the message, put null to send the message to everyone - * @param bool $multicall - * @return bool - * @throws InvalidArgumentException + * @deprecated + * @see chatSend() */ - function chatSendServerMessage($message, $receiver = null, $multicall = false) + function chatSendToLanguage($messages, $recipient=null, $multicall=false) { - if(!is_string($message)) - { - throw new InvalidArgumentException('message = '.print_r($message, true)); - } - - $params = array($message); - $method = 'ChatSendServerMessage'; - if(!is_null($receiver)) - { - if(!($logins = $this->getLogins($receiver))) - { - throw new InvalidArgumentException('receiver = '.print_r($receiver, true)); - } - $params[] = $logins; - $method .= 'ToLogin'; - } - - return $this->execute($method, $params, $multicall); - } - - /** - * Send a localised text message to selected clients. - * The parameter is an array of structures {Lang='??', Text='...'}. - * If no matching language is found, the last text in the array is used. - * @param array $messages - * @param Structures\Player|string|mixed[] $receiver Structures\Player(s) who will receive the message, put null to send the message to everyone - * @param bool $multicall - * @return bool - * @throws InvalidArgumentException - */ - function chatSendToLanguage(array $messages, $receiver = null, $multicall = false) - { - if(!is_array($messages)) throw new InvalidArgumentException('messages = '.print_r($messages, true)); - - if($receiver == null) - { - $receiverString = ''; - } - else if(!($receiverString = $this->getLogins($receiver))) - { - throw new InvalidArgumentException('receiver = '.print_r($receiver, true)); - } - - return $this->execute(ucfirst(__FUNCTION__), array($messages, $receiverString), $multicall); - } - - /** - * Send a text message to every Structures\Player or the a specified player(s). - * If Structures\Player is null, the message will be delivered to every Structures\Player - * @param string $message - * @param Structures\Player|string|mixed[] $receiver Structures\Player(s) who will receive the message, put null to send the message to everyone - * @param bool $multicall - * @return bool - * @throws InvalidArgumentException - */ - function chatSend($message, $receiver, $multicall = false) - { - if(!is_string($message)) throw new InvalidArgumentException('message = '.print_r($message, true)); - - $params = array($message); - $method = 'ChatSend'; - if(!is_null($receiver)) - { - if(!($logins = $this->getLogins($receiver))) - { - throw new InvalidArgumentException('players = '.print_r($receiver, true)); - } - $params[] = $logins; - $method .= 'ToLogin'; - } - - return $this->execute($method, $params, $multicall); + return $this->chatSend($messages, $recipient, false, $multicall); } /** * Returns the last chat lines. Maximum of 40 lines. - * @return array + * Only available to Admin. + * @return string[] */ function getChatLines() { @@ -681,808 +543,716 @@ class Connection } /** - * The chat messages are no longer dispatched to the players, they only go to the rpc callback - * and the controller has to manually forward them. The second (optional) parameter allows all - * messages from the server to be automatically forwarded. + * The chat messages are no longer dispatched to the players, they only go to the rpc callback and the controller has to manually forward them. + * Only available to Admin. * @param bool $enable - * @param bool $serverAutomaticForward + * @param bool $excludeServer Allows all messages from the server to be automatically forwarded. * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function chatEnableManualRouting($enable, $serverAutomaticForward = false, $multicall = false) + function chatEnableManualRouting($enable, $excludeServer=false, $multicall=false) { if(!is_bool($enable)) - { throw new InvalidArgumentException('enable = '.print_r($enable, true)); - } - if(!is_bool($serverAutomaticForward)) - { - throw new InvalidArgumentException('serverAutomaticForward = '.print_r($serverAutomaticForward, true)); - } + if(!is_bool($excludeServer)) + throw new InvalidArgumentException('excludeServer = '.print_r($excludeServer, true)); - return $this->execute(ucfirst(__FUNCTION__), array($enable, $serverAutomaticForward), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($enable, $excludeServer), $multicall); } /** - * (Text, SenderLogin, DestLogin) Send a text message to the specified DestLogin (or everybody if empty) - * on behalf of SenderLogin. DestLogin can be a single login or a list of comma-separated logins. + * Send a message to the specified recipient (or everybody if empty) on behalf of sender. * Only available if manual routing is enabled. + * Only available to Admin. * @param string $message - * @param Structures\Player|string $sender - * @param Structures\Player|string $receiver + * @param mixed $sender Login or player object + * @param mixed $recipient Login, player object or array; empty for all * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function chatForwardToLogin($message, $sender, $receiver = null, $multicall = false) + function chatForward($message, $sender, $recipient=null, $multicall=false) { if(!is_string($message)) - { throw new InvalidArgumentException('message = '.print_r($message, true)); - } - if(!($senderLogin = $this->getLogin($sender))) - { - throw new InvalidArgumentException('sender must be set'); - } - $receiverLogin = $this->getLogin($receiver) ? : ''; - return $this->execute(ucfirst(__FUNCTION__), array($message, $senderLogin, $receiverLogin), $multicall); + $senderLogin = $this->getLogin($sender); + if($senderLogin === false) + throw new InvalidArgumentException('sender = '.print_r($sender, true)); + $recipientLogins = $this->getLogins($recipient, true); + if($recipientLogins === false) + throw new InvalidArgumentException('recipient = '.print_r($recipient, true)); + + return $this->execute(ucfirst(__FUNCTION__).'ToLogin', array($message, $senderLogin, $recipientLogins), $multicall); } /** - * Display a notice on the client with the specified UId. - * The parameters are : - * the Uid of the client to whom the notice is sent, - * the text message to display, - * the UId of the avatar to display next to it (or '255' for no avatar), - * an optional 'max duration' in seconds (default: 3). - * @param string $message - * @param Structures\Player|string|mixed[] $receiver - * @param Structures\Player|string $player - * @param int $variant 0, 1 or 2 - * @param bool $multicall - * @return bool - * @throws InvalidArgumentException + * @deprecated + * @see chatForward() */ - function sendNotice($receiver, $message, $player = null, $variant = 0, $multicall = false) + function chatForwardToLogin($message, $sender, $recipient=null, $multicall=false) { - if(!is_string($message)) - { - throw new InvalidArgumentException('message = '.print_r($message, true)); - } - - $params = array(); - $method = 'SendNotice'; - if(!is_null($receiver)) - { - if(!($login = $this->getLogins($receiver))) - throw new InvalidArgumentException('receiver = '.print_r($receiver, true)); - else $params[] = $login; - - $method .= 'ToLogin'; - } - - $params[] = $message; - $params[] = $this->getLogin($player) ? : ''; - $params[] = $variant; - return $this->execute($method, $params, $multicall); + return $this->chatForward($message, $sender, $recipient, $multicall); } /** - * Display a manialink page on the client of the specified Structures\Player(s). - * The first parameter is the login of the player, - * the other are identical to 'SendDisplayManialinkPage'. - * The players can be an object of player Type or an array of Structures\Player object - * @param null|Structures\Player|string|mixed[] $playerLogin - * @param string $manialink - * @param int $timeout - * @param bool $hideOnClick + * Display a notice on all clients. + * Only available to Admin. + * @param mixed $recipient Login, player object or array; empty for all + * @param string $message + * @param mixed $avatar Login or player object whose avatar will be displayed; empty for none + * @param int $variant 0: normal, 1: sad, 2: happy * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function sendDisplayManialinkPage($players, $manialink, $timeout, $hideOnClick, $multicall = false) + function sendNotice($recipient, $message, $avatar=null, $variant=0, $multicall=false) { - $params = array(); - $method = 'SendDisplayManialinkPage'; - if(!is_null($players)) - { - if(!($login = $this->getLogins($players))) throw new InvalidArgumentException('players = '.print_r($players, true)); - else $params[] = $login; + $logins = $this->getLogins($recipient, true); + if($logins === false) + throw new InvalidArgumentException('recipient = '.print_r($recipient, true)); + if(!is_string($message)) + throw new InvalidArgumentException('message = '.print_r($message, true)); + $avatarLogin = $this->getLogin($avatar, true); + if($avatarLogin === false) + throw new InvalidArgumentException('avatar = '.print_r($avatar, true)); + if(!is_int($variant) || $variant < 0 || $variant > 2) + throw new InvalidArgumentException('variant = '.print_r($variant, true)); - $method .= 'ToLogin'; - } + if($logins === '') + return $this->execute(ucfirst(__FUNCTION__), array($message, $avatar, $variant), $multicall); + return $this->execute(ucfirst(__FUNCTION__).'ToLogin', array($logins, $message, $avatarLogin, $variant), $multicall); + } - if(!is_string($manialink)) - { - throw new InvalidArgumentException('manialink = '.print_r($manialink, true)); - } + /** + * Display a manialink page on all clients. + * Only available to Admin. + * @param mixed $recipient Login, player object or array; empty for all + * @param string $manialinks XML string + * @param int $timeout Seconds before autohide, 0 for permanent + * @param bool $hideOnClick Hide as soon as the user clicks on a page option + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function sendDisplayManialinkPage($recipient, $manialinks, $timeout=0, $hideOnClick=false, $multicall=false) + { + $logins = $this->getLogins($recipient, true); + if($logins === false) + throw new InvalidArgumentException('recipient = '.print_r($recipient, true)); + if(!is_string($manialinks)) + throw new InvalidArgumentException('manialinks = '.print_r($manialinks, true)); if(!is_int($timeout)) - { throw new InvalidArgumentException('timeout = '.print_r($timeout, true)); - } if(!is_bool($hideOnClick)) - { throw new InvalidArgumentException('hideOnClick = '.print_r($hideOnClick, true)); - } - $params[] = $manialink; - $params[] = $timeout; - $params[] = $hideOnClick; - return $this->execute($method, $params, $multicall); + if($logins === '') + return $this->execute(ucfirst(__FUNCTION__), array($manialinks, $timeout, $hideOnClick), $multicall); + return $this->execute(ucfirst(__FUNCTION__).'ToLogin', array($logins, $manialinks, $timeout, $hideOnClick), $multicall); } /** - * Hide the displayed manialink page on the client with the specified login. - * Login can be a single login or a list of comma-separated logins. - * @param null|Structures\Player|string|mixed[] $players + * Hide the displayed manialink page. + * Only available to Admin. + * @param mixed $recipient Login, player object or array; empty for all * @param bool $multicall * @return bool - * @throws InvalidArgumentException */ - function sendHideManialinkPage($players = null, $multicall = false) + function sendHideManialinkPage($recipient=null, $multicall=false) { - $params = array(); - $method = 'SendHideManialinkPage'; - if(!is_null($players)) - { - if(!($login = $this->getLogins($players))) throw new InvalidArgumentException('players = '.print_r($players, true)); - else $params[] = $login; + $logins = $this->getLogins($recipient, true); + if($logins === false) + throw new InvalidArgumentException('recipient = '.print_r($recipient, true)); - $method .= 'ToLogin'; - } - - return $this->execute($method, $params, $multicall); + if($logins === '') + return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); + return $this->execute(ucfirst(__FUNCTION__).'ToLogin', array($logins), $multicall); } /** - * Returns the latest results from the current manialink page, - * as an array of structs {string Login, int PlayerId, int Result} - * Result==0 -> no answer, Result>0.... -> answer from the player. - * @return array + * Returns the latest results from the current manialink page as an array of structs {string Login, int PlayerId, int Result}: + * - Result == 0 -> no answer + * - Result > 0 -> answer from the player. + * @param bool $multicall + * @return Structures\PlayerAnswer[] */ function getManialinkPageAnswers() { - return $this->execute(ucfirst(__FUNCTION__)); + return Structures\PlayerAnswer::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__))); } /** - * Opens a link in the client with the specified players. - * The parameters are the login of the client to whom the link to open is sent, the link url, and the 'LinkType' - * (0 in the external browser, 1 in the internal manialink browser). - * Login can be a single login or a list of comma-separated logins. Only available to - * @param Structures\Player|string|mixed[] $player - * @param string $link - * @param int $linkType + * Opens a link in the client with the specified login. + * Only available to Admin. + * @param mixed $recipient Login, player object or array + * @param string $link URL to open + * @param int $linkType 0: in the external browser, 1: in the internal manialink browser * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function sendOpenLink($player, $link, $linkType, $multicall = false) + function sendOpenLink($recipient, $link, $linkType, $multicall=false) { - if(!($login = $this->getLogins($player))) - { - throw new InvalidArgumentException('player must be set'); - } + $logins = $this->getLogins($recipient); + if($logins === false) + throw new InvalidArgumentException('recipient = '.print_r($recipient, true)); if(!is_string($link)) - { throw new InvalidArgumentException('link = '.print_r($link, true)); - } if($linkType !== 0 && $linkType !== 1) - { throw new InvalidArgumentException('linkType = '.print_r($linkType, true)); - } - return $this->execute('SendOpenLinkToLogin', array($login, $link, $linkType), $multicall); + return $this->execute(ucfirst(__FUNCTION__).'ToLogin', array($logins, $link, $linkType), $multicall); } /** - * Kick the player with an optional message. - * @param Structures\Player|string $playerLogin + * Kick the player with the specified login, with an optional message. + * Only available to Admin. + * @param mixed $player Login or player object * @param string $message * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function kick($player, $message = '', $multicall = false) + function kick($player, $message='', $multicall=false) { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); if(!is_string($message)) - { throw new InvalidArgumentException('message = '.print_r($message, true)); - } - return $this->execute('Kick', array($login, $message), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($login, $message), $multicall); } /** - * Ban the player with an optional message. - * @param Structures\Player|string $player + * Ban the player with the specified login, with an optional message. + * Only available to Admin. + * @param mixed $player Login or player object * @param string $message * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function ban($player, $message = '', $multicall = false) + function ban($player, $message='', $multicall=false) { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); if(!is_string($message)) - { throw new InvalidArgumentException('message = '.print_r($message, true)); - } - return $this->execute('Ban', array($login, $message), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($login, $message), $multicall); } /** - * Ban the player with a message. + * Ban the player with the specified login, with a message. * Add it to the black list, and optionally save the new list. - * @param Structures\Player|string $player + * Only available to Admin. + * @param mixed $player Login or player object * @param string $message - * @param bool $saveList + * @param bool $save * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function banAndBlackList($player, $message, $saveList = false, $multicall = false) + function banAndBlackList($player, $message, $save=false, $multicall=false) { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } - if(!is_string($message) || !$message) - { + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + if(!is_string($message)) throw new InvalidArgumentException('message = '.print_r($message, true)); - } - if(!is_bool($saveList)) - { - throw new InvalidArgumentException('saveList = '.print_r($saveList, true)); - } + if(!is_bool($save)) + throw new InvalidArgumentException('save = '.print_r($save, true)); - return $this->execute(ucfirst(__FUNCTION__), array($login, $message, $saveList), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($player, $message, $save), $multicall); } /** - * Unban the player - * @param Structures\Player|string $player + * Unban the player with the specified login. + * Only available to Admin. + * @param mixed $player Login or player object * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function unBan($player, $multicall = false) + function unBan($player, $multicall=false) { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall); } /** * Clean the ban list of the server. + * Only available to Admin. * @param bool $multicall * @return bool */ - function cleanBanList($multicall = false) + function cleanBanList($multicall=false) { return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); } /** - * Returns the list of banned players. This method takes two parameters. - * The first parameter specifies the maximum number of infos to be returned, - * the second one the starting index in the list. The list is an array of structures. - * Each structure contains the following fields : Login, ClientName and IPAddress. - * @param int $length specifies the maximum number of infos to be returned - * @param int $offset specifies the starting index in the list - * @return Structures\Player[] The list is an array of Structures\Player + * Returns the list of banned players. + * @param int $length Maximum number of infos to be returned + * @param int $offset Starting index in the list + * @return Structures\PlayerBan[] * @throws InvalidArgumentException */ function getBanList($length, $offset) { - if(!is_int($length)) throw new InvalidArgumentException('length = '.print_r($length, true)); - if(!is_int($offset)) throw new InvalidArgumentException('offset = '.print_r($offset, true)); + if(!is_int($length)) + throw new InvalidArgumentException('length = '.print_r($length, true)); + if(!is_int($offset)) + throw new InvalidArgumentException('offset = '.print_r($offset, true)); - $result = $this->execute(ucfirst(__FUNCTION__), array($length, $offset)); - return Structures\Player::fromArrayOfArray($result); + return Structures\PlayerBan::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__), array($length, $offset))); } /** - * Blacklist the player - * @param Structures\Player|string $player + * Blacklist the player with the specified login. + * Only available to SuperAdmin. + * @param mixed $player Login or player object * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function blackList($player, $multicall = false) + function blackList($player, $multicall=false) { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall); } /** - * UnBlackList the player - * @param Structures\Player|string $player + * UnBlackList the player with the specified login. + * Only available to SuperAdmin. + * @param mixed $player Login or player object * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function unBlackList($player, $multicall = false) + function unBlackList($player, $multicall=false) { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall); } /** * Clean the blacklist of the server. + * Only available to SuperAdmin. * @param bool $multicall * @return bool */ - function cleanBlackList($multicall = false) + function cleanBlackList($multicall=false) { return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); } /** * Returns the list of blacklisted players. - * This method takes two parameters. - * The first parameter specifies the maximum number of infos to be returned, - * the second one the starting index in the list. The list is an array of structures. - * Each structure contains the following fields : Login. - * @param int $length specifies the maximum number of infos to be returned - * @param int $offset specifies the starting index in the list - * @return Structures\Player[] The list is an array of structures. Each structure contains the following fields : Login. + * @param int $length Maximum number of infos to be returned + * @param int $offset Starting index in the list + * @return Structures\Player[] * @throws InvalidArgumentException */ function getBlackList($length, $offset) { - if(!is_int($length)) throw new InvalidArgumentException('length = '.print_r($length, true)); - if(!is_int($offset)) throw new InvalidArgumentException('offset = '.print_r($offset, true)); + if(!is_int($length)) + throw new InvalidArgumentException('length = '.print_r($length, true)); + if(!is_int($offset)) + throw new InvalidArgumentException('offset = '.print_r($offset, true)); - $result = $this->execute(ucfirst(__FUNCTION__), array($length, $offset)); - return Structures\Player::fromArrayOfArray($result); + return Structures\Player::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__), array($length, $offset))); } /** * Load the black list file with the specified file name. - * @param string $filename blackList file name + * Only available to Admin. + * @param string $filename * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function loadBlackList($filename, $multicall = false) + function loadBlackList($filename, $multicall=false) { - if(!is_string($filename)) throw new InvalidArgumentException('filename = '.print_r($filename, true)); + if(!is_string($filename)) + throw new InvalidArgumentException('filename = '.print_r($filename, true)); return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall); } /** * Save the black list in the file with specified file name. - * @param string $filename blackList filename + * Only available to Admin. + * @param string $filename * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function saveBlackList($filename, $multicall = false) + function saveBlackList($filename, $multicall=false) { - if(!is_string($filename)) throw new InvalidArgumentException('filename = '.print_r($filename, true)); + if(!is_string($filename)) + throw new InvalidArgumentException('filename = '.print_r($filename, true)); return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall); } /** - * Add the player to the guest list. - * @param Structures\Player|string $player + * Add the player with the specified login on the guest list. + * Only available to Admin. + * @param mixed $player Login or player object * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function addGuest($player, $multicall = false) + function addGuest($player, $multicall=false) { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall); } /** - * Remove the player from the guest list. - * @param Structures\Player|string $player + * Remove the player with the specified login from the guest list. + * Only available to Admin. + * @param mixed $player Login or player object * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function removeGuest($player, $multicall = false) + function removeGuest($player, $multicall=false) { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall); } /** * Clean the guest list of the server. + * Only available to Admin. * @param bool $multicall * @return bool */ - function cleanGuestList($multicall = false) + function cleanGuestList($multicall=false) { return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); } /** * Returns the list of players on the guest list. - * This method takes two parameters. - * The first parameter specifies the maximum number of infos to be returned, - * the second one the starting index in the list. The list is an array of structures. - * Each structure contains the following fields : Login. - * @param int $length specifies the maximum number of infos to be returned - * @param int $offset specifies the starting index in the list - * @return Structures\Player[] The list is an array of structures. Each structure contains the following fields : Login. + * @param int $length Maximum number of infos to be returned + * @param int $offset Starting index in the list + * @return Structures\Player[] + * @return array * @throws InvalidArgumentException */ function getGuestList($length, $offset) { if(!is_int($length)) - { throw new InvalidArgumentException('length = '.print_r($length, true)); - } if(!is_int($offset)) - { throw new InvalidArgumentException('offset = '.print_r($offset, true)); - } - $result = $this->execute(ucfirst(__FUNCTION__), array($length, $offset)); - return Structures\Player::fromArrayOfArray($result); + return Structures\Player::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__), array($length, $offset))); } /** - * * Load the guest list file with the specified file name. - * @param string $filename blackList file name + * Only available to Admin. + * @param string $filename * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function loadGuestList($filename, $multicall = false) + function loadGuestList($filename, $multicall=false) { if(!is_string($filename)) - { throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall); } /** * Save the guest list in the file with specified file name. - * @param string $filename blackList file name + * Only available to Admin. + * @param string $filename * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function saveGuestList($filename, $multicall = false) + function saveGuestList($filename, $multicall=false) { if(!is_string($filename)) - { throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall); } /** * Sets whether buddy notifications should be sent in the chat. - * login is the login of the player, or '' for global setting, - * enabled is the value. - * @param null|Structures\Player|string $player the player, or null for global setting - * @param bool $enable the value. + * Only available to Admin. + * @param mixed $player Login or player object; empty for global setting + * @param bool $enable * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setBuddyNotification($player, $enable, $multicall = false) + function setBuddyNotification($player, $enable, $multicall=false) { + $login = $this->getLogin($player, true); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); if(!is_bool($enable)) - { throw new InvalidArgumentException('enable = '.print_r($enable, true)); - } - $player = $this->getLogin($player) ? : ''; - - return $this->execute(ucfirst(__FUNCTION__), array($player, $enable), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($login, $enable), $multicall); } /** - * Gets whether buddy notifications are enabled for login, or '' to get the global setting. - * @param null|Structures\Player|string $player the player, or null for global setting + * Gets whether buddy notifications are enabled. + * @param mixed $player Login or player object; empty for global setting * @return bool * @throws InvalidArgumentException */ function getBuddyNotification($player) { - $player = $this->getLogin($player) ? : ''; + $login = $this->getLogin($player, true); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); - return $this->execute(ucfirst(__FUNCTION__), array($player)); + return $this->execute(ucfirst(__FUNCTION__), array($login)); } /** - * Write the data to the specified file. The filename is relative to the Tracks path - * @param string $filename The file to be written - * @param string $localFilename The file to be read to obtain the data - * @param bool $multicall - * @return bool - * @throws InvalidArgumentException - */ - function writeFile($filename, $localFilename, $multicall = false) - { - if(!is_string($filename)) - { - throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } - if(!file_exists($localFilename)) - { - throw new InvalidArgumentException('localFilename = '.print_r($localFilename, true)); - } - - $inputData = file_get_contents($localFilename); - $data = new Xmlrpc\Base64($inputData); - - return $this->execute(ucfirst(__FUNCTION__), array($filename, $data), $multicall); - } - - /** - * Write the data to the specified file. The filename is relative to the Tracks path - * @param string $filename The file to be written - * @param string $data the data to be written - * @param bool $multicall - * @return bool - * @throws InvalidArgumentException - */ - function writeFileFromString($filename, $data, $multicall = false) - { - if(!is_string($filename)) - { - throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } - - $data = new Xmlrpc\Base64($data); - - return $this->execute('WriteFile', array($filename, $data), $multicall); - } - - /** - * Send the data to the specified player. - * Login can be a single login or a list of comma-separated logins. - * @param Structures\Player|string|mixed[] $players + * Write the data to the specified file. The filename is relative to the Maps path. + * Only available to Admin. * @param string $filename - * @param bool $multicall - * @return bool - * @throws InvalidArgumentException - */ - function tunnelSendData($players, $filename, $multicall = false) - { - if(!($login = $this->getLogins($players))) - { - throw new InvalidArgumentException('players = '.print_r($players, true)); - } - if(!file_exists($filename)) - { - throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } - - $inputData = file_get_contents($filename); - $data = new Xmlrpc\Base64($inputData); - - return $this->execute('TunnelSendDataToLogin', array($login, $data), $multicall); - } - - /** - * Send the data to the specified player. - * Login can be a single login or a list of comma-separated logins. - * @param Structures\Player|string|mixed[] $players * @param string $data * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function tunnelSendDataFromString($players, $data, $multicall = false) + function writeFile($filename, $data, $multicall=false) { - if(!($login = $this->getLogins($players))) - { - throw new InvalidArgumentException('players = '.print_r($players, true)); - } + if(!is_string($filename)) + throw new InvalidArgumentException('filename = '.print_r($filename, true)); + if(!is_string($data)) + throw new InvalidArgumentException('data = '.print_r($data, true)); $data = new Xmlrpc\Base64($data); + return $this->execute(ucfirst(__FUNCTION__), array($filename, $data), $multicall); + } - return $this->execute('TunnelSendDataToLogin', array($login, $data), $multicall); + /** + * Write the data to the specified file. The filename is relative to the Maps path. + * Only available to Admin. + * @param string $filename + * @param string $localFilename + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function writeFileFromFile($filename, $localFilename, $multicall=false) + { + if(!file_exists($localFilename)) + throw new InvalidArgumentException('localFilename = '.print_r($localFilename, true)); + + $contents = file_get_contents($localFilename); + return $this->writeFile($filename, $contents, $multicall); + } + + /** + * Send the data to the specified player. Login can be a single login or a list of comma-separated logins. + * Only available to Admin. + * @param mixed $recipient Login, player object or array + * @param string $data + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function tunnelSendData($recipient, $data, $multicall=false) + { + $logins = $this->getLogins($recipient); + if($logins === false) + throw new InvalidArgumentException('recipient = '.print_r($recipient, true)); + if(!is_string($data)) + throw new InvalidArgumentException('data = '.print_r($data, true)); + + $data = new Xmlrpc\Base64($data); + return $this->execute(ucfirst(__FUNCTION__).'ToLogin', array($logins, $data), $multicall); + } + + /** + * Send the data to the specified player. Login can be a single login or a list of comma-separated logins. + * Only available to Admin. + * @param mixed $recipient Login or player object or array + * @param string $filename + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function tunnelSendDataFromFile($recipient, $filename, $multicall=false) + { + if(!file_exists($filename)) + throw new InvalidArgumentException('filename = '.print_r($filename, true)); + + $contents = file_get_contents($filename); + return $this->tunnelSendData($recipient, $contents, $multicall); } /** * Just log the parameters and invoke a callback. * Can be used to talk to other xmlrpc clients connected, or to make custom votes. * If used in a callvote, the first parameter will be used as the vote message on the clients. - * @param string $message the message to log - * @param string $callback optionnal callback name + * Only available to Admin. + * @param string $message + * @param string $callback * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function dedicatedEcho($message, $callback = '', $multicall = false) + function dedicatedEcho($message, $callback='', $multicall=false) { if(!is_string($message)) - { throw new InvalidArgumentException('message = '.print_r($message, true)); - } if(!is_string($callback)) - { throw new InvalidArgumentException('callback = '.print_r($callback, true)); - } return $this->execute('Echo', array($message, $callback), $multicall); } /** - * Ignore the specified Structures\Player. - * @param Structures\Player|string $player + * Ignore the player with the specified login. + * Only available to Admin. + * @param mixed $player Login or player object * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function ignore($player, $multicall = false) + function ignore($player, $multicall=false) { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall); } /** - * Unignore the specified player. - * @param Structures\Player|string $player + * Unignore the player with the specified login. + * Only available to Admin. + * @param mixed $player Login or player object * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function unIgnore($player, $multicall = false) + function unIgnore($player, $multicall=false) { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall); } /** * Clean the ignore list of the server. + * Only available to Admin. * @param bool $multicall * @return bool */ - function cleanIgnoreList($multicall = false) + function cleanIgnoreList($multicall=false) { return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); } /** - * Returns the list of ignored players. This method takes two parameters. - * The first parameter specifies the maximum number of infos to be returned, - * the second one the starting index in the list. The list is an array of structures. - * Each structure contains the following fields : Login. - * @param int $length specifies the maximum number of infos to be returned - * @param int $offset specifies the starting index in the list - * @return Structures\Player[] The list is an array of structures. Each structure contains the following fields : Login. + * Returns the list of ignored players. + * @param int $length Maximum number of infos to be returned + * @param int $offset Starting index in the list + * @return Structures\Player[] * @throws InvalidArgumentException */ function getIgnoreList($length, $offset) { if(!is_int($length)) - { throw new InvalidArgumentException('length = '.print_r($length, true)); - } if(!is_int($offset)) - { throw new InvalidArgumentException('offset = '.print_r($offset, true)); - } - $result = $this->execute(ucfirst(__FUNCTION__), array($length, $offset)); - return Structures\Player::fromArrayOfArray($result); + return Structures\Player::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__), array($length, $offset))); } /** - * Pay coppers from the server account to a player, returns the BillId. - * This method takes three parameters: - * Login of the payee, - * Coppers to pay and - * Label to send with the payment. - * The creation of the transaction itself may cost coppers, - * so you need to have coppers on the server account. - * @param Structures\Player|string $player + * Pay planets from the server account to a player. + * The creation of the transaction itself may cost planets, so you need to have planets on the server account. + * Only available to Admin. + * @param mixed $payee Login or player object * @param int $amount - * @param string $label + * @param string $message * @param bool $multicall - * @return int The Bill Id + * @return int BillId * @throws InvalidArgumentException */ - function pay($player, $amount, $label, $multicall = false) + function pay($payee, $amount, $message, $multicall=false) { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } + $login = $this->getLogin($payee); + if($login === false) + throw new InvalidArgumentException('payee = '.print_r($payee, true)); if(!is_int($amount) || $amount < 1) - { throw new InvalidArgumentException('amount = '.print_r($amount, true)); - } - if(!is_string($label)) - { - throw new InvalidArgumentException('label = '.print_r($label, true)); - } + if(!is_string($message)) + throw new InvalidArgumentException('message = '.print_r($message, true)); - return $this->execute(ucfirst(__FUNCTION__), array($login, $amount, $label), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($login, $amount, $message), $multicall); } /** * Create a bill, send it to a player, and return the BillId. - * This method takes four parameters: - * LoginFrom of the payer, - * Coppers the player has to pay, - * Label of the transaction and - * optional LoginTo of the payee (if empty string, then the server account is used). - * The creation of the transaction itself may cost coppers, - * so you need to have coppers on the server account. - * @param Structures\Player|string $fromPlayer + * The creation of the transaction itself may cost planets, so you need to have planets on the server account. + * Only available to Admin. + * @param mixed $payer Login or player object * @param int $amount - * @param string $label - * @param Structures\Player|string|null $toPlayer + * @param string $message + * @param mixed $payee Login or player object; empty for server account * @param bool $multicall - * @return int + * @return int BillId * @throws InvalidArgumentException */ - function sendBill($fromPlayer, $amount, $label, $toPlayer = null, $multicall = false) + function sendBill($payer, $amount, $message, $payee, $multicall=false) { - + $payerLogin = $this->getLogin($payer); + if($payerLogin === false) + throw new InvalidArgumentException('payer = '.print_r($payer, true)); if(!is_int($amount) || $amount < 1) - { throw new InvalidArgumentException('amount = '.print_r($amount, true)); - } - if(!is_string($label)) - { - throw new InvalidArgumentException('label = '.print_r($label, true)); - } - if(!($from = $this->getLogin($fromPlayer))) - { - throw new InvalidArgumentException('fromPlayer must be set'); - } + if(!is_string($message)) + throw new InvalidArgumentException('message = '.print_r($message, true)); + $payeeLogin = $this->getLogin($payee, true); + if($payeeLogin === false) + throw new InvalidArgumentException('payee = '.print_r($payee, true)); - $to = $this->getLogin($toPlayer) ? : ''; - - return $this->execute(ucfirst(__FUNCTION__), array($from, $amount, $label, $to), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($payerLogin, $amount, $message, $payeeLogin), $multicall); } /** * Returns the current state of a bill. - * This method takes one parameter, the BillId. - * Returns a struct containing - * State, StateName and TransactionId. - * Possible enum values are: CreatingTransaction, Issued, ValidatingPayement, Payed, Refused, Error. * @param int $billId * @return Structures\Bill * @throws InvalidArgumentException @@ -1490,12 +1260,9 @@ class Connection function getBillState($billId) { if(!is_int($billId)) - { throw new InvalidArgumentException('billId = '.print_r($billId, true)); - } - $result = $this->execute(ucfirst(__FUNCTION__), array($billId)); - return Structures\Bill::fromArray($result); + return Structures\Bill::fromArray($this->execute(ucfirst(__FUNCTION__), array($billId))); } /** @@ -1504,56 +1271,49 @@ class Connection */ function getServerPlanets() { - return $this->execute('GetServerPlanets'); + return $this->execute(ucfirst(__FUNCTION__)); } /** - * Get some system infos. - * Return a struct containing: - * PublishedIp, Port, P2PPort, ServerLogin, ServerPlayerId + * Get some system infos, including connection rates (in kbps). * @return Structures\SystemInfos */ function getSystemInfo() { - $result = $this->execute(ucfirst(__FUNCTION__)); - return Structures\SystemInfos::fromArray($result); + return Structures\SystemInfos::fromArray($this->execute(ucfirst(__FUNCTION__))); } /** - * Sets up- and download speed for the server in kbps. - * @param int $downloadRate the download rate in kbps - * @param int $uploadRate the upload rate in kbps + * Set the download and upload rates (in kbps). + * @param int $downloadRate + * @param int $uploadRate * @param bool $multicall * @return bool + * @throws InvalidArgumentException */ - function setConnectionRates($downloadRate, $uploadRate, $multicall = false) + function setConnectionRates($downloadRate, $uploadRate, $multicall=false) { if(!is_int($downloadRate)) - { throw new InvalidArgumentException('downloadRate = '.print_r($downloadRate, true)); - } if(!is_int($uploadRate)) - { throw new InvalidArgumentException('uploadRate = '.print_r($uploadRate, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($downloadRate, $uploadRate), $multicall); } /** * Returns the list of tags and associated values set on this server. - * The list is an array of structures {string Name, string Value}. * Only available to Admin. - * @return array + * @param bool $multicall + * @return Structures\Tag[] */ function getServerTags() { - return $this->execute(ucfirst(__FUNCTION__)); + return Structures\Tag::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__))); } /** - * Set a tag and its value on the server. This method takes two parameters. - * The first parameter specifies the name of the tag, and the second one its value. + * Set a tag and its value on the server. * Only available to Admin. * @param string $key * @param string $value @@ -1561,16 +1321,13 @@ class Connection * @return bool * @throws InvalidArgumentException */ - function setServerTag($key, $value, $multicall = false) + function setServerTag($key, $value, $multicall=false) { if(!is_string($key)) - { throw new InvalidArgumentException('key = '.print_r($key, true)); - } if(!is_string($value)) - { throw new InvalidArgumentException('value = '.print_r($value, true)); - } + return $this->execute(ucfirst(__FUNCTION__), array($key, $value), $multicall); } @@ -1582,12 +1339,11 @@ class Connection * @return bool * @throws InvalidArgumentException */ - function unsetServerTag($key, $multicall = false) + function unsetServerTag($key, $multicall=false) { if(!is_string($key)) - { throw new InvalidArgumentException('key = '.print_r($key, true)); - } + return $this->execute(ucfirst(__FUNCTION__), array($key), $multicall); } @@ -1597,26 +1353,25 @@ class Connection * @param bool $multicall * @return bool */ - function resetServerTags($multicall = false) + function resetServerTags($multicall=false) { return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); } /** * Set a new server name in utf8 format. - * @param string $serverName + * Only available to Admin. + * @param string $name * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setServerName($serverName, $multicall = false) + function setServerName($name, $multicall=false) { - if(!is_string($serverName)) - { - throw new InvalidArgumentException('serverName = '.print_r($serverName, true)); - } + if(!is_string($name)) + throw new InvalidArgumentException('name = '.print_r($name, true)); - return $this->execute(ucfirst(__FUNCTION__), array($serverName), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($name), $multicall); } /** @@ -1630,19 +1385,18 @@ class Connection /** * Set a new server comment in utf8 format. - * @param string $serverComment + * Only available to Admin. + * @param string $comment * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setServerComment($serverComment, $multicall = false) + function setServerComment($comment, $multicall=false) { - if(!is_string($serverComment)) - { - throw new InvalidArgumentException('serverComment = '.print_r($serverComment, true)); - } + if(!is_string($comment)) + throw new InvalidArgumentException('comment = '.print_r($comment, true)); - return $this->execute(ucfirst(__FUNCTION__), array($serverComment), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($comment), $multicall); } /** @@ -1655,26 +1409,24 @@ class Connection } /** - * Set whether the server should be hidden from the public server list - * (0 = visible, 1 = always hidden, 2 = hidden from nations). - * @param int $visibility + * Set whether the server should be hidden from the public server list. + * Only available to Admin. + * @param int $visibility 0: visible, 1: always hidden, 2: hidden from nations * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setHideServer($visibility, $multicall = false) + function setHideServer($visibility, $multicall=false) { - if($visibility !== 0 && $visibility !== 1 && $visibility !== 2) - { + if(!is_int($visibility) || $visibility < 0 || $visibility > 2) throw new InvalidArgumentException('visibility = '.print_r($visibility, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($visibility), $multicall); } /** * Get whether the server wants to be hidden from the public server list. - * @return string + * @return int */ function getHideServer() { @@ -1692,25 +1444,23 @@ class Connection /** * Set a new password for the server. - * @param string $serverPassword + * Only available to Admin. + * @param string $password * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setServerPassword($serverPassword, $multicall = false) + function setServerPassword($password, $multicall=false) { - if(!is_string($serverPassword)) - { - throw new InvalidArgumentException('serverPassword = '.print_r($serverPassword, true)); - } + if(!is_string($password)) + throw new InvalidArgumentException('password = '.print_r($password, true)); - return $this->execute(ucfirst(__FUNCTION__), array($serverPassword), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($password), $multicall); } /** * Get the server password if called as Admin or Super Admin, else returns if a password is needed or not. - * Get the server name in utf8 format. - * @return bool|string + * @return string|bool */ function getServerPassword() { @@ -1719,24 +1469,23 @@ class Connection /** * Set a new password for the spectator mode. - * @param string $serverPassword + * Only available to Admin. + * @param string $password * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setServerPasswordForSpectator($serverPassword, $multicall = false) + function setServerPasswordForSpectator($password, $multicall=false) { - if(!is_string($serverPassword)) - { - throw new InvalidArgumentException('serverPassword = '.print_r($serverPassword, true)); - } + if(!is_string($password)) + throw new InvalidArgumentException('password = '.print_r($password, true)); - return $this->execute(ucfirst(__FUNCTION__), array($serverPassword), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($password), $multicall); } /** * Get the password for spectator mode if called as Admin or Super Admin, else returns if a password is needed or not. - * @return bool|string + * @return string|bool */ function getServerPasswordForSpectator() { @@ -1745,26 +1494,24 @@ class Connection /** * Set a new maximum number of players. + * Only available to Admin. * Requires a map restart to be taken into account. * @param int $maxPlayers * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setMaxPlayers($maxPlayers, $multicall = false) + function setMaxPlayers($maxPlayers, $multicall=false) { if(!is_int($maxPlayers)) - { throw new InvalidArgumentException('maxPlayers = '.print_r($maxPlayers, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($maxPlayers), $multicall); } /** * Get the current and next maximum number of players allowed on server. - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * @return int[] {int CurrentValue, int NextValue} */ function getMaxPlayers() { @@ -1773,26 +1520,24 @@ class Connection /** * Set a new maximum number of spectators. + * Only available to Admin. * Requires a map restart to be taken into account. * @param int $maxSpectators * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setMaxSpectators($maxSpectators, $multicall = false) + function setMaxSpectators($maxSpectators, $multicall=false) { if(!is_int($maxSpectators)) - { - throw new InvalidArgumentException('maxPlayers = '.print_r($maxSpectators, true)); - } + throw new InvalidArgumentException('maxSpectators = '.print_r($maxSpectators, true)); return $this->execute(ucfirst(__FUNCTION__), array($maxSpectators), $multicall); } /** - * Get the current and next maximum number of spectators allowed on server. - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * Get the current and next maximum number of Spectators allowed on server. + * @return int[] {int CurrentValue, int NextValue} */ function getMaxSpectators() { @@ -1803,90 +1548,73 @@ class Connection * Declare if the server is a lobby, the number and maximum number of players currently managed by it, and the average level of the players. * Only available to Admin. * @param bool $isLobby - * @param int $lobbyPlayers + * @param int $currentPlayers * @param int $maxPlayers - * @param double $lobbyPlayersLevel + * @param float $averageLevel * @param bool $multicall * @return bool + * @throws InvalidArgumentException */ - function setLobbyInfo($isLobby, $lobbyPlayers, $maxPlayers, $lobbyPlayersLevel, $multicall = false) + function setLobbyInfo($isLobby, $currentPlayers, $maxPlayers, $averageLevel, $multicall=false) { if(!is_bool($isLobby)) - { throw new InvalidArgumentException('isLobby = '.print_r($isLobby, true)); - } - if(!is_int($lobbyPlayers)) - { - throw new InvalidArgumentException('lobbyPlayers = '.print_r($lobbyPlayers, true)); - } + if(!is_int($currentPlayers)) + throw new InvalidArgumentException('currentPlayers = '.print_r($currentPlayers, true)); if(!is_int($maxPlayers)) - { throw new InvalidArgumentException('maxPlayers = '.print_r($maxPlayers, true)); - } - if(!is_double($lobbyPlayersLevel)) - { - throw new InvalidArgumentException('lobbyPlayersLevel = '.print_r($lobbyPlayersLevel, true)); - } - return $this->execute(ucfirst(__FUNCTION__), array($isLobby, $lobbyPlayers, $maxPlayers, $lobbyPlayersLevel), $multicall); + if(!is_float($averageLevel)) + throw new InvalidArgumentException('averageLevel = '.print_r($averageLevel, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($isLobby, $currentPlayers, $maxPlayers, $averageLevel), $multicall); } /** * Get whether the server if a lobby, the number and maximum number of players currently managed by it. - * The struct returned contains 4 fields IsLobby, LobbyPlayers, LobbyMaxPlayers, and LobbyPlayersLevel. * @return Structures\LobbyInfo */ function getLobbyInfo() { - $result = $this->execute(ucfirst(__FUNCTION__)); - return Structures\LobbyInfo::fromArray($result); + return Structures\LobbyInfo::fromArray($this->execute(ucfirst(__FUNCTION__))); } /** * Customize the clients 'leave server' dialog box. - * Parameters are: ManialinkPage, SendToServer url '#qjoin=login@title', - * ProposeAddToFavorites and DelayQuitButton (in milliseconds). * Only available to Admin. - * @param string $manialinkPage - * @param string $sendToServer - * @param bool $proposeAddToFavorites + * @param string $manialink + * @param string $sendToServer Server URL, eg. '#qjoin=login@title' + * @param bool $askFavorite + * @param int $quitButtonDelay In milliseconds * @param bool $multicall * @return bool + * @throws InvalidArgumentException */ - function customizeQuitDialog($manialinkPage, $sendToServer, $proposeAddToFavorites, $delayQuitButton, $multicall = false) + function customizeQuitDialog($manialink, $sendToServer, $askFavorite, $quitButtonDelay, $multicall=false) { - if(!is_string($manialinkPage)) - { - throw new InvalidArgumentException('manialinkPage = '.print_r($manialinkPage, true)); - } + if(!is_string($manialink)) + throw new InvalidArgumentException('manialink = '.print_r($manialink, true)); if(!is_string($sendToServer)) - { throw new InvalidArgumentException('sendToServer = '.print_r($sendToServer, true)); - } - if(!is_bool($proposeAddToFavorites)) - { - throw new InvalidArgumentException('proposeAddToFavorites = '.print_r($proposeAddToFavorites, true)); - } - if(!is_int($delayQuitButton)) - { - throw new InvalidArgumentException('delayQuitButton = '.print_r($delayQuitButton, true)); - } - return $this->execute(ucfirst(__FUNCTION__), array($manialinkPage, $sendToServer, $proposeAddToFavorites, $delayQuitButton), $multicall); + if(!is_bool($askFavorite)) + throw new InvalidArgumentException('askFavorite = '.print_r($askFavorite, true)); + if(!is_int($quitButtonDelay)) + throw new InvalidArgumentException('quitButtonDelay = '.print_r($quitButtonDelay, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($manialink, $sendToServer, $askFavorite, $quitButtonDelay), $multicall); } /** - * Set whether, when a player is switching to spectator, the server should still consider him a player - * and keep his player slot, or not. Only available to Admin. + * Set whether, when a player is switching to spectator, the server should still consider him a player and keep his player slot, or not. + * Only available to Admin. * @param bool $keep * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function keepPlayerSlots($keep, $multicall = false) + function keepPlayerSlots($keep, $multicall=false) { if(!is_bool($keep)) - { throw new InvalidArgumentException('keep = '.print_r($keep, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($keep), $multicall); } @@ -1902,17 +1630,16 @@ class Connection /** * Enable or disable peer-to-peer upload from server. + * Only available to Admin. * @param bool $enable * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function enableP2PUpload($enable, $multicall = false) + function enableP2PUpload($enable, $multicall=false) { if(!is_bool($enable)) - { throw new InvalidArgumentException('enable = '.print_r($enable, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($enable), $multicall); } @@ -1927,24 +1654,23 @@ class Connection } /** - * Enable or disable peer-to-peer download from server. + * Enable or disable peer-to-peer download for server. + * Only available to Admin. * @param bool $enable * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function enableP2PDownload($enable, $multicall = false) + function enableP2PDownload($enable, $multicall=false) { if(!is_bool($enable)) - { throw new InvalidArgumentException('enable = '.print_r($enable, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($enable), $multicall); } /** - * Returns if the peer-to-peer download from server is enabled. + * Returns if the peer-to-peer download for server is enabled. * @return bool */ function isP2PDownload() @@ -1954,17 +1680,16 @@ class Connection /** * Allow clients to download maps from the server. + * Only available to Admin. * @param bool $allow * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function allowMapDownload($allow, $multicall = false) + function allowMapDownload($allow, $multicall=false) { if(!is_bool($allow)) - { throw new InvalidArgumentException('allow = '.print_r($allow, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($allow), $multicall); } @@ -1979,19 +1704,231 @@ class Connection } /** - * Enable the autosaving of all replays (vizualisable replays with all players, - * but not validable) on the server. + * Returns the path of the game datas directory. + * Only available to Admin. + * @return string + */ + function gameDataDirectory() + { + return $this->execute(ucfirst(__FUNCTION__)); + } + + /** + * Returns the path of the maps directory. + * Only available to Admin. + * @return string + */ + function getMapsDirectory() + { + return $this->execute(ucfirst(__FUNCTION__)); + } + + /** + * Returns the path of the skins directory. + * Only available to Admin. + * @return string + */ + function getSkinsDirectory() + { + return $this->execute(ucfirst(__FUNCTION__)); + } + + /** + * @deprecated since version 2013-04-11 + * Set Team names and colors. + * Only available to Admin. + * @param string $name1 + * @param float $color1 + * @param string $path1 + * @param string $name2 + * @param float $color2 + * @param string $path2 + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function setTeamInfo($name1, $color1, $path1, $name2, $color2, $path2, $multicall=false) + { + if(!is_string($name1)) + throw new InvalidArgumentException('name1 = '.print_r($name1, true)); + if(!is_float($color1)) + throw new InvalidArgumentException('color1 = '.print_r($color1, true)); + if(!is_string($path1)) + throw new InvalidArgumentException('path1 = '.print_r($path1, true)); + if(!is_string($name2)) + throw new InvalidArgumentException('name2 = '.print_r($name2, true)); + if(!is_float($color2)) + throw new InvalidArgumentException('color2 = '.print_r($color2, true)); + if(!is_string($path2)) + throw new InvalidArgumentException('path2 = '.print_r($path2, true)); + + return $this->execute(ucfirst(__FUNCTION__), array('unused', 0., 'World', $name1, $color1, $path1, $name2, $color2, $path2), $multicall); + } + + /** + * Return info for a given team. + * Only available to Admin. + * @param int $team 0: no clan, 1 or 2 + * @return Structures\Team + * @throws InvalidArgumentException + */ + function getTeamInfo($team) + { + if(!is_int($team) || $team < 0 || $team > 2) + throw new InvalidArgumentException('team = '.print_r($team, true)); + + return Structures\Team::fromArray($this->execute(ucfirst(__FUNCTION__), array($team))); + } + + /** + * Set the clublinks to use for the two teams. + * Only available to Admin. + * @param string $team1 + * @param string $team2 + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function setForcedClubLinks($team1, $team2, $multicall=false) + { + if(!is_string($team1)) + throw new InvalidArgumentException('team1 = '.print_r($team1, true)); + if(!is_string($team2)) + throw new InvalidArgumentException('team2 = '.print_r($team2, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($team1, $team2), $multicall); + } + + /** + * Get the forced clublinks. + * @return string[] + */ + function getForcedClubLinks() + { + return $this->execute(ucfirst(__FUNCTION__)); + } + + /** + * (debug tool) Connect a fake player to the server and returns the login. + * Only available to Admin. + * @param bool $multicall + * @return string + */ + function connectFakePlayer($multicall=false) + { + return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); + } + + /** + * (debug tool) Disconnect a fake player. + * Only available to Admin. + * @param string $login Fake player login or '*' for all + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function disconnectFakePlayer($login, $multicall=false) + { + if(!is_string($login)) + throw new InvalidArgumentException('login = '.print_r($login, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall); + } + + /** + * Returns the token infos for a player. + * @param mixed $player Login or player object + * @param bool $multicall + * @return array {int TokenCost, bool CanPayToken} + * @throws InvalidArgumentException + */ + function getDemoTokenInfosForPlayer($player) + { + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($login)); + } + + /** + * Disable player horns. + * Only available to Admin. + * @param bool $disable + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function disableHorns($disable, $multicall=false) + { + if(!is_bool($disable)) + throw new InvalidArgumentException('disable = '.print_r($disable, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($disable), $multicall); + } + + /** + * Returns whether the horns are disabled. + * @return bool + */ + function areHornsDisabled() + { + return $this->execute(ucfirst(__FUNCTION__)); + } + + /** + * Disable the automatic mesages when a player connects/disconnects from the server. + * Only available to Admin. + * @param bool $disable + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function disableServiceAnnounces($disable, $multicall=false) + { + if(!is_bool($disable)) + throw new InvalidArgumentException('disable = '.print_r($disable, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($disable), $multicall); + } + + /** + * Returns whether the automatic mesages are disabled. + * @return bool + */ + function areServiceAnnouncesDisabled() + { + return $this->execute(ucfirst(__FUNCTION__)); + } + + /** + * Enable the autosaving of all replays (vizualisable replays with all players, but not validable) on the server. + * Only available to SuperAdmin. * @param bool $enable * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function autoSaveReplays($enable, $multicall = false) + function autoSaveReplays($enable, $multicall=false) + { + if(!is_bool($enable)) + throw new InvalidArgumentException('enable = '.print_r($enable, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($enable), $multicall); + } + + /** + * Enable the autosaving on the server of validation replays, every time a player makes a new time. + * Only available to SuperAdmin. + * @param bool $enable + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function autoSaveValidationReplays($enable, $multicall=false) { if(!is_bool($enable)) - { throw new InvalidArgumentException('enable = '.print_r($enable, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($enable), $multicall); } @@ -2005,23 +1942,6 @@ class Connection return $this->execute(ucfirst(__FUNCTION__)); } - /** - * Enable the autosaving on the server of validation replays, every time a player makes a new time. - * @param bool $enable - * @param bool $multicall - * @return bool - * @throws InvalidArgumentException - */ - function autoSaveValidationReplays($enable, $multicall = false) - { - if(!is_bool($enable)) - { - throw new InvalidArgumentException('enable = '.print_r($enable, true)); - } - - return $this->execute(ucfirst(__FUNCTION__), array($enable), $multicall); - } - /** * Returns if autosaving of validation replays is enabled on the server. * @return bool @@ -2033,82 +1953,75 @@ class Connection /** * Saves the current replay (vizualisable replays with all players, but not validable). - * Pass a filename, or '' for an automatic filename. - * @param string $filename + * Only available to Admin. + * @param string $filename Empty for automatic filename * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function saveCurrentReplay($filename = '', $multicall = false) + function saveCurrentReplay($filename='', $multicall=false) { if(!is_string($filename)) - { throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall); } /** * Saves a replay with the ghost of all the players' best race. - * First parameter is the player object(or null for all players), - * Second parameter is the filename, or '' for an automatic filename. - * @param null|Structures\Player|string $player the player (or null for all players) - * @param string $filename is the filename, or '' for an automatic filename + * Only available to Admin. + * @param mixed $player Login or player object; empty for all + * @param string $filename Empty for automatic filename * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function saveBestGhostsReplay($player = null, $filename = '', $multicall = false) + function saveBestGhostsReplay($player=null, $filename='', $multicall=false) { + $login = $this->getLogin($player, true); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); if(!is_string($filename)) - { throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } - $playerLogin = $this->getLogin($player) ? : ''; - - return $this->execute(ucfirst(__FUNCTION__), array($playerLogin, $filename), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($login, $filename), $multicall); } /** * Returns a replay containing the data needed to validate the current best time of the player. - * The parameter is the login of the player. - * @param Structures\Player|string $player + * @param mixed $player Login or player object * @return string * @throws InvalidArgumentException */ function getValidationReplay($player) { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + return $this->execute(ucfirst(__FUNCTION__), array($login))->scalar; } /** - * Set a new ladder mode between ladder disabled (0) and forced (1). + * Set a new ladder mode. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $mode + * @param int $mode 0: disabled, 1: forced * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setLadderMode($mode, $multicall = false) + function setLadderMode($mode, $multicall=false) { if($mode !== 0 && $mode !== 1) - { throw new InvalidArgumentException('mode = '.print_r($mode, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($mode), $multicall); } /** * Get the current and next ladder mode on server. - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * @return int[] {int CurrentValue, int NextValue} */ function getLadderMode() { @@ -2117,36 +2030,33 @@ class Connection /** * Get the ladder points limit for the players allowed on this server. - * The struct returned contains two fields LadderServerLimitMin and LadderServerLimitMax. - * @return array + * @return Structures\LadderLimits */ function getLadderServerLimits() { - return $this->execute(ucfirst(__FUNCTION__)); + return Structures\LadderLimits::fromArray($this->execute(ucfirst(__FUNCTION__))); } /** - * Set the network vehicle quality to Fast (0) or High (1). + * Set the network vehicle quality. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $quality + * @param int $quality 0: fast, 1: high * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setVehicleNetQuality($quality, $multicall = false) + function setVehicleNetQuality($quality, $multicall=false) { if($quality !== 0 && $quality !== 1) - { throw new InvalidArgumentException('quality = '.print_r($quality, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($quality), $multicall); } /** * Get the current and next network vehicle quality on server. - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * @return int[] {int CurrentValue, int NextValue} */ function getVehicleNetQuality() { @@ -2154,46 +2064,38 @@ class Connection } /** - * Set new server options using the struct passed as parameters. This struct must contain the following fields : - * Name, Comment, Password, PasswordForSpectator, NextMaxPlayers, NextMaxSpectators, IsP2PUpload, IsP2PDownload, - * NextLadderMode, NextVehicleNetQuality, NextCallVoteTimeOut, CallVoteRatio, AllowMapDownload, AutoSaveReplays, - * - * and optionally for forever: - * RefereePassword, RefereeMode, AutoSaveValidationReplays, HideServer, UseChangingValidationSeed, - * ClientInputsMaxLatency, KeepPlayerSlots. - * + * Set new server options using the struct passed as parameters. + * Mandatory fields: + * Name, Comment, Password, PasswordForSpectator, CallVoteRatio + * Optional fields: + * NextMaxPlayers, NextMaxSpectators, IsP2PUpload, IsP2PDownload, NextLadderMode, + * NextVehicleNetQuality, NextCallVoteTimeOut, AllowMapDownload, AutoSaveReplays, + * RefereePassword, RefereeMode, AutoSaveValidationReplays, HideServer, UseChangingValidationSeed, + * ClientInputsMaxLatency, DisableHorns, DisableServiceAnnounces, KeepPlayerSlots. * Only available to Admin. - * A change of NextMaxPlayers, NextMaxSpectators, NextLadderMode, NextVehicleNetQuality, NextCallVoteTimeOut - * or UseChangingValidationSeed requires a map restart to be taken into account. - * @param array $options + * A change of NextMaxPlayers, NextMaxSpectators, NextLadderMode, NextVehicleNetQuality, + * NextCallVoteTimeOut or UseChangingValidationSeed requires a map restart to be taken into account. + * @param struct $options * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setServerOptions(array $options, $multicall = false) + function setServerOptions($options, $multicall=false) { - if(!is_array($options) || !array_key_exists('Name', $options) || !array_key_exists('Comment', $options) - || !array_key_exists('Password', $options) || !array_key_exists('PasswordForSpectator', $options) - || !array_key_exists('NextCallVoteTimeOut', $options) || !array_key_exists('CallVoteRatio', $options) - || (array_key_exists('IsP2PUpload', $options) xor array_key_exists('IsP2PDownload', $options)) - || (array_key_exists('NextMaxPlayer', $options) xor array_key_exists('NextMaxSpectator', $options)) - || (array_key_exists('RefereePassword', $options) xor array_key_exists('RefereeMode', $options))) - { + if(!is_array($options) + || !(isset($options['Name']) && is_string($options['Name'])) + || !(isset($options['Comment']) && is_string($options['Comment'])) + || !(isset($options['Password']) && is_string($options['Password'])) + || !(isset($options['PasswordForSpectator']) && is_string($options['PasswordForSpectator'])) + || !(isset($options['CallVoteRatio']) && Structures\VoteRatio::isRatio($options['CallVoteRatio']))) throw new InvalidArgumentException('options = '.print_r($options, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($options), $multicall); } /** - * Returns a struct containing the server options: - * Name, Comment, Password, PasswordForSpectator, CurrentMaxPlayers, NextMaxPlayers, CurrentMaxSpectators, - * NextMaxSpectators, KeepPlayerSlots, IsP2PUpload, IsP2PDownload, CurrentLadderMode, NextLadderMode, - * CurrentVehicleNetQuality, NextVehicleNetQuality, CurrentCallVoteTimeOut, NextCallVoteTimeOut, CallVoteRatio, - * AllowMapDownload, AutoSaveReplays, RefereePassword, RefereeMode, AutoSaveValidationReplays, HideServer, - * CurrentUseChangingValidationSeed, NextUseChangingValidationSeed, ClientInputsMaxLatency. + * Returns a struct containing the server options * @return Structures\ServerOptions - * @throws InvalidArgumentException */ function getServerOptions() { @@ -2208,12 +2110,11 @@ class Connection * @return bool * @throws InvalidArgumentException */ - function setForcedTeams($enable, $multicall = false) + function setForcedTeams($enable, $multicall=false) { if(!is_bool($enable)) - { throw new InvalidArgumentException('enable = '.print_r($enable, true)); - } + return $this->execute(ucfirst(__FUNCTION__), array($enable), $multicall); } @@ -2227,21 +2128,19 @@ class Connection } /** - * Defines the packmask of the server. Can be 'United', 'Nations', 'Sunrise', 'Original', - * or any of the environment names. (Only maps matching the packmask will be - * allowed on the server, so that player connecting to it know what to expect.) + * Defines the packmask of the server. + * Only maps matching the packmask will be allowed on the server, so that player connecting to it know what to expect. * Only available when the server is stopped. + * Only available to Admin. * @param string $packMask * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setServerPackMask($packMask, $multicall = false) + function setServerPackMask($packMask, $multicall=false) { if(!is_string($packMask)) - { - throw new InvalidArgumentException('packMask = '.print_r($packMask, true)); - } + throw new InvalidArgumentException('packMask = '.print_r($enable, true)); return $this->execute(ucfirst(__FUNCTION__), array($packMask), $multicall); } @@ -2256,40 +2155,39 @@ class Connection } /** - * Set the mods to apply on the clients. Parameters: - * Override, if true even the maps with a mod will be overridden by the server setting; - * Mods, an array of structures [{EnvName, Url}, ...]. + * Set the mods to apply on the clients. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param bool $override - * @param array $mods + * @param bool $override If true, even the maps with a mod will be overridden by the server setting + * @param Structures\Mod|Structures\Mod[] $mods Array of structures [{string Env, string Url}, ...] * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setForcedMods($override, $mods, $multicall = false) + function setForcedMods($override, $mods, $multicall=false) { if(!is_bool($override)) - { throw new InvalidArgumentException('override = '.print_r($override, true)); - } if(is_array($mods)) { - $modList = array(); - foreach($mods as $mod) + foreach($mods as $i => &$mod) { - if(!($mod instanceof Structures\Mod)) throw new InvalidArgumentException('mods = '.print_r($mods, true)); - else $modList[] = $mod->toArray(); + if(!($mod instanceof Structures\Mod)) + throw new InvalidArgumentException('mods['.$i.'] = '.print_r($mod, true)); + $mod = $mod->toArray(); } } - elseif($mods instanceof Structures\Mod) $modList = array($mods->toArray()); - else throw new InvalidArgumentException('mods = '.print_r($mods, true)); + elseif($mods instanceof Structures\Mod) + $mods = array($mods->toArray()); + else + throw new InvalidArgumentException('mods = '.print_r($mods, true)); - return $this->execute(ucfirst(__FUNCTION__), array($override, $modList), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($override, $mods), $multicall); } /** * Get the mods settings. - * @return array the first value is a boolean which indicate if the mods override existing mods, the second is an array of objet of Structures\Mod type + * @return array {bool Override, Structures\Mod[] Mods} */ function getForcedMods() { @@ -2299,25 +2197,21 @@ class Connection } /** - * Set the music to play on the clients. Parameters: - * Override, if true even the maps with a custom music will be overridden by the server setting, - * UrlOrFileName for the music. - * Requires a map restart to be taken into account - * @param bool $override - * @param string $music + * Set the music to play on the clients. + * Only available to Admin. + * Requires a map restart to be taken into account. + * @param bool $override If true, even the maps with a custom music will be overridden by the server setting + * @param string $music Url or filename for the music * @param bool $multicall + * @return bool * @throws InvalidArgumentException */ - function setForcedMusic($override, $music, $multicall = false) + function setForcedMusic($override, $music, $multicall=false) { if(!is_bool($override)) - { throw new InvalidArgumentException('override = '.print_r($override, true)); - } if(!is_string($music)) - { throw new InvalidArgumentException('music = '.print_r($music, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($override, $music), $multicall); } @@ -2332,58 +2226,48 @@ class Connection } /** - * Defines a list of remappings for player skins. It expects a list of structs Orig, Name, Checksum, Url. - * Orig is the name of the skin to remap, or '*' for any other. Name, Checksum, Url define the skin to use. - * (They are optional, you may set value '' for any of those. All 3 null means same as Orig). + * Defines a list of remappings for player skins. * Will only affect players connecting after the value is set. - * @param Structures\Skin[] $skins + * Only available to Admin. + * @param Structures\ForcedSkin|Structures\ForcedSkin[] $skins List of structs {Orig, Name, Checksum, Url}: + * - Orig is the name of the skin to remap, or '*' for any other + * - Name, Checksum, Url define the skin to use (you may set value '' for any of those, all 3 null means same as Orig). * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setForcedSkins(array $skins, $multicall = false) + function setForcedSkins($skins, $multicall=false) { - if(!is_array($skins)) + if(is_array($skins)) { + foreach($skins as $i => &$skin) + { + if(!($skin instanceof Structures\ForcedSkin)) + throw new InvalidArgumentException('skins['.$i.'] = '.print_r($skin, true)); + $skin = $skin->toArray(); + } + + } + elseif($skins instanceof Structures\ForcedSkin) + $skins = array($skins->toArray()); + else throw new InvalidArgumentException('skins = '.print_r($skins, true)); - } - $skinParameter = array(); - foreach($skins as $key => $skin) - { - if($skin instanceof Structures\Skin) - { - $skinParameter[$key] = array(); - $skinParameter[$key]['Orig'] = $skin->orig; - $skinParameter[$key]['Name'] = $skin->name; - $skinParameter[$key]['Checksum'] = $skin->checksum; - $skinParameter[$key]['Url'] = $skin->url; - } - elseif(!is_array($skin) || !array_key_exists('Orig', $skin) && !array_key_exists('Name', $skin) && !array_key_exists('Checksum', - $skin) && !array_key_exists('Url', $skin)) - { - throw new InvalidArgumentException('skins['.$key.'] = '.print_r($skins[$key], true)); - } - else - { - $skinParameter[$key] = $skin; - } - } - - return $this->execute(ucfirst(__FUNCTION__), array($skinParameter), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($skins), $multicall); } /** * Get the current forced skins. - * @return Structures\Skin[] + * @return Structures\ForcedSkin[] */ function getForcedSkins() { - return Structures\Skin::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__))); + return Structures\ForcedSkin::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__))); } /** * Returns the last error message for an internet connection. + * Only available to Admin. * @return string */ function getLastConnectionErrorMessage() @@ -2393,25 +2277,23 @@ class Connection /** * Set a new password for the referee mode. - * @param string $refereePassword + * Only available to Admin. + * @param string $password * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setRefereePassword($refereePassword, $multicall = false) + function setRefereePassword($password, $multicall=false) { - if(!is_string($refereePassword)) - { - throw new InvalidArgumentException('refereePassword = '.print_r($refereePassword, true)); - } + if(!is_string($password)) + throw new InvalidArgumentException('password = '.print_r($password, true)); - return $this->execute(ucfirst(__FUNCTION__), array($refereePassword), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($password), $multicall); } /** - * Get the password for referee mode if called as Admin or Super Admin, - * else returns if a password is needed or not. - * @return bool|string + * Get the password for referee mode if called as Admin or Super Admin, else returns if a password is needed or not. + * @return string|bool */ function getRefereePassword() { @@ -2419,25 +2301,24 @@ class Connection } /** - * Set the referee validation mode. 0 = validate the top3 players, 1 = validate all players. Only available to Admin. - * @param int $refereeMode + * Set the referee validation mode. + * Only available to Admin. + * @param int $mode 0: validate the top3 players, 1: validate all players * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setRefereeMode($refereeMode, $multicall = false) + function setRefereeMode($mode, $multicall=false) { - if($refereeMode !== 0 && $refereeMode !== 1) - { - throw new InvalidArgumentException('refereeMode = '.print_r($refereeMode, true)); - } + if($mode !== 0 && $mode !== 1) + throw new InvalidArgumentException('mode = '.print_r($mode, true)); - return $this->execute(ucfirst(__FUNCTION__), array($refereeMode), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($mode), $multicall); } /** * Get the referee validation mode. - * @return bool|string + * @return int */ function getRefereeMode() { @@ -2446,26 +2327,24 @@ class Connection /** * Set whether the game should use a variable validation seed or not. + * Only available to Admin. * Requires a map restart to be taken into account. * @param bool $enable * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setUseChangingValidationSeed($enable, $multicall = false) + function setUseChangingValidationSeed($enable, $multicall=false) { if(!is_bool($enable)) - { throw new InvalidArgumentException('enable = '.print_r($enable, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($enable), $multicall); } /** * Get the current and next value of UseChangingValidationSeed. - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * @return bool[] {bool CurrentValue, bool NextValue} */ function getUseChangingValidationSeed() { @@ -2474,23 +2353,24 @@ class Connection /** * Set the maximum time the server must wait for inputs from the clients before dropping data, or '0' for auto-adaptation. - * Only used by ShootMania. Only available to Admin. + * Only used by ShootMania. + * Only available to Admin. * @param int $latency * @param bool $multicall * @return bool + * @throws InvalidArgumentException */ - function setClientInputsMaxLatency($latency, $multicall = false) + function setClientInputsMaxLatency($latency, $multicall=false) { if(!is_int($latency)) - { throw new InvalidArgumentException('latency = '.print_r($latency, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($latency), $multicall); } /** - * Get the current ClientInputsMaxLatency. Only used by ShootMania. + * Get the current ClientInputsMaxLatency. + * Only used by ShootMania. * @return int */ function getClientInputsMaxLatency() @@ -2500,17 +2380,16 @@ class Connection /** * Sets whether the server is in warm-up phase or not. + * Only available to Admin. * @param bool $enable * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setWarmUp($enable, $multicall = false) + function setWarmUp($enable, $multicall=false) { if(!is_bool($enable)) - { throw new InvalidArgumentException('enable = '.print_r($enable, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($enable), $multicall); } @@ -2525,8 +2404,7 @@ class Connection } /** - * Get the current rules script. - * TODO Check if correct + * Get the current mode script. * @return string */ function getModeScriptText() @@ -2535,82 +2413,23 @@ class Connection } /** - * Set the rules script and restart. + * Set the mode script and restart. * Only available to Admin. - * TODO Check if correct * @param string $script * @param bool $multicall * @return bool + * @throws InvalidArgumentException */ - function setModeScriptText($script, $multicall = false) + function setModeScriptText($script, $multicall=false) { + if(!is_string($script)) + throw new InvalidArgumentException('script = '.print_r($script, true)); + return $this->execute(ucfirst(__FUNCTION__), array($script), $multicall); } /** - * Get the xml-rpc variables of the mode script. - * Only available to Admin. - * @return array - */ - function getModeScriptVariables() - { - return $this->execute(ucfirst(__FUNCTION__)); - } - - /** - * Set the variables of the rules script. Only available to Admin. - * @param array $variables - * @param bool $multicall - */ - function setModeScriptVariables($variables, $multicall = false) - { - return $this->execute(ucfirst(__FUNCTION__), array($variables), $multicall); - } - - /** - * Send an event to the mode script. Only available to Admin. - * @param string $param1 - * @param string $param2 - * @param bool $multicall - * @return bool - */ - function triggerModeScriptEvent($param1, $param2, $multicall = false) - { - if(!is_string($param1)) - { - throw new InvalidArgumentException('param1 = '.print_r($param1, true)); - } - if(!is_string($param2)) - { - throw new InvalidArgumentException('param2 = '.print_r($param2, true)); - } - return $this->execute(ucfirst(__FUNCTION__), array($param1, $param2), $multicall); - } - - /** - * Send an event to the mode script. Only available to Admin. - * @param string $param1 - * @param mixed[] $param2 - * @param bool $multicall - * @return bool - */ - function triggerModeScriptEventArray($param1, $param2, $multicall = false) - { - if(!is_string($param1)) - { - throw new InvalidArgumentException('param1 = '.print_r($param1, true)); - } - if(!is_array($param2)) - { - throw new InvalidArgumentException('param2 = '.print_r($param2, true)); - } - return $this->execute(ucfirst(__FUNCTION__), array($param1, $param2), $multicall); - } - - /** - * Returns the description of the current rules script, - * as a structure containing: Name, CompatibleTypes, - * Description and the settings available. + * Returns the description of the current mode script. * @return Structures\ScriptInfo */ function getModeScriptInfo() @@ -2619,8 +2438,8 @@ class Connection } /** - * Returns the current parameters of the mode script. - * @return array + * Returns the current settings of the mode script. + * @return array {mixed , ...} */ function getModeScriptSettings() { @@ -2628,24 +2447,30 @@ class Connection } /** - * Set the parameters of the rules script. Only available to Admin. - * @param array $rules + * Change the settings of the mode script. + * Only available to Admin. + * @param mixed[] $settings {mixed , ...} * @param bool $multicall * @return bool + * @throws InvalidArgumentException */ - function setModeScriptSettings($rules, $multicall = false) + function setModeScriptSettings($settings, $multicall=false) { - return $this->execute(ucfirst(__FUNCTION__), array($rules), $multicall); + if(!is_array($settings)) + throw new InvalidArgumentException('settings = '.print_r($settings, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($settings), $multicall); } /** * Send commands to the mode script. * Only available to Admin. - * @param array $commands + * @param mixed[] $commands * @param bool $multicall * @return bool + * @throws InvalidArgumentException */ - function sendModeScriptCommands(array $commands, $multicall = false) + function sendModeScriptCommands($commands, $multicall=false) { return $this->execute(ucfirst(__FUNCTION__), array($commands), $multicall); } @@ -2653,176 +2478,237 @@ class Connection /** * Change the settings and send commands to the mode script. * Only available to Admin. - * @param array $settings - * @param array $commands + * @param mixed[] $settings {mixed , ...} + * @param mixed[] $commands * @param bool $multicall * @return bool + * @throws InvalidArgumentException */ - function setModeScriptSettingsAndCommands(array $settings, array $commands, $multicall = false) + function setModeScriptSettingsAndCommands($settings, $commands, $multicall=false) { return $this->execute(ucfirst(__FUNCTION__), array($settings, $commands), $multicall); } /** - * Restarts the map, with an optional boolean parameter DontClearCupScores (only available in cup mode). - * @param bool $dontClearCupScores - * @param bool $multicall - * @return bool - * @throws InvalidArgumentException + * Returns the current xml-rpc variables of the mode script. + * @return array {mixed , ...} */ - function restartMap($dontClearCupScores = false, $multicall = false) - { - if(!is_bool($dontClearCupScores)) - { - throw new InvalidArgumentException('dontClearCupScores = '.print_r($dontClearCupScores, true)); - } - - return $this->execute(ucfirst(__FUNCTION__), array($dontClearCupScores), $multicall); - } - - /** - * Switch to next map, with an optional boolean parameter DontClearCupScores (only available in cup mode). - * @param bool $dontClearCupScores - * @param bool $multicall - * @return bool - * @throws InvalidArgumentException - */ - function nextMap($dontClearCupScores = false, $multicall = false) - { - if(!is_bool($dontClearCupScores)) - { - throw new InvalidArgumentException('dontClearCupScores = '.print_r($dontClearCupScores, true)); - } - - return $this->execute(ucfirst(__FUNCTION__), array($dontClearCupScores), $multicall); - } - - /** - * Attempt to balance teams. Only available to Admin. - * @return bool - */ - function autoTeamBalance() + function getModeScriptVariables() { return $this->execute(ucfirst(__FUNCTION__)); } /** - * Stop the server. + * Set the xml-rpc variables of the mode script. + * Only available to Admin. + * @param mixed[] $variables + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function setModeScriptVariables($variables, $multicall=false) + { + return $this->execute(ucfirst(__FUNCTION__), array($variables), $multicall); + } + + /** + * Send an event to the mode script. + * Only available to Admin. + * @param string $event + * @param string $params + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function triggerModeScriptEvent($event, $params='', $multicall=false) + { + if(!is_string($event)) + throw new InvalidArgumentException('event = '.print_r($event, true)); + if(!is_string($params)) + throw new InvalidArgumentException('params = '.print_r($params, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($event, $params), $multicall); + } + + /** + * Send an event to the mode script. + * Only available to Admin. + * @param string $event + * @param mixed[] $params + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function triggerModeScriptEventArray($event, $params, $multicall=false) + { + if(!is_string($event)) + throw new InvalidArgumentException('events = '.print_r($event, true)); + if(!is_array($params)) + throw new InvalidArgumentException('params = '.print_r($params, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($event, $params), $multicall); + } + + /** + * Get the script cloud variables of given object. + * Only available to Admin. + * @param string $arg1 + * @param string $arg2 + * @param bool $multicall + * @return array + * @throws InvalidArgumentException + */ + function getScriptCloudVariables($arg1, $arg2, $multicall=false) + { + if(!is_string($arg1)) + throw new InvalidArgumentException('$arg1 = '.print_r($arg1, true)); + if(!is_string($arg2)) + throw new InvalidArgumentException('$arg2 = '.print_r($arg2, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($arg1, $arg2), $multicall); + } + + /** + * Set the script cloud variables of given object. Only available to Admin. + * @param string $arg1 + * @param string $arg2 + * @param struct $arg3 + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function setScriptCloudVariables($arg1, $arg2, $arg3, $multicall=false) + { + if(!is_string($arg1)) + throw new InvalidArgumentException('$arg1 = '.print_r($arg1, true)); + if(!is_string($arg2)) + throw new InvalidArgumentException('$arg2 = '.print_r($arg2, true)); + if(!is_struct($arg3)) + throw new InvalidArgumentException('$arg3 = '.print_r($arg3, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($arg1, $arg2, $arg3), $multicall); + } + + /** + * Restarts the map. + * Only available to Admin. + * @param bool $dontClearCupScores Only available in legacy cup mode * @param bool $multicall * @return bool */ - function stopServer($multicall = false) + function restartMap($dontClearCupScores=false, $multicall=false) + { + if(!is_bool($dontClearCupScores)) + throw new InvalidArgumentException('dontClearCupScores = '.print_r($dontClearCupScores, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($dontClearCupScores), $multicall); + } + + /** + * Switch to next map. + * Only available to Admin. + * @param bool $dontClearCupScores Only available in legacy cup mode + * @param bool $multicall + * @return bool + */ + function nextMap($dontClearCupScores=false, $multicall=false) + { + if(!is_bool($dontClearCupScores)) + throw new InvalidArgumentException('dontClearCupScores = '.print_r($dontClearCupScores, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($dontClearCupScores), $multicall); + } + + /** + * Attempt to balance teams. + * Only available to Admin. + * @param bool $multicall + * @return bool + */ + function autoTeamBalance($multicall=false) { return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); } /** - * In Rounds or Laps mode, force the end of round without waiting for all players to giveup/finish. + * Stop the server. + * Only available to SuperAdmin. * @param bool $multicall * @return bool */ - function forceEndRound($multicall = false) + function stopServer($multicall=false) + { + return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); + } + + /** + * In legacy Rounds or Laps mode, force the end of round without waiting for all players to giveup/finish. + * Only available to Admin. + * @param bool $multicall + * @return bool + */ + function forceEndRound($multicall=false) { return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); } /** * Set new game settings using the struct passed as parameters. - * This struct must contain the following fields : - * GameMode, ChatTime, RoundsPointsLimit, RoundsUseNewRules, RoundsForcedLaps, TimeAttackLimit, - * TimeAttackSynchStartPeriod, TeamPointsLimit, TeamMaxPoints, TeamUseNewRules, LapsNbLaps, LapsTimeLimit, - * FinishTimeout, and optionally: AllWarmUpDuration, DisableRespawn, ForceShowAllOpponents, RoundsPointsLimitNewRules, - * TeamPointsLimitNewRules, CupPointsLimit, CupRoundsPerMap, CupNbWinners, CupWarmUpDuration. + * Only available to Admin. * Requires a map restart to be taken into account. * @param Structures\GameInfos $gameInfos * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setGameInfos(Structures\GameInfos $gameInfos, $multicall = false) + function setGameInfos($gameInfos, $multicall=false) { + if(!($gameInfos instanceof Structures\GameInfos)) + throw new InvalidArgumentException('gameInfos = '.print_r($gameInfos, true)); + return $this->execute(ucfirst(__FUNCTION__), array($gameInfos->toArray()), $multicall); } /** - * Optional parameter for compatibility: - * struct version (0 = united, 1 = forever). - * Returns a struct containing the current game settings, ie: - * GameMode, ChatTime, NbMap, RoundsPointsLimit, RoundsUseNewRules, RoundsForcedLaps, - * TimeAttackLimit, TimeAttackSynchStartPeriod, TeamPointsLimit, TeamMaxPoints, TeamUseNewRules, - * LapsNbLaps, LapsTimeLimit, FinishTimeout, - * additionally for version 1: AllWarmUpDuration, DisableRespawn, ForceShowAllOpponents, RoundsPointsLimitNewRules, - * TeamPointsLimitNewRules, CupPointsLimit, CupRoundsPerMap, CupNbWinners, CupWarmUpDuration. - * @param int $compatibility + * Returns a struct containing the current game settings. * @return Structures\GameInfos - * @throws InvalidArgumentException */ - function getCurrentGameInfo($compatibility = 1) + function getCurrentGameInfo() { - if($compatibility !== 1 && $compatibility != 0) - { - throw new InvalidArgumentException('compatibility = '.print_r($compatibility, true)); - } - - return Structures\GameInfos::fromArray($this->execute(ucfirst(__FUNCTION__), array($compatibility))); + return Structures\GameInfos::fromArray($this->execute(ucfirst(__FUNCTION__))); } /** - * Optional parameter for compatibility: - * struct version (0 = united, 1 = forever). - * Returns a struct containing the game settings for the next map, ie: - * GameMode, ChatTime, NbMap, RoundsPointsLimit, RoundsUseNewRules, RoundsForcedLaps, - * TimeAttackLimit, TimeAttackSynchStartPeriod, TeamPointsLimit, TeamMaxPoints, TeamUseNewRules, - * LapsNbLaps, LapsTimeLimit, FinishTimeout, - * additionally for version 1: AllWarmUpDuration, DisableRespawn, ForceShowAllOpponents, RoundsPointsLimitNewRules, - * TeamPointsLimitNewRules, CupPointsLimit, CupRoundsPerMap, CupNbWinners, CupWarmUpDuration. - * @param int $compatibility + * Returns a struct containing the game settings for the next map. * @return Structures\GameInfos - * @throws InvalidArgumentException */ - function getNextGameInfo($compatibility = 1) + function getNextGameInfo() { - if($compatibility !== 1 && $compatibility != 0) - { - throw new InvalidArgumentException('compatibility = '.print_r($compatibility, true)); - } - - return Structures\GameInfos::fromArray($this->execute(ucfirst(__FUNCTION__), array($compatibility))); + return Structures\GameInfos::fromArray($this->execute(ucfirst(__FUNCTION__))); } /** - * Optional parameter for compatibility: struct version (0 = united, 1 = forever). - * Returns a struct containing two other structures, - * the first containing the current game settings and the second the game settings for next map. - * The first structure is named CurrentGameInfos and the second NextGameInfos. - * @param int $compatibility - * @return Structures\GameInfos[] - * @throws InvalidArgumentException + * Returns a struct containing two other structures, the first containing the current game settings and the second the game settings for next map. + * @return Structures\GameInfos[] {Structures\GameInfos CurrentGameInfos, Structures\GameInfos NextGameInfos} */ - function getGameInfos($compatibility = 1) + function getGameInfos() { - if($compatibility !== 1 && $compatibility != 0) - { - throw new InvalidArgumentException('compatibility = '.print_r($compatibility, true)); - } - - return Structures\GameInfos::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__), array($compatibility))); + return Structures\GameInfos::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__))); } /** - * Set a new game mode between Rounds (0), TimeAttack (1), Team (2), Laps (3), Stunts (4) and Cup (5). + * Set a new game mode. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $gameMode + * @param int $gameMode 0: Script, 1: Rounds, 2: TimeAttack, 3: Team, 4: Laps, 5: Cup, 6: Stunt * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setGameMode($gameMode, $multicall = false) + function setGameMode($gameMode, $multicall=false) { - if(!is_int($gameMode) && ($gameMode < 0 || $gameMode > 5)) - { + if(!is_int($gameMode) || $gameMode < 0 || $gameMode > 6) throw new InvalidArgumentException('gameMode = '.print_r($gameMode, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($gameMode), $multicall); } @@ -2837,25 +2723,24 @@ class Connection } /** - * Set a new chat time value in milliseconds (actually 'chat time' is the duration of the end race podium, 0 means no podium displayed.). - * @param int $chatTime + * Set a new chat time value (actually the duration of the podium). + * Only available to Admin. + * @param int $chatTime In milliseconds, 0: no podium displayed * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setChatTime($chatTime, $multicall = false) + function setChatTime($chatTime, $multicall=false) { if(!is_int($chatTime)) - { throw new InvalidArgumentException('chatTime = '.print_r($chatTime, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($chatTime), $multicall); } /** - * Get the current and next chat time. The struct returned contains two fields CurrentValue and NextValue. - * @return array + * Get the current and next chat time. + * @return int[] {int CurrentValue, int NextValue} */ function getChatTime() { @@ -2863,27 +2748,25 @@ class Connection } /** - * Set a new finish timeout (for rounds/laps mode) value in milliseconds. - * 0 means default. 1 means adaptative to the duration of the map. + * Set a new finish timeout value for legacy laps and rounds based modes. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $finishTimeout + * @param int $timeout In milliseconds, 0: default, 1: adaptative to the map duration * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setFinishTimeout($finishTimeout, $multicall = false) + function setFinishTimeout($timeout, $multicall=false) { - if(!is_int($finishTimeout)) - { - throw new InvalidArgumentException('chatTime = '.print_r($finishTimeout, true)); - } + if(!is_int($timeout)) + throw new InvalidArgumentException('timeout = '.print_r($timeout, true)); - return $this->execute(ucfirst(__FUNCTION__), array($finishTimeout), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($timeout), $multicall); } /** - * Get the current and next FinishTimeout. The struct returned contains two fields CurrentValue and NextValue. - * @return array + * Get the current and next FinishTimeout. + * @return int[] {int CurrentValue, int NextValue} */ function getFinishTimeout() { @@ -2892,27 +2775,24 @@ class Connection /** * Set whether to enable the automatic warm-up phase in all modes. - * 0 = no, otherwise it's the duration of the phase, expressed in number of rounds (in rounds/team mode), - * or in number of times the gold medal time (other modes). + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $warmUpDuration + * @param int $duration 0: disable, number of rounds in rounds based modes, number of times the gold medal time otherwise * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setAllWarmUpDuration($warmUpDuration, $multicall = false) + function setAllWarmUpDuration($duration, $multicall=false) { - if(!is_int($warmUpDuration)) - { - throw new InvalidArgumentException('warmUpDuration = '.print_r($warmUpDuration, true)); - } + if(!is_int($duration)) + throw new InvalidArgumentException('duration = '.print_r($duration, true)); - return $this->execute(ucfirst(__FUNCTION__), array($warmUpDuration), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($duration), $multicall); } /** - * Get whether the automatic warm-up phase is enabled in all modes. The struct returned contains two fields CurrentValue and NextValue. - * @return array + * Get whether the automatic warm-up phase is enabled in all modes. + * @return int[] {int CurrentValue, int NextValue} */ function getAllWarmUpDuration() { @@ -2921,25 +2801,24 @@ class Connection /** * Set whether to disallow players to respawn. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param bool $disableRespawn + * @param bool $disable * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setDisableRespawn($disableRespawn, $multicall = false) + function setDisableRespawn($disable, $multicall=false) { - if(!is_bool($disableRespawn)) - { - throw new InvalidArgumentException('disableRespawn = '.print_r($disableRespawn, true)); - } + if(!is_bool($disable)) + throw new InvalidArgumentException('disable = '.print_r($disable, true)); - return $this->execute(ucfirst(__FUNCTION__), array($disableRespawn), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($disable), $multicall); } /** - * Get whether players are disallowed to respawn. The struct returned contains two fields CurrentValue and NextValue. - * @return array + * Get whether players are disallowed to respawn. + * @return bool[] {bool CurrentValue, bool NextValue} */ function getDisableRespawn() { @@ -2947,27 +2826,25 @@ class Connection } /** - * Set whether to override the players preferences and always display all opponents - * 0=no override, 1=show all, other value=minimum number of opponents. + * Set whether to override the players preferences and always display all opponents. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $forceShowAllOpponents + * @param int $opponents 0: no override, 1: show all, else: minimum number of opponents * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setForceShowAllOpponents($forceShowAllOpponents, $multicall = false) + function setForceShowAllOpponents($opponents, $multicall=false) { - if(!is_int($forceShowAllOpponents)) - { - throw new InvalidArgumentException('forceShowAllOpponents = '.print_r($forceShowAllOpponents, true)); - } + if(!is_int($opponents)) + throw new InvalidArgumentException('opponents = '.print_r($opponents, true)); - return $this->execute(ucfirst(__FUNCTION__), array($forceShowAllOpponents), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($opponents), $multicall); } /** - * Get whether players are forced to show all opponents. The struct returned contains two fields CurrentValue and NextValue. - * @return array + * Get whether players are forced to show all opponents. + * @return int[] {int CurrentValue, int NextValue} */ function getForceShowAllOpponents() { @@ -2975,21 +2852,25 @@ class Connection } /** - * Set a new rules script name for script mode. Only available to Admin. + * Set a new mode script name for script mode. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param string $scriptName + * @param string $script * @param bool $multicall * @return bool + * @throws InvalidArgumentException */ - function setScriptName($scriptName, $multicall = false) + function setScriptName($script, $multicall=false) { - return $this->execute(ucfirst(__FUNCTION__), array($scriptName), $multicall); + if(!is_string($script)) + throw new InvalidArgumentException('script = '.print_r($script, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($script), $multicall); } /** - * Get the current and next rules script name for script mode. - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * Get the current and next mode script name for script mode. + * @return string[] {string CurrentValue, string NextValue} */ function getScriptName() { @@ -2997,26 +2878,25 @@ class Connection } /** - * Set a new time limit for time attack mode. + * Set a new time limit for legacy time attack mode. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $timeAttackLimit + * @param int $limit In milliseconds * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setTimeAttackLimit($timeAttackLimit, $multicall = false) + function setTimeAttackLimit($limit, $multicall=false) { - if(!is_int($timeAttackLimit)) - { - throw new InvalidArgumentException('timeAttackLimit = '.print_r($timeAttackLimit, true)); - } + if(!is_int($limit)) + throw new InvalidArgumentException('limit = '.print_r($limit, true)); - return $this->execute(ucfirst(__FUNCTION__), array($timeAttackLimit), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($limit), $multicall); } /** - * Get the current and next time limit for time attack mode. The struct returned contains two fields CurrentValue and NextValue. - * @return array + * Get the current and next time limit for legacy time attack mode. + * @return int[] {int CurrentValue, int NextValue} */ function getTimeAttackLimit() { @@ -3024,27 +2904,25 @@ class Connection } /** - * Set a new synchronized start period for time attack mode. + * Set a new synchronized start period for legacy time attack mode. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $timeAttackSynchPeriod + * @param int $synch * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setTimeAttackSynchStartPeriod($timeAttackSynchPeriod, $multicall = false) + function setTimeAttackSynchStartPeriod($synch, $multicall=false) { - if(!is_int($timeAttackSynchPeriod)) - { - throw new InvalidArgumentException('timeAttackSynchPeriod = '.print_r($timeAttackSynchPeriod, true)); - } + if(!is_int($synch)) + throw new InvalidArgumentException('synch = '.print_r($synch, true)); - return $this->execute(ucfirst(__FUNCTION__), array($timeAttackSynchPeriod), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($synch), $multicall); } /** - * Get the current and synchronized start period for time attack mode. - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * Get the current and synchronized start period for legacy time attack mode. + * @return int[] {int CurrentValue, int NextValue} */ function getTimeAttackSynchStartPeriod() { @@ -3052,27 +2930,25 @@ class Connection } /** - * Set a new time limit for laps mode. + * Set a new time limit for legacy laps mode. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $lapsTimeLimit + * @param int $limit * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setLapsTimeLimit($lapsTimeLimit, $multicall = false) + function setLapsTimeLimit($limit, $multicall=false) { - if(!is_int($lapsTimeLimit)) - { - throw new InvalidArgumentException('lapsTimeLimit = '.print_r($lapsTimeLimit, true)); - } + if(!is_int($limit)) + throw new InvalidArgumentException('limit = '.print_r($limit, true)); - return $this->execute(ucfirst(__FUNCTION__), array($lapsTimeLimit), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($limit), $multicall); } /** - * Get the current and next time limit for laps mode. - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * Get the current and next time limit for legacy laps mode. + * @return int[] {int CurrentValue, int NextValue} */ function getLapsTimeLimit() { @@ -3080,27 +2956,25 @@ class Connection } /** - * Set a new number of laps for laps mode. + * Set a new number of laps for legacy laps mode. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $nbLaps + * @param int $laps * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setNbLaps($nbLaps, $multicall = false) + function setNbLaps($laps, $multicall=false) { - if(!is_int($nbLaps)) - { - throw new InvalidArgumentException('nbLaps = '.print_r($nbLaps, true)); - } + if(!is_int($laps)) + throw new InvalidArgumentException('laps = '.print_r($laps, true)); - return $this->execute(ucfirst(__FUNCTION__), array($nbLaps), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($laps), $multicall); } /** - * Get the current and next number of laps for laps mode. - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * Get the current and next number of laps for legacy laps mode. + * @return int[] {int CurrentValue, int NextValue} */ function getNbLaps() { @@ -3108,29 +2982,25 @@ class Connection } /** - * Set a new number of laps for rounds mode - * 0 = default, use the number of laps from the maps, - * otherwise forces the number of rounds for multilaps maps. + * Set a new number of laps for legacy rounds mode. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $roundForcedLaps + * @param int $laps 0: map default * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setRoundForcedLaps($roundForcedLaps, $multicall = false) + function setRoundForcedLaps($laps, $multicall=false) { - if(!is_int($roundForcedLaps)) - { - throw new InvalidArgumentException('roundForcedLaps = '.print_r($roundForcedLaps, true)); - } + if(!is_int($laps)) + throw new InvalidArgumentException('laps = '.print_r($laps, true)); - return $this->execute(ucfirst(__FUNCTION__), array($roundForcedLaps), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($laps), $multicall); } /** * Get the current and next number of laps for rounds mode. - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * @return int[] {int CurrentValue, int NextValue} */ function getRoundForcedLaps() { @@ -3138,27 +3008,25 @@ class Connection } /** - * Set a new points limit for rounds mode (value set depends on UseNewRulesRound). + * Set a new points limit for legacy rounds mode (value set depends on UseNewRulesRound). + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $roundPointsLimit + * @param int $limit * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setRoundPointsLimit($roundPointsLimit, $multicall = false) + function setRoundPointsLimit($limit, $multicall=false) { - if(!is_int($roundPointsLimit)) - { - throw new InvalidArgumentException('roundPointsLimit = '.print_r($roundPointsLimit, true)); - } + if(!is_int($limit)) + throw new InvalidArgumentException('limit = '.print_r($limit, true)); - return $this->execute(ucfirst(__FUNCTION__), array($roundPointsLimit), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($limit), $multicall); } /** * Get the current and next points limit for rounds mode (values returned depend on UseNewRulesRound). - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * @return int[] {int CurrentValue, int NextValue} */ function getRoundPointsLimit() { @@ -3166,33 +3034,27 @@ class Connection } /** - * Set the points used for the scores in rounds mode. - * Points is an array of decreasing integers for the players from the first to last. - * And you can add an optional boolean to relax the constraint checking on the scores. - * @param array $roundCustomPoints - * @param bool $relaxChecking + * Set the points used for the scores in legacy rounds mode. + * Only available to Admin. + * @param int[] $points Array of decreasing integers for the players from the first to last + * @param bool $relax True to relax the constraint checking on the scores * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setRoundCustomPoints(array $roundCustomPoints, $relaxChecking = false, $multicall = false) + function setRoundCustomPoints($points, $relax=false, $multicall=false) { - if(!is_array($roundCustomPoints)) - { - throw new InvalidArgumentException('roundCustomPoints = '.print_r($roundCustomPoints, true)); - } - if(!is_bool($relaxChecking)) - { - throw new InvalidArgumentException('relaxChecking = '.print_r($relaxChecking, true)); - } + if(!is_array($points)) + throw new InvalidArgumentException('points = '.print_r($points, true)); + if(!is_bool($relax)) + throw new InvalidArgumentException('relax = '.print_r($relax, true)); - return $this->execute(ucfirst(__FUNCTION__), array($roundCustomPoints, $relaxChecking), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($points, $relax), $multicall); } /** - * Gets the points used for the scores in rounds mode. - * @param bool $multicall - * @return array + * Gets the points used for the scores in legacy rounds mode. + * @return int[] */ function getRoundCustomPoints() { @@ -3200,27 +3062,25 @@ class Connection } /** - * Set the points used for the scores in rounds mode. - * Points is an array of decreasing integers for the players from the first to last. - * And you can add an optional boolean to relax the constraint checking on the scores. - * @param bool $useNewRulesRound + * Set if new rules are used for legacy rounds mode. + * Only available to Admin. + * Requires a map restart to be taken into account. + * @param bool $newRules * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setUseNewRulesRound($useNewRulesRound, $multicall = false) + function setUseNewRulesRound($newRules, $multicall=false) { - if(!is_bool($useNewRulesRound)) - { - throw new InvalidArgumentException('useNewRulesRound = '.print_r($useNewRulesRound, true)); - } + if(!is_bool($newRules)) + throw new InvalidArgumentException('newRules = '.print_r($newRules, true)); - return $this->execute(ucfirst(__FUNCTION__), array($useNewRulesRound), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($newRules), $multicall); } /** - * Gets the points used for the scores in rounds mode. - * @return array + * Get if the new rules are used for legacy rounds mode (Current and next values). + * @return bool[] {bool CurrentValue, bool NextValue} */ function getUseNewRulesRound() { @@ -3229,26 +3089,24 @@ class Connection /** * Set a new points limit for team mode (value set depends on UseNewRulesTeam). + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $teamPointsLimit + * @param int $limit * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setTeamPointsLimit($teamPointsLimit, $multicall = false) + function setTeamPointsLimit($limit, $multicall=false) { - if(!is_int($teamPointsLimit)) - { - throw new InvalidArgumentException('teamPointsLimit = '.print_r($teamPointsLimit, true)); - } + if(!is_int($limit)) + throw new InvalidArgumentException('limit = '.print_r($limit, true)); - return $this->execute(ucfirst(__FUNCTION__), array($teamPointsLimit), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($limit), $multicall); } /** * Get the current and next points limit for team mode (values returned depend on UseNewRulesTeam). - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * @return int[] {int CurrentValue, int NextValue} */ function getTeamPointsLimit() { @@ -3257,26 +3115,24 @@ class Connection /** * Set a new number of maximum points per round for team mode. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $maxPointsTeam + * @param int $max * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setMaxPointsTeam($maxPointsTeam, $multicall = false) + function setMaxPointsTeam($max, $multicall=false) { - if(!is_int($maxPointsTeam)) - { - throw new InvalidArgumentException('maxPointsTeam = '.print_r($maxPointsTeam, true)); - } + if(!is_int($max)) + throw new InvalidArgumentException('max = '.print_r($max, true)); - return $this->execute(ucfirst(__FUNCTION__), array($maxPointsTeam), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($max), $multicall); } /** * Get the current and next number of maximum points per round for team mode. - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * @return int[] {int CurrentValue, int NextValue} */ function getMaxPointsTeam() { @@ -3285,26 +3141,24 @@ class Connection /** * Set if new rules are used for team mode. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param bool $useNewRulesTeam + * @param bool $newRules * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setUseNewRulesTeam($useNewRulesTeam, $multicall = false) + function setUseNewRulesTeam($newRules, $multicall=false) { - if(!is_bool($useNewRulesTeam)) - { - throw new InvalidArgumentException('useNewRulesTeam = '.print_r($useNewRulesTeam, true)); - } + if(!is_bool($newRules)) + throw new InvalidArgumentException('newRules = '.print_r($newRules, true)); - return $this->execute(ucfirst(__FUNCTION__), array($useNewRulesTeam), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($newRules), $multicall); } /** * Get if the new rules are used for team mode (Current and next values). - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * @return bool[] {bool CurrentValue, bool NextValue} */ function getUseNewRulesTeam() { @@ -3313,26 +3167,24 @@ class Connection /** * Set the points needed for victory in Cup mode. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $pointsLimit + * @param int $limit * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setCupPointsLimit($pointsLimit, $multicall = false) + function setCupPointsLimit($limit, $multicall=false) { - if(!is_int($pointsLimit)) - { - throw new InvalidArgumentException('pointsLimit = '.print_r($pointsLimit, true)); - } + if(!is_int($limit)) + throw new InvalidArgumentException('limit = '.print_r($limit, true)); - return $this->execute(ucfirst(__FUNCTION__), array($pointsLimit), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($limit), $multicall); } /** * Get the points needed for victory in Cup mode. - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * @return int[] {int CurrentValue, int NextValue} */ function getCupPointsLimit() { @@ -3341,27 +3193,24 @@ class Connection /** * Sets the number of rounds before going to next map in Cup mode. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $roundsPerMap + * @param int $rounds * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setCupRoundsPerMap($roundsPerMap, $multicall = false) + function setCupRoundsPerMap($rounds, $multicall=false) { - if(!is_int($roundsPerMap)) - { - throw new InvalidArgumentException('roundsPerMap = '.print_r($roundsPerMap, true)); - } + if(!is_int($rounds)) + throw new InvalidArgumentException('rounds = '.print_r($rounds, true)); - return $this->execute(ucfirst(__FUNCTION__), array($roundsPerMap), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($rounds), $multicall); } /** * Get the number of rounds before going to next map in Cup mode. - * The struct returned contains two fields CurrentValue and NextValue. - * @param bool $multicall - * @return array + * @return int[] {int CurrentValue, int NextValue} */ function getCupRoundsPerMap() { @@ -3370,27 +3219,24 @@ class Connection /** * Set whether to enable the automatic warm-up phase in Cup mode. - * 0 = no, otherwise it's the duration of the phase, expressed in number of rounds. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $warmUpDuration + * @param int $duration Number of rounds, 0: no warm-up * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setCupWarmUpDuration($warmUpDuration, $multicall = false) + function setCupWarmUpDuration($duration, $multicall=false) { - if(!is_int($warmUpDuration)) - { - throw new InvalidArgumentException('warmUpDuration = '.print_r($warmUpDuration, true)); - } + if(!is_int($duration)) + throw new InvalidArgumentException('duration = '.print_r($duration, true)); - return $this->execute(ucfirst(__FUNCTION__), array($warmUpDuration), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($duration), $multicall); } /** * Get whether the automatic warm-up phase is enabled in Cup mode. - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * @return int[] {int CurrentValue, int NextValue} */ function getCupWarmUpDuration() { @@ -3399,26 +3245,24 @@ class Connection /** * Set the number of winners to determine before the match is considered over. + * Only available to Admin. * Requires a map restart to be taken into account. - * @param int $nbWinners + * @param int $winners * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function setCupNbWinners($nbWinners, $multicall = false) + function setCupNbWinners($winners, $multicall=false) { - if(!is_int($nbWinners)) - { - throw new InvalidArgumentException('nbWinners = '.print_r($nbWinners, true)); - } + if(!is_int($winners)) + throw new InvalidArgumentException('winners = '.print_r($winners, true)); - return $this->execute(ucfirst(__FUNCTION__), array($nbWinners), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($winners), $multicall); } /** * Get the number of winners to determine before the match is considered over. - * The struct returned contains two fields CurrentValue and NextValue. - * @return array + * @return int[] {int CurrentValue, int NextValue} */ function getCupNbWinners() { @@ -3445,220 +3289,66 @@ class Connection /** * Sets the map index in the selection that will be played next (unless the current one is restarted...) - * @param int $nextMapIndex - * @param bool $multicall - * @throws InvalidArgumentException - * @return bool - */ - function setNextMapIndex($nextMapIndex, $multicall = false) - { - if(!is_int($nextMapIndex)) - { - throw new InvalidArgumentException('nextMapIndex = '.print_r($nextMapIndex, true)); - } - - return $this->execute(ucfirst(__FUNCTION__), array($nextMapIndex), $multicall); - } - - /** - * Immediately jumps to the map designated by the index in the selection - * @param int $nextMapIndex - * @param bool $multicall - * @throws InvalidArgumentException - * @return bool - */ - function jumpToMapIndex($mapIndex, $multicall = false) - { - if(!is_int($mapIndex)) - { - throw new InvalidArgumentException('mapIndex = '.print_r($mapIndex, true)); - } - - return $this->execute(ucfirst(__FUNCTION__), array($mapIndex), $multicall); - } - - /** - * Set Team names and colors. Only available to Admin. - * @param string $teamName1 - * @param float $teamColor1 - * @param string $team1Country - * @param string $teamName2 - * @param float $teamColor2 - * @param string $team2Country - * @param bool $multicall - * @return bool - * @throws InvalidArgumentException - * @deprecated since version 2013-04-11 - */ - function setTeamInfo($teamName1, $teamColor1, $team1Country, $teamName2, $teamColor2, $team2Country, $multicall = false) - { - if(!is_float($teamColor1)) - { - throw new InvalidArgumentException('teamColor1 = '.print_r($teamColor1, true)); - } - if(!is_float($teamColor2)) - { - throw new InvalidArgumentException('teamColor2 = '.print_r($teamColor2, true)); - } - if(!is_string($teamName1)) - { - throw new InvalidArgumentException('teamName1 = '.print_r($teamName1, true)); - } - if(!is_string($teamName2)) - { - throw new InvalidArgumentException('teamName2 = '.print_r($teamName2, true)); - } - return $this->execute(ucfirst(__FUNCTION__), - array('unused', 0., 'World', $teamName1, $teamColor1, $team1Country, $teamName2, $teamColor2, $team2Country), - $multicall); - } - - /** - * Return Team info for a given clan (0 = no clan, 1, 2). - * The structure contains: name, zonePath, city, emblemUrl, huePrimary, hueSecondary, rGB, clubLinkUrl. - * Only available to Admin. - * @param int $teamId - * @return Structures\Team - * @throws InvalidArgumentException - */ - function getTeamInfo($teamId) - { - if(!is_int($teamId)) - { - throw new InvalidArgumentException('teamId = '.print_r($teamId, true)); - } - return Structures\Team::fromArray($this->execute(ucfirst(__FUNCTION__), array($teamId))); - } - - /** - * Set the clublinks to use for the two clans. - * Only available to Admin. - * @param string $team1ClubLink - * @param string $team2ClubLink + * @param int $index * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function setForcedClubLinks($team1ClubLink, $team2ClubLink, $multicall = false) + function setNextMapIndex($index, $multicall=false) { - if(!is_string($team1ClubLink)) - { - throw new InvalidArgumentException('team1ClubLink = '.print_r($team1ClubLink, true)); - } - if(!is_string($team2ClubLink)) - { - throw new InvalidArgumentException('team2ClubLink = '.print_r($team2ClubLink, true)); - } - return $this->execute(ucfirst(__FUNCTION__), array($team1ClubLink, $team2ClubLink), $multicall); + if(!is_int($index)) + throw new InvalidArgumentException('index = '.print_r($index, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($index), $multicall); } /** - * Get the forced clublinks. - * @return array - */ - function getForcedClubLinks() - { - return $this->execute(ucfirst(__FUNCTION__)); - } - - /** - * (debug tool) Connect a fake player to the server and returns the login. - * Only available to Admin. - * @param bool $multicall - * @return string - */ - function connectFakePlayer($multicall = false) - { - return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); - } - - /** - * (debug tool) Disconnect a fake player, or all the fake players if login is '*'. - * Only available to Admin. - * @param string $fakePlayerLogin + * Sets the map in the selection that will be played next (unless the current one is restarted...) + * @param string $ident * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function disconnectFakePlayer($fakePlayerLogin, $multicall = false) + function setNextMapIdent($ident, $multicall=false) { - if(!is_string($fakePlayerLogin)) - { - throw new InvalidArgumentException('fakePlayerLogin = '.print_r($fakePlayerLogin, true)); - } - return $this->execute(ucfirst(__FUNCTION__), array($fakePlayerLogin), $multicall); + if(!is_string($ident)) + throw new InvalidArgumentException('ident = '.print_r($ident, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($ident), $multicall); } /** - * Returns the token infos for a player. - * The returned structure is { TokenCost, CanPayToken }. - * @param Structures\Player|string $player - * @return array - */ - function getDemoTokenInfosForPlayer($player) - { - $login = $this->getLogin($player); - return (object) $this->execute(ucfirst(__FUNCTION__), array($login)); - } - - /** - * Disable player horns. Only available to Admin. - * @param bool $disable + * Immediately jumps to the map designated by the index in the selection. + * @param int $index * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function disableHorns($disable, $multicall = false) + function jumpToMapIndex($index, $multicall=false) { - if(!is_bool($disable)) - { - throw new InvalidArgumentException('disable = '.print_r($disable, true)); - } + if(!is_int($index)) + throw new InvalidArgumentException('index = '.print_r($index, true)); - return $this->execute(ucfirst(__FUNCTION__), array($disable), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($index), $multicall); } /** - * Returns whether the horns are disabled. - * @return bool - */ - function areHornsDisabled() - { - return $this->execute(ucfirst(__FUNCTION__)); - } - - /** - * Disable the automatic mesages when a player connects/disconnects from the server. - * Only available to Admin. - * @param bool $disable + * Immediately jumps to the map designated by its identifier (it must be in the selection). + * @param string $ident * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function disableServiceAnnounces($disable = true, $multicall = false) + function jumpToMapIdent($ident, $multicall=false) { - if(!is_bool($disable)) - { - throw new InvalidArgumentException('disable = '.print_r($disable, true)); - } + if(!is_string($ident)) + throw new InvalidArgumentException('ident = '.print_r($ident, true)); - return $this->execute(ucfirst(__FUNCTION__), array($disable), $multicall); - } - - /** - * Returns whether the automatic mesages are disabled. - * @return bool - */ - function areServiceAnnouncesDisabled() - { - return $this->execute(ucfirst(__FUNCTION__)); + return $this->execute(ucfirst(__FUNCTION__), array($ident), $multicall); } /** * Returns a struct containing the infos for the current map. - * The struct contains the following fields : Name, UId, FileName, - * Author, Environnement, Mood, BronzeTime, SilverTime, GoldTime, - * AuthorTime, CopperPrice, LapRace, NbLaps and NbCheckpoints. * @return Structures\Map */ function getCurrentMapInfo() @@ -3668,10 +3358,6 @@ class Connection /** * Returns a struct containing the infos for the next map. - * The struct contains the following fields : Name, UId, FileName, - * Author, Environnement, Mood, BronzeTime, SilverTime, GoldTime, - * AuthorTime, CopperPrice, LapRace, NbLaps and NbCheckpoints. - * (NbLaps and NbCheckpoints are also present but always set to -1) * @return Structures\Map */ function getNextMapInfo() @@ -3681,10 +3367,6 @@ class Connection /** * Returns a struct containing the infos for the map with the specified filename. - * The struct contains the following fields : Name, UId, FileName, - * Author, Environnement, Mood, BronzeTime, SilverTime, GoldTime, - * AuthorTime, CopperPrice, LapRace, NbLaps and NbCheckpoints. - * (NbLaps and NbCheckpoints are also present but always set to -1) * @param string $filename * @return Structures\Map * @throws InvalidArgumentException @@ -3692,408 +3374,349 @@ class Connection function getMapInfo($filename) { if(!is_string($filename)) - { throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } - $temp = $this->execute(ucfirst(__FUNCTION__), array($filename)); - return Structures\Map::fromArray($temp); + return Structures\Map::fromArray($this->execute(ucfirst(__FUNCTION__), array($filename))); } /** * Returns a boolean if the map with the specified filename matches the current server settings. * @param string $filename + * @param bool $multicall * @return bool + * @throws InvalidArgumentException */ - function checkMapForCurrentServerParams($filename) + function checkMapForCurrentServerParams($filename, $multicall=false) { if(!is_string($filename)) - { throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } - return $this->execute(ucfirst(__FUNCTION__), array($filename)); + return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall); } /** * Returns a list of maps among the current selection of the server. - * This method take two parameters. - * The first parameter specifies the maximum number of infos to be returned, - * the second one the starting index in the selection. - * The list is an array of structures. Each structure contains the following fields : Name, UId, FileName, Environnement, Author, GoldTime and CopperPrice. - * @param int $length specifies the maximum number of infos to be returned - * @param int $offset specifies the starting index in the list - * @return Structures\Map[] The list is an array of Map + * @param int $length Maximum number of infos to be returned + * @param int $offset Starting index in the list + * @return Structures\Map[] * @throws InvalidArgumentException */ function getMapList($length, $offset) { if(!is_int($length)) - { throw new InvalidArgumentException('length = '.print_r($length, true)); - } if(!is_int($offset)) - { throw new InvalidArgumentException('offset = '.print_r($offset, true)); - } return Structures\Map::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__), array($length, $offset))); } /** * Add the map with the specified filename at the end of the current selection. + * Only available to Admin. * @param string $filename * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function addMap($filename, $multicall = false) + function addMap($filename, $multicall=false) { if(!is_string($filename)) - { throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall); } /** - * Add the list of maps with the specified filename at the end of the current selection. - * @param array $filenames + * Add the list of maps with the specified filenames at the end of the current selection. + * Only available to Admin. + * @param string[] $filenames * @param bool $multicall - * @throws InvalidArgumentException * @return int + * @throws InvalidArgumentException */ - function addMapList(array $filenames, $multicall = false) + function addMapList($filenames, $multicall=false) { if(!is_array($filenames)) - { throw new InvalidArgumentException('filenames = '.print_r($filenames, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filenames), $multicall); } /** * Remove the map with the specified filename from the current selection. + * Only available to Admin. * @param string $filename * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function removeMap($filename, $multicall = false) + function removeMap($filename, $multicall=false) { if(!is_string($filename)) - { throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall); } /** * Remove the list of maps with the specified filenames from the current selection. - * The list of maps to remove is an array of strings. - * @param array $filenames + * Only available to Admin. + * @param string[] $filenames * @param bool $multicall - * @throws InvalidArgumentException * @return int + * @throws InvalidArgumentException */ - function removeMapList(array $filenames, $multicall = false) + function removeMapList($filenames, $multicall=false) { if(!is_array($filenames)) - { throw new InvalidArgumentException('filenames = '.print_r($filenames, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filenames), $multicall); } /** * Insert the map with the specified filename after the current map. + * Only available to Admin. * @param string $filename - * @throws InvalidArgumentException + * @param bool $multicall * @return bool + * @throws InvalidArgumentException */ - function insertMap($filename, $multicall = false) + function insertMap($filename, $multicall=false) { if(!is_string($filename)) - { throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall); } /** * Insert the list of maps with the specified filenames after the current map. - * The list of maps to remove is an array of strings. - * @param array $filenames - * @throws InvalidArgumentException + * Only available to Admin. + * @param string[] $filenames + * @param bool $multicall * @return int + * @throws InvalidArgumentException */ - function insertMapList(array $filenames, $multicall = false) + function insertMapList($filenames, $multicall=false) { if(!is_array($filenames)) - { throw new InvalidArgumentException('filenames = '.print_r($filenames, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filenames), $multicall); } /** * Set as next map the one with the specified filename, if it is present in the selection. + * Only available to Admin. * @param string $filename * @param bool $multicall - * @throws InvalidArgumentException * @return bool + * @throws InvalidArgumentException */ - function chooseNextMap($filename, $multicall = false) + function chooseNextMap($filename, $multicall=false) { if(!is_string($filename)) - { throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall); } /** * Set as next maps the list of maps with the specified filenames, if they are present in the selection. - * The list of maps to remove is an array of strings. + * Only available to Admin. * @param array $filenames * @param bool $multicall - * @throws InvalidArgumentException * @return int + * @throws InvalidArgumentException */ - function chooseNextMapList(array $filenames, $multicall = false) + function chooseNextMapList($filenames, $multicall=false) { if(!is_array($filenames)) - { throw new InvalidArgumentException('filenames = '.print_r($filenames, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filenames), $multicall); } /** - * Set a list of maps defined in the playlist with the specified filename - * as the current selection of the server, and load the gameinfos from the same file. + * Set a list of maps defined in the playlist with the specified filename as the current selection of the server, and load the gameinfos from the same file. + * Only available to Admin. * @param string $filename - * @throws InvalidArgumentException + * @param bool $multicall * @return int + * @throws InvalidArgumentException */ - function loadMatchSettings($filename, $multicall = false) + function loadMatchSettings($filename, $multicall=false) { if(!is_string($filename)) - { throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall); } /** * Add a list of maps defined in the playlist with the specified filename at the end of the current selection. + * Only available to Admin. * @param string $filename - * @throws InvalidArgumentException + * @param bool $multicall * @return int + * @throws InvalidArgumentException */ - function appendPlaylistFromMatchSettings($filename, $multicall = false) + function appendPlaylistFromMatchSettings($filename, $multicall=false) { if(!is_string($filename)) - { throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall); } /** * Save the current selection of map in the playlist with the specified filename, as well as the current gameinfos. + * Only available to Admin. * @param string $filename * @param bool $multicall - * @throws InvalidArgumentException * @return int + * @throws InvalidArgumentException */ - function saveMatchSettings($filename, $multicall = false) + function saveMatchSettings($filename, $multicall=false) { if(!is_string($filename)) - { throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall); } /** * Insert a list of maps defined in the playlist with the specified filename after the current map. + * Only available to Admin. * @param string $filename - * @throws InvalidArgumentException + * @param bool $multicall * @return int + * @throws InvalidArgumentException */ - function insertPlaylistFromMatchSettings($filename, $multicall = false) + function insertPlaylistFromMatchSettings($filename, $multicall=false) { if(!is_string($filename)) - { throw new InvalidArgumentException('filename = '.print_r($filename, true)); - } return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall); } /** - * Returns the list of players on the server. This method take two parameters. - * The first parameter specifies the maximum number of infos to be returned, - * the second one the starting index in the list, - * an optional 3rd parameter is used for compatibility: struct version (0 = united, 1 = forever, 2 = forever, including the servers). - * The list is an array of Structures\Player. - * LadderRanking is 0 when not in official mode, - * Flags = ForceSpectator(0,1,2) + IsReferee * 10 + IsPodiumReady * 100 + IsUsingStereoscopy * 1000 + - * IsManagedByAnOtherServer * 10000 + IsServer * 100000 + HasPlayerSlot * 1000000 - * SpectatorStatus = Spectator + TemporarySpectator * 10 + PureSpectator * 100 + AutoTarget * 1000 + CurrentTargetId * 10000 - * @param int $length specifies the maximum number of infos to be returned - * @param int $offset specifies the starting index in the list - * @param int $compatibility - * @return Structures\Player[] The list is an array of Structures\Player + * Returns the list of players on the server. + * @param int $length Maximum number of infos to be returned + * @param int $offset Starting index in the list + * @param int $compatibility 0: united, 1: forever, 2: forever including servers + * @return Structures\PlayerInfo[] * @throws InvalidArgumentException */ - function getPlayerList($length, $offset, $compatibility = 1) + function getPlayerList($length, $offset, $compatibility=1) { if(!is_int($length)) - { throw new InvalidArgumentException('length = '.print_r($length, true)); - } if(!is_int($offset)) - { throw new InvalidArgumentException('offset = '.print_r($offset, true)); - } - if(!is_int($compatibility)) - { + if(!is_int($compatibility) || $compatibility < 0 || $compatibility > 2) throw new InvalidArgumentException('compatibility = '.print_r($compatibility, true)); - } - return Structures\Player::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__), array($length, $offset, $compatibility))); + return Structures\PlayerInfo::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__), array($length, $offset, $compatibility))); } /** - * Returns a object of type Structures\Player containing the infos on the player with the specified login, - * with an optional parameter for compatibility: struct version (0 = united, 1 = forever). - * The structure is identical to the ones from GetPlayerList. Forever PlayerInfo struct is: - * Login, NickName, PlayerId, TeamId, SpectatorStatus, LadderRanking, and Flags. - * LadderRanking is 0 when not in official mode, - * Flags = ForceSpectator(0,1,2) + IsReferee * 10 + IsPodiumReady * 100 + IsUsingStereoscopy * 1000 + - * IsManagedByAnOtherServer * 10000 + IsServer * 100000 + HasPlayerSlot * 1000000 - * SpectatorStatus = Spectator + TemporarySpectator * 10 + PureSpectator * 100 + AutoTarget * 1000 + CurrentTargetId * 10000 - * @param int $playerLogin - * @param int $compatibility - * @return Structures\Player + * Returns a struct containing the infos on the player with the specified login. + * @param mixed $player Login or player object + * @param int $compatibility 0: united, 1: forever + * @return Structures\PlayerInfo * @throws InvalidArgumentException */ - function getPlayerInfo($playerLogin, $compatibility = 1) + function getPlayerInfo($player, $compatibility=1) { - if(!is_string($playerLogin)) - { - throw new InvalidArgumentException('playerLogin = '.print_r($playerLogin, true)); - } - if(!is_int($compatibility)) - { + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + if($compatibility !== 0 && $compatibility !== 1) throw new InvalidArgumentException('compatibility = '.print_r($compatibility, true)); - } - return Structures\Player::fromArray($this->execute(ucfirst(__FUNCTION__), array($playerLogin, $compatibility))); + return Structures\PlayerInfo::fromArray($this->execute(ucfirst(__FUNCTION__), array($login, $compatibility))); } /** - * Returns an object of type Structures\Player containing the infos on the player with the specified login. - * The structure contains the following fields : - * Login, NickName, PlayerId, TeamId, IPAddress, DownloadRate, UploadRate, Language, IsSpectator, - * IsInOfficialMode, a structure named Avatar, an array of structures named Skins, a structure named LadderStats, - * HoursSinceZoneInscription and OnlineRights (0: nations account, 3: united account). - * Each structure of the array Skins contains two fields Environnement and a struct PackDesc. - * Each structure PackDesc, as well as the struct Avatar, contains two fields FileName and Checksum. - * @param int $playerLogin - * @return Structures\Player + * Returns a struct containing the infos on the player with the specified login. + * @param mixed $player Login or player object + * @return Structures\PlayerDetailedInfo * @throws InvalidArgumentException */ - function getDetailedPlayerInfo($playerLogin) + function getDetailedPlayerInfo($player) { - if(!is_string($playerLogin)) - { - throw new InvalidArgumentException('playerLogin = '.print_r($playerLogin, true)); - } + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); - return Structures\Player::fromArray($this->execute(ucfirst(__FUNCTION__), array($playerLogin))); + return Structures\PlayerDetailedInfo::fromArray($this->execute(ucfirst(__FUNCTION__), array($login))); } /** - * Returns an object of Structures\Player type containing the infos on the player with the specified login. - * The structure contains the following fields : Login, NickName, PlayerId, TeamId, IPAddress, DownloadRate, UploadRate, - * Language, IsSpectator, IsInOfficialMode, a structure named Avatar, an array of structures named Skins, a structure named LadderStats, - * HoursSinceZoneInscription and OnlineRights (0: nations account, 3: united account). - * Each structure of the array Skins contains two fields Environnement and a struct PackDesc. - * Each structure PackDesc, as well as the struct Avatar, contains two fields FileName and Checksum. - * @param int $compatibility - * @return Structures\Player + * Returns a struct containing the player infos of the game server + * (ie: in case of a basic server, itself; in case of a relay server, the main server) + * @param int $compatibility 0: united, 1: forever + * @return Structures\PlayerInfo * @throws InvalidArgumentException */ - function getMainServerPlayerInfo($compatibility = 1) + function getMainServerPlayerInfo($compatibility=1) { if(!is_int($compatibility)) - { throw new InvalidArgumentException('compatibility = '.print_r($compatibility, true)); - } - return Structures\Player::fromArray($this->execute(ucfirst(__FUNCTION__), array($compatibility))); + return Structures\PlayerInfo::fromArray($this->execute(ucfirst(__FUNCTION__), array($compatibility))); } /** * Returns the current rankings for the race in progress. - * (in team mode, the scores for the two teams are returned. - * In other modes, it's the individual players' scores) This method take two parameters. - * The first parameter specifies the maximum number of infos to be returned, - * the second one the starting index in the ranking. - * The ranking returned is a list of Structures\Player. - * It also contains an array BestCheckpoints that contains the checkpoint times for the best race. - * @param int $length specifies the maximum number of infos to be returned - * @param int $offset specifies the starting index in the list - * @return Structures\Player[] The list is an array of Structures\Player. + * (In trackmania legacy team modes, the scores for the two teams are returned. + * In other modes, it's the individual players' scores) + * The ranking returned is a list of structures. + * Each structure contains the following fields : Login, NickName, PlayerId and Rank. + * In addition, for legacy trackmania modes it also contains BestTime, Score, NbrLapsFinished, LadderScore, + * and an array BestCheckpoints that contains the checkpoint times for the best race. + * @param int $length Maximum number of infos to be returned + * @param int $offset Starting index in the list + * @return Structures\PlayerRanking[] * @throws InvalidArgumentException */ function getCurrentRanking($length, $offset) { if(!is_int($length)) - { throw new InvalidArgumentException('length = '.print_r($length, true)); - } if(!is_int($offset)) - { throw new InvalidArgumentException('offset = '.print_r($offset, true)); - } - return Structures\Player::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__), array($length, $offset))); + return Structures\PlayerRanking::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__), array($length, $offset))); } /** * Returns the current ranking for the race in progressof the player with the specified login (or list of comma-separated logins). - * The ranking returned is a list of structures that contains the following fields : - * Login, NickName, PlayerId, Rank, BestTime, Score, NbrLapsFinished and LadderScore. - * It also contains an array BestCheckpoints that contains the checkpoint times for the best race. - * @param Structures\Player|Structures\Player[] $player + * The ranking returned is a list of structures. + * Each structure contains the following fields : Login, NickName, PlayerId and Rank. + * In addition, for legacy trackmania modes it also contains BestTime, Score, NbrLapsFinished, LadderScore, + * and an array BestCheckpoints that contains the checkpoint times for the best race. + * @param mixed $players Login, player object or array + * @param bool $multicall + * @return Structures\PlayerRanking[] * @throws InvalidArgumentException - * @return Structures\Player[] The list is an array of Structures\Player. */ - function getCurrentRankingForLogin($player = null) + function getCurrentRankingForLogin($players, $multicall=false) { - $login = $this->getLogin($player) ? : ''; + $logins = $this->getLogins($players); + if($logins === false) + throw new InvalidArgumentException('players = '.print_r($players, true)); - return Structures\Player::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__), array($login))); + return Structures\PlayerRanking::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__), array($logins), $multicall)); } /** * Returns the current winning team for the race in progress. (-1: if not in team mode, or draw match) - * @return int -1, 0 or 1 + * @return int */ function getCurrentWinnerTeam() { @@ -4101,154 +3724,149 @@ class Connection } /** - * Force the scores of the current game. Only available in rounds and team mode. - * You have to pass an array of structs {int PlayerId, int Score}. And a boolean SilentMode - - * if true, the scores are silently updated (only available for SuperAdmin), allowing an external controller to do its custom counting... - * @param array $scores + * Force the scores of the current game. + * Only available in rounds and team mode. + * Only available to Admin/SuperAdmin. + * @param int[][] $scores Array of structs {int PlayerId, int Score} + * @param bool $silent True to update silently (only available for SuperAdmin) * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function forceScores(array $scores, $silentMode = false, $multicall = false) + function forceScores($scores, $silent, $multicall=false) { if(!is_array($scores)) - { throw new InvalidArgumentException('scores = '.print_r($scores, true)); - } - - for($i = 0; $i < count($scores); $i++) + foreach($scores as $i => $score) { - if(!is_int($scores[$i]['PlayerId'])) - { - throw new InvalidArgumentException('score['.$i.'][\'PlayerId\'] = '.print_r($scores[$i]['PlayerId'], true)); - } - if(!is_int($scores[$i]['Score'])) - { - throw new InvalidArgumentException('score['.$i.'][\'Score\'] = '.print_r($scores[$i]['Score'], true)); - } + if(!is_array($score)) + throw new InvalidArgumentException('score['.$i.'] = '.print_r($score, true)); + if(!isset($score['PlayerId']) || !is_int($score['PlayerId'])) + throw new InvalidArgumentException('score['.$i.']["PlayerId"] = '.print_r($score, true)); + if(!isset($score['Score']) || !is_int($score['Score'])) + throw new InvalidArgumentException('score['.$i.']["Score"] = '.print_r($score, true)); } + if(!is_bool($silent)) + throw new InvalidArgumentException('silent = '.print_r($silent, true)); - return $this->execute(ucfirst(__FUNCTION__), array($scores, $silentMode), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($scores, $silent), $multicall); } /** - * Force the team of the player. Only available in team mode. You have to pass the login and the team number (0 or 1). - * @param Structures\Player|string $player - * @param int $teamNumber + * Force the team of the player. + * Only available in team mode. + * Only available to Admin. + * @param mixed $player Login or player object + * @param int $team 0 or 1 * @param bool $multicall * @return bool + * @throws InvalidArgumentException */ - function forcePlayerTeam($player, $teamNumber, $multicall = false) + function forcePlayerTeam($player, $team, $multicall=false) { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } - if($teamNumber !== 0 && $teamNumber !== 1) - { - throw new InvalidArgumentException('teamNumber = '.print_r($teamNumber, true)); - } + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + if($team !== 0 && $team !== 1) + throw new InvalidArgumentException('team = '.print_r($team, true)); - return $this->execute('ForcePlayerTeam', array($login, $teamNumber), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($login, $team), $multicall); } /** * Force the spectating status of the player. - * You have to pass the login and the spectator mode - * (0: user selectable, 1: spectator, 2: player, 3: spectator but keep selectable). * Only available to Admin. - * @param Structures\Player|string $player - * @param int $spectatorMode - * @param bool $multicall - * @return bool - */ - function forceSpectator($player, $spectatorMode, $multicall = false) - { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } - if(array_search($spectatorMode, range(0, 3), true) === false) - { - throw new InvalidArgumentException('spectatorMode = '.print_r($spectatorMode, true)); - } - - return $this->execute('ForceSpectator', array($login, $spectatorMode), $multicall); - } - - /** - * Force spectators to look at a specific player. You have to pass the login of the spectator (or '' for all) and - * the login of the target (or '' for automatic), and an integer for the camera type to use (-1 = leave unchanged, 0 = replay, 1 = follow, 2 = free). - * @param Structures\Player|string $player - * @param Structures\Player|string $target - * @param int $cameraType - * @param bool $multicall - * @return bool - */ - function forceSpectatorTarget($player, $target, $cameraType, $multicall = false) - { - if(!($playerLogin = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } - if(!($targetLogin = $this->getLogin($target))) - { - throw new InvalidArgumentException('target must be set'); - } - if($cameraType !== -1 && $cameraType !== 0 && $cameraType !== 1 && $cameraType !== 2) - { - throw new InvalidArgumentException('cameraType = '.print_r($cameraType, true)); - } - - return $this->execute('ForceSpectatorTarget', array($playerLogin, $targetLogin, $cameraType), $multicall); - } - - /** - * Pass the login of the spectator. A spectator that once was a player keeps his player slot, so that he can go back to race mode. - * Calling this function frees this slot for another player to connect. - * @param Structures\Player|string $player - * @param bool $multicall - * @return bool - */ - function spectatorReleasePlayerSlot($player, $multicall = false) - { - if(!($login = $this->getLogin($player))) - { - throw new InvalidArgumentException('player must be set'); - } - return $this->execute('SpectatorReleasePlayerSlot', array($login), $multicall); - } - - /** - * Enable control of the game flow: the game will wait for the caller to validate state transitions. - * @param bool $flowControlEnable + * @param mixed $player Login or player object + * @param int $mode 0: user selectable, 1: spectator, 2: player, 3: spectator but keep selectable * @param bool $multicall * @return bool * @throws InvalidArgumentException */ - function manualFlowControlEnable($flowControlEnable, $multicall = false) + function forceSpectator($player, $mode, $multicall=false) { - if(!is_bool($flowControlEnable)) - { - throw new InvalidArgumentException('flowControlEnable = '.print_r($flowControlEnable, true)); - } + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + if(!is_int($mode) || $mode < 0 || $mode > 3) + throw new InvalidArgumentException('mode = '.print_r($mode, true)); - return $this->execute(ucfirst(__FUNCTION__), array($flowControlEnable), $multicall); + return $this->execute(ucfirst(__FUNCTION__), array($login, $mode), $multicall); + } + + /** + * Force spectators to look at a specific player. + * Only available to Admin. + * @param mixed $spectator Login or player object; empty for all + * @param mixed $target Login or player object; empty for automatic + * @param int $camera -1: leave unchanged, 0: replay, 1: follow, 2: free + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function forceSpectatorTarget($spectator, $target, $camera, $multicall=false) + { + $spectatorLogin = $this->getLogin($spectator, true); + if($spectatorLogin === false) + throw new InvalidArgumentException('player = '.print_r($spectator, true)); + $targetLogin = $this->getLogin($target, true); + if($targetLogin === false) + throw new InvalidArgumentException('target = '.print_r($target, true)); + if(!is_int($camera) || $camera < -1 || $camera > 2) + throw new InvalidArgumentException('camera = '.print_r($camera, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($spectatorLogin, $targetLogin, $camera), $multicall); + } + + /** + * Pass the login of the spectator. + * A spectator that once was a player keeps his player slot, so that he can go back to race mode. + * Calling this function frees this slot for another player to connect. + * Only available to Admin. + * @param mixed $player Login or player object + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function spectatorReleasePlayerSlot($player, $multicall=false) + { + $login = $this->getLogin($player); + if($login === false) + throw new InvalidArgumentException('player = '.print_r($player, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall); + } + + /** + * Enable control of the game flow: the game will wait for the caller to validate state transitions. + * Only available to Admin. + * @param bool $enable + * @param bool $multicall + * @return bool + * @throws InvalidArgumentException + */ + function manualFlowControlEnable($enable, $multicall=false) + { + if(!is_bool($enable)) + throw new InvalidArgumentException('enable = '.print_r($enable, true)); + + return $this->execute(ucfirst(__FUNCTION__), array($enable), $multicall); } /** * Allows the game to proceed. + * Only available to Admin. * @param bool $multicall * @return bool */ - function manualFlowControlProceed($multicall = false) + function manualFlowControlProceed($multicall=false) { return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); } /** - * Returns whether the manual control of the game flow is enabled. 0 = no, 1 = yes by the xml-rpc client making the call, 2 = yes, by some other xml-rpc client. - * @return int + * Returns whether the manual control of the game flow is enabled. + * Only available to Admin. + * @return int 0: no, 1: yes by the xml-rpc client making the call, 2: yes by some other xml-rpc client */ function manualFlowControlIsEnabled() { @@ -4256,7 +3874,9 @@ class Connection } /** - * Returns the transition that is currently blocked, or '' if none. (That's exactly the value last received by the callback.) + * Returns the transition that is currently blocked, or '' if none. + * (That's exactly the value last received by the callback.) + * Only available to Admin. * @return string */ function manualFlowControlGetCurTransition() @@ -4266,9 +3886,7 @@ class Connection /** * Returns the current match ending condition. - * Return values are: 'Playing', 'ChangeMap' or 'Finished'. - * @param bool $multicall - * @return string + * @return string 'Playing', 'ChangeMap' or 'Finished' */ function checkEndMatchCondition() { @@ -4276,10 +3894,8 @@ class Connection } /** - * Returns an object Structures\NetworkStats. - * The structure contains the following fields : Uptime, NbrConnection, MeanConnectionTime, MeanNbrPlayer, - * RecvNetRate, SendNetRate, TotalReceivingSize, TotalSendingSize and an array of structures named PlayerNetInfos. - * Each structure of the array PlayerNetInfos is a Structures\Player object contains the following fields : Login, IPAddress, LastTransferTime, DeltaBetweenTwoLastNetState, PacketLossRate. + * Returns a struct containing the networks stats of the server. + * Only available to SuperAdmin. * @return Structures\NetworkStats */ function getNetworkStats() @@ -4289,110 +3905,73 @@ class Connection /** * Start a server on lan, using the current configuration. + * Only available to SuperAdmin. * @param bool $multicall * @return bool */ - function startServerLan($multicall = false) + function startServerLan($multicall=false) { return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); } /** - * Start a server on internet using the 'Login' and 'Password' specified in the struct passed as parameters. - * @param array $ids - * @param bool $multicall - * @return bool - * @throws InvalidArgumentException - */ - function startServerInternet($multicall = false) - { - return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); - } - - /** - * Returns the current status of the server. - * @return Structures\Status - */ - function getStatus() - { - return Structures\Status::fromArray($this->execute(ucfirst(__FUNCTION__))); - } - - /** - * Quit the application. + * Start a server on internet, using the current configuration. + * Only available to SuperAdmin. * @param bool $multicall * @return bool */ - function quitGame($multicall = false) + function startServerInternet($multicall=false) { return $this->execute(ucfirst(__FUNCTION__), array(), $multicall); } - /** - * Returns the path of the game datas directory. - * @return string - */ - function gameDataDirectory() - { - return $this->execute(ucfirst(__FUNCTION__)); - } - - /** - * Returns the path of the maps directory. - * @return string - */ - function getMapsDirectory() - { - return $this->execute(ucfirst(__FUNCTION__)); - } - - /** - * Returns the path of the skins directory. - * @return string - */ - function getSkinsDirectory() - { - return $this->execute(ucfirst(__FUNCTION__)); - } - /** * Returns the login of the given player - * @param mixed $player Structures\Player or string - * @return string + * @param mixed $player + * @return string|bool */ - private function getLogin($player) + private function getLogin($player, $allowEmpty=false) { - if(is_string($player)) return $player; - if($player instanceof Structures\Player) return $player->login; - return null; + if(is_object($player)) + { + if(property_exists($player, 'login')) + $player = $player->login; + else + return false; + } + if(empty($player)) + return $allowEmpty ? '' : false; + if(is_string($player)) + return $player; + return false; } /** * Returns logins of given players - * @param mixed $player Structures\Player or string or array - * @return string + * @param mixed $players + * @return string|bool */ - private function getLogins($players) + private function getLogins($players, $allowEmpty=false) { if(is_array($players)) { $logins = array(); foreach($players as $player) { - if(($login = $this->getLogin($player))) $logins[] = $login; - else return null; + $login = $this->getLogin($player); + if($login === false) + return false; + else + $logins[] = $login; } return implode(',', $logins); } - return $this->getLogin($players); + return $this->getLogin($players, $allowEmpty); } - } /** * Exception Dedicated to Invalid Argument Error on Request Call */ class InvalidArgumentException extends \Exception {} - -?> diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/AbstractStructure.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/AbstractStructure.php index c474538c..049996ad 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/AbstractStructure.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/AbstractStructure.php @@ -4,7 +4,7 @@ * * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ - + namespace Maniaplanet\DedicatedServer\Structures; abstract class AbstractStructure @@ -13,37 +13,37 @@ abstract class AbstractStructure { if(!is_array($array)) return $array; - + $object = new static; foreach($array as $key => $value) $object->{lcfirst($key)} = $value; return $object; } - + static public function fromArrayOfArray($array) { if(!is_array($array)) return $array; - + $result = array(); foreach($array as $key => $value) $result[$key] = static::fromArray($value); return $result; } - + static public function getPropertyFromArray($array, $property) { return array_map(get_called_class().'::extractProperty', $array, array_fill(0, count($array), $property)); } - + static protected function extractProperty($element, $property) { if(!is_a($element, get_called_class()) || !property_exists($element, $property)) throw new \InvalidArgumentException('property '.$property.' does not exists in class: '.get_called_class()); - + return $element->$property; } - + function toArray() { $out = array(); @@ -52,5 +52,3 @@ abstract class AbstractStructure return $out; } } - -?> \ No newline at end of file diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Bill.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Bill.php index d8ed30f9..e4d8f30a 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Bill.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Bill.php @@ -4,6 +4,7 @@ * * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ + namespace Maniaplanet\DedicatedServer\Structures; class Bill extends AbstractStructure @@ -14,9 +15,11 @@ class Bill extends AbstractStructure const STATE_PAYED = 4; const STATE_REFUSED = 5; const STATE_ERROR = 6; - + + /** @var int */ public $state; + /** @var string */ public $stateName; + /** @var int */ public $transactionId; } -?> \ No newline at end of file diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Command.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Command.php index c9355a66..e2b3d3d0 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Command.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Command.php @@ -1,18 +1,20 @@ diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/GameInfos.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/GameInfos.php index 489790ee..9077f68b 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/GameInfos.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/GameInfos.php @@ -4,6 +4,7 @@ * * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ + namespace Maniaplanet\DedicatedServer\Structures; class GameInfos extends AbstractStructure @@ -19,29 +20,52 @@ class GameInfos extends AbstractStructure const GAMEMODE_CUP = 5; const GAMEMODE_STUNTS = 6; + /** @var int */ public $gameMode; + /** @var string */ public $scriptName; + /** @var int */ public $nbMaps; + /** @var int */ public $chatTime; + /** @var int */ public $finishTimeout; + /** @var int */ public $allWarmUpDuration; + /** @var bool */ public $disableRespawn; + /** @var int */ public $forceShowAllOpponents; + /** @var int */ public $roundsPointsLimit; + /** @var int */ public $roundsForcedLaps; + /** @var bool */ public $roundsUseNewRules; + /** @var int */ public $roundsPointsLimitNewRules; + /** @var int */ public $teamPointsLimit; + /** @var int */ public $teamMaxPoints; + /** @var bool */ public $teamUseNewRules; + /** @var int */ public $teamPointsLimitNewRules; + /** @var int */ public $timeAttackLimit; + /** @var int */ public $timeAttackSynchStartPeriod; + /** @var int */ public $lapsNbLaps; + /** @var int */ public $lapsTimeLimit; + /** @var int */ public $cupPointsLimit; + /** @var int */ public $cupRoundsPerMap; + /** @var int */ public $cupNbWinners; + /** @var int */ public $cupWarmUpDuration; } -?> diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/LobbyInfo.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/LobbyInfo.php index 82e2259d..ae7f6ef2 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/LobbyInfo.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/LobbyInfo.php @@ -4,14 +4,17 @@ * * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ + namespace Maniaplanet\DedicatedServer\Structures; class LobbyInfo extends AbstractStructure { + /** var bool */ public $isLobby; + /** var int */ public $lobbyPlayers; + /** var int */ public $lobbyMaxPlayers; + /** var float */ public $lobbyPlayersLevel; } - -?> \ No newline at end of file diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Map.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Map.php index 49019738..d33fe3f8 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Map.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Map.php @@ -4,24 +4,41 @@ * * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ + namespace Maniaplanet\DedicatedServer\Structures; class Map extends AbstractStructure { + /** var string */ public $uId; + /** var string */ public $name; + /** var string */ public $fileName; + /** var string */ public $author; + /** var string */ public $environnement; + /** var string */ public $mood; + /** var int */ public $bronzeTime; + /** var int */ public $silverTime; + /** var int */ public $goldTime; + /** var int */ public $authorTime; + /** var int */ public $copperPrice; + /** var bool */ public $lapRace; + /** var int */ public $nbLaps; + /** var int */ public $nbCheckpoints; + /** var string */ public $mapType; + /** var string */ public $mapStyle; -} \ No newline at end of file +} diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Mod.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Mod.php index 497df50d..00931433 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Mod.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Mod.php @@ -4,15 +4,13 @@ * * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ + namespace Maniaplanet\DedicatedServer\Structures; class Mod extends AbstractStructure { + /** var string */ public $env; + /** var string */ public $url; - - function toArray() - { - return array('Env'=>$this->env,'Url'=>$this->url); - } -} \ No newline at end of file +} diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Music.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Music.php index bc810e58..d28d3f63 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Music.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Music.php @@ -4,11 +4,15 @@ * * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ + namespace Maniaplanet\DedicatedServer\Structures; class Music extends AbstractStructure { + /** var bool */ public $override; - public $url; + /** var string */ + public $url; + /** var string */ public $file; -} \ No newline at end of file +} diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/NetworkStats.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/NetworkStats.php index 5236664e..8b7cbedd 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/NetworkStats.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/NetworkStats.php @@ -4,24 +4,34 @@ * * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ + namespace Maniaplanet\DedicatedServer\Structures; class NetworkStats extends AbstractStructure { + /** @var int */ public $uptime; + /** @var int */ public $nbrConnection; + /** @var int */ public $meanConnectionTime; + /** @var int */ public $meanNbrPlayer; + /** @var int */ public $recvNetRate; + /** @var int */ public $sendNetRate; + /** @var int */ public $totalReceivingSize; + /** @var int */ public $totalSendingSize; + /** @var PlayerNetInfo[] */ public $playerNetInfos; static public function fromArray($array) { $object = parent::fromArray($array); - $object->playerNetInfos = Player::fromArrayOfArray($object->playerNetInfos); + $object->playerNetInfos = PlayerNetInfo::fromArrayOfArray($object->playerNetInfos); return $object; } -} \ No newline at end of file +} diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Player.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Player.php index 594d9def..cd8058e2 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Player.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Player.php @@ -8,90 +8,6 @@ namespace Maniaplanet\DedicatedServer\Structures; class Player extends AbstractStructure { - public $playerId; + /** @var string */ public $login; - public $nickName; - public $teamId; - public $path; - public $language; - public $clientVersion; - public $clientName; - public $iPAddress; - public $downloadRate; - public $uploadRate; - public $isSpectator; - public $isInOfficialMode; - public $avatar; - public $skins; - public $ladderStats; - public $hoursSinceZoneInscription; - public $onlineRights; - public $rank; - public $bestTime; - public $bestCheckpoints; - public $score; - public $nbrLapsFinished; - public $ladderScore; - public $stateUpdateLatency; - public $stateUpdatePeriod; - public $latestNetworkActivity; - public $packetLossRate; - public $spectatorStatus; - public $ladderRanking; - public $flags; - public $isConnected = true; - public $allies = array(); - public $clubLink; - - //Flags details - public $forceSpectator; - public $isReferee; - public $isPodiumReady; - public $isUsingStereoscopy; - public $isManagedByAnOtherServer; - public $isServer; - public $hasPlayerSlot; - public $isBroadcasting; - public $hasJoinedGame; - - //SpectatorStatus details - public $spectator; - public $temporarySpectator; - public $pureSpectator; - public $autoTarget; - public $currentTargetId; - - function getArrayFromPath() - { - return explode('|', $this->path); - } - - /** - * @return Player - */ - static public function fromArray($array) - { - $object = parent::fromArray($array); - - $object->skins = Skin::fromArrayOfArray($object->skins); - //Detail flags - $object->forceSpectator = $object->flags % 10; // 0, 1 or 2 - $object->isReferee = (bool) (intval($object->flags / 10) % 10); - $object->isPodiumReady = (bool) (intval($object->flags / 100) % 10); - $object->isUsingStereoscopy = (bool) (intval($object->flags / 1000) % 10); - $object->isManagedByAnOtherServer = (bool) (intval($object->flags / 10000) % 10); - $object->isServer = (bool) (intval($object->flags / 100000) % 10); - $object->hasPlayerSlot = (bool) (intval($object->flags / 1000000) % 10); - $object->isBroadcasting = (bool) (intval($object->flags / 10000000) % 10); - $object->hasJoinedGame = (bool) (intval($object->flags / 100000000) % 10); - //Details spectatorStatus - $object->spectator = (bool) ($object->spectatorStatus % 10); - $object->temporarySpectator = (bool) (intval($object->spectatorStatus / 10) % 10); - $object->pureSpectator = (bool) (intval($object->spectatorStatus / 100) % 10); - $object->autoTarget = (bool) (intval($object->spectatorStatus / 1000) % 10); - $object->currentTargetId = intval($object->spectatorStatus / 10000); - - return $object; - } } -?> \ No newline at end of file diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/ScriptInfo.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/ScriptInfo.php index 6371002b..d361124f 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/ScriptInfo.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/ScriptInfo.php @@ -9,29 +9,24 @@ namespace Maniaplanet\DedicatedServer\Structures; class ScriptInfo extends AbstractStructure { - + /** @var string */ public $name; + /** @var string */ public $compatibleMapTypes; + /** @var string */ public $description; + /** @var string */ public $version; + /** @var ScriptSettings[] */ public $paramDescs = array(); + /** @var Command[] */ public $commandDescs = array(); static public function fromArray($array) { $object = parent::fromArray($array); - - if($object->paramDescs) - { - $object->paramDescs = ScriptSettings::fromArrayOfArray($object->paramDescs); - } - if($object->commandDescs) - { - $object->commandDescs = Command::fromArrayOfArray($object->commandDescs); - } + $object->paramDescs = ScriptSettings::fromArrayOfArray($object->paramDescs); + $object->commandDescs = Command::fromArrayOfArray($object->commandDescs); return $object; } - } - -?> \ No newline at end of file diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/ScriptSettings.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/ScriptSettings.php index a53818a9..876f4455 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/ScriptSettings.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/ScriptSettings.php @@ -7,14 +7,14 @@ namespace Maniaplanet\DedicatedServer\Structures; -final class ScriptSettings extends AbstractStructure +class ScriptSettings extends AbstractStructure { - + /** @var string */ public $name; + /** @var string */ public $desc; + /** @var string */ public $type; + /** @var string */ public $default; - } - -?> diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/ServerOptions.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/ServerOptions.php index 4535816a..6b35c889 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/ServerOptions.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/ServerOptions.php @@ -9,36 +9,66 @@ namespace Maniaplanet\DedicatedServer\Structures; class ServerOptions extends AbstractStructure { + /** @var string */ public $name; + /** @var string */ public $comment; + /** @var string */ public $password; + /** @var string */ public $passwordForSpectator; + /** @var int */ public $hideServer; + /** @var int */ public $currentMaxPlayers; + /** @var int */ public $nextMaxPlayers; + /** @var int */ public $currentMaxSpectators; + /** @var int */ public $nextMaxSpectators; + /** @var bool */ public $isP2PUpload; + /** @var bool */ public $isP2PDownload; + /** @var bool */ public $currentLadderMode; + /** @var int */ public $nextLadderMode; + /** @var float */ public $ladderServerLimitMax; + /** @var float */ public $ladderServerLimitMin; + /** @var int */ public $currentVehicleNetQuality; + /** @var int */ public $nextVehicleNetQuality; + /** @var int */ public $currentCallVoteTimeOut; + /** @var int */ public $nextCallVoteTimeOut; + /** @var float */ public $callVoteRatio; + /** @var bool */ public $allowMapDownload; + /** @var bool */ public $autoSaveReplays; + /** @var bool */ public $autoSaveValidationReplays; + /** @var string */ public $refereePassword; + /** @var int */ public $refereeMode; + /** @var bool */ public $currentUseChangingValidationSeed; - public $useChangingValidationSeed; + /** @var bool */ public $nextUseChangingValidationSeed; + /** @var int */ public $clientInputsMaxLatency; + /** @var bool */ public $keepPlayerSlots; + /** @var bool */ public $disableHorns; + /** @var bool */ public $disableServiceAnnounces; -} \ No newline at end of file +} diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Skin.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Skin.php index a11735d5..859a38b4 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Skin.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Skin.php @@ -4,13 +4,20 @@ * * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ - + namespace Maniaplanet\DedicatedServer\Structures; class Skin extends AbstractStructure { - public $orig; - public $name; - public $checksum; - public $url; -} \ No newline at end of file + /** @var string */ + public $environnement; + /** @var FileDesc */ + public $packDesc; + + static function fromArray($array) + { + $object = parent::fromArray($array); + $object->packDesc = FileDesc::fromArray($object->packDesc); + return $object; + } +} diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Status.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Status.php index 139629a6..8f16cb95 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Status.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Status.php @@ -4,6 +4,7 @@ * * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ + namespace Maniaplanet\DedicatedServer\Structures; class Status extends AbstractStructure @@ -15,6 +16,8 @@ class Status extends AbstractStructure const PLAY = 4; const EXITING = 6; + /** @var int */ public $code; + /** @var string */ public $name; -} \ No newline at end of file +} diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/SystemInfos.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/SystemInfos.php index ca645dbe..11bf3e74 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/SystemInfos.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/SystemInfos.php @@ -4,19 +4,29 @@ * * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ + namespace Maniaplanet\DedicatedServer\Structures; class SystemInfos extends AbstractStructure { + /** @var string */ public $publishedIp; + /** @var int */ public $port; + /** @var int */ public $p2PPort; + /** @var string */ public $titleId; + /** @var string */ public $serverLogin; + /** @var int */ public $serverPlayerId; + /** @var int */ public $connectionDownloadRate; + /** @var int */ public $connectionUploadRate; + /** @var bool */ public $isServer; + /** @var bool */ public $isDedicated; } -?> \ No newline at end of file diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Team.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Team.php index 988fddcb..2fc1c7d3 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Team.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Team.php @@ -9,14 +9,20 @@ namespace Maniaplanet\DedicatedServer\Structures; class Team extends AbstractStructure { + /** @var string */ public $name; + /** @var string */ public $zonePath; + /** @var string */ public $city; + /** @var string */ public $emblemUrl; + /** @var float */ public $huePrimary; + /** @var float */ public $hueSecondary; + /** @var string */ public $rGB; + /** @var string */ public $clubLinkUrl; } - -?> \ No newline at end of file diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Version.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Version.php index 0b40e82e..82473f57 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Version.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Version.php @@ -4,15 +4,19 @@ * * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ - + namespace Maniaplanet\DedicatedServer\Structures; class Version extends AbstractStructure { + /** @var string */ public $name; + /** @var string */ public $titleId; + /** @var string */ public $version; + /** @var string */ public $build; + /** @var string */ public $apiVersion; } -?> \ No newline at end of file diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Vote.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Vote.php index d06925b6..9e63d5e8 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Vote.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/Vote.php @@ -4,7 +4,7 @@ * * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ - + namespace Maniaplanet\DedicatedServer\Structures; class Vote extends AbstractStructure @@ -13,10 +13,32 @@ class Vote extends AbstractStructure const STATE_CANCELLED = 'VoteCancelled'; const STATE_PASSED = 'VotePassed'; const STATE_FAILED = 'VoteFailed'; - + + /** @var string */ public $status; + /** @var string */ public $callerLogin; + /** @var string */ public $cmdName; + /** @var mixed[] */ public $cmdParam; + + /** + * @param string $cmdName + * @param mixed[] $cmdParam + */ + function __construct($cmdName='', $cmdParam=array()) + { + $this->cmdName = $cmdName; + $this->cmdParam = $cmdParam; + } + + /** + * @return bool + */ + function isValid() + { + return is_string($this->cmdName) + && is_array($this->cmdParam); + } } -?> \ No newline at end of file diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/VoteRatio.php b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/VoteRatio.php index 5e575344..5273e12d 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Structures/VoteRatio.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Structures/VoteRatio.php @@ -4,7 +4,7 @@ * * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3 */ - + namespace Maniaplanet\DedicatedServer\Structures; class VoteRatio extends AbstractStructure @@ -17,15 +17,41 @@ class VoteRatio extends AbstractStructure const COMMAND_TEAM_BALANCE = 'AutoTeamBalance'; const COMMAND_KICK = 'Kick'; const COMMAND_BAN = 'Ban'; - + + /** @var string '*' for default */ public $command; + /** @var string Empty to match all votes for the command */ public $param; + /** @var float Must be in range [0,1] or -1 to disable */ public $ratio; - public function __construct($command = null, $ratio = null) + /** + * @param string $command + * @param float $ratio + */ + public function __construct($command = '', $ratio = 0.) { $this->command = $command; $this->ratio = $ratio; + $this->param = ''; + } + + /** + * @return bool + */ + function isValid() + { + return is_string($this->command) + && is_string($this->param) + && self::isRatio($this->ratio); + } + + /** + * @param float $ratio + * @return bool + */ + static function isRatio($ratio) + { + return is_float($ratio) && ($ratio === -1. || ($ratio >= 0. && $ratio <= 1.)); } } -?> \ No newline at end of file diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/Base64.php b/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/Base64.php index ba5df913..076aabfa 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/Base64.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/Base64.php @@ -19,6 +19,12 @@ class Base64 { $this->scalar = $data; } -} -?> \ No newline at end of file + /** + * @return string + */ + function __toString() + { + return $this->scalar; + } +} diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/Exception.php b/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/Exception.php index 82c054e0..944d4852 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/Exception.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/Exception.php @@ -8,5 +8,3 @@ namespace Maniaplanet\DedicatedServer\Xmlrpc; class Exception extends \Exception {} - -?> diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/FaultException.php b/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/FaultException.php index c7bff0b0..f151ad91 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/FaultException.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/FaultException.php @@ -57,5 +57,3 @@ class MapNotCompatibleOrCompleteException extends FaultException{} class LadderModeUnknownException extends FaultException{} class PlayerAlreadyIgnoredException extends FaultException{} class PlayerNotIgnoredException extends FaultException{} - -?> diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/GbxRemote.php b/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/GbxRemote.php index 5350eaf8..e6deb62a 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/GbxRemote.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/GbxRemote.php @@ -17,7 +17,6 @@ class GbxRemote private $socket; private $timeouts = array( - 'open' => 5, 'read' => 5000, 'write' => 5000 ); @@ -29,13 +28,12 @@ class GbxRemote /** * @param string $host * @param int $port - * @param int[string] $timeouts Override default timeouts for 'open' (in s), 'read' (in ms) and 'write' (in ms) socket operations + * @param int $timeout Timeout when opening connection */ - function __construct($host, $port, $timeouts = array()) + function __construct($host, $port, $timeout = 5) { $this->requestHandle = (int) 0x80000000; - $this->timeouts = array_merge($this->timeouts, $timeouts); - $this->connect($host, $port); + $this->connect($host, $port, $timeout); } function __destruct() @@ -45,10 +43,10 @@ class GbxRemote /** * Change timeouts - * @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 + * @param int $read read timeout (in ms), 0 to leave unchanged + * @param int $write write timeout (in ms), 0 to leave unchanged */ - function setTimeouts($read=null, $write=null) + function setTimeouts($read=0, $write=0) { if($read) $this->timeouts['read'] = $read; @@ -68,12 +66,12 @@ class GbxRemote /** * @param string $host * @param int $port + * @param int $timeout * @throws TransportException */ - private function connect($host, $port) + private function connect($host, $port, $timeout) { - $this->socket = @fsockopen($host, $port, $errno, $errstr, $this->timeouts['open']); - + $this->socket = @fsockopen($host, $port, $errno, $errstr, $timeout); if(!$this->socket) throw new TransportException('Cannot open socket', TransportException::NOT_INITIALIZED); @@ -114,12 +112,13 @@ class GbxRemote if(strlen($xml) > self::MAX_REQUEST_SIZE-8) { - if($method != 'system.multicall' || count($args) < 2) + if($method != 'system.multicall' || count($args[0]) < 2) throw new MessageException('Request too large', MessageException::REQUEST_TOO_LARGE); - $mid = count($args) >> 1; - $this->query('system.multicall', array_slice($args, 0, $mid)); - $this->query('system.multicall', array_slice($args, $mid)); + $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); } $this->writeMessage($xml); @@ -151,7 +150,7 @@ class GbxRemote $call = array_shift($this->multicallBuffer); return $this->query($call['methodName'], $call['params']); default: - $result = $this->query('system.multicall', $this->multicallBuffer); + $result = $this->query('system.multicall', array($this->multicallBuffer)); $this->multicallBuffer = array(); return $result; } @@ -185,9 +184,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) { @@ -205,12 +204,8 @@ class GbxRemote $this->callbacksBuffer[] = $value; } - if(!$waitResponse){ - $r=array($this->socket); - $w=null; - $e=null; + if(!$waitResponse) $n = @stream_select($r, $w, $e, 0); - } }; } @@ -310,5 +305,3 @@ class MessageException extends Exception const REQUEST_TOO_LARGE = 1; const RESPONSE_TOO_LARGE = 2; } - -?> diff --git a/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/Request.php b/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/Request.php index 1925754a..605f042f 100644 --- a/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/Request.php +++ b/application/core/Libs/Maniaplanet/DedicatedServer/Xmlrpc/Request.php @@ -22,9 +22,12 @@ if(extension_loaded('xmlrpc')) * @param mixed[] $args * @return string */ - static function encode($method, $args) + static function encode($method, $args, $escape=true) { - return xmlrpc_encode_request($method, $args, self::$options); + $opts = self::$options; + if(!$escape) + $opts['escaping'] = array(); + return xmlrpc_encode_request($method, $args, $opts); } /** @@ -40,7 +43,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); } @@ -59,55 +62,80 @@ else * @param mixed[] $args * @return string */ - static function encode($method, $args) + static function encode($method, $args, $escape=true) { - $xml = ''; + $xml = ''.self::escape($method, $escape).''; + if(!$args) + return $xml.''; + + $xml .= ''; foreach($args as $arg) - $xml .= ''.self::encodeValue($arg).''; - $xml .= ''; - return $xml; + $xml .= ''.self::encodeValue($arg, $escape).''; + return $xml.''; } /** * @param mixed $v * @return string */ - private static function encodeValue($v) + private static function encodeValue($v, $escape=true) { switch(gettype($v)) { case 'boolean': - return ''; + return ''.self::escape((int) $v, $escape).''; case 'integer': - return ''; + return ''.self::escape($v, $escape).''; case 'double': - return ''; + return ''.self::escape($v, $escape).''; case 'string': - return ''; + case 'NULL': + if(!$v) + return ''; + return ''.self::escape($v, $escape).''; case 'object': if($v instanceof Base64) - return 'scalar).']]>'; + { + if(!$v->scalar) + return ''; + return ''.self::escape(base64_encode($v->scalar), $escape).''; + } if($v instanceof \DateTime) - return 'format(self::DATE_FORMAT).']]>'; + return ''.self::escape($v->format(self::DATE_FORMAT), $escape).''; $v = get_object_vars($v); - // fallthrough + // fallthrough case 'array': $return = ''; + // empty array case + if(!$v) + return ''; // pure array case if(array_keys($v) === range(0, count($v) - 1)) { foreach($v as $item) - $return .= ''.self::encodeValue($item).''; + $return .= ''.self::encodeValue($item, $escape).''; return ''.$return.''; } // else it's a struct foreach($v as $name => $value) - $return .= ''.self::encodeValue($value).''; + $return .= ''.self::escape($name, $escape).''.self::encodeValue($value, $escape).''; return ''.$return.''; } return ''; } + /** + * @param string $str + * @param bool $escape + * @return string + */ + private static function escape($str, $escape=true) + { + if($escape) + return ''; + return $str; + } + /** * @param string $message * @return mixed @@ -142,7 +170,7 @@ else switch($elt->getName()) { case 'boolean': - return (bool) $elt; + return (bool) (int) $elt; case 'i4': case 'int': return (int) $elt; @@ -170,5 +198,3 @@ else } class ParseException extends Exception {} - -?>