PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/ManiaLive/DedicatedApi/Connection.php

http://manialive.googlecode.com/
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

  1. <?php
  2. /**
  3. * ManiaLive - TrackMania dedicated server manager in PHP
  4. *
  5. * @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
  6. * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
  7. * @version $Revision: 352 $:
  8. * @author $Author: melot.philippe $:
  9. * @date $Date: 2012-03-23 11:37:38 +0100 (Fri, 23 Mar 2012) $:
  10. */
  11. namespace ManiaLive\DedicatedApi;
  12. use ManiaLive\DedicatedApi\Xmlrpc\Request;
  13. use ManiaLive\DedicatedApi\Structures\Music;
  14. use ManiaLive\DedicatedApi\Structures\Player;
  15. use ManiaLive\DedicatedApi\Structures\Status;
  16. use ManiaLive\DedicatedApi\Structures\Vote;
  17. use ManiaLive\DedicatedApi\Structures\ServerOptions;
  18. use ManiaLive\Event\Dispatcher;
  19. use ManiaLive\Utilities\Console;
  20. /**
  21. * Dedicated Server Connection Instance
  22. * Methods returns nothing if $multicall = true
  23. */
  24. class Connection extends \ManiaLib\Utils\Singleton
  25. {
  26. /**
  27. * XML-RPC client instance
  28. * @var
  29. */
  30. protected $xmlrpcClient;
  31. /**
  32. * @return Connection
  33. */
  34. static function getInstance()
  35. {
  36. return parent::getInstance();
  37. }
  38. /**
  39. * Constructor of the class
  40. * @param int $port represents the communication port
  41. * @param string $hostname represents the ip to reach
  42. * @param string $superAdminPassword represents the SuperAdmin password
  43. * @param string $adminPassword represents the Admin password
  44. * @param string $userPassword represents the User password
  45. */
  46. protected function __construct()
  47. {
  48. $config = Config::getInstance();
  49. $this->xmlrpcClient = new Xmlrpc\ClientMulticall($config->host, $config->port);
  50. Console::printlnFormatted('XML-RPC connection established');
  51. $this->authenticate($config->user, $config->password);
  52. $this->setApiVersion('2011-10-06');
  53. Console::printlnFormatted('Successfully authentified with XML-RPC server');
  54. }
  55. /**
  56. * Close the current socket connexion
  57. * Never call this method, use instead DedicatedApiFactory::deleteConnection($hostname,$port)
  58. */
  59. function terminate()
  60. {
  61. $this->xmlrpcClient->terminate();
  62. }
  63. /**
  64. *
  65. * Read a Call back on the DedicatedServer and call the method if handle
  66. * @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
  67. */
  68. function executeCallbacks()
  69. {
  70. $this->xmlrpcClient->readCallbacks();
  71. $calls = $this->xmlrpcClient->getCallbackResponses();
  72. if (!empty($calls))
  73. {
  74. foreach ($calls as $call)
  75. {
  76. $method = preg_replace('/^[[:alpha:]]+\./', '', $call[0]); // remove trailing "Whatever."
  77. $params = (array) $call[1];
  78. Dispatcher::dispatch(new Callback\Event($method, $params));
  79. }
  80. }
  81. }
  82. /**
  83. * Execute the calls in queue and return the result
  84. * TODO Prendre en compte les retours du mutliQuery (via un handler ?)
  85. */
  86. function executeMulticall()
  87. {
  88. $this->xmlrpcClient->multiqueryIgnoreResult();
  89. }
  90. /**
  91. * Add a call in queur. It will be executed by the next Call from the user to executemulticall
  92. * @param string $methodName
  93. * @param string $authLevel
  94. * @param array $params
  95. */
  96. protected function execute($methodName, $params = array(), $multicall=false)
  97. {
  98. if ($multicall)
  99. {
  100. $this->xmlrpcClient->addCall($methodName, $params);
  101. }
  102. else
  103. {
  104. array_unshift($params, $methodName);
  105. call_user_func_array(array($this->xmlrpcClient, 'query'), $params);
  106. return $this->xmlrpcClient->getResponse();
  107. }
  108. }
  109. /**
  110. * Given the name of a method, return an array of legal signatures.
  111. * Each signature is an array of strings.
  112. * The first item of each signature is the return type, and any others items are parameter types.
  113. * @param string $methodName
  114. * @return array
  115. */
  116. function methodSignature($methodName)
  117. {
  118. return $this->execute('system.methodSignature', array( $methodName ));
  119. }
  120. /**
  121. * Change the password for the specified login/user.
  122. * @param string $username
  123. * @param string $password
  124. * @return bool
  125. * @throws InvalidArgumentException
  126. */
  127. function changeAuthPassword($username, $password)
  128. {
  129. if (!is_string($password))
  130. {
  131. throw new InvalidArgumentException('password = '.print_r($password,true));
  132. }
  133. if ($username != 'User' && $username != 'Admin' && $username != 'SuperAdmin')
  134. {
  135. throw new InvalidArgumentException('username = '.print_r($username,true));
  136. }
  137. return $this->execute(ucfirst(__FUNCTION__), array($username, $password), false);
  138. }
  139. /**
  140. * Allow the GameServer to call you back.
  141. * @param bool $enable
  142. * @param bool $multicall
  143. * @return bool
  144. */
  145. function enableCallbacks($enable, $multicall = false)
  146. {
  147. return $this->execute(ucfirst(__FUNCTION__), array((bool) $enable), $multicall);
  148. }
  149. /**
  150. * Define the wanted api.
  151. * @param string $version
  152. * @param bool $multicall
  153. * @return bool
  154. */
  155. protected function setApiVersion($version, $multicall = false)
  156. {
  157. return $this->execute(ucfirst(__FUNCTION__), array((string) $version), $multicall);
  158. }
  159. /**
  160. * Returns a struct with the Name, Version, Build and ApiVersion of the application remotely controled.
  161. * @return ManiaLive\DedicatedApi\Structures\Version
  162. * @throws InvalidArgumentException
  163. */
  164. function getVersion()
  165. {
  166. $result = $this->execute(ucfirst(__FUNCTION__));
  167. return Structures\Version::fromArray($result);
  168. }
  169. function authenticate($username, $password)
  170. {
  171. return $this->execute(ucfirst(__FUNCTION__), array($username, $password), false);
  172. }
  173. /**
  174. * Call a vote for a cmd. The command is a XML string corresponding to an XmlRpc request.
  175. * You can additionally specifiy specific parameters for this vote: a ratio, a time out
  176. * and who is voting. Special timeout values: a timeout of '0' means default, '1' means
  177. * indefinite; a ratio of '-1' means default; Voters values: '0' means only active players,
  178. * '1' means any player, '2' is for everybody, pure spectators included.
  179. * @param ManiaLive\DedicatedApi\Structures\Vote $vote
  180. * @param double $ratio -1 means default, else ration should be between 0 and 1
  181. * @param int $timeout time to vote in millisecondes, '0' means default
  182. * @param int $voters Voters values: '0' means only active players, '1' means any player, '2' is for everybody, pure spectators included
  183. * @param bool $multicall
  184. * @throws InvalidArgumentException
  185. */
  186. function callVote(Vote $vote, $ratio = 0.5, $timeout = 0, $voters = 1, $multicall = false)
  187. {
  188. if (is_null($vote))
  189. {
  190. throw new InvalidArgumentException('vote must be set');
  191. }
  192. if (!is_double($ratio))
  193. {
  194. throw new InvalidArgumentException('ratio = '.print_r($ratio,true));
  195. }
  196. if (!is_int($timeout))
  197. {
  198. throw new InvalidArgumentException('timeout = '.print_r($timeout,true));
  199. }
  200. if (!is_int($voters))
  201. {
  202. throw new InvalidArgumentException('voters = '.print_r($voters,true));
  203. }
  204. if (!is_array($vote->cmdParam))
  205. {
  206. throw new InvalidArgumentException('vote->cmdParam = '.print_r($vote->cmdParam,true));
  207. }
  208. $tmpCmd = new Xmlrpc\Request($vote->cmdName, $vote->cmdParam);
  209. return $this->execute(ucfirst(__FUNCTION__).'Ex', array($tmpCmd->getXml(), $ratio, $timeout, $voters), $multicall);
  210. }
  211. /**
  212. * Call a vote to kick a player.
  213. * You can additionally specifiy specific parameters for this vote: a ratio, a time out
  214. * and who is voting. Special timeout values: a timeout of '0' means default, '1' means
  215. * indefinite; a ratio of '-1' means default; Voters values: '0' means only active players,
  216. * '1' means any player, '2' is for everybody, pure spectators included.
  217. * @param Player|string $player Player or string
  218. * @param double $ratio -1 means default, else ration should be between 0 and 1
  219. * @param int $timeout time to vote in millisecondes, '0' means default
  220. * @param int $voters Voters values: '0' means only active players, '1' means any player, '2' is for everybody, pure spectators included
  221. * @param bool $multicall
  222. * @throws InvalidArgumentException
  223. */
  224. function callVoteKick($player, $ratio = 0.5, $timeout = 0, $voters = 1, $multicall = false)
  225. {
  226. if (! ($login = $this->getLogin($player)))
  227. {
  228. throw new InvalidArgumentException('player must be set');
  229. }
  230. if (!is_double($ratio))
  231. {
  232. throw new InvalidArgumentException('ratio = '.print_r($ratio,true));
  233. }
  234. if (!is_int($timeout))
  235. {
  236. throw new InvalidArgumentException('timeout = '.print_r($timeout,true));
  237. }
  238. if (!is_int($voters))
  239. {
  240. throw new InvalidArgumentException('voters = '.print_r($voters,true));
  241. }
  242. $tmpCmd = new Xmlrpc\Request('Kick', array($login));
  243. return $this->execute('CallVoteEx', array($tmpCmd->getXml(), $ratio, $timeout, $voters), $multicall);
  244. }
  245. /**
  246. * Call a vote to ban a player.
  247. * You can additionally specifiy specific parameters for this vote: a ratio, a time out
  248. * and who is voting. Special timeout values: a timeout of '0' means default, '1' means
  249. * indefinite; a ratio of '-1' means default; Voters values: '0' means only active players,
  250. * '1' means any player, '2' is for everybody, pure spectators included.
  251. * @param Player|string $player
  252. * @param double $ratio -1 means default, else ration should be between 0 and 1
  253. * @param int $timeout time to vote in millisecondes, '0' means default
  254. * @param int $voters Voters values: '0' means only active players, '1' means any player, '2' is for everybody, pure spectators included
  255. * @param bool $multicall
  256. * @throws InvalidArgumentException
  257. */
  258. function callVoteBan(Player $player, $ratio = 0.6, $timeout = 0, $voters = 1, $multicall = false)
  259. {
  260. if (! ($login = $this->getLogin($player)))
  261. {
  262. throw new InvalidArgumentException('player must be set');
  263. }
  264. if (!is_double($ratio))
  265. {
  266. throw new InvalidArgumentException('ratio = '.print_r($ratio,true));
  267. }
  268. if (!is_int($timeout))
  269. {
  270. throw new InvalidArgumentException('timeout = '.print_r($timeout,true));
  271. }
  272. if (!is_int($voters))
  273. {
  274. throw new InvalidArgumentException('voters = '.print_r($voters,true));
  275. }
  276. $tmpCmd = new Xmlrpc\Request('Ban', array($login));
  277. return $this->execute('CallVoteEx', array($tmpCmd->getXml(), $ratio, $timeout, $voters), $multicall);
  278. }
  279. /**
  280. * Call a vote to restart the current Map.
  281. * You can additionally specifiy specific parameters for this vote: a ratio, a time out
  282. * and who is voting. Special timeout values: a timeout of '0' means default, '1' means
  283. * indefinite; a ratio of '-1' means default; Voters values: '0' means only active players,
  284. * '1' means any player, '2' is for everybody, pure spectators included.
  285. * @param double $ratio -1 means default, else ration should be between 0 and 1
  286. * @param int $timeout time to vote in millisecondes, '0' means default
  287. * @param int $voters Voters values: '0' means only active players, '1' means any player, '2' is for everybody, pure spectators included
  288. * @param bool $multicall
  289. * @throws InvalidArgumentException
  290. */
  291. function callVoteRestartMap($ratio = 0.5, $timeout = 0, $voters = 1, $multicall = false)
  292. {
  293. if (!is_double($ratio))
  294. {
  295. throw new InvalidArgumentException('ratio = '.print_r($ratio,true));
  296. }
  297. if (!is_int($timeout))
  298. {
  299. throw new InvalidArgumentException('timeout = '.print_r($timeout,true));
  300. }
  301. if (!is_int($voters))
  302. {
  303. throw new InvalidArgumentException('voters = '.print_r($voters,true));
  304. }
  305. $tmpCmd = new Xmlrpc\Request('MapRestart', array());
  306. return $this->execute('CallVoteEx', array($tmpCmd->getXml(), $ratio, $timeout, $voters), $multicall);
  307. }
  308. /**
  309. * Call a vote to go to the next Map.
  310. * You can additionally specifiy specific parameters for this vote: a ratio, a time out
  311. * and who is voting. Special timeout values: a timeout of '0' means default, '1' means
  312. * indefinite; a ratio of '-1' means default; Voters values: '0' means only active players,
  313. * '1' means any player, '2' is for everybody, pure spectators included.
  314. * @param double $ratio -1 means default, else ration should be between 0 and 1
  315. * @param int $timeout time to vote in millisecondes, '0' means default
  316. * @param int $voters Voters values: '0' means only active players, '1' means any player, '2' is for everybody, pure spectators included
  317. * @param bool $multicall
  318. * @throws InvalidArgumentException
  319. */
  320. function callVoteNextMap($ratio = 0.5, $timeout = 0, $voters = 1, $multicall = false)
  321. {
  322. if (!is_double($ratio))
  323. {
  324. throw new InvalidArgumentException('ratio = '.print_r($ratio,true));
  325. }
  326. if (!is_int($timeout))
  327. {
  328. throw new InvalidArgumentException('timeout = '.print_r($timeout,true));
  329. }
  330. if (!is_int($voters))
  331. {
  332. throw new InvalidArgumentException('voters = '.print_r($voters,true));
  333. }
  334. $tmpCmd = new Xmlrpc\Request('NextMap', array());
  335. return $this->execute('CallVoteEx', array($tmpCmd->getXml(), $ratio, $timeout, $voters), $multicall);
  336. }
  337. /**
  338. * Used internaly by game.
  339. * @param bool $multicall
  340. * @return bool
  341. */
  342. protected function internalCallVote($multicall = false)
  343. {
  344. return $this->execute(ucfirst(__FUNCTION__), array(), $multicall);
  345. }
  346. /**
  347. * Cancel the current vote.
  348. * @param bool $multicall
  349. * @return bool
  350. */
  351. function cancelVote($multicall = false)
  352. {
  353. return $this->execute(ucfirst(__FUNCTION__), array(), $multicall);
  354. }
  355. /**
  356. * Returns the vote currently in progress.
  357. * The returned structure is { CallerLogin, CmdName, CmdParam }.
  358. * @return ManiaLive\DedicatedApi\Structures\Vote
  359. */
  360. function getCurrentCallVote()
  361. {
  362. return Vote::fromArray($this->execute(ucfirst(__FUNCTION__)));
  363. }
  364. /**
  365. * Set a new timeout for waiting for votes. A zero value disables callvote.
  366. * Requires a map restart to be taken into account
  367. * @param int $timeout time to vote in millisecondes, '0' disables callvote
  368. * @param bool $multicall
  369. * @return bool
  370. * @throws InvalidArgumentException
  371. */
  372. function setCallVoteTimeOut($timeout, $multicall = false)
  373. {
  374. if (!is_int($timeout))
  375. {
  376. throw new InvalidArgumentException('timeout = '.print_r($timeout, true));
  377. }
  378. return $this->execute(ucfirst(__FUNCTION__), array($timeout), $multicall);
  379. }
  380. /**
  381. * Get the current and next timeout for waiting for votes.
  382. * The struct returned contains two fields 'CurrentValue' and 'NextValue'.
  383. * @return array
  384. */
  385. function getCallVoteTimeOut()
  386. {
  387. return $this->execute(ucfirst(__FUNCTION__));
  388. }
  389. /**
  390. * Set a new default ratio for passing a vote.
  391. * Must lie between 0 and 1.
  392. * @param double $ratio
  393. * @param bool $multicall
  394. * @return bool
  395. * @throws InvalidArgumentException
  396. */
  397. function setCallVoteRatio($ratio, $multicall = false)
  398. {
  399. if (!is_double($ratio) && ($ratio < 0 || $ratio > 1))
  400. {
  401. throw new InvalidArgumentException('ratio = '.print_r($ratio, true));
  402. }
  403. return $this->execute(ucfirst(__FUNCTION__), array($ratio), $multicall);
  404. }
  405. /**
  406. * Get the current default ratio for passing a vote.
  407. * This value lies between 0 and 1.
  408. * @return double
  409. */
  410. function getCallVoteRatio()
  411. {
  412. return $this->execute(ucfirst(__FUNCTION__));
  413. }
  414. /**
  415. * Set new ratios for passing specific votes.
  416. * The parameter is an array of struct
  417. * {string votecommand, double ratio}, ratio is in [0,1] or -1 for vote disabled.
  418. * @param array $ratios
  419. * @param bool $multicall
  420. * @return bool
  421. * @throws InvalidArgumentException
  422. */
  423. function setCallVoteRatios(array $ratios, $multicall = false)
  424. {
  425. if (!is_array($ratios))
  426. {
  427. throw new InvalidArgumentException('ratio = '.print_r($ratio, true));
  428. }
  429. for($i = 0; $i < count($ratios); $i++)
  430. {
  431. if (!is_array($ratios[$i]) && !array_key_exists('Command', $ratios[$i]) && !array_key_exists('Ratio', $ratios[$i]))
  432. {
  433. throw new InvalidArgumentException('ratios['.$i.'] = '.print_r($ratio, true));
  434. }
  435. if (!is_string($ratios[$i]['Command']))
  436. {
  437. throw new InvalidArgumentException('ratios['.$i.'][Command] = '.print_r($ratios[$i][0],true));
  438. }
  439. if (!is_double($ratios[$i]['Ratio']) && ($ratios[$i]['Ratio'] != -1 && ($ratios[$i]['Ratio'] < 0 || $ratios[$i]['Ratio'] > 1)))
  440. {
  441. throw new InvalidArgumentException('ratios['.$i.'][Ratio] = '.print_r($ratios[$i]['Ratio'],true));
  442. }
  443. }
  444. return $this->execute(ucfirst(__FUNCTION__), array($ratios), $multicall);
  445. }
  446. /**
  447. * Get the current ratios for passing votes.
  448. * @return array
  449. */
  450. function getCallVoteRatios()
  451. {
  452. return $this->execute(ucfirst(__FUNCTION__));
  453. }
  454. /**
  455. * Send a localised text message to specied clients.
  456. * The parameter is an array of structures {Lang='??', Text='...'}.
  457. * If no matching language is found, the last text in the array is used.
  458. * @param array $messages
  459. * @param Player|string|array[Player|string] $receiver Player(s) who will receive the message, put null to send the message to everyone
  460. * @param bool $multicall
  461. * @return bool
  462. * @throws InvalidArgumentException
  463. */
  464. function chatSendServerMessageToLanguage(array $messages, $receiver = null, $multicall = false)
  465. {
  466. if (!is_array($messages))
  467. {
  468. throw new InvalidArgumentException('messages = '.print_r($messages,true));
  469. }
  470. if (is_null($receiver))
  471. {
  472. $receiverString = '';
  473. }
  474. else if (! ($receiverString = $this->getLogins($receiver)))
  475. {
  476. throw new InvalidArgumentException('receiver = '.print_r($receiver,true));
  477. }
  478. return $this->execute(ucfirst(__FUNCTION__), array($messages, $receiverString), $multicall);
  479. }
  480. /**
  481. * Send a text message without the server login to everyone if players is null.
  482. * Players can be a Player object or an array of Player
  483. * @param string $message
  484. * @param Player|string|array[Player|string] $receiver Player(s) who will receive the message, put null to send the message to everyone
  485. * @param bool $multicall
  486. * @return bool
  487. * @throws InvalidArgumentException
  488. */
  489. function chatSendServerMessage($message, $receiver = null, $multicall = false)
  490. {
  491. if (!is_string($message))
  492. {
  493. throw new InvalidArgumentException('message = '.print_r($message,true));
  494. }
  495. $params = array($message);
  496. $method = 'ChatSendServerMessage';
  497. if (!is_null($receiver))
  498. {
  499. if (! ($logins = $this->getLogins($receiver)))
  500. {
  501. throw new InvalidArgumentException('receiver = '.print_r($receiver,true));
  502. }
  503. $params[] = $logins;
  504. $method .= 'ToLogin';
  505. }
  506. return $this->execute($method, $params, $multicall);
  507. }
  508. /**
  509. * Send a localised text message to selected clients.
  510. * The parameter is an array of structures {Lang='??', Text='...'}.
  511. * If no matching language is found, the last text in the array is used.
  512. * @param array $messages
  513. * @param Player|string|array[Player|string] $receiver Player(s) who will receive the message, put null to send the message to everyone
  514. * @param bool $multicall
  515. * @return bool
  516. * @throws InvalidArgumentException
  517. */
  518. function chatSendToLanguage(array $messages, $receiver = null, $multicall = false)
  519. {
  520. if (!is_array($messages))
  521. throw new InvalidArgumentException('messages = '.print_r($messages,true));
  522. if ($receiver == null)
  523. {
  524. $receiverString = '';
  525. }
  526. else if (! ($receiverString = $this->getLogins($receiver)))
  527. {
  528. throw new InvalidArgumentException('receiver = '.print_r($receiver,true));
  529. }
  530. return $this->execute(ucfirst(__FUNCTION__), array($messages, $receiverString), $multicall);
  531. }
  532. /**
  533. * Send a text message to every Player or the a specified player(s).
  534. * If Player is null, the message will be delivered to every Player
  535. * @param string $message
  536. * @param Player|string|array[Player|string] $receiver Player(s) who will receive the message, put null to send the message to everyone
  537. * @param bool $multicall
  538. * @return bool
  539. * @throws InvalidArgumentException
  540. */
  541. function chatSend($message, $receiver, $multicall = false)
  542. {
  543. if (!is_string($message))
  544. throw new InvalidArgumentException('message = '.print_r($message,true));
  545. $params = array($message);
  546. $method = 'ChatSend';
  547. if (!is_null($receiver))
  548. {
  549. if (! ($logins = $this->getLogins($receiver)))
  550. {
  551. throw new InvalidArgumentException('players = '.print_r($receiver,true));
  552. }
  553. $params[] = $logins;
  554. $method .= 'ToLogin';
  555. }
  556. return $this->execute($method, $params, $multicall);
  557. }
  558. /**
  559. * Returns the last chat lines. Maximum of 40 lines.
  560. * @return array
  561. */
  562. function getChatLines()
  563. {
  564. return $this->execute(ucfirst(__FUNCTION__));
  565. }
  566. /**
  567. * The chat messages are no longer dispatched to the players, they only go to the rpc callback
  568. * and the controller has to manually forward them. The second (optional) parameter allows all
  569. * messages from the server to be automatically forwarded.
  570. * @param bool $enable
  571. * @param bool $serverAutomaticForward
  572. * @param bool $multicall
  573. * @return bool
  574. * @throws InvalidArgumentException
  575. */
  576. function chatEnableManualRouting($enable, $serverAutomaticForward = false, $multicall = false)
  577. {
  578. if (!is_bool($enable))
  579. {
  580. throw new InvalidArgumentException('enable = '.print_r($enable,true));
  581. }
  582. if (!is_bool($serverAutomaticForward))
  583. {
  584. throw new InvalidArgumentException('serverAutomaticForward = '.print_r($serverAutomaticForward,true));
  585. }
  586. return $this->execute(ucfirst(__FUNCTION__), array($enable,$serverAutomaticForward), $multicall);
  587. }
  588. /**
  589. * (Text, SenderLogin, DestLogin) Send a text message to the specified DestLogin (or everybody if empty)
  590. * on behalf of SenderLogin. DestLogin can be a single login or a list of comma-separated logins.
  591. * Only available if manual routing is enabled.
  592. * @param string $message
  593. * @param Player|string $sender
  594. * @param Player|string $receiver
  595. * @param bool $multicall
  596. * @return bool
  597. * @throws InvalidArgumentException
  598. */
  599. function chatForwardToLogin($message, $sender, $receiver = null, $multicall = false)
  600. {
  601. if (!is_string($message))
  602. {
  603. throw new InvalidArgumentException('message = '.print_r($message,true));
  604. }
  605. if (! ($senderLogin = $this->getLogin($sender)))
  606. {
  607. throw new InvalidArgumentException('sender must be set');
  608. }
  609. $receiverLogin = $this->getLogin($receiver) ?: '';
  610. return $this->execute(ucfirst(__FUNCTION__), array($message,$senderLogin,$receiverLogin), $multicall);
  611. }
  612. /**
  613. * Display a notice on the client with the specified UId.
  614. * The parameters are :
  615. * the Uid of the client to whom the notice is sent,
  616. * the text message to display,
  617. * the UId of the avatar to display next to it (or '255' for no avatar),
  618. * an optional 'max duration' in seconds (default: 3).
  619. * @param string $message
  620. * @param Player|string|array[Player|string] $receiver
  621. * @param Player|string $player
  622. * @param int $variant 0, 1 or 2
  623. * @param bool $multicall
  624. * @return bool
  625. * @throws InvalidArgumentException
  626. */
  627. function sendNotice($receiver, $message, $player = null, $variant = 0, $multicall = false)
  628. {
  629. if (!is_string($message))
  630. {
  631. throw new InvalidArgumentException('message = '.print_r($message,true));
  632. }
  633. $params = array();
  634. $method = 'SendNotice';
  635. if (!is_null($receiver))
  636. {
  637. if (! ($login = $this->getLogins($receiver)))
  638. throw new InvalidArgumentException('receiver = '.print_r($receiver,true));
  639. else
  640. $params[] = $login;
  641. $method .= 'ToLogin';
  642. }
  643. $params[] = $message;
  644. $params[] = $this->getLogin($player) ?: '';
  645. $params[] = $variant;
  646. return $this->execute($method, $params, $multicall);
  647. }
  648. /**
  649. * Display a manialink page on the client of the specified Player(s).
  650. * The first parameter is the login of the player,
  651. * the other are identical to 'SendDisplayManialinkPage'.
  652. * The players can be an object of player Type or an array of Player object
  653. * @param null|Player|string|array[Player|string] $playerLogin
  654. * @param string $manialink
  655. * @param int $timeout
  656. * @param bool $hideOnClick
  657. * @param bool $multicall
  658. * @return bool
  659. * @throws InvalidArgumentException
  660. */
  661. function sendDisplayManialinkPage($players, $manialink, $timeout, $hideOnClick, $multicall = false)
  662. {
  663. $params = array();
  664. $method = 'SendDisplayManialinkPage';
  665. if (!is_null($players))
  666. {
  667. if (! ($login = $this->getLogins($players)))
  668. throw new InvalidArgumentException('players = '.print_r($players,true));
  669. else
  670. $params[] = $login;
  671. $method .= 'ToLogin';
  672. }
  673. if (!is_string($manialink))
  674. {
  675. throw new InvalidArgumentException('manialink = '.print_r($manialink,true));
  676. }
  677. if (!is_int($timeout))
  678. {
  679. throw new InvalidArgumentException('timeout = '.print_r($timeout,true));
  680. }
  681. if (!is_bool($hideOnClick))
  682. {
  683. throw new InvalidArgumentException('hideOnClick = '.print_r($hideOnClick,true));
  684. }
  685. $params[] = $manialink;
  686. $params[] = $timeout;
  687. $params[] = $hideOnClick;
  688. return $this->execute($method, $params, $multicall);
  689. }
  690. /**
  691. * Hide the displayed manialink page on the client with the specified login.
  692. * Login can be a single login or a list of comma-separated logins.
  693. * @param null|Player|string|array[Player|string] $players
  694. * @param bool $multicall
  695. * @return bool
  696. * @throws InvalidArgumentException
  697. */
  698. function sendHideManialinkPage($players = null, $multicall = false)
  699. {
  700. $params = array();
  701. $method = 'SendHideManialinkPage';
  702. if (!is_null($players))
  703. {
  704. if (! ($login = $this->getLogins($players)))
  705. throw new InvalidArgumentException('players = '.print_r($players,true));
  706. else
  707. $params[] = $login;
  708. $method .= 'ToLogin';
  709. }
  710. return $this->execute($method, $params, $multicall);
  711. }
  712. /**
  713. * Returns the latest results from the current manialink page,
  714. * as an array of structs {string Login, int PlayerId, int Result}
  715. * Result==0 -> no answer, Result>0.... -> answer from the player.
  716. * @return array
  717. */
  718. function getManialinkPageAnswers()
  719. {
  720. return $this->execute(ucfirst(__FUNCTION__));
  721. }
  722. /**
  723. * Kick the player with an optional message.
  724. * @param Player|string $playerLogin
  725. * @param string $message
  726. * @param bool $multicall
  727. * @return bool
  728. * @throws InvalidArgumentException
  729. */
  730. function kick($player, $message = '', $multicall = false)
  731. {
  732. if (! ($login = $this->getLogin($player)))
  733. {
  734. throw new InvalidArgumentException('player must be set');
  735. }
  736. if (!is_string($message))
  737. {
  738. throw new InvalidArgumentException('message = '.print_r($message,true));
  739. }
  740. return $this->execute('Kick', array($login, $message), $multicall);
  741. }
  742. /**
  743. * Ban the player with an optional message.
  744. * @param Player|string $player
  745. * @param string $message
  746. * @param bool $multicall
  747. * @return bool
  748. * @throws InvalidArgumentException
  749. */
  750. function ban(Player $player, $message = '', $multicall = false)
  751. {
  752. if (! ($login = $this->getLogin($player)))
  753. {
  754. throw new InvalidArgumentException('player must be set');
  755. }
  756. if (!is_string($message))
  757. {
  758. throw new InvalidArgumentException('message = '.print_r($message,true));
  759. }
  760. return $this->execute('Ban', array($login, $message), $multicall);
  761. }
  762. /**
  763. * Ban the player with a message.
  764. * Add it to the black list, and optionally save the new list.
  765. * @param Player|string $player
  766. * @param string $message
  767. * @param bool $saveList
  768. * @param bool $multicall
  769. * @return bool
  770. * @throws InvalidArgumentException
  771. */
  772. function banAndBlackList($player, $message, $saveList = false, $multicall = false)
  773. {
  774. if (! ($login = $this->getLogin($player)))
  775. {
  776. throw new InvalidArgumentException('player must be set');
  777. }
  778. if (!is_string($message) || !$message)
  779. {
  780. throw new InvalidArgumentException('message = '.print_r($message, true));
  781. }
  782. if (!is_bool($saveList))
  783. {
  784. throw new InvalidArgumentException('saveList = '.print_r($saveList,true));
  785. }
  786. return $this->execute(ucfirst(__FUNCTION__), array($login, $message, $saveList), $multicall);
  787. }
  788. /**
  789. * Unban the player
  790. * @param Player|string $player
  791. * @param bool $multicall
  792. * @return bool
  793. * @throws InvalidArgumentException
  794. */
  795. function unBan($player, $multicall = false)
  796. {
  797. if (! ($login = $this->getLogin($player)))
  798. {
  799. throw new InvalidArgumentException('player must be set');
  800. }
  801. return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
  802. }
  803. /**
  804. * Clean the ban list of the server.
  805. * @param bool $multicall
  806. * @return bool
  807. */
  808. function cleanBanList($multicall = false)
  809. {
  810. return $this->execute(ucfirst(__FUNCTION__), array(), $multicall);
  811. }
  812. /**
  813. * Returns the list of banned players. This method takes two parameters.
  814. * The first parameter specifies the maximum number of infos to be returned,
  815. * the second one the starting index in the list. The list is an array of structures.
  816. * Each structure contains the following fields : Login, ClientName and IPAddress.
  817. * @param int $length specifies the maximum number of infos to be returned
  818. * @param int $offset specifies the starting index in the list
  819. * @return array[DedicatedApi\Structures\Player] The list is an array of object. Each object is an instance of DedicatedApi\Structures\Player
  820. * @throws InvalidArgumentException
  821. */
  822. function getBanList($length, $offset)
  823. {
  824. if (!is_int($length))
  825. throw new InvalidArgumentException('length = '.print_r($length,true));
  826. if (!is_int($offset))
  827. throw new InvalidArgumentException('offset = '.print_r($offset,true));
  828. $result = $this->execute(ucfirst(__FUNCTION__), array($length, $offset));
  829. return Structures\Player::fromArrayOfArray($result);
  830. }
  831. /**
  832. * Blacklist the player
  833. * @param Player|string $player
  834. * @param bool $multicall
  835. * @return bool
  836. * @throws InvalidArgumentException
  837. */
  838. function blackList($player, $multicall = false)
  839. {
  840. if (! ($login = $this->getLogin($player)))
  841. {
  842. throw new InvalidArgumentException('player must be set');
  843. }
  844. return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
  845. }
  846. /**
  847. * UnBlackList the player
  848. * @param Player|string $player
  849. * @param bool $multicall
  850. * @return bool
  851. * @throws InvalidArgumentException
  852. */
  853. function unBlackList($player, $multicall = false)
  854. {
  855. if (! ($login = $this->getLogin($player)))
  856. {
  857. throw new InvalidArgumentException('player must be set');
  858. }
  859. return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
  860. }
  861. /**
  862. * Clean the blacklist of the server.
  863. * @param bool $multicall
  864. * @return bool
  865. */
  866. function cleanBlackList($multicall = false)
  867. {
  868. return $this->execute(ucfirst(__FUNCTION__), array(), $multicall);
  869. }
  870. /**
  871. * Returns the list of blacklisted players.
  872. * This method takes two parameters.
  873. * The first parameter specifies the maximum number of infos to be returned,
  874. * the second one the starting index in the list. The list is an array of structures.
  875. * Each structure contains the following fields : Login.
  876. * @param int $length specifies the maximum number of infos to be returned
  877. * @param int $offset specifies the starting index in the list
  878. * @return array[DedicatedApi\Structures\Player] The list is an array of structures. Each structure contains the following fields : Login.
  879. * @throws InvalidArgumentException
  880. */
  881. function getBlackList($length, $offset)
  882. {
  883. if (!is_int($length))
  884. throw new InvalidArgumentException('length = '.print_r($length,true));
  885. if (!is_int($offset))
  886. throw new InvalidArgumentException('offset = '.print_r($offset,true));
  887. $result = $this->execute(ucfirst(__FUNCTION__), array($length, $offset));
  888. return Structures\Player::fromArrayOfArray($result);
  889. }
  890. /**
  891. * Load the black list file with the specified file name.
  892. * @param string $filename blackList file name
  893. * @param bool $multicall
  894. * @return bool
  895. * @throws InvalidArgumentException
  896. */
  897. function loadBlackList($filename, $multicall = false)
  898. {
  899. if (!is_string($filename))
  900. throw new InvalidArgumentException('filename = '.print_r($filename,true));
  901. return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall);
  902. }
  903. /**
  904. * Save the black list in the file with specified file name.
  905. * @param string $filename blackList filename
  906. * @param bool $multicall
  907. * @return bool
  908. * @throws InvalidArgumentException
  909. */
  910. function saveBlackList($filename, $multicall = false)
  911. {
  912. if (!is_string($filename))
  913. throw new InvalidArgumentException('filename = '.print_r($filename,true));
  914. return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall);
  915. }
  916. /**
  917. * Add the player to the guest list.
  918. * @param Player|string $player
  919. * @param bool $multicall
  920. * @return bool
  921. * @throws InvalidArgumentException
  922. */
  923. function addGuest($player, $multicall = false)
  924. {
  925. if (! ($login = $this->getLogin($player)))
  926. {
  927. throw new InvalidArgumentException('player must be set');
  928. }
  929. return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
  930. }
  931. /**
  932. * Remove the player from the guest list.
  933. * @param Player|string $player
  934. * @param bool $multicall
  935. * @return bool
  936. * @throws InvalidArgumentException
  937. */
  938. function removeGuest($player, $multicall = false)
  939. {
  940. if (! ($login = $this->getLogin($player)))
  941. {
  942. throw new InvalidArgumentException('player must be set');
  943. }
  944. return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
  945. }
  946. /**
  947. * Clean the guest list of the server.
  948. * @param bool $multicall
  949. * @return bool
  950. */
  951. function cleanGuestList($multicall = false)
  952. {
  953. return $this->execute(ucfirst(__FUNCTION__), array(), $multicall);
  954. }
  955. /**
  956. * Returns the list of players on the guest list.
  957. * This method takes two parameters.
  958. * The first parameter specifies the maximum number of infos to be returned,
  959. * the second one the starting index in the list. The list is an array of structures.
  960. * Each structure contains the following fields : Login.
  961. * @param int $length specifies the maximum number of infos to be returned
  962. * @param int $offset specifies the starting index in the list
  963. * @return array[DedicatedApi\Structures\Player] The list is an array of structures. Each structure contains the following fields : Login.
  964. * @throws InvalidArgumentException
  965. */
  966. function getGuestList($length, $offset)
  967. {
  968. if (!is_int($length))
  969. {
  970. throw new InvalidArgumentException('length = '.print_r($length,true));
  971. }
  972. if (!is_int($offset))
  973. {
  974. throw new InvalidArgumentException('offset = '.print_r($offset,true));
  975. }
  976. $result = $this->execute(ucfirst(__FUNCTION__), array($length, $offset));
  977. return Structures\Player::fromArrayOfArray($result);
  978. }
  979. /**
  980. *
  981. * Load the guest list file with the specified file name.
  982. * @param string $filename blackList file name
  983. * @param bool $multicall
  984. * @return bool
  985. * @throws InvalidArgumentException
  986. */
  987. function loadGuestList($filename, $multicall = false)
  988. {
  989. if (!is_string($filename))
  990. {
  991. throw new InvalidArgumentException('filename = '.print_r($filename,true));
  992. }
  993. return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall);
  994. }
  995. /**
  996. * Save the guest list in the file with specified file name.
  997. * @param string $filename blackList file name
  998. * @param bool $multicall
  999. * @return bool
  1000. * @throws InvalidArgumentException
  1001. */
  1002. function saveGuestList($filename, $multicall = false)
  1003. {
  1004. if (!is_string($filename))
  1005. {
  1006. throw new InvalidArgumentException('filename = '.print_r($filename,true));
  1007. }
  1008. return $this->execute(ucfirst(__FUNCTION__), array($filename), $multicall);
  1009. }
  1010. /**
  1011. * Sets whether buddy notifications should be sent in the chat.
  1012. * login is the login of the player, or '' for global setting,
  1013. * enabled is the value.
  1014. * @param null|Player|string $player the player, or null for global setting
  1015. * @param bool $enable the value.
  1016. * @param bool $multicall
  1017. * @return bool
  1018. * @throws InvalidArgumentException
  1019. */
  1020. function setBuddyNotification(Player $player, $enable, $multicall = false)
  1021. {
  1022. if (!is_bool($enable))
  1023. {
  1024. throw new InvalidArgumentException('enable = '.print_r($enable,true));
  1025. }
  1026. $player = $this->getLogin($player) ?: '';
  1027. return $this->execute(ucfirst(__FUNCTION__), array($player, $enable), $multicall);
  1028. }
  1029. /**
  1030. * Gets whether buddy notifications are enabled for login, or '' to get the global setting.
  1031. * @param null|Player|string $player the player, or null for global setting
  1032. * @return bool
  1033. * @throws InvalidArgumentException
  1034. */
  1035. function getBuddyNotification($player)
  1036. {
  1037. $player = $this->getLogin($player) ?: '';
  1038. return $this->execute(ucfirst(__FUNCTION__), $params);
  1039. }
  1040. /**
  1041. * Write the data to the specified file. The filename is relative to the Tracks path
  1042. * @param string $filename The file to be written
  1043. * @param string $localFilename The file to be read to obtain the data
  1044. * @param bool $multicall
  1045. * @return bool
  1046. * @throws InvalidArgumentException
  1047. */
  1048. function writeFile($filename, $localFilename, $multicall = false)
  1049. {
  1050. if (!is_string($filename))
  1051. {
  1052. throw new InvalidArgumentException('filename = '.print_r($filename, true));
  1053. }
  1054. if (!file_exists($localFilename))
  1055. {
  1056. throw new InvalidArgumentException('localFilename = '.print_r($localFilename,true));
  1057. }
  1058. $inputData = file_get_contents($localFilename);
  1059. $data = new Xmlrpc\Base64($inputData);
  1060. if(strlen($data->getXml()) > 1024 * 1024 - 15)
  1061. {
  1062. throw new InvalidArgumentException('file is too big');
  1063. }
  1064. return $this->execute(ucfirst(__FUNCTION__), array($filename, $data), $multicall);
  1065. }
  1066. /**
  1067. * Write the data to the specified file. The filename is relative to the Tracks path
  1068. * @param string $filename The file to be written
  1069. * @param string $data the data to be written
  1070. * @param bool $multicall
  1071. * @return bool
  1072. * @throws InvalidArgumentException
  1073. */
  1074. function writeFileFromString($filename, $data, $multicall = false)
  1075. {
  1076. if (!is_string($filename))
  1077. {
  1078. throw new InvalidArgumentException('filename = '.print_r($filename, true));
  1079. }
  1080. $data = new Xmlrpc\Base64($data);
  1081. if(strlen($data->getXml()) > 1024 * 1024 - 15)
  1082. {
  1083. throw new InvalidArgumentException('data are too big');
  1084. }
  1085. return $this->execute('WriteFile', array($filename, $data), $multicall);
  1086. }
  1087. /**
  1088. * Send the data to the specified player.
  1089. * Login can be a single login or a list of comma-separated logins.
  1090. * @param Player|string|array[Player|string] $players
  1091. * @param string $filename
  1092. * @param bool $multicall
  1093. * @return bool
  1094. * @throws InvalidArgumentException
  1095. */
  1096. function tunnelSendData($players, $filename, $multicall = false)
  1097. {
  1098. if (! ($login = $this->getLogins($players)))
  1099. {
  1100. throw new InvalidArgumentException('players = '.print_r($players,true));
  1101. }
  1102. if (!file_exists($filename))
  1103. {
  1104. throw new InvalidArgumentException('filename = '.print_r($filename,true));
  1105. }
  1106. if (filesize($filename) > 4 * 1024)
  1107. {
  1108. throw new InvalidArgumentException('file is too big');
  1109. }
  1110. $inputData = file_get_contents($filename);
  1111. $data = new Xmlrpc\Base64($inputData);
  1112. return $this->execute('TunnelSendDataToLogin', array($login, $data), $multicall);
  1113. }
  1114. /**
  1115. * Send the data to the specified player.
  1116. * Login can be a single login or a list of comma-separated logins.
  1117. * @param Player|string|array[Player|string] $players
  1118. * @param string $data
  1119. * @param bool $multicall
  1120. * @return bool
  1121. * @throws InvalidArgumentException
  1122. */
  1123. function tunnelSendDataFromString($players, $data, $multicall = false)
  1124. {
  1125. if (! ($login = $this->getLogins($players)))
  1126. {
  1127. throw new InvalidArgumentException('players = '.print_r($players,true));
  1128. }
  1129. $data = new Xmlrpc\Base64($data);
  1130. return $this->execute('TunnelSendDataToLogin', array($login, $data), $multicall);
  1131. }
  1132. /**
  1133. * Just log the parameters and invoke a callback.
  1134. * Can be used to talk to other xmlrpc clients connected, or to make custom votes.
  1135. * If used in a callvote, the first parameter will be used as the vote message on the clients.
  1136. * @param string $message the message to log
  1137. * @param string $callback optionnal callback name
  1138. * @param bool $multicall
  1139. * @return bool
  1140. * @throws InvalidArgumentException
  1141. */
  1142. function dedicatedEcho ($message, $callback = '', $multicall = false)
  1143. {
  1144. if (!is_string($message))
  1145. {
  1146. throw new InvalidArgumentException('message = '.print_r($message, true));
  1147. }
  1148. if (!is_string($callback))
  1149. {
  1150. throw new InvalidArgumentException('callback = '.print_r($callback, true));
  1151. }
  1152. return $this->execute('Echo', array($message, $callback), $multicall);
  1153. }
  1154. /**
  1155. * Ignore the specified Player.
  1156. * @param Player|string $player
  1157. * @param bool $multicall
  1158. * @return bool
  1159. * @throws InvalidArgumentException
  1160. */
  1161. function ignore($player, $multicall = false)
  1162. {
  1163. if (! ($login = $this->getLogin($player)))
  1164. {
  1165. throw new InvalidArgumentException('player must be set');
  1166. }
  1167. return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
  1168. }
  1169. /**
  1170. * Unignore the specified player.
  1171. * @param Player|string $player
  1172. * @param bool $multicall
  1173. * @return bool
  1174. * @throws InvalidArgumentException
  1175. */
  1176. function unIgnore(Player $player, $multicall = false)
  1177. {
  1178. if (! ($login = $this->getLogin($player)))
  1179. {
  1180. throw new InvalidArgumentException('player must be set');
  1181. }
  1182. return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
  1183. }
  1184. /**
  1185. * Clean the ignore list of the server.
  1186. * @param bool $multicall
  1187. * @return bool
  1188. */
  1189. function cleanIgnoreList($multicall = false)
  1190. {
  1191. return $this->execute(ucfirst(__FUNCTION__), array(), $multicall);
  1192. }
  1193. /**
  1194. * Returns the list of ignored players. This method takes two parameters.
  1195. * The first parameter specifies the maximum number of infos to be returned,
  1196. * the second one the starting index in the list. The list is an array of structures.
  1197. * Each structure contains the following fields : Login.
  1198. * @param int $length specifies the maximum number of infos to be returned
  1199. * @param int $offset specifies the starting index in the list
  1200. * @return array[DedicatedApi\Structures\Player] The list is an array of structures. Each structure contains the following fields : Login.
  1201. * @throws InvalidArgumentException
  1202. */
  1203. function getIgnoreList($length, $offset)
  1204. {
  1205. if (!is_int($length))
  1206. {
  1207. throw new InvalidArgumentException('length = '.print_r($length,true));
  1208. }
  1209. if (!is_int($offset))
  1210. {
  1211. throw new InvalidArgumentException('offset = '.print_r($offset,true));
  1212. }
  1213. $result = $this->execute(ucfirst(__FUNCTION__), array($length, $offset));
  1214. return Structures\Player::fromArrayOfArray($result);
  1215. }
  1216. /**
  1217. * Pay coppers from the server account to a player, returns the BillId.
  1218. * This method takes three parameters:
  1219. * Login of the payee,
  1220. * Coppers to pay and
  1221. * Label to send with the payment.
  1222. * The creation of the transaction itself may cost coppers,
  1223. * so you need to have coppers on the server account.
  1224. * @param Player|string $player
  1225. * @param int $amount
  1226. * @param string $label
  1227. * @param bool $multicall
  1228. * @return int The Bill Id
  1229. * @throws InvalidArgumentException
  1230. */
  1231. function pay($player, $amount, $label, $multicall = false)
  1232. {
  1233. if (! ($login = $this->getLogin($player)))
  1234. {
  1235. throw new InvalidArgumentException('player must be set');
  1236. }
  1237. if (!is_int($amount) || $amount < 1)
  1238. {
  1239. throw new InvalidArgumentException('amount = '.print_r($amount, true));
  1240. }
  1241. if (!is_string($label))
  1242. {
  1243. throw new InvalidArgumentException('label = '.print_r($label, true));
  1244. }
  1245. return $this->execute(ucfirst(__FUNCTION__), array($login, $amount, $label), $multicall);
  1246. }
  1247. /**
  1248. * Create a bill, send it to a player, and return the BillId.
  1249. * This method takes four parameters:
  1250. * LoginFrom of the payer,
  1251. * Coppers the player has to pay,
  1252. * Label of the transaction and
  1253. * optional LoginTo of the payee (if empty string, then the server account is used).
  1254. * The creation of the transaction itself may cost coppers,
  1255. * so you need to have coppers on the server account.
  1256. * @param Player|string $fromPlayer
  1257. * @param int $amount
  1258. * @param string $label
  1259. * @param Player|string|null $toPlayer
  1260. * @param bool $multicall
  1261. * @return int
  1262. * @throws InvalidArgumentException
  1263. */
  1264. function sendBill($fromPlayer, $amount, $label, $toPlayer = null, $multicall = false)
  1265. {
  1266. if (!is_int($amount) || $amount < 1)
  1267. {
  1268. throw new InvalidArgumentException('amount = '.print_r($amount, true));
  1269. }
  1270. if (!is_string($label))
  1271. {
  1272. throw new InvalidArgumentException('label = '.print_r($label, true));
  1273. }
  1274. if (! ($from = $this->getLogin($fromPlayer)))
  1275. {
  1276. throw new InvalidArgumentException('fromPlayer must be set');
  1277. }
  1278. $to = $this->getLogin($toPlayer) ?: '';
  1279. return $this->execute(ucfirst(__FUNCTION__), array($from, $amount, $label, $to), $multicall);
  1280. }
  1281. /**
  1282. * Returns the current state of a bill.
  1283. * This method takes one parameter, the BillId.
  1284. * Returns a struct containing
  1285. * State, StateName and TransactionId.
  1286. * Possible enum values are: CreatingTransaction, Issued, ValidatingPayement, Payed, Refused, Error.
  1287. * @param int $billId
  1288. * @return Bill
  1289. * @throws InvalidArgumentException
  1290. */
  1291. function getBillState($billId)
  1292. {
  1293. if (!is_int($billId))
  1294. {
  1295. throw new InvalidArgumentException('billId = '.print_r($billId, true));
  1296. }
  1297. $result = $this->execute(ucfirst(__FUNCTION__), array($billId));
  1298. return Structures\Bill::fromArray($result);
  1299. }
  1300. /**
  1301. * Returns the current number of planets on the server account.
  1302. * @return int
  1303. */
  1304. function getServerPlanets()
  1305. {
  1306. return $this->execute('GetServerPlanets');
  1307. }
  1308. /**
  1309. * Get some system infos.
  1310. * Return a struct containing:
  1311. * PublishedIp, Port, P2PPort, ServerLogin, ServerPlayerId
  1312. * @return ManiaLive\DedicatedApi\Structures\SystemInfos
  1313. */
  1314. function getSystemInfo()
  1315. {
  1316. $result = $this->execute(ucfirst(__FUNCTION__));
  1317. return Structures\SystemInfos::fromArray($result);
  1318. }
  1319. /**
  1320. * Sets up- and download speed for the server in kbps.
  1321. * @param int $downloadRate the download rate in kbps
  1322. * @param int $uploadRate the upload rate in kbps
  1323. * @param bool $multicall
  1324. * @return bool
  1325. */
  1326. function setConnectionRates($downloadRate, $uploadRate, $multicall = false)
  1327. {
  1328. if (!is_int($downloadRate))
  1329. {
  1330. throw new InvalidArgumentException('downloadRate = '.print_r($downloadRate, true));
  1331. }
  1332. if (!is_int($uploadRate))
  1333. {
  1334. throw new InvalidArgumentException('uploadRate = '.print_r($uploadRate, true));
  1335. }
  1336. return $this->execute(ucfirst(__FUNCTION__),array($downloadRate, $uploadRate),$multicall);
  1337. }
  1338. /**
  1339. * Set a new server name in utf8 format.
  1340. * @param string $serverName
  1341. * @param bool $multicall
  1342. * @return bool
  1343. * @throws InvalidArgumentException
  1344. */
  1345. function setServerName($serverName, $multicall = false)
  1346. {
  1347. if (!is_string($serverName))
  1348. {
  1349. throw new InvalidArgumentException('serverName = '.print_r($serverName,true));
  1350. }
  1351. return $this->execute(ucfirst(__FUNCTION__), array($serverName), $multicall);
  1352. }
  1353. /**
  1354. * Get the server name in utf8 format.
  1355. * @return string
  1356. */
  1357. function getServerName()
  1358. {
  1359. return $this->execute(ucfirst(__FUNCTION__));
  1360. }
  1361. /**
  1362. * Set a new server comment in utf8 format.
  1363. * @param string $serverComment
  1364. * @param bool $multicall
  1365. * @return bool
  1366. * @throws InvalidArgumentException
  1367. */
  1368. function setServerComment($serverComment, $multicall = false)
  1369. {
  1370. if (!is_string($serverComment))
  1371. {
  1372. throw new InvalidArgumentException('serverComment = '.print_r($serverComment,true));
  1373. }
  1374. return $this->execute(ucfirst(__FUNCTION__), array($serverComment), $multicall);
  1375. }
  1376. /**
  1377. * Get the server comment in utf8 format.
  1378. * @return string
  1379. */
  1380. function getServerComment()
  1381. {
  1382. return $this->execute(ucfirst(__FUNCTION__));
  1383. }
  1384. /**
  1385. * Set whether the server should be hidden from the public server list
  1386. * (0 = visible, 1 = always hidden, 2 = hidden from nations).
  1387. * @param int $visibility
  1388. * @param bool $multicall
  1389. * @return bool
  1390. * @throws InvalidArgumentException
  1391. */
  1392. function setHideServer($visibility, $multicall = false)
  1393. {
  1394. if ($visibility !== 0 && $visibility !== 1 && $visibility !== 2)
  1395. {
  1396. throw new InvalidArgumentException('visibility = '.print_r($visibility,true));
  1397. }
  1398. return $this->execute(ucfirst(__FUNCTION__), array($visibility), $multicall);
  1399. }
  1400. /**
  1401. * Get whether the server wants to be hidden from the public server list.
  1402. * @return string
  1403. */
  1404. function getHideServer()
  1405. {
  1406. return $this->execute(ucfirst(__FUNCTION__));
  1407. }
  1408. /**
  1409. * Returns true if this is a relay server.
  1410. * @return bool
  1411. */
  1412. function isRelayServer()
  1413. {
  1414. return $this->execute(ucfirst(__FUNCTION__));
  1415. }
  1416. /**
  1417. * Set a new password for the server.
  1418. * @param string $serverPassword
  1419. * @param bool $multicall
  1420. * @return bool
  1421. * @throws InvalidArgumentException
  1422. */
  1423. function setServerPassword($serverPassword, $multicall = false)
  1424. {
  1425. if (!is_string($serverPassword))
  1426. {
  1427. throw new DedicatedApiInvalidArgumentExcepption('serverPassword = '.print_r($serverPassword,true));
  1428. }
  1429. return $this->execute(ucfirst(__FUNCTION__), array($serverPassword), $multicall);
  1430. }
  1431. /**
  1432. * Get the server password if called as Admin or Super Admin, else returns if a password is needed or not.
  1433. * Get the server name in utf8 format.
  1434. * @return bool|string
  1435. */
  1436. function getServerPassword()
  1437. {
  1438. return $this->execute(ucfirst(__FUNCTION__));
  1439. }
  1440. /**
  1441. * Set a new password for the spectator mode.
  1442. * @param string $serverPassword
  1443. * @param bool $multicall
  1444. * @return bool
  1445. * @throws InvalidArgumentException
  1446. */
  1447. function setServerPasswordForSpectator($serverPassword, $multicall = false)
  1448. {
  1449. if (!is_string($serverPassword))
  1450. {
  1451. throw new DedicatedApiInvalidArgumentExcepption('serverPassword = '.print_r($serverPassword,true));
  1452. }
  1453. return $this->execute(ucfirst(__FUNCTION__), array($serverPassword), $multicall);
  1454. }
  1455. /**
  1456. * Get the password for spectator mode if called as Admin or Super Admin, else returns if a password is needed or not.
  1457. * @return bool|string
  1458. */
  1459. function getServerPasswordForSpectator()
  1460. {
  1461. return $this->execute(ucfirst(__FUNCTION__));
  1462. }
  1463. /**
  1464. * Set a new maximum number of players.
  1465. * Requires a map restart to be taken into account.
  1466. * @param int $maxPlayers
  1467. * @param bool $multicall
  1468. * @return bool
  1469. * @throws InvalidArgumentException
  1470. */
  1471. function setMaxPlayers($maxPlayers, $multicall = false)
  1472. {
  1473. if (!is_int($maxPlayers))
  1474. {
  1475. throw new InvalidArgumentException('maxPlayers = '.print_r($maxPlayers, true));
  1476. }
  1477. return $this->execute(ucfirst(__FUNCTION__), array($maxPlayers), $multicall);
  1478. }
  1479. /**
  1480. * Get the current …

Large files files are truncated, but you can click here to view the full file