From 496039a6276e7da3dfad16c2bb07f89a681a8822 Mon Sep 17 00:00:00 2001 From: kremsy Date: Wed, 22 Mar 2017 18:10:21 +0100 Subject: [PATCH] added draft of new callback structure (made example) --- core/Callbacks/Callbacks.php | 14 +++-- core/Callbacks/LibXmlRpcCallbacks.php | 6 +++ .../ManiaPlanet/CallbacksListStructure.php | 53 +++++++++++++++++++ .../Trackmania/DefaultEventStructure.php | 14 +++++ 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 core/Callbacks/Structures/ManiaPlanet/CallbacksListStructure.php create mode 100644 core/Callbacks/Structures/Trackmania/DefaultEventStructure.php diff --git a/core/Callbacks/Callbacks.php b/core/Callbacks/Callbacks.php index 24559956..df8cc2bb 100644 --- a/core/Callbacks/Callbacks.php +++ b/core/Callbacks/Callbacks.php @@ -28,6 +28,12 @@ interface Callbacks { /* * Common Callbacks */ + //NEW Callbacks + + const XMLRPC_CALLBACKSLIST = 'Callbacks.XmlRpcCallbacksList'; + + + //OLD Callbacks /** BeginMatch Callback: MatchNumber */ const BEGINMATCH = 'Callbacks.BeginMatch'; /** LoadingMap Callback: MapNumber */ @@ -126,14 +132,14 @@ interface Callbacks { * TrackMania Callbacks */ /** OnStartLine Callback */ - const STARTLINE = 'Callbacks.StartLine'; + const ONSTARTLINE = 'Callbacks.StartLine'; /** OnWayPoint Callback */ - const WAYPOINT = 'Callbacks.WayPoint'; + const ONWAYPOINT = 'Callbacks.WayPoint'; /** OnGiveUp Callback */ - const GIVEUP = 'Callbacks.GiveUp'; + const ONGIVEUP = 'Callbacks.GiveUp'; /** OnRespawn Callback */ const ONRESPAWN = 'Callbacks.Respawn'; /** OnStunt Callback */ - const STUNT = 'Callbacks.Stunt'; + const ONSTUNT = 'Callbacks.Stunt'; } diff --git a/core/Callbacks/LibXmlRpcCallbacks.php b/core/Callbacks/LibXmlRpcCallbacks.php index 7e4008c9..3526fcac 100644 --- a/core/Callbacks/LibXmlRpcCallbacks.php +++ b/core/Callbacks/LibXmlRpcCallbacks.php @@ -4,6 +4,7 @@ namespace ManiaControl\Callbacks; use ManiaControl\Callbacks\Structures\ArmorEmptyStructure; use ManiaControl\Callbacks\Structures\CaptureStructure; +use ManiaControl\Callbacks\Structures\ManiaPlanet\CallbacksListStructure; use ManiaControl\Callbacks\Structures\NearMissStructure; use ManiaControl\Callbacks\Structures\PlayerHitStructure; use ManiaControl\ManiaControl; @@ -42,6 +43,11 @@ class LibXmlRpcCallbacks implements CallbackListener { */ public function handleScriptCallback($name, $data) { switch ($name) { + //New callbacks + case 'XmlRpc.CallbacksList': + $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::XMLRPC_CALLBACKSLIST, new CallbacksListStructure($this->maniaControl, $data)); + break; + //OLD Callbacks case 'LibXmlRpc_BeginMatch': $this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINMATCH, $data[0]); break; diff --git a/core/Callbacks/Structures/ManiaPlanet/CallbacksListStructure.php b/core/Callbacks/Structures/ManiaPlanet/CallbacksListStructure.php new file mode 100644 index 00000000..00750ef5 --- /dev/null +++ b/core/Callbacks/Structures/ManiaPlanet/CallbacksListStructure.php @@ -0,0 +1,53 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class CallbacksListStructure { + /** @var string $responseId */ + private $responseId; + /** @var array $callbacks */ + private $callbacks; + + /** @var ManiaControl $maniaControl */ + private $maniaControl; + + /** + * Construct a new Armor Empty Structure + * + * @param ManiaControl $maniaControl + * @param array $data + */ + public function __construct(ManiaControl $maniaControl, $data) { + $this->maniaControl = $maniaControl; + + //Not tested yet, TODO test + $json = json_decode($data); + + $this->responseId = $json->responseId; + $this->callbacks = $json->callbacks; + } + + /** + * @return string + */ + public function getResponseId() { + return $this->responseId; + } + + /** + * @return array + */ + public function getCallbacks() { + return $this->callbacks; + } + +} \ No newline at end of file diff --git a/core/Callbacks/Structures/Trackmania/DefaultEventStructure.php b/core/Callbacks/Structures/Trackmania/DefaultEventStructure.php new file mode 100644 index 00000000..2a3fd4e0 --- /dev/null +++ b/core/Callbacks/Structures/Trackmania/DefaultEventStructure.php @@ -0,0 +1,14 @@ +