From a3040125e9309213a74e659224ee0ecdb05ff5ab Mon Sep 17 00:00:00 2001 From: kremsy Date: Thu, 24 Apr 2014 23:11:09 +0200 Subject: [PATCH] callbacks improvement --- application/core/Callbacks/Callbacks.php | 20 +++++++++- .../Callbacks/LibXmlRpcCallbackManager.php | 19 ++++++++++ .../core/Callbacks/ShootManiaCallbacks.php | 31 +++++++++++++++ application/core/Server/RankingManager.php | 38 ++++++++++--------- 4 files changed, 90 insertions(+), 18 deletions(-) diff --git a/application/core/Callbacks/Callbacks.php b/application/core/Callbacks/Callbacks.php index aab87a9f..2792223e 100644 --- a/application/core/Callbacks/Callbacks.php +++ b/application/core/Callbacks/Callbacks.php @@ -1,6 +1,6 @@ registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallbacks'); } + /** + * Handle Script Callbacks + * + * @param $name + * @param $data + */ public function handleScriptCallbacks($name, $data) { switch($name) { case 'LibXmlRpc_BeginMatch': @@ -61,6 +67,19 @@ class LibXmlRpcCallbackManager implements CallbackListener { case 'LibXmlRpc_EndWarmUp': $this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDWARMUP); break; + case 'LibXmlRpc_PlayerRanking': //TODO really useful? what does it have what RankingsManager not have? + $this->triggerPlayerRanking($data[0]); + break; } } + + /** + * Triggers the Ranking of a Player + * + * @param $data + */ + private function triggerPlayerRanking($data) { + $player = $this->maniaControl->playerManager->getPlayer($data[1]); + $this->maniaControl->callbackManager->triggerCallback(Callbacks::PLAYERRANKING, $player, $data[0], $data[6], $data[5]); + } } \ No newline at end of file diff --git a/application/core/Callbacks/ShootManiaCallbacks.php b/application/core/Callbacks/ShootManiaCallbacks.php index 685db2f0..d820e17d 100644 --- a/application/core/Callbacks/ShootManiaCallbacks.php +++ b/application/core/Callbacks/ShootManiaCallbacks.php @@ -34,10 +34,41 @@ class ShootManiaCallbacks implements CallbackListener { $this->maniaControl = $maniaControl; // Register for script callbacks + $callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallbacks'); $callbackManager->registerScriptCallbackListener(self::SCB_TIMEATTACK_ONCHECKPOINT, $this, 'callback_TimeAttack_OnCheckpoint'); $callbackManager->registerScriptCallbackListener(self::SCB_TIMEATTACK_ONFINISH, $this, 'callback_TimeAttack_OnFinish'); } + /** + * Handle Script Callbacks + * + * @param $name + * @param $data + */ + public function handleScriptCallbacks($name, $data) { + switch($name) { + case 'LibXmlRpc_Rankings': + $this->maniaControl->server->rankingManager->updateRankings($data[0]); + break; + case 'LibXmlRpc_Scores': + $this->maniaControl->callbackManager->triggerCallback(Callbacks::AFKSTATUS, $data[0]); + break; + case 'LibAFK_IsAFK': + $this->triggerAfkStatus($data[0]); + break; + } + } + + /** + * Triggers the AFK Status of an Player + * + * @param $login + */ + private function triggerAfkStatus($login) { + $player = $this->maniaControl->playerManager->getPlayer($login); + $this->maniaControl->callbackManager->triggerCallback(Callbacks::AFKSTATUS, $player); + } + /** * Handle TimeAttack OnCheckpoint Script Callback * diff --git a/application/core/Server/RankingManager.php b/application/core/Server/RankingManager.php index 767a7bd3..3c854f24 100644 --- a/application/core/Server/RankingManager.php +++ b/application/core/Server/RankingManager.php @@ -4,16 +4,16 @@ namespace ManiaControl\Server; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackManager; +use ManiaControl\Callbacks\Callbacks; use ManiaControl\ManiaControl; -use Maniaplanet\DedicatedServer\Xmlrpc\Exception; use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException; /** * Class managing Rankings * - * @author kremsy + * @author kremsy * @copyright ManiaControl Copyright © 2014 ManiaControl Team - * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ class RankingManager implements CallbackListener { /* @@ -21,15 +21,6 @@ class RankingManager implements CallbackListener { */ private $rankings = array(); - /** - * Get Rankings - * - * @return mixed - */ - public function getRankings() { - return $this->rankings; - } - /** * Construct player manager * @@ -46,7 +37,7 @@ class RankingManager implements CallbackListener { } /** - * Initialize the Rankings + * Initialize the Rankings (never call this Method) */ public function onInit() { try { @@ -55,9 +46,18 @@ class RankingManager implements CallbackListener { } } + /** + * Get Rankings + * + * @return array + */ + public function getRankings() { + return $this->rankings; + } + /** - * Handle stats on callbacks + * Handle stats on callbacks (never call this Method) * * @param array $callback */ @@ -66,7 +66,6 @@ class RankingManager implements CallbackListener { //TODO not tested in TrackMania switch($callbackName) { - case 'LibXmlRpc_Rankings': case 'updateRankings': $this->updateRankings($callback[1][1][0]); break; @@ -80,11 +79,11 @@ class RankingManager implements CallbackListener { } /** - * Update Game Rankings + * Update Game Rankings (never call this Method) * * @param $data */ - private function updateRankings($data) { + public function updateRankings($data) { if (!is_string($data)) { return; } @@ -99,6 +98,7 @@ class RankingManager implements CallbackListener { array_multisort($this->rankings, SORT_DESC, SORT_NUMERIC); //TODO if Local Records activated-> sort asc + $this->maniaControl->callbackManager->triggerCallback(Callbacks::RANKINGSUPDATED, $this->getRankings()); } /** @@ -118,4 +118,8 @@ class RankingManager implements CallbackListener { } return null; } + + public function getPlayerRanking() { + //TODO complete this + } } \ No newline at end of file