added trackmania switch case for callbacks

This commit is contained in:
kremsy 2017-03-25 13:44:03 +01:00
parent e8586586a3
commit 9a19691420
3 changed files with 37 additions and 11 deletions

View File

@ -80,6 +80,9 @@ interface Callbacks {
const SM_ONPLAYERTHROWSOBJECT = "Shootmania.Event.OnPlayerThrowsObject";
const SM_ONPLAYERREQUESTACTIONCHANGE = "Shootmania.Event.OnPlayerRequestActionChange";
const TM_EVENTDEFAULT = "Trackmania.Event.Default";
//ManiaControl Callbacks
/** BeginMap Callback: Map */
const BEGINMAP = 'Callbacks.BeginMap';

View File

@ -75,7 +75,6 @@ class ShootManiaCallbacks implements CallbackListener {
case Callbacks::SM_ONCAPTURE:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::SM_ONCAPTURE, new OnCaptureStructure($this->maniaControl, $data));
break;
break;
//Old Callbacks
case 'LibXmlRpc_Rankings':
$this->maniaControl->getServer()->getRankingManager()->updateRankings($data[0]);

View File

@ -3,6 +3,7 @@
namespace ManiaControl\Callbacks;
use ManiaControl\Callbacks\Models\RecordCallback;
use ManiaControl\Callbacks\Structures\Trackmania\DefaultEventStructure;
use ManiaControl\ManiaControl;
use ManiaControl\Utils\Formatter;
@ -29,12 +30,35 @@ class TrackManiaCallbacks implements CallbackListener {
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
$this->maniaControl = $maniaControl;
// Register for script callbacks
$callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallbacks');
// Register for callbacks
$callbackManager->registerCallbackListener(Callbacks::ONWAYPOINT, $this, 'handleOnWayPointCallback');
$callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this, 'handlePlayerCheckpointCallback');
$callbackManager->registerCallbackListener(CallbackManager::CB_TM_PLAYERFINISH, $this, 'handlePlayerFinishCallback');
}
/**
* Handle Script Callbacks
*
* @param string $name
* @param mixed $data
*/
public function handleScriptCallbacks($name, $data) {
if (!$this->maniaControl->getCallbackManager()->callbackListeningExists($name)) {
return;
}
switch ($name) {
//MP4 New Callbacks
case Callbacks::TM_EVENTDEFAULT:
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_EVENTDEFAULT, new DefaultEventStructure($this->maniaControl, $data));
break;
}
}
/**
* Handle OnWayPoint Callback
*
@ -52,11 +76,11 @@ class TrackManiaCallbacks implements CallbackListener {
$wayPointCallback->rawCallback = $callback;
$wayPointCallback->setPlayer($player);
$wayPointCallback->blockId = $callback[1];
$wayPointCallback->time = (int)$callback[2];
$wayPointCallback->checkpoint = (int)$callback[3];
$wayPointCallback->time = (int) $callback[2];
$wayPointCallback->checkpoint = (int) $callback[3];
$wayPointCallback->isEndRace = Formatter::parseBoolean($callback[4]);
$wayPointCallback->lapTime = (int)$callback[5];
$wayPointCallback->lapCheckpoint = (int)$callback[6];
$wayPointCallback->lapTime = (int) $callback[5];
$wayPointCallback->lapCheckpoint = (int) $callback[6];
$wayPointCallback->lap = 0;
$wayPointCallback->isEndLap = Formatter::parseBoolean($callback[7]);
@ -94,9 +118,9 @@ class TrackManiaCallbacks implements CallbackListener {
$checkpointCallback->isLegacyCallback = true;
$checkpointCallback->rawCallback = $callback;
$checkpointCallback->setPlayer($player);
$checkpointCallback->time = (int)$data[2];
$checkpointCallback->lap = (int)$data[3];
$checkpointCallback->checkpoint = (int)$data[4];
$checkpointCallback->time = (int) $data[2];
$checkpointCallback->lap = (int) $data[3];
$checkpointCallback->checkpoint = (int) $data[4];
$checkpointCallback->lapCheckpoint = $checkpointCallback->checkpoint;
if ($checkpointCallback->lap > 0) {
@ -132,7 +156,7 @@ class TrackManiaCallbacks implements CallbackListener {
$finishCallback->isLegacyCallback = true;
$finishCallback->rawCallback = $callback;
$finishCallback->setPlayer($player);
$finishCallback->time = (int)$data[2];
$finishCallback->time = (int) $data[2];
$this->maniaControl->getCallbackManager()->triggerCallback($finishCallback);
}