diff --git a/application/core/Callbacks/CallbackManager.php b/application/core/Callbacks/CallbackManager.php index 3523aec7..4ebb2bd0 100644 --- a/application/core/Callbacks/CallbackManager.php +++ b/application/core/Callbacks/CallbackManager.php @@ -53,6 +53,7 @@ class CallbackManager { */ private $maniaControl = null; private $callbackListeners = array(); + private $scriptCallbackListener = array(); private $last1Second = -1; private $last5Second = -1; private $last1Minute = -1; @@ -92,6 +93,28 @@ class CallbackManager { return true; } + /** + * Register a new script callback listener + * + * @param string $callbackName + * @param CallbackListener $listener + * @param string $method + * @return bool + */ + public function registerScriptCallbackListener($callbackName, CallbackListener $listener, $method) { + if (!method_exists($listener, $method)) { + trigger_error( + "Given listener (" . get_class($listener) . + ") can't handle script callback '{$callbackName}' (no method '{$method}')!"); + return false; + } + if (!array_key_exists($callbackName, $this->scriptCallbackListener)) { + $this->scriptCallbackListener[$callbackName] = array(); + } + array_push($this->scriptCallbackListener[$callbackName], array($listener, $method)); + return true; + } + /** * Trigger a specific callback * @@ -107,6 +130,21 @@ class CallbackManager { } } + /** + * Trigger a specific script callback + * + * @param string $callbackName + * @param array $callback + */ + public function triggerScriptCallback($callbackName, array $callback) { + if (!array_key_exists($callbackName, $this->scriptCallbackListener)) { + return; + } + foreach ($this->scriptCallbackListener[$callbackName] as $listener) { + call_user_func(array($listener[0], $listener[1]), $callback); + } + } + /** * Trigger internal and manage server callbacks */ @@ -141,6 +179,7 @@ class CallbackManager { case self::CB_MP_MODESCRIPTCALLBACK: { $this->handleScriptCallback($callback); + $this->triggerCallback(self::CB_MP_MODESCRIPTCALLBACK, $callback); break; } default: @@ -158,22 +197,24 @@ class CallbackManager { * @param array $callback */ private function handleScriptCallback(array $callback) { - $scriptCallbackName = $callback[1][0]; + $scriptCallbackData = $callback[1]; + $scriptCallbackName = $scriptCallbackData[0]; switch ($scriptCallbackName) { case 'EndMap': { - $this->triggerCallback(self::CB_MP_MODESCRIPTCALLBACK, $callback); + $this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData); $this->triggerCallback(self::CB_MC_ENDMAP, $callback); break; } case 'LibXmlRpc_EndMap': { - $this->triggerCallback(self::CB_MP_MODESCRIPTCALLBACK, $callback); + $this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData); $this->triggerCallback(self::CB_MC_ENDMAP, $callback); break; } default: { + $this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData); break; } } diff --git a/application/FML/Controls/Audio.php b/application/core/FML/Controls/Audio.php similarity index 100% rename from application/FML/Controls/Audio.php rename to application/core/FML/Controls/Audio.php diff --git a/application/FML/Controls/Control.php b/application/core/FML/Controls/Control.php similarity index 100% rename from application/FML/Controls/Control.php rename to application/core/FML/Controls/Control.php diff --git a/application/FML/Controls/Entry.php b/application/core/FML/Controls/Entry.php similarity index 100% rename from application/FML/Controls/Entry.php rename to application/core/FML/Controls/Entry.php diff --git a/application/FML/Controls/FileEntry.php b/application/core/FML/Controls/FileEntry.php similarity index 100% rename from application/FML/Controls/FileEntry.php rename to application/core/FML/Controls/FileEntry.php diff --git a/application/FML/Controls/Frame.php b/application/core/FML/Controls/Frame.php similarity index 100% rename from application/FML/Controls/Frame.php rename to application/core/FML/Controls/Frame.php diff --git a/application/FML/Controls/Frame3d.php b/application/core/FML/Controls/Frame3d.php similarity index 100% rename from application/FML/Controls/Frame3d.php rename to application/core/FML/Controls/Frame3d.php diff --git a/application/FML/Controls/Gauge.php b/application/core/FML/Controls/Gauge.php similarity index 100% rename from application/FML/Controls/Gauge.php rename to application/core/FML/Controls/Gauge.php diff --git a/application/FML/Controls/Label.php b/application/core/FML/Controls/Label.php similarity index 100% rename from application/FML/Controls/Label.php rename to application/core/FML/Controls/Label.php diff --git a/application/FML/Controls/Labels/Label_Button.php b/application/core/FML/Controls/Labels/Label_Button.php similarity index 100% rename from application/FML/Controls/Labels/Label_Button.php rename to application/core/FML/Controls/Labels/Label_Button.php diff --git a/application/FML/Controls/Labels/Label_Text.php b/application/core/FML/Controls/Labels/Label_Text.php similarity index 100% rename from application/FML/Controls/Labels/Label_Text.php rename to application/core/FML/Controls/Labels/Label_Text.php diff --git a/application/FML/Controls/Quad.php b/application/core/FML/Controls/Quad.php similarity index 100% rename from application/FML/Controls/Quad.php rename to application/core/FML/Controls/Quad.php diff --git a/application/FML/Controls/Quads/Quad_321Go.php b/application/core/FML/Controls/Quads/Quad_321Go.php similarity index 100% rename from application/FML/Controls/Quads/Quad_321Go.php rename to application/core/FML/Controls/Quads/Quad_321Go.php diff --git a/application/FML/Controls/Quads/Quad_BgRaceScore2.php b/application/core/FML/Controls/Quads/Quad_BgRaceScore2.php similarity index 100% rename from application/FML/Controls/Quads/Quad_BgRaceScore2.php rename to application/core/FML/Controls/Quads/Quad_BgRaceScore2.php diff --git a/application/FML/Controls/Quads/Quad_Bgs1.php b/application/core/FML/Controls/Quads/Quad_Bgs1.php similarity index 100% rename from application/FML/Controls/Quads/Quad_Bgs1.php rename to application/core/FML/Controls/Quads/Quad_Bgs1.php diff --git a/application/FML/Controls/Quads/Quad_Bgs1InRace.php b/application/core/FML/Controls/Quads/Quad_Bgs1InRace.php similarity index 100% rename from application/FML/Controls/Quads/Quad_Bgs1InRace.php rename to application/core/FML/Controls/Quads/Quad_Bgs1InRace.php diff --git a/application/FML/Controls/Quads/Quad_BgsChallengeMedals.php b/application/core/FML/Controls/Quads/Quad_BgsChallengeMedals.php similarity index 100% rename from application/FML/Controls/Quads/Quad_BgsChallengeMedals.php rename to application/core/FML/Controls/Quads/Quad_BgsChallengeMedals.php diff --git a/application/FML/Controls/Quads/Quad_BgsPlayerCard.php b/application/core/FML/Controls/Quads/Quad_BgsPlayerCard.php similarity index 100% rename from application/FML/Controls/Quads/Quad_BgsPlayerCard.php rename to application/core/FML/Controls/Quads/Quad_BgsPlayerCard.php diff --git a/application/FML/Controls/Quads/Quad_Copilot.php b/application/core/FML/Controls/Quads/Quad_Copilot.php similarity index 100% rename from application/FML/Controls/Quads/Quad_Copilot.php rename to application/core/FML/Controls/Quads/Quad_Copilot.php diff --git a/application/FML/Controls/Quads/Quad_Emblems.php b/application/core/FML/Controls/Quads/Quad_Emblems.php similarity index 100% rename from application/FML/Controls/Quads/Quad_Emblems.php rename to application/core/FML/Controls/Quads/Quad_Emblems.php diff --git a/application/FML/Controls/Quads/Quad_EnergyBar.php b/application/core/FML/Controls/Quads/Quad_EnergyBar.php similarity index 100% rename from application/FML/Controls/Quads/Quad_EnergyBar.php rename to application/core/FML/Controls/Quads/Quad_EnergyBar.php diff --git a/application/FML/Controls/Quads/Quad_Hud3dEchelons.php b/application/core/FML/Controls/Quads/Quad_Hud3dEchelons.php similarity index 100% rename from application/FML/Controls/Quads/Quad_Hud3dEchelons.php rename to application/core/FML/Controls/Quads/Quad_Hud3dEchelons.php diff --git a/application/FML/Controls/Quads/Quad_Icons128x128_1.php b/application/core/FML/Controls/Quads/Quad_Icons128x128_1.php similarity index 100% rename from application/FML/Controls/Quads/Quad_Icons128x128_1.php rename to application/core/FML/Controls/Quads/Quad_Icons128x128_1.php diff --git a/application/FML/Controls/Quads/Quad_Icons128x128_Blink.php b/application/core/FML/Controls/Quads/Quad_Icons128x128_Blink.php similarity index 100% rename from application/FML/Controls/Quads/Quad_Icons128x128_Blink.php rename to application/core/FML/Controls/Quads/Quad_Icons128x128_Blink.php diff --git a/application/FML/Controls/Quads/Quad_Icons128x32_1.php b/application/core/FML/Controls/Quads/Quad_Icons128x32_1.php similarity index 100% rename from application/FML/Controls/Quads/Quad_Icons128x32_1.php rename to application/core/FML/Controls/Quads/Quad_Icons128x32_1.php diff --git a/application/FML/Controls/Quads/Quad_Icons64x64_1.php b/application/core/FML/Controls/Quads/Quad_Icons64x64_1.php similarity index 100% rename from application/FML/Controls/Quads/Quad_Icons64x64_1.php rename to application/core/FML/Controls/Quads/Quad_Icons64x64_1.php diff --git a/application/FML/Controls/Quads/Quad_Icons64x64_2.php b/application/core/FML/Controls/Quads/Quad_Icons64x64_2.php similarity index 100% rename from application/FML/Controls/Quads/Quad_Icons64x64_2.php rename to application/core/FML/Controls/Quads/Quad_Icons64x64_2.php diff --git a/application/FML/Controls/Quads/Quad_ManiaPlanetLogos.php b/application/core/FML/Controls/Quads/Quad_ManiaPlanetLogos.php similarity index 100% rename from application/FML/Controls/Quads/Quad_ManiaPlanetLogos.php rename to application/core/FML/Controls/Quads/Quad_ManiaPlanetLogos.php diff --git a/application/FML/Controls/Quads/Quad_ManiaplanetSystem.php b/application/core/FML/Controls/Quads/Quad_ManiaplanetSystem.php similarity index 100% rename from application/FML/Controls/Quads/Quad_ManiaplanetSystem.php rename to application/core/FML/Controls/Quads/Quad_ManiaplanetSystem.php diff --git a/application/FML/Controls/Quads/Quad_MedalsBig.php b/application/core/FML/Controls/Quads/Quad_MedalsBig.php similarity index 100% rename from application/FML/Controls/Quads/Quad_MedalsBig.php rename to application/core/FML/Controls/Quads/Quad_MedalsBig.php diff --git a/application/FML/Controls/Quads/Quad_TitleLogos.php b/application/core/FML/Controls/Quads/Quad_TitleLogos.php similarity index 100% rename from application/FML/Controls/Quads/Quad_TitleLogos.php rename to application/core/FML/Controls/Quads/Quad_TitleLogos.php diff --git a/application/FML/Controls/Quads/Quad_UIConstruction_Buttons.php b/application/core/FML/Controls/Quads/Quad_UIConstruction_Buttons.php similarity index 100% rename from application/FML/Controls/Quads/Quad_UIConstruction_Buttons.php rename to application/core/FML/Controls/Quads/Quad_UIConstruction_Buttons.php diff --git a/application/FML/Controls/Quads/Quad_UiSMSpectatorScoreBig.php b/application/core/FML/Controls/Quads/Quad_UiSMSpectatorScoreBig.php similarity index 100% rename from application/FML/Controls/Quads/Quad_UiSMSpectatorScoreBig.php rename to application/core/FML/Controls/Quads/Quad_UiSMSpectatorScoreBig.php diff --git a/application/FML/Controls/Video.php b/application/core/FML/Controls/Video.php similarity index 100% rename from application/FML/Controls/Video.php rename to application/core/FML/Controls/Video.php diff --git a/application/FML/Elements/Format.php b/application/core/FML/Elements/Format.php similarity index 100% rename from application/FML/Elements/Format.php rename to application/core/FML/Elements/Format.php diff --git a/application/FML/Elements/Including.php b/application/core/FML/Elements/Including.php similarity index 100% rename from application/FML/Elements/Including.php rename to application/core/FML/Elements/Including.php diff --git a/application/FML/Elements/Music.php b/application/core/FML/Elements/Music.php similarity index 100% rename from application/FML/Elements/Music.php rename to application/core/FML/Elements/Music.php diff --git a/application/FML/Elements/SimpleScript.php b/application/core/FML/Elements/SimpleScript.php similarity index 100% rename from application/FML/Elements/SimpleScript.php rename to application/core/FML/Elements/SimpleScript.php diff --git a/application/FML/ManiaLink.php b/application/core/FML/ManiaLink.php similarity index 100% rename from application/FML/ManiaLink.php rename to application/core/FML/ManiaLink.php diff --git a/application/FML/Script/Script.php b/application/core/FML/Script/Script.php similarity index 100% rename from application/FML/Script/Script.php rename to application/core/FML/Script/Script.php diff --git a/application/FML/Script/ScriptFeature.php b/application/core/FML/Script/ScriptFeature.php similarity index 100% rename from application/FML/Script/ScriptFeature.php rename to application/core/FML/Script/ScriptFeature.php diff --git a/application/FML/Script/Sections/Constants.php b/application/core/FML/Script/Sections/Constants.php similarity index 100% rename from application/FML/Script/Sections/Constants.php rename to application/core/FML/Script/Sections/Constants.php diff --git a/application/FML/Script/Sections/Functions.php b/application/core/FML/Script/Sections/Functions.php similarity index 100% rename from application/FML/Script/Sections/Functions.php rename to application/core/FML/Script/Sections/Functions.php diff --git a/application/FML/Script/Sections/Globals.php b/application/core/FML/Script/Sections/Globals.php similarity index 100% rename from application/FML/Script/Sections/Globals.php rename to application/core/FML/Script/Sections/Globals.php diff --git a/application/FML/Script/Sections/Includes.php b/application/core/FML/Script/Sections/Includes.php similarity index 100% rename from application/FML/Script/Sections/Includes.php rename to application/core/FML/Script/Sections/Includes.php diff --git a/application/FML/Script/Sections/Labels.php b/application/core/FML/Script/Sections/Labels.php similarity index 100% rename from application/FML/Script/Sections/Labels.php rename to application/core/FML/Script/Sections/Labels.php diff --git a/application/FML/Script/Templates/Main.txt b/application/core/FML/Script/Templates/Main.txt similarity index 100% rename from application/FML/Script/Templates/Main.txt rename to application/core/FML/Script/Templates/Main.txt diff --git a/application/FML/Script/Templates/TooltipMouseOut.txt b/application/core/FML/Script/Templates/TooltipMouseOut.txt similarity index 100% rename from application/FML/Script/Templates/TooltipMouseOut.txt rename to application/core/FML/Script/Templates/TooltipMouseOut.txt diff --git a/application/FML/Script/Templates/TooltipMouseOver.txt b/application/core/FML/Script/Templates/TooltipMouseOver.txt similarity index 100% rename from application/FML/Script/Templates/TooltipMouseOver.txt rename to application/core/FML/Script/Templates/TooltipMouseOver.txt diff --git a/application/FML/Script/Tooltips.php b/application/core/FML/Script/Tooltips.php similarity index 100% rename from application/FML/Script/Tooltips.php rename to application/core/FML/Script/Tooltips.php diff --git a/application/FML/Types/BgColorable.php b/application/core/FML/Types/BgColorable.php similarity index 100% rename from application/FML/Types/BgColorable.php rename to application/core/FML/Types/BgColorable.php diff --git a/application/FML/Types/Container.php b/application/core/FML/Types/Container.php similarity index 100% rename from application/FML/Types/Container.php rename to application/core/FML/Types/Container.php diff --git a/application/FML/Types/Linkable.php b/application/core/FML/Types/Linkable.php similarity index 100% rename from application/FML/Types/Linkable.php rename to application/core/FML/Types/Linkable.php diff --git a/application/FML/Types/NewLineable.php b/application/core/FML/Types/NewLineable.php similarity index 100% rename from application/FML/Types/NewLineable.php rename to application/core/FML/Types/NewLineable.php diff --git a/application/FML/Types/Playable.php b/application/core/FML/Types/Playable.php similarity index 100% rename from application/FML/Types/Playable.php rename to application/core/FML/Types/Playable.php diff --git a/application/FML/Types/Renderable.php b/application/core/FML/Types/Renderable.php similarity index 100% rename from application/FML/Types/Renderable.php rename to application/core/FML/Types/Renderable.php diff --git a/application/FML/Types/Scriptable.php b/application/core/FML/Types/Scriptable.php similarity index 100% rename from application/FML/Types/Scriptable.php rename to application/core/FML/Types/Scriptable.php diff --git a/application/FML/Types/Styleable.php b/application/core/FML/Types/Styleable.php similarity index 100% rename from application/FML/Types/Styleable.php rename to application/core/FML/Types/Styleable.php diff --git a/application/FML/Types/SubStyleable.php b/application/core/FML/Types/SubStyleable.php similarity index 100% rename from application/FML/Types/SubStyleable.php rename to application/core/FML/Types/SubStyleable.php diff --git a/application/FML/Types/TextFormatable.php b/application/core/FML/Types/TextFormatable.php similarity index 100% rename from application/FML/Types/TextFormatable.php rename to application/core/FML/Types/TextFormatable.php diff --git a/application/FML/autoload.php b/application/core/FML/autoload.php similarity index 100% rename from application/FML/autoload.php rename to application/core/FML/autoload.php diff --git a/application/core/Manialinks/ManialinkUtil.php b/application/core/Manialinks/ManialinkUtil.php index 60ceb938..f9baf239 100644 --- a/application/core/Manialinks/ManialinkUtil.php +++ b/application/core/Manialinks/ManialinkUtil.php @@ -2,7 +2,7 @@ namespace ManiaControl\Manialinks; -require_once __DIR__ . '/../../FML/autoload.php'; +require_once __DIR__ . '/../FML/autoload.php'; /** * Manialink utility class diff --git a/application/core/Maps/Map.php b/application/core/Maps/Map.php index 98d380d5..dcf05393 100644 --- a/application/core/Maps/Map.php +++ b/application/core/Maps/Map.php @@ -23,6 +23,7 @@ class Map { public $copperPrice = 0; public $mapType = ''; public $mapStyle = ''; + public $nbCheckpoints = -1; public $mx = null; public $authorLogin = ''; public $authorNick = ''; @@ -60,6 +61,7 @@ class Map { $this->copperPrice = $rpc_infos['CopperPrice']; $this->mapType = $rpc_infos['MapType']; $this->mapStyle = $rpc_infos['MapStyle']; + $this->nbCheckpoints = $rpc_infos['NbCheckpoints']; $mapsDirectory = $this->maniaControl->server->getMapsDirectory(); if ($this->maniaControl->server->checkAccess($mapsDirectory)) { diff --git a/application/plugins/DonationPlugin.php b/application/plugins/Donations.php similarity index 100% rename from application/plugins/DonationPlugin.php rename to application/plugins/Donations.php diff --git a/application/plugins/Endurance.php b/application/plugins/Endurance.php new file mode 100644 index 00000000..835c082e --- /dev/null +++ b/application/plugins/Endurance.php @@ -0,0 +1,94 @@ +maniaControl = $maniaControl; + + // Plugin information + $this->name = 'Endurance Plugin'; + $this->version = self::VERSION; + $this->author = 'steeffeen'; + $this->description = "Plugin enabling Support for the TM Game Mode 'Endurance' by TGYoshi."; + + // Register for callbacks + $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'callback_OnInit'); + $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'callback_BeginMap'); + $this->maniaControl->callbackManager->registerScriptCallbackListener(self::CB_CHECKPOINT, $this, 'callback_Checkpoint'); + } + + /** + * Handle ManiaControl OnInit callback + * + * @param array $callback + */ + public function callback_OnInit(array $callback) { + $this->currentMap = $this->maniaControl->mapManager->getCurrentMap(); + $this->playerLapTimes = array(); + } + + /** + * Handle BeginMap callback + * + * @param array $callback + */ + public function callback_BeginMap(array $callback) { + $this->currentMap = $this->maniaControl->mapManager->getCurrentMap(); + $this->playerLapTimes = array(); + } + + /** + * Handle Endurance Checkpoint callback + * + * @param array $callback + */ + public function callback_Checkpoint(array $callback) { + $callbackData = json_decode($callback[1]); + if ($callbackData->Checkpoint % $this->currentMap->nbCheckpoints != 0) { + return; + } + $player = $this->maniaControl->playerManager->getPlayer($callbackData->Login); + if (!$player) { + return; + } + $time = $callbackData->Time; + if ($time <= 0) { + return; + } + if (isset($this->playerLapTimes[$player->login])) { + $time -= $this->playerLapTimes[$player->login]; + } + $this->playerLapTimes[$player->login] = $callbackData->Time; + // Trigger trackmania player finish callback + $finishCallback = array($player->pid, $player->login, $time); + $finishCallback = array(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback); + $this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback); + } +} + +?>