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
namespace ManiaControl\Callbacks;
//TODO method class for all the libxmlrpc get Methods, to fetch the callback asnyc
/**
* Callbacks Interface
*
@ -9,6 +9,7 @@ namespace ManiaControl\Callbacks;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
interface Callbacks {
//Common Callbacks
const SCRIPTCALLBACK = 'Callbacks.ScriptCallback';
/** BeginMatch Callback, param1 MatchNumber */
const BEGINMATCH = "Callbacks.BeginMatch";
@ -36,4 +37,21 @@ interface Callbacks {
const BEGINWARMUP = "Callbacks.BeginWarmUp";
/** EndWarmup Callback, no parameters */
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');
}
/**
* 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]);
}
}

View File

@ -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
*

View File

@ -4,8 +4,8 @@ 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;
/**
@ -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
}
}