callbacks improvement

This commit is contained in:
kremsy 2014-04-24 23:11:09 +02:00 committed by Steffen Schröder
parent 2ff970101d
commit a3040125e9
4 changed files with 90 additions and 18 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
namespace ManiaControl\Callbacks; namespace ManiaControl\Callbacks;
//TODO method class for all the libxmlrpc get Methods, to fetch the callback asnyc
/** /**
* Callbacks Interface * Callbacks Interface
* *
@ -9,6 +9,7 @@ namespace ManiaControl\Callbacks;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
interface Callbacks { interface Callbacks {
//Common Callbacks
const SCRIPTCALLBACK = 'Callbacks.ScriptCallback'; const SCRIPTCALLBACK = 'Callbacks.ScriptCallback';
/** BeginMatch Callback, param1 MatchNumber */ /** BeginMatch Callback, param1 MatchNumber */
const BEGINMATCH = "Callbacks.BeginMatch"; const BEGINMATCH = "Callbacks.BeginMatch";
@ -36,4 +37,21 @@ interface Callbacks {
const BEGINWARMUP = "Callbacks.BeginWarmUp"; const BEGINWARMUP = "Callbacks.BeginWarmUp";
/** EndWarmup Callback, no parameters */ /** EndWarmup Callback, no parameters */
const ENDWARMUP = "Callbacks.EndWarmUp"; const ENDWARMUP = "Callbacks.EndWarmUp";
/** PlayerRanking callback, returned after LibXmlRpc_PlayerRanking
* try to avoid to use this, just use the Get function of the RankingsManager instead
* param1 Player $player
* param2 int $rank
* param3 int $currentPoints
* param4 int AFKStatus */
const PLAYERRANKING = 'Callbacks.PlayerRanking';
//Shootmania Callbacks
/** RankingsUpdated Callback, param1 Sorted Rankings */
const RANKINGSUPDATED = 'Callbacks.RankingsUpdated';
/** RankingsUpdated Callback, returned after LibXmlRpc_PlayerRanking param1 Scores */
const SCORES = 'Callbacks.Scores';
/** Returns the AFKStatus of an Player, returned after param1 Scores */ //returned after TODO
const AFKSTATUS = 'Callbacks.AfkStatus';
/** Returns if the GameMode has Warmup aktivated, returned after param1 Scores */ //returned after TODO
const WARMUPSTATUS = 'Callbacks.WarmupStatus';
} }

View File

@ -21,6 +21,12 @@ class LibXmlRpcCallbackManager implements CallbackListener {
$callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallbacks'); $callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallbacks');
} }
/**
* Handle Script Callbacks
*
* @param $name
* @param $data
*/
public function handleScriptCallbacks($name, $data) { public function handleScriptCallbacks($name, $data) {
switch($name) { switch($name) {
case 'LibXmlRpc_BeginMatch': case 'LibXmlRpc_BeginMatch':
@ -61,6 +67,19 @@ class LibXmlRpcCallbackManager implements CallbackListener {
case 'LibXmlRpc_EndWarmUp': case 'LibXmlRpc_EndWarmUp':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDWARMUP); $this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDWARMUP);
break; 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]);
}
} }

View File

@ -34,10 +34,41 @@ class ShootManiaCallbacks implements CallbackListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Register for script callbacks // 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_ONCHECKPOINT, $this, 'callback_TimeAttack_OnCheckpoint');
$callbackManager->registerScriptCallbackListener(self::SCB_TIMEATTACK_ONFINISH, $this, 'callback_TimeAttack_OnFinish'); $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 * Handle TimeAttack OnCheckpoint Script Callback
* *

View File

@ -4,16 +4,16 @@ namespace ManiaControl\Server;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException; use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
/** /**
* Class managing Rankings * Class managing Rankings
* *
* @author kremsy * @author kremsy
* @copyright ManiaControl Copyright © 2014 ManiaControl Team * @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 { class RankingManager implements CallbackListener {
/* /*
@ -21,15 +21,6 @@ class RankingManager implements CallbackListener {
*/ */
private $rankings = array(); private $rankings = array();
/**
* Get Rankings
*
* @return mixed
*/
public function getRankings() {
return $this->rankings;
}
/** /**
* Construct player manager * Construct player manager
* *
@ -46,7 +37,7 @@ class RankingManager implements CallbackListener {
} }
/** /**
* Initialize the Rankings * Initialize the Rankings (never call this Method)
*/ */
public function onInit() { public function onInit() {
try { 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 * @param array $callback
*/ */
@ -66,7 +66,6 @@ class RankingManager implements CallbackListener {
//TODO not tested in TrackMania //TODO not tested in TrackMania
switch($callbackName) { switch($callbackName) {
case 'LibXmlRpc_Rankings':
case 'updateRankings': case 'updateRankings':
$this->updateRankings($callback[1][1][0]); $this->updateRankings($callback[1][1][0]);
break; break;
@ -80,11 +79,11 @@ class RankingManager implements CallbackListener {
} }
/** /**
* Update Game Rankings * Update Game Rankings (never call this Method)
* *
* @param $data * @param $data
*/ */
private function updateRankings($data) { public function updateRankings($data) {
if (!is_string($data)) { if (!is_string($data)) {
return; return;
} }
@ -99,6 +98,7 @@ class RankingManager implements CallbackListener {
array_multisort($this->rankings, SORT_DESC, SORT_NUMERIC); array_multisort($this->rankings, SORT_DESC, SORT_NUMERIC);
//TODO if Local Records activated-> sort asc //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; return null;
} }
public function getPlayerRanking() {
//TODO complete this
}
} }