From 7a668b53baf568401e506d94a716f8bcc9518719 Mon Sep 17 00:00:00 2001 From: kremsy Date: Fri, 24 Mar 2017 22:08:51 +0100 Subject: [PATCH] added dumpable interface, implemented all ManiaPlanet Callbacks --- core/Callbacks/Callbacks.php | 13 +-- core/Callbacks/LibXmlRpcCallbacks.php | 82 +++++++++++++++++++ core/Callbacks/Structures/BaseStructure.php | 3 +- core/General/DumpTrait.php | 19 +++++ core/General/Dumpable.php | 14 ++++ core/ManiaControl.php | 2 +- core/Maps/Map.php | 52 ++++++------ core/Players/Player.php | 15 ++-- .../ModeScriptEventManager.php | 4 +- 9 files changed, 158 insertions(+), 46 deletions(-) create mode 100644 core/General/DumpTrait.php create mode 100644 core/General/Dumpable.php rename core/{Server => Script}/ModeScriptEventManager.php (96%) diff --git a/core/Callbacks/Callbacks.php b/core/Callbacks/Callbacks.php index f15ae0d6..622a9508 100644 --- a/core/Callbacks/Callbacks.php +++ b/core/Callbacks/Callbacks.php @@ -35,15 +35,15 @@ interface Callbacks { const MP_STARTSERVEREND = 'Callbacks.ManiaPlanetStartServerEnd'; const MP_STARTMATCHSTART = 'Callbacks.ManiaPlanetStartMatchStart'; const MP_STARTMATCHEND = 'Callbacks.ManiaPlanetStartMatchEnd'; - const MP_STARTMAPSTART = 'Callbacks.ManiaPlanetStartMapStart'; - const MP_STARTMAPEND = 'Callbacks.ManiaPlanetStartMapEnd'; + //const MP_STARTMAPSTART = 'Callbacks.ManiaPlanetStartMapStart'; + //const MP_STARTMAPEND = 'Callbacks.ManiaPlanetStartMapEnd'; const MP_STARTROUNDSTART = 'Callbacks.ManiaPlanetStartRoundStart'; const MP_STARTROUNDEND = 'Callbacks.ManiaPlanetStartRoundEnd'; const MP_STARTTURNSTART = 'Callbacks.ManiaPlanetStartTurnStart'; const MP_STARTTURNEND = 'Callbacks.ManiaPlanetStartTurnEnd'; const MP_STARTPLAYLOOPSTART = 'Callbacks.ManiaPlanetStartPlayLoopStart'; const MP_STARTPLAYLOOPEND = 'Callbacks.ManiaPlanetStartPlayLoopEnd'; - const MP_ENDTTURNSTART = 'Callbacks.ManiaPlanetEndTurnStart'; + const MP_ENDTURNSTART = 'Callbacks.ManiaPlanetEndTurnStart'; const MP_ENDTURNEND = 'Callbacks.ManiaPlanetEndTurnEnd'; const MP_ENDROUNDSTART = 'Callbacks.ManiaPlanetEndRoundStart'; const MP_ENDROUNDEND = 'Callbacks.ManiaPlanetEndRoundEnd'; @@ -60,13 +60,16 @@ interface Callbacks { const MP_PODIUMSTART = 'Callbacks.ManiaPlanetPodiumStart'; const MP_PODIUMEND = 'Callbacks.ManiaPlanetPodiumEnd'; + //ManiaControl Callbacks + /** BeginMap Callback: Map */ + const BEGINMAP = 'Callbacks.BeginMap'; + //OLD Callbacks /** BeginMatch Callback: MatchNumber */ const BEGINMATCH = 'Callbacks.BeginMatch'; /** LoadingMap Callback: MapNumber */ const LOADINGMAP = 'Callbacks.LoadingMap'; - /** BeginMap Callback: Map */ - const BEGINMAP = 'Callbacks.BeginMap'; + /** BeginSubMatch Callback: SubmatchNumber */ const BEGINSUBMATCH = 'Callbacks.BeginSubmatch'; /** BeginRound Callback: RoundNumber */ diff --git a/core/Callbacks/LibXmlRpcCallbacks.php b/core/Callbacks/LibXmlRpcCallbacks.php index 0e77917b..9cc751ee 100644 --- a/core/Callbacks/LibXmlRpcCallbacks.php +++ b/core/Callbacks/LibXmlRpcCallbacks.php @@ -60,6 +60,88 @@ class LibXmlRpcCallbacks implements CallbackListener { case 'ManiaPlanet.StartMatch_Start': $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTMATCHSTART, new StartEndStructure($this->maniaControl, $data)); break; + case 'ManiaPlanet.StartMatch_End': + $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; + case 'ManiaPlanet.StartRound_Start': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTROUNDSTART, new StartEndStructure($this->maniaControl, $data)); + break; + case 'ManiaPlanet.StartRound_End': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTROUNDEND, new StartEndStructure($this->maniaControl, $data)); + break; + case 'ManiaPlanet.StartTurn_Start': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTTURNSTART, new StartEndStructure($this->maniaControl, $data)); + break; + case 'ManiaPlanet.StartTurn_End': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTTURNEND, new StartEndStructure($this->maniaControl, $data)); + break; + case 'ManiaPlanet.StartPlayLoop_Start': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTPLAYLOOPSTART, new StartEndStructure($this->maniaControl, $data)); + break; + case 'ManiaPlanet.StartPlayLoop_End': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTPLAYLOOPEND, new StartEndStructure($this->maniaControl, $data)); + break; + case 'ManiaPlanet.EndTurn_Start': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDTURNSTART, new StartEndStructure($this->maniaControl, $data)); + break; + case 'ManiaPlanet.EndTurn_End': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDTURNEND, new StartEndStructure($this->maniaControl, $data)); + break; + case 'ManiaPlanet.EndRound_Start': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDROUNDSTART, new StartEndStructure($this->maniaControl, $data)); + break; + case 'ManiaPlanet.EndRound_End': + $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; + case 'ManiaPlanet.EndMatch_Start': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDMATCHSTART, new StartEndStructure($this->maniaControl, $data)); + break; + case 'ManiaPlanet.EndMatch_End': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDMATCHEND, new StartEndStructure($this->maniaControl, $data)); + break; + case 'Maniaplanet.EndServer_Start': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDSERVERSTART, new StartServerStructure($this->maniaControl, $data)); + break; + case 'Maniaplanet.EndServer_End': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDSERVEREND, new StartServerStructure($this->maniaControl, $data)); + break; + case 'Maniaplanet.LoadingMap_Start': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_LOADINGMAPSTART); + break; + case 'Maniaplanet.LoadingMap_End': + $jsonData = json_decode($data[0]); + $map = $this->maniaControl->getMapManager()->getMapByUid($jsonData->map->uid); //Verify Json + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_LOADINGMAPEND, $map); + break; + case 'Maniaplanet.UnloadingMap_Start': + $jsonData = json_decode($data[0]); + $map = $this->maniaControl->getMapManager()->getMapByUid($jsonData->map->uid); //Verify Json + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_LOADINGMAPSTART, $map); + break; + case 'Maniaplanet.UnloadingMap_End': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_LOADINGMAPEND); + break; + case 'Maniaplanet.Podium_Start': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_PODIUMSTART); + break; + case 'Maniaplanet.Podium_End': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_PODIUMEND); + break; + //OLD Callbacks case 'LibXmlRpc_BeginMatch': $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINMATCH, $data[0]); diff --git a/core/Callbacks/Structures/BaseStructure.php b/core/Callbacks/Structures/BaseStructure.php index f66dbb21..0310d222 100644 --- a/core/Callbacks/Structures/BaseStructure.php +++ b/core/Callbacks/Structures/BaseStructure.php @@ -3,6 +3,7 @@ namespace ManiaControl\Callbacks\Structures; +use ManiaControl\General\Dumpable; use ManiaControl\ManiaControl; /** @@ -12,7 +13,7 @@ use ManiaControl\ManiaControl; * @copyright 2014-2017 ManiaControl Team * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ -abstract class BaseStructure { +abstract class BaseStructure implements Dumpable { /** @var ManiaControl $maniaControl */ protected $maniaControl; private $plainJsonObject; diff --git a/core/General/DumpTrait.php b/core/General/DumpTrait.php new file mode 100644 index 00000000..72815407 --- /dev/null +++ b/core/General/DumpTrait.php @@ -0,0 +1,19 @@ +mx && ($this->lastUpdate < strtotime($this->mx->updated) || $this->uid !== $this->mx->uid)); } - /** - * Var_Dump the Map - */ - public function dump() { - var_dump(json_decode(json_encode($this))); - } } diff --git a/core/Players/Player.php b/core/Players/Player.php index 79933ef4..77767131 100644 --- a/core/Players/Player.php +++ b/core/Players/Player.php @@ -2,6 +2,8 @@ namespace ManiaControl\Players; +use ManiaControl\General\Dumpable; +use ManiaControl\General\DumpTrait; use ManiaControl\ManiaControl; use ManiaControl\Utils\ClassUtil; use ManiaControl\Utils\Formatter; @@ -14,7 +16,9 @@ use Maniaplanet\DedicatedServer\Structures\LadderStats; * @copyright 2014-2017 ManiaControl Team * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ -class Player { +class Player implements Dumpable { + use DumpTrait; + /* * Public Properties */ @@ -345,14 +349,7 @@ class Player { } return false; } - - /** - * Var_Dump the Player - */ - public function dump() { - var_dump(json_decode(json_encode($this))); - } - + /** * Var_Dump the Players Cache */ diff --git a/core/Server/ModeScriptEventManager.php b/core/Script/ModeScriptEventManager.php similarity index 96% rename from core/Server/ModeScriptEventManager.php rename to core/Script/ModeScriptEventManager.php index 2d18b6ba..3644c685 100644 --- a/core/Server/ModeScriptEventManager.php +++ b/core/Script/ModeScriptEventManager.php @@ -6,9 +6,7 @@ * @copyright 2014-2017 ManiaControl Team * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ -namespace ManiaControl\Server; - -//TODO maybe own folder +namespace ManiaControl\Script; use ManiaControl\ManiaControl;