2014-04-24 17:41:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Callbacks;
|
|
|
|
|
2014-10-10 14:40:00 +02:00
|
|
|
use ManiaControl\Callbacks\Structures\PlayerHitStructure;
|
2014-04-24 17:41:05 +02:00
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
|
2014-05-02 16:13:45 +02:00
|
|
|
/**
|
2014-05-13 01:18:47 +02:00
|
|
|
* Class converting LibXmlRpc Callbacks
|
2014-05-02 16:13:45 +02:00
|
|
|
*
|
2014-05-02 17:50:30 +02:00
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
|
|
|
* @copyright 2014 ManiaControl Team
|
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-05-02 16:13:45 +02:00
|
|
|
*/
|
2014-05-13 01:18:47 +02:00
|
|
|
class LibXmlRpcCallbacks implements CallbackListener {
|
2014-04-24 17:41:05 +02:00
|
|
|
/*
|
2014-08-02 22:31:46 +02:00
|
|
|
* Private properties
|
2014-04-24 17:41:05 +02:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2014-04-24 17:41:05 +02:00
|
|
|
private $maniaControl = null;
|
|
|
|
|
|
|
|
/**
|
2014-04-24 21:55:47 +02:00
|
|
|
* Create a new LibXmlRpc Callbacks Instance
|
2014-04-24 17:41:05 +02:00
|
|
|
*
|
2014-05-02 17:50:30 +02:00
|
|
|
* @param ManiaControl $maniaControl
|
2014-05-02 16:13:45 +02:00
|
|
|
* @param CallbackManager $callbackManager
|
2014-04-24 17:41:05 +02:00
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2014-05-13 01:18:47 +02:00
|
|
|
|
|
|
|
$callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallback');
|
2014-04-24 17:41:05 +02:00
|
|
|
}
|
|
|
|
|
2014-04-24 23:11:09 +02:00
|
|
|
/**
|
2014-05-13 01:18:47 +02:00
|
|
|
* Handle the Script Callback
|
2014-04-24 23:11:09 +02:00
|
|
|
*
|
2014-05-02 16:13:45 +02:00
|
|
|
* @param string $name
|
2014-05-03 21:12:44 +02:00
|
|
|
* @param mixed $data
|
2014-04-24 23:11:09 +02:00
|
|
|
*/
|
2014-05-13 01:18:47 +02:00
|
|
|
public function handleScriptCallback($name, $data) {
|
2014-10-10 14:40:00 +02:00
|
|
|
var_dump($name);
|
2014-05-02 17:50:30 +02:00
|
|
|
switch ($name) {
|
2014-04-24 17:41:05 +02:00
|
|
|
case 'LibXmlRpc_BeginMatch':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINMATCH, $data[0]);
|
2014-04-24 17:41:05 +02:00
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_LoadingMap':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::LOADINGMAP, $data[0]);
|
2014-04-24 17:41:05 +02:00
|
|
|
break;
|
2014-04-24 21:55:47 +02:00
|
|
|
case 'BeginMap':
|
2014-04-24 17:41:05 +02:00
|
|
|
case 'LibXmlRpc_BeginMap':
|
2014-06-23 15:45:40 +02:00
|
|
|
if (!isset($data[2])) {
|
|
|
|
$data[2] = 'False';
|
|
|
|
}
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getMapManager()->handleScriptBeginMap($data[1], $data[2]);
|
2014-04-24 17:41:05 +02:00
|
|
|
break;
|
2014-04-24 21:55:47 +02:00
|
|
|
case 'LibXmlRpc_BeginSubmatch':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINSUBMATCH, $data[0]);
|
2014-04-24 21:55:47 +02:00
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_BeginTurn':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINTURN, $data[0]);
|
2014-04-24 21:55:47 +02:00
|
|
|
break;
|
2014-05-24 16:11:35 +02:00
|
|
|
case 'LibXmlRpc_BeginPlaying':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINPLAYING);
|
2014-05-24 16:11:35 +02:00
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_EndPlaying':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDPLAYING);
|
2014-05-24 16:11:35 +02:00
|
|
|
break;
|
2014-04-24 21:55:47 +02:00
|
|
|
case 'LibXmlRpc_EndTurn':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDTURN, $data[0]);
|
2014-04-24 21:55:47 +02:00
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_EndRound':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDROUND, $data[0]);
|
2014-04-24 21:55:47 +02:00
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_EndSubmatch':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDSUBMATCH, $data[0]);
|
2014-04-24 21:55:47 +02:00
|
|
|
break;
|
|
|
|
case 'EndMap':
|
|
|
|
case 'LibXmlRpc_EndMap':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getMapManager()->handleScriptEndMap();
|
2014-04-24 21:55:47 +02:00
|
|
|
break;
|
2014-05-24 16:11:35 +02:00
|
|
|
case 'LibXmlRpc_BeginPodium':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINPODIUM);
|
2014-05-24 16:11:35 +02:00
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_EndPodium':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDPODIUM);
|
2014-05-24 16:11:35 +02:00
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_UnloadingMap':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::UNLOADINGMAP, $data[0]);
|
2014-05-24 16:11:35 +02:00
|
|
|
break;
|
2014-04-24 21:55:47 +02:00
|
|
|
case 'LibXmlRpc_EndMatch':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDMATCH, $data[0]);
|
2014-04-24 21:55:47 +02:00
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_BeginWarmUp':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINWARMUP);
|
2014-04-24 21:55:47 +02:00
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_EndWarmUp':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDWARMUP);
|
2014-04-24 21:55:47 +02:00
|
|
|
break;
|
2014-05-24 16:43:37 +02:00
|
|
|
case 'LibXmlRpc_PlayerRanking':
|
|
|
|
//TODO really useful? what does it have what RankingsManager not have?
|
2014-04-24 23:11:09 +02:00
|
|
|
$this->triggerPlayerRanking($data[0]);
|
|
|
|
break;
|
2014-05-24 16:20:29 +02:00
|
|
|
case 'LibXmlRpc_OnStartLine':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONSTARTLINE, $data[0]);
|
2014-05-24 16:20:29 +02:00
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_OnWayPoint':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONWAYPOINT, $data);
|
2014-05-24 16:20:29 +02:00
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_OnGiveUp':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONGIVEUP, $data[0]);
|
2014-05-24 16:20:29 +02:00
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_OnRespawn':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONRESPAWN, $data[0]);
|
2014-05-24 16:20:29 +02:00
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_OnStunt':
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONSTUNT, $data);
|
2014-05-24 16:20:29 +02:00
|
|
|
break;
|
2014-10-10 14:40:00 +02:00
|
|
|
case 'LibXmlRpc_OnShoot': //TODO testing
|
|
|
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($data[0]);
|
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONSHOOT, $player, $data[1]);
|
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_OnHit':
|
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONHIT, new PlayerHitStructure($this->maniaControl, $data));
|
|
|
|
break;
|
2014-04-24 17:41:05 +02:00
|
|
|
}
|
|
|
|
}
|
2014-04-24 23:11:09 +02:00
|
|
|
|
2014-10-10 14:40:00 +02:00
|
|
|
|
2014-04-24 23:11:09 +02:00
|
|
|
/**
|
2014-05-13 01:18:47 +02:00
|
|
|
* Trigger the Ranking of a Player
|
2014-04-24 23:11:09 +02:00
|
|
|
*
|
2014-05-02 16:13:45 +02:00
|
|
|
* @param array $data
|
2014-04-24 23:11:09 +02:00
|
|
|
*/
|
2014-05-02 16:13:45 +02:00
|
|
|
private function triggerPlayerRanking(array $data) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($data[1]);
|
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::PLAYERRANKING, $player, $data[0], $data[6], $data[5]);
|
2014-04-24 23:11:09 +02:00
|
|
|
}
|
2014-05-13 01:18:47 +02:00
|
|
|
}
|