TrackManiaControl/core/Callbacks/LibXmlRpcCallbacks.php

308 lines
14 KiB
PHP
Raw Normal View History

2014-04-24 17:41:05 +02:00
<?php
namespace ManiaControl\Callbacks;
use ManiaControl\Callbacks\Structures\ArmorEmptyStructure;
use ManiaControl\Callbacks\Structures\CaptureStructure;
2017-03-24 17:08:27 +01:00
use ManiaControl\Callbacks\Structures\ManiaPlanet\StartEndStructure;
2017-03-24 16:49:54 +01:00
use ManiaControl\Callbacks\Structures\ManiaPlanet\StartServerStructure;
use ManiaControl\Callbacks\Structures\NearMissStructure;
2014-10-10 14:40:00 +02:00
use ManiaControl\Callbacks\Structures\PlayerHitStructure;
use ManiaControl\Callbacks\Structures\ShootMania\StatusCallbackStructure;
use ManiaControl\Callbacks\Structures\XmlRpc\ListStructure;
2014-04-24 17:41:05 +02:00
use ManiaControl\ManiaControl;
/**
* Class converting LibXmlRpc Callbacks
*
2014-05-02 17:50:30 +02:00
* @author ManiaControl Team <mail@maniacontrol.com>
2017-02-04 11:49:23 +01:00
* @copyright 2014-2017 ManiaControl Team
2014-05-02 17:50:30 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class LibXmlRpcCallbacks implements CallbackListener {
2014-04-24 17:41:05 +02:00
/*
* Private properties
2014-04-24 17:41:05 +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
* @param CallbackManager $callbackManager
2014-04-24 17:41:05 +02:00
*/
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
$this->maniaControl = $maniaControl;
$callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallback');
2014-04-24 17:41:05 +02:00
}
2014-04-24 23:11:09 +02:00
/**
* Handle the Script Callback
2014-04-24 23:11:09 +02:00
*
* @param string $name
* @param mixed $data
2014-04-24 23:11:09 +02:00
*/
public function handleScriptCallback($name, $data) {
2017-03-25 13:57:42 +01:00
if (!$this->maniaControl->getCallbackManager()->callbackListeningExists($name)) {
2017-03-25 20:19:45 +01:00
//return; //Leave that disabled while testing/implementing Callbacks
}
2014-05-02 17:50:30 +02:00
switch ($name) {
//New callbacks
2017-03-25 13:57:42 +01:00
case Callbacks::XMLRPC_CALLBACKSLIST:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::XMLRPC_CALLBACKSLIST, new ListStructure($this->maniaControl, $data));
break;
case Callbacks::XMLRPC_ENABLEDCALLBACKS:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::XMLRPC_ENABLEDCALLBACKS, new ListStructure($this->maniaControl, $data));
break;
case Callbacks::XMLRPC_DISABLEDCALLBACKS:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::XMLRPC_DISABLEDCALLBACKS, new ListStructure($this->maniaControl, $data));
break;
case Callbacks::XMLRPC_APIVERSION:
//TODO
break;
case Callbacks::XMLRPC_ALLAPIVERSIONS:
//TODO
break;
case Callbacks::XMLRPC_DOCUMENTATION:
//TODO
break;
case Callbacks::XMLRPC_METHODSLIST:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::XMLRPC_METHODSLIST, new ListStructure($this->maniaControl, $data));
break;
case Callbacks::XMLRPC_METHODHELP:
//TODO
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_STARTSERVERSTART:
2017-03-24 16:49:54 +01:00
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTSERVERSTART, new StartServerStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_STARTSERVEREND:
2017-03-24 16:49:54 +01:00
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTSERVEREND, new StartServerStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_STARTMATCHSTART:
2017-03-24 17:08:27 +01:00
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTMATCHSTART, new StartEndStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_STARTMATCHEND:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTMATCHEND, new StartEndStructure($this->maniaControl, $data));
break;
case 'Maniaplanet.StartMap_Start': //Use the MapManager Callback
//No use for this Implementation right now (as the MapManager Callback should be used
break;
case 'Maniaplanet.StartMap_End': //Use the MapManager Callback
$jsonData = json_decode($data[0]);
$this->maniaControl->getMapManager()->handleScriptBeginMap($jsonData->map->uid, 'False');
//TODO Test if json is correctly parsed
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_STARTROUNDSTART:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTROUNDSTART, new StartEndStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_STARTROUNDEND:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTROUNDEND, new StartEndStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_STARTTURNSTART:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTTURNSTART, new StartEndStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_STARTTURNEND:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTTURNEND, new StartEndStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_STARTPLAYLOOP:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTPLAYLOOP, new StartEndStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_ENDPLAYLOOP:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDPLAYLOOP, new StartEndStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_ENDTURNSTART:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDTURNSTART, new StartEndStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_ENDTURNEND:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDTURNEND, new StartEndStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_ENDROUNDSTART:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDROUNDSTART, new StartEndStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_ENDROUNDEND:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDROUNDEND, new StartEndStructure($this->maniaControl, $data));
break;
case 'Maniaplanet.EndMap_Start':
//no need for this implementation, callback handled by Map Manager
break;
case 'Maniaplanet.EndMap_End': //Use the MapManager Callback
$this->maniaControl->getMapManager()->handleScriptEndMap(); //Verify if better here or at EndMap_End
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_ENDMATCHSTART:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDMATCHSTART, new StartEndStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_ENDMATCHEND:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDMATCHEND, new StartEndStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_ENDSERVERSTART:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDSERVERSTART, new StartServerStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_ENDSERVEREND:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDSERVEREND, new StartServerStructure($this->maniaControl, $data));
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_LOADINGMAPSTART:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_LOADINGMAPSTART);
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_LOADINGMAPEND:
$jsonData = json_decode($data[0]);
$map = $this->maniaControl->getMapManager()->getMapByUid($jsonData->map->uid); //Verify Json
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_LOADINGMAPEND, $map);
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_UNLOADINGMAPSTART:
$jsonData = json_decode($data[0]);
$map = $this->maniaControl->getMapManager()->getMapByUid($jsonData->map->uid); //Verify Json
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_LOADINGMAPSTART, $map);
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_UNLOADINGMAPEND:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_LOADINGMAPEND);
break;
2017-03-25 13:57:42 +01:00
case Callbacks::MP_PODIUMSTART:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_PODIUMSTART);
break;
2017-03-25 19:15:50 +01:00
case Callbacks::MP_PODIUMEND:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_PODIUMEND);
break;
2017-04-07 17:28:04 +02:00
case Callbacks::MP_WARMUP_START:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_WARMUP_START);
break;
case Callbacks::MP_WARMUP_END:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_WARMUP_END);
break;
case Callbacks::MP_WARMUP_STATUS:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_WARMUP_STATUS, new StatusCallbackStructure($this->maniaControl, $data));
2017-04-07 17:28:04 +02:00
break;
//OLD Callbacks
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-12-21 23:21:59 +01:00
case 'LibXmlRpc_BeginTurnStop':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINTURNSTOP, $data[0]);
break;
2014-12-20 18:43:51 +01:00
case 'LibXmlRpc_BeginRound':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINROUND, $data[0]);
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;
2014-12-21 23:21:59 +01:00
case 'LibXmlRpc_EndTurnStop':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDTURNSTOP, $data[0]);
break;
2014-04-24 21:55:47 +02:00
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;
2015-01-23 19:17:02 +01:00
case 'LibXmlRpc_EndRoundStop':
2015-01-23 19:18:29 +01:00
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ENDROUNDSTOP, $data[0]);
2015-01-23 19:17:02 +01:00
break;
2014-04-24 21:55:47 +02:00
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;
2017-02-04 11:41:31 +01:00
case 'LibXmlRpc_Rankings':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::RANKINGS, $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;
case 'LibXmlRpc_OnShoot':
2014-10-10 14:40:00 +02:00
$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;
case 'LibXmlRpc_OnNearMiss':
2014-10-10 18:55:49 +02:00
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONNEARMISS, new NearMissStructure($this->maniaControl, $data));
break;
case 'LibXmlRpc_OnArmorEmpty':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONARMOREMPTY, new ArmorEmptyStructure($this->maniaControl, $data));
break;
case 'LibXmlRpc_OnCapture':
2014-12-20 18:43:51 +01:00
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONCAPTURE, new CaptureStructure($this->maniaControl, $data));
break;
case 'LibXmlRpc_OnPlayerRequestRespawn':
$player = $this->maniaControl->getPlayerManager()->getPlayer($data[0]);
2014-12-20 18:43:51 +01:00
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::ONPLAYERREQUESTRESPAWN, $player);
break;
2015-08-20 18:48:14 +02:00
case 'LibXmlRpc_Scores':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SCORES, $data);
break;
case 'LibXmlRpc_ScoresReady':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SCORESREADY, $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
/**
* Trigger the Ranking of a Player
2014-04-24 23:11:09 +02:00
*
* @param array $data
2014-04-24 23:11:09 +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
}
}