/libraries/ManiaLive/DedicatedApi/Connection.php
PHP | 2164 lines | 1067 code | 213 blank | 884 comment | 167 complexity | 97bbb6977e7e1e30b3996b3765d27363 MD5 | raw file
Possible License(s): LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * ManiaLive - TrackMania dedicated server manager in PHP
- *
- * @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
- * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
- * @version $Revision: 352 $:
- * @author $Author: melot.philippe $:
- * @date $Date: 2012-03-23 11:37:38 +0100 (Fri, 23 Mar 2012) $:
- */
- namespace ManiaLive\DedicatedApi;
- use ManiaLive\DedicatedApi\Xmlrpc\Request;
- use ManiaLive\DedicatedApi\Structures\Music;
- use ManiaLive\DedicatedApi\Structures\Player;
- use ManiaLive\DedicatedApi\Structures\Status;
- use ManiaLive\DedicatedApi\Structures\Vote;
- use ManiaLive\DedicatedApi\Structures\ServerOptions;
- use ManiaLive\Event\Dispatcher;
- use ManiaLive\Utilities\Console;
- /**
- * Dedicated Server Connection Instance
- * Methods returns nothing if $multicall = true
- */
- class Connection extends \ManiaLib\Utils\Singleton
- {
- /**
- * XML-RPC client instance
- * @var
- */
- protected $xmlrpcClient;
- /**
- * @return Connection
- */
- static function getInstance()
- {
- return parent::getInstance();
- }
- /**
- * Constructor of the class
- * @param int $port represents the communication port
- * @param string $hostname represents the ip to reach
- * @param string $superAdminPassword represents the SuperAdmin password
- * @param string $adminPassword represents the Admin password
- * @param string $userPassword represents the User password
- */
- protected function __construct()
- {
- $config = Config::getInstance();
- $this->xmlrpcClient = new Xmlrpc\ClientMulticall($config->host, $config->port);
- Console::printlnFormatted('XML-RPC connection established');
- $this->authenticate($config->user, $config->password);
- $this->setApiVersion('2011-10-06');
- Console::printlnFormatted('Successfully authentified with XML-RPC server');
- }
- /**
- * Close the current socket connexion
- * Never call this method, use instead DedicatedApiFactory::deleteConnection($hostname,$port)
- */
- function terminate()
- {
- $this->xmlrpcClient->terminate();
- }
- /**
- *
- * 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
- */
- function executeCallbacks()
- {
- $this->xmlrpcClient->readCallbacks();
- $calls = $this->xmlrpcClient->getCallbackResponses();
- if (!empty($calls))
- {
- foreach ($calls as $call)
- {
- $method = preg_replace('/^[[:alpha:]]+\./', '', $call[0]); // remove trailing "Whatever."
- $params = (array) $call[1];
- Dispatcher::dispatch(new Callback\Event($method, $params));
- }
- }
- }
- /**
- * Execute the calls in queue and return the result
- * TODO Prendre en compte les retours du mutliQuery (via un handler ?)
- */
- function executeMulticall()
- {
- $this->xmlrpcClient->multiqueryIgnoreResult();
- }
- /**
- * Add a call in queur. It will be executed by the next Call from the user to executemulticall
- * @param string $methodName
- * @param string $authLevel
- * @param array $params
- */
- protected function execute($methodName, $params = array(), $multicall=false)
- {
- if ($multicall)
- {
- $this->xmlrpcClient->addCall($methodName, $params);
- }
- else
- {
- array_unshift($params, $methodName);
- call_user_func_array(array($this->xmlrpcClient, 'query'), $params);
- return $this->xmlrpcClient->getResponse();
- }
- }
- /**
- * 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
- * @param string $password
- * @return bool
- * @throws InvalidArgumentException
- */
- function changeAuthPassword($username, $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));
- }
- return $this->execute(ucfirst(__FUNCTION__), array($username, $password), false);
- }
- /**
- * Allow the GameServer to call you back.
- * @param bool $enable
- * @param bool $multicall
- * @return bool
- */
- function enableCallbacks($enable, $multicall = false)
- {
- return $this->execute(ucfirst(__FUNCTION__), array((bool) $enable), $multicall);
- }
- /**
- * Define the wanted api.
- * @param string $version
- * @param bool $multicall
- * @return bool
- */
- protected function setApiVersion($version, $multicall = false)
- {
- return $this->execute(ucfirst(__FUNCTION__), array((string) $version), $multicall);
- }
- /**
- * Returns a struct with the Name, Version, Build and ApiVersion of the application remotely controled.
- * @return ManiaLive\DedicatedApi\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);
- }
- /**
- * 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 ManiaLive\DedicatedApi\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
- * @param bool $multicall
- * @throws InvalidArgumentException
- */
- function callVote(Vote $vote, $ratio = 0.5, $timeout = 0, $voters = 1, $multicall = false)
- {
- if (is_null($vote))
- {
- throw new InvalidArgumentException('vote must be set');
- }
- if (!is_double($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 = new Xmlrpc\Request($vote->cmdName, $vote->cmdParam);
- return $this->execute(ucfirst(__FUNCTION__).'Ex', array($tmpCmd->getXml(), $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 Player|string $player 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_double($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 = new Xmlrpc\Request('Kick', array($login));
- return $this->execute('CallVoteEx', array($tmpCmd->getXml(), $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 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 $player, $ratio = 0.6, $timeout = 0, $voters = 1, $multicall = false)
- {
- if (! ($login = $this->getLogin($player)))
- {
- throw new InvalidArgumentException('player must be set');
- }
- if (!is_double($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 = new Xmlrpc\Request('Ban', array($login));
- return $this->execute('CallVoteEx', array($tmpCmd->getXml(), $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_double($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 = new Xmlrpc\Request('MapRestart', array());
- return $this->execute('CallVoteEx', array($tmpCmd->getXml(), $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_double($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 = new Xmlrpc\Request('NextMap', array());
- return $this->execute('CallVoteEx', array($tmpCmd->getXml(), $ratio, $timeout, $voters), $multicall);
- }
- /**
- * Used internaly by game.
- * @param bool $multicall
- * @return bool
- */
- protected function internalCallVote($multicall = false)
- {
- return $this->execute(ucfirst(__FUNCTION__), array(), $multicall);
- }
- /**
- * Cancel the current vote.
- * @param bool $multicall
- * @return bool
- */
- 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 ManiaLive\DedicatedApi\Structures\Vote
- */
- function getCurrentCallVote()
- {
- return Vote::fromArray($this->execute(ucfirst(__FUNCTION__)));
- }
- /**
- * 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
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- 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
- */
- function getCallVoteTimeOut()
- {
- return $this->execute(ucfirst(__FUNCTION__));
- }
- /**
- * Set a new default ratio for passing a vote.
- * Must lie between 0 and 1.
- * @param double $ratio
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function setCallVoteRatio($ratio, $multicall = false)
- {
- if (!is_double($ratio) && ($ratio < 0 || $ratio > 1))
- {
- 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
- */
- function getCallVoteRatio()
- {
- return $this->execute(ucfirst(__FUNCTION__));
- }
- /**
- * Set new ratios for passing specific votes.
- * The parameter is an array of struct
- * {string votecommand, double ratio}, ratio is in [0,1] or -1 for vote disabled.
- * @param array $ratios
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function setCallVoteRatios(array $ratios, $multicall = false)
- {
- if (!is_array($ratios))
- {
- throw new InvalidArgumentException('ratio = '.print_r($ratio, true));
- }
- for($i = 0; $i < count($ratios); $i++)
- {
- if (!is_array($ratios[$i]) && !array_key_exists('Command', $ratios[$i]) && !array_key_exists('Ratio', $ratios[$i]))
- {
- throw new InvalidArgumentException('ratios['.$i.'] = '.print_r($ratio, true));
- }
- if (!is_string($ratios[$i]['Command']))
- {
- throw new InvalidArgumentException('ratios['.$i.'][Command] = '.print_r($ratios[$i][0],true));
- }
- if (!is_double($ratios[$i]['Ratio']) && ($ratios[$i]['Ratio'] != -1 && ($ratios[$i]['Ratio'] < 0 || $ratios[$i]['Ratio'] > 1)))
- {
- throw new InvalidArgumentException('ratios['.$i.'][Ratio] = '.print_r($ratios[$i]['Ratio'],true));
- }
- }
- return $this->execute(ucfirst(__FUNCTION__), array($ratios), $multicall);
- }
- /**
- * Get the current ratios for passing votes.
- * @return array
- */
- function getCallVoteRatios()
- {
- return $this->execute(ucfirst(__FUNCTION__));
- }
- /**
- * 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 Player|string|array[Player|string] $receiver Player(s) who will receive the message, put null to send the message to everyone
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function chatSendServerMessageToLanguage(array $messages, $receiver = null, $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));
- }
- return $this->execute(ucfirst(__FUNCTION__), array($messages, $receiverString), $multicall);
- }
- /**
- * Send a text message without the server login to everyone if players is null.
- * Players can be a Player object or an array of Player
- * @param string $message
- * @param Player|string|array[Player|string] $receiver Player(s) who will receive the message, put null to send the message to everyone
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function chatSendServerMessage($message, $receiver = 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 Player|string|array[Player|string] $receiver 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 Player or the a specified player(s).
- * If Player is null, the message will be delivered to every Player
- * @param string $message
- * @param Player|string|array[Player|string] $receiver 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);
- }
- /**
- * Returns the last chat lines. Maximum of 40 lines.
- * @return array
- */
- function getChatLines()
- {
- return $this->execute(ucfirst(__FUNCTION__));
- }
- /**
- * 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.
- * @param bool $enable
- * @param bool $serverAutomaticForward
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function chatEnableManualRouting($enable, $serverAutomaticForward = 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));
- }
- return $this->execute(ucfirst(__FUNCTION__), array($enable,$serverAutomaticForward), $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.
- * Only available if manual routing is enabled.
- * @param string $message
- * @param Player|string $sender
- * @param Player|string $receiver
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function chatForwardToLogin($message, $sender, $receiver = 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);
- }
- /**
- * 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 Player|string|array[Player|string] $receiver
- * @param Player|string $player
- * @param int $variant 0, 1 or 2
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function sendNotice($receiver, $message, $player = null, $variant = 0, $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);
- }
- /**
- * Display a manialink page on the client of the specified 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 Player object
- * @param null|Player|string|array[Player|string] $playerLogin
- * @param string $manialink
- * @param int $timeout
- * @param bool $hideOnClick
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function sendDisplayManialinkPage($players, $manialink, $timeout, $hideOnClick, $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;
- $method .= 'ToLogin';
- }
- if (!is_string($manialink))
- {
- throw new InvalidArgumentException('manialink = '.print_r($manialink,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);
- }
- /**
- * 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|Player|string|array[Player|string] $players
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function sendHideManialinkPage($players = 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;
- $method .= 'ToLogin';
- }
- return $this->execute($method, $params, $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
- */
- function getManialinkPageAnswers()
- {
- return $this->execute(ucfirst(__FUNCTION__));
- }
- /**
- * Kick the player with an optional message.
- * @param Player|string $playerLogin
- * @param string $message
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function kick($player, $message = '', $multicall = false)
- {
- if (! ($login = $this->getLogin($player)))
- {
- throw new InvalidArgumentException('player must be set');
- }
- if (!is_string($message))
- {
- throw new InvalidArgumentException('message = '.print_r($message,true));
- }
- return $this->execute('Kick', array($login, $message), $multicall);
- }
- /**
- * Ban the player with an optional message.
- * @param Player|string $player
- * @param string $message
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function ban(Player $player, $message = '', $multicall = false)
- {
- if (! ($login = $this->getLogin($player)))
- {
- throw new InvalidArgumentException('player must be set');
- }
- if (!is_string($message))
- {
- throw new InvalidArgumentException('message = '.print_r($message,true));
- }
- return $this->execute('Ban', array($login, $message), $multicall);
- }
- /**
- * Ban the player with a message.
- * Add it to the black list, and optionally save the new list.
- * @param Player|string $player
- * @param string $message
- * @param bool $saveList
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function banAndBlackList($player, $message, $saveList = false, $multicall = false)
- {
- if (! ($login = $this->getLogin($player)))
- {
- throw new InvalidArgumentException('player must be set');
- }
- if (!is_string($message) || !$message)
- {
- throw new InvalidArgumentException('message = '.print_r($message, true));
- }
- if (!is_bool($saveList))
- {
- throw new InvalidArgumentException('saveList = '.print_r($saveList,true));
- }
- return $this->execute(ucfirst(__FUNCTION__), array($login, $message, $saveList), $multicall);
- }
- /**
- * Unban the player
- * @param Player|string $player
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function unBan($player, $multicall = false)
- {
- if (! ($login = $this->getLogin($player)))
- {
- throw new InvalidArgumentException('player must be set');
- }
- return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
- }
- /**
- * Clean the ban list of the server.
- * @param bool $multicall
- * @return bool
- */
- 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 array[DedicatedApi\Structures\Player] The list is an array of object. Each object is an instance of DedicatedApi\Structures\Player
- * @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));
- $result = $this->execute(ucfirst(__FUNCTION__), array($length, $offset));
- return Structures\Player::fromArrayOfArray($result);
- }
- /**
- * Blacklist the player
- * @param Player|string $player
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function blackList($player, $multicall = false)
- {
- if (! ($login = $this->getLogin($player)))
- {
- throw new InvalidArgumentException('player must be set');
- }
- return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
- }
- /**
- * UnBlackList the player
- * @param Player|string $player
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function unBlackList($player, $multicall = false)
- {
- if (! ($login = $this->getLogin($player)))
- {
- throw new InvalidArgumentException('player must be set');
- }
- return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
- }
- /**
- * Clean the blacklist of the server.
- * @param bool $multicall
- * @return bool
- */
- 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 array[DedicatedApi\Structures\Player] The list is an array of structures. Each structure contains the following fields : Login.
- * @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));
- $result = $this->execute(ucfirst(__FUNCTION__), array($length, $offset));
- return Structures\Player::fromArrayOfArray($result);
- }
- /**
- * Load the black list file with the specified file name.
- * @param string $filename blackList file name
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function loadBlackList($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 black list in the file with specified file name.
- * @param string $filename blackList filename
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function saveBlackList($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 player to the guest list.
- * @param Player|string $player
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function addGuest($player, $multicall = false)
- {
- if (! ($login = $this->getLogin($player)))
- {
- throw new InvalidArgumentException('player must be set');
- }
- return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
- }
- /**
- * Remove the player from the guest list.
- * @param Player|string $player
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function removeGuest($player, $multicall = false)
- {
- if (! ($login = $this->getLogin($player)))
- {
- throw new InvalidArgumentException('player must be set');
- }
- return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
- }
- /**
- * Clean the guest list of the server.
- * @param bool $multicall
- * @return bool
- */
- 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 array[DedicatedApi\Structures\Player] The list is an array of structures. Each structure contains the following fields : Login.
- * @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);
- }
- /**
- *
- * Load the guest list file with the specified file name.
- * @param string $filename blackList file name
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- 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
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- 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|Player|string $player the player, or null for global setting
- * @param bool $enable the value.
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function setBuddyNotification(Player $player, $enable, $multicall = false)
- {
- 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);
- }
- /**
- * Gets whether buddy notifications are enabled for login, or '' to get the global setting.
- * @param null|Player|string $player the player, or null for global setting
- * @return bool
- * @throws InvalidArgumentException
- */
- function getBuddyNotification($player)
- {
- $player = $this->getLogin($player) ?: '';
- return $this->execute(ucfirst(__FUNCTION__), $params);
- }
- /**
- * 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);
- if(strlen($data->getXml()) > 1024 * 1024 - 15)
- {
- throw new InvalidArgumentException('file is too big');
- }
- 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);
- if(strlen($data->getXml()) > 1024 * 1024 - 15)
- {
- throw new InvalidArgumentException('data are too big');
- }
- 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 Player|string|array[Player|string] $players
- * @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));
- }
- if (filesize($filename) > 4 * 1024)
- {
- throw new InvalidArgumentException('file is too big');
- }
- $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 Player|string|array[Player|string] $players
- * @param string $data
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function tunnelSendDataFromString($players, $data, $multicall = false)
- {
- if (! ($login = $this->getLogins($players)))
- {
- throw new InvalidArgumentException('players = '.print_r($players,true));
- }
- $data = new Xmlrpc\Base64($data);
- return $this->execute('TunnelSendDataToLogin', array($login, $data), $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
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- 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 Player.
- * @param Player|string $player
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function ignore($player, $multicall = false)
- {
- if (! ($login = $this->getLogin($player)))
- {
- throw new InvalidArgumentException('player must be set');
- }
- return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
- }
- /**
- * Unignore the specified player.
- * @param Player|string $player
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function unIgnore(Player $player, $multicall = false)
- {
- if (! ($login = $this->getLogin($player)))
- {
- throw new InvalidArgumentException('player must be set');
- }
- return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
- }
- /**
- * Clean the ignore list of the server.
- * @param bool $multicall
- * @return bool
- */
- 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 array[DedicatedApi\Structures\Player] The list is an array of structures. Each structure contains the following fields : Login.
- * @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);
- }
- /**
- * 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 Player|string $player
- * @param int $amount
- * @param string $label
- * @param bool $multicall
- * @return int The Bill Id
- * @throws InvalidArgumentException
- */
- function pay($player, $amount, $label, $multicall = false)
- {
- if (! ($login = $this->getLogin($player)))
- {
- throw new InvalidArgumentException('player must be set');
- }
- 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));
- }
- return $this->execute(ucfirst(__FUNCTION__), array($login, $amount, $label), $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 Player|string $fromPlayer
- * @param int $amount
- * @param string $label
- * @param Player|string|null $toPlayer
- * @param bool $multicall
- * @return int
- * @throws InvalidArgumentException
- */
- function sendBill($fromPlayer, $amount, $label, $toPlayer = null, $multicall = false)
- {
- 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');
- }
- $to = $this->getLogin($toPlayer) ?: '';
- return $this->execute(ucfirst(__FUNCTION__), array($from, $amount, $label, $to), $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 Bill
- * @throws InvalidArgumentException
- */
- 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);
- }
- /**
- * Returns the current number of planets on the server account.
- * @return int
- */
- function getServerPlanets()
- {
- return $this->execute('GetServerPlanets');
- }
- /**
- * Get some system infos.
- * Return a struct containing:
- * PublishedIp, Port, P2PPort, ServerLogin, ServerPlayerId
- * @return ManiaLive\DedicatedApi\Structures\SystemInfos
- */
- function getSystemInfo()
- {
- $result = $this->execute(ucfirst(__FUNCTION__));
- return Structures\SystemInfos::fromArray($result);
- }
- /**
- * 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
- * @param bool $multicall
- * @return bool
- */
- 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);
- }
- /**
- * Set a new server name in utf8 format.
- * @param string $serverName
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function setServerName($serverName, $multicall = false)
- {
- if (!is_string($serverName))
- {
- throw new InvalidArgumentException('serverName = '.print_r($serverName,true));
- }
- return $this->execute(ucfirst(__FUNCTION__), array($serverName), $multicall);
- }
- /**
- * Get the server name in utf8 format.
- * @return string
- */
- function getServerName()
- {
- return $this->execute(ucfirst(__FUNCTION__));
- }
- /**
- * Set a new server comment in utf8 format.
- * @param string $serverComment
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function setServerComment($serverComment, $multicall = false)
- {
- if (!is_string($serverComment))
- {
- throw new InvalidArgumentException('serverComment = '.print_r($serverComment,true));
- }
- return $this->execute(ucfirst(__FUNCTION__), array($serverComment), $multicall);
- }
- /**
- * Get the server comment in utf8 format.
- * @return string
- */
- function getServerComment()
- {
- return $this->execute(ucfirst(__FUNCTION__));
- }
- /**
- * Set whether the server should be hidden from the public server list
- * (0 = visible, 1 = always hidden, 2 = hidden from nations).
- * @param int $visibility
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function setHideServer($visibility, $multicall = false)
- {
- if ($visibility !== 0 && $visibility !== 1 && $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
- */
- function getHideServer()
- {
- return $this->execute(ucfirst(__FUNCTION__));
- }
- /**
- * Returns true if this is a relay server.
- * @return bool
- */
- function isRelayServer()
- {
- return $this->execute(ucfirst(__FUNCTION__));
- }
- /**
- * Set a new password for the server.
- * @param string $serverPassword
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function setServerPassword($serverPassword, $multicall = false)
- {
- if (!is_string($serverPassword))
- {
- throw new DedicatedApiInvalidArgumentExcepption('serverPassword = '.print_r($serverPassword,true));
- }
- return $this->execute(ucfirst(__FUNCTION__), array($serverPassword), $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
- */
- function getServerPassword()
- {
- return $this->execute(ucfirst(__FUNCTION__));
- }
- /**
- * Set a new password for the spectator mode.
- * @param string $serverPassword
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- function setServerPasswordForSpectator($serverPassword, $multicall = false)
- {
- if (!is_string($serverPassword))
- {
- throw new DedicatedApiInvalidArgumentExcepption('serverPassword = '.print_r($serverPassword,true));
- }
- return $this->execute(ucfirst(__FUNCTION__), array($serverPassword), $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
- */
- function getServerPasswordForSpectator()
- {
- return $this->execute(ucfirst(__FUNCTION__));
- }
- /**
- * Set a new maximum number of players.
- * Requires a map restart to be taken into account.
- * @param int $maxPlayers
- * @param bool $multicall
- * @return bool
- * @throws InvalidArgumentException
- */
- 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 …
Large files files are truncated, but you can click here to view the full file