libxmlrpc callbacks

This commit is contained in:
kremsy 2014-04-24 21:55:47 +02:00 committed by Steffen Schröder
parent 8f1b5ae791
commit 335901edd8
5 changed files with 136 additions and 130 deletions

View File

@ -251,6 +251,6 @@ class CallbackManager {
$scriptCallbackData = $callback[1]; $scriptCallbackData = $callback[1];
$scriptCallbackName = $scriptCallbackData[0]; $scriptCallbackName = $scriptCallbackData[0];
$this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData); $this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData);
$this->triggerCallback(Callbacks::ScriptCallback, $scriptCallbackName, $scriptCallbackData[1]); $this->triggerCallback(Callbacks::SCRIPTCALLBACK, $scriptCallbackName, $scriptCallbackData[1]);
} }
} }

View File

@ -9,11 +9,31 @@ 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 {
const ScriptCallback = 'Callbacks.ScriptCallback'; const SCRIPTCALLBACK = 'Callbacks.ScriptCallback';
/** BeginMatch Callback, param1 MapNumber */ /** BeginMatch Callback, param1 MatchNumber */
const BeginMatch = "Callbacks.BeginMatch"; const BEGINMATCH = "Callbacks.BeginMatch";
/** LoadingMap Callback, param1 MapNumber */ /** LoadingMap Callback, Number of Map */
const LoadingMap = "Callbacks.LoadingMap"; const LOADINGMAP = "Callbacks.LoadingMap";
/** BeginMap Callback, param1 MapNumber */ /** BeginMap Callback, triggered by MapManager, param1 Map Object */
const BeginMap = "Callbacks.BeginMap"; const BEGINMAP = "Callbacks.BeginMap";
/** BeginSubMatch Callback, param1 Number of Submatch */
const BEGINSUBMATCH = "Callbacks.BeginSubmatch";
/** BeginRound Callback, param1 Number of Round */
const BEGINROUND = "Callbacks.BeginRound";
/** BeginTurn Callback, param1 Number of Turn */
const BEGINTURN = "Callbacks.BeginTurn";
/** EndTurn Callback, param1 Number of Turn */
const ENDTURN = "Callbacks.EndTurn";
/** EndRound Callback, param1 Number of Round */
const ENDROUND = "Callbacks.EndRound";
/** EndSubMatch Callback, param1 Number of Submatch */
const ENDSUBMATCH = "Callbacks.EndSubmatch";
/** BeginMap Callback, triggered by MapManager, param1 Map Object */
const ENDMAP = "Callbacks.EndMap";
/** EndMatch Callback, param1 MatchNumber */
const ENDMATCH = "Callbacks.EndMatch";
/** BeginWarmup Callback, no parameters */
const BEGINWARMUP = "Callbacks.BeginWarmUp";
/** EndWarmup Callback, no parameters */
const ENDWARMUP = "Callbacks.EndWarmUp";
} }

View File

@ -1,10 +1,4 @@
<?php <?php
/**
* Created by PhpStorm.
* User: Lukas
* Date: 24.04.14
* Time: 16:57
*/
namespace ManiaControl\Callbacks; namespace ManiaControl\Callbacks;
@ -18,34 +12,55 @@ class LibXmlRpcCallbackManager implements CallbackListener{
private $maniaControl = null; private $maniaControl = null;
/** /**
* Create a new ShootMania Callbacks Instance * Create a new LibXmlRpc Callbacks Instance
* *
* @param ManiaControl $maniaControl * @param ManiaControl $maniaControl
*/ */
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) { public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$callbackManager->registerCallbackListener(Callbacks::ScriptCallback, $this, 'handleScriptCallbacks'); $callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallbacks');
} }
public function handleScriptCallbacks($name, $data) { public function handleScriptCallbacks($name, $data) {
switch($name) { switch($name) {
case 'LibXmlRpc_BeginMatch': case 'LibXmlRpc_BeginMatch':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BeginMatch, $data[0]); $this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINMATCH, $data[0]);
break; break;
case 'LibXmlRpc_LoadingMap': case 'LibXmlRpc_LoadingMap':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::LoadingMap, $data[0]); $this->maniaControl->callbackManager->triggerCallback(Callbacks::LOADINGMAP, $data[0]);
break; break;
case 'BeginMap':
case 'LibXmlRpc_BeginMap': case 'LibXmlRpc_BeginMap':
//$this->maniaControl->callbackManager->triggerCallback(Callbacks::BeginMap, $data[0]);
$this->maniaControl->mapManager->handleScriptBeginMap($data[0]); $this->maniaControl->mapManager->handleScriptBeginMap($data[0]);
break; break;
case 'LibXmlRpc_BeginSubmatch':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINSUBMATCH, $data[0]);
break;
case 'LibXmlRpc_BeginTurn':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINTURN, $data[0]);
break;
case 'LibXmlRpc_EndTurn':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDTURN, $data[0]);
break;
case 'LibXmlRpc_EndRound':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDROUND, $data[0]);
break;
case 'LibXmlRpc_EndSubmatch':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDSUBMATCH, $data[0]);
break;
case 'EndMap':
case 'LibXmlRpc_EndMap':
$this->maniaControl->mapManager->handleScriptEndMap($data[0]);
break;
case 'LibXmlRpc_EndMatch':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDMATCH, $data[0]);
break;
case 'LibXmlRpc_BeginWarmUp':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINWARMUP);
break;
case 'LibXmlRpc_EndWarmUp':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDWARMUP);
break;
} }
var_dump($name);
var_dump($data);
} }
} }

View File

@ -15,10 +15,6 @@ class ShootManiaCallbacks implements CallbackListener {
/* /*
* Constants * Constants
*/ */
const SCB_LIBXMLRPC_BEGINMAP = 'LibXmlRpc_BeginMap';
const SCB_LIBXMLRPC_ENDMAP = 'LibXmlRpc_EndMap';
const SCB_OLD_BEGINMAP = 'BeginMap';
const SCB_OLD_ENDMAP = 'EndMap';
const SCB_TIMEATTACK_ONSTART = 'TimeAttack_OnStart'; const SCB_TIMEATTACK_ONSTART = 'TimeAttack_OnStart';
const SCB_TIMEATTACK_ONRESTART = 'TimeAttack_OnRestart'; const SCB_TIMEATTACK_ONRESTART = 'TimeAttack_OnRestart';
const SCB_TIMEATTACK_ONCHECKPOINT = 'TimeAttack_OnCheckpoint'; const SCB_TIMEATTACK_ONCHECKPOINT = 'TimeAttack_OnCheckpoint';
@ -38,33 +34,10 @@ class ShootManiaCallbacks implements CallbackListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Register for script callbacks // Register for script callbacks
$callbackManager->registerScriptCallbackListener(self::SCB_LIBXMLRPC_BEGINMAP, $this, 'callback_LibXmlRpc_BeginMap');
$callbackManager->registerScriptCallbackListener(self::SCB_OLD_BEGINMAP, $this, 'callback_LibXmlRpc_BeginMap');
$callbackManager->registerScriptCallbackListener(self::SCB_LIBXMLRPC_ENDMAP, $this, 'callback_LibXmlRpc_EndMap');
$callbackManager->registerScriptCallbackListener(self::SCB_OLD_ENDMAP, $this, 'callback_LibXmlRpc_EndMap');
$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 LibXmlRpc BeginMap Script Callback
*
* @param array $callback
*/
public function callback_LibXmlRpc_BeginMap(array $callback) {
$this->maniaControl->mapManager->handleScriptBeginMap($callback);
}
/**
* Handle LibXmlRpc EndMap Script Callback
*
* @param array $callback
*/
public function callback_LibXmlRpc_EndMap(array $callback) {
$this->maniaControl->mapManager->handleScriptEndMap($callback);
}
/** /**
* Handle TimeAttack OnCheckpoint Script Callback * Handle TimeAttack OnCheckpoint Script Callback
* *
@ -79,8 +52,7 @@ class ShootManiaCallbacks implements CallbackListener {
} }
// Trigger trackmania player checkpoint callback // Trigger trackmania player checkpoint callback
$checkpointCallback = array($player->pid, $player->login, $time, 0, 0); $checkpointCallback = array($player->pid, $player->login, $time, 0, 0);
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERCHECKPOINT, $this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERCHECKPOINT, array(CallbackManager::CB_TM_PLAYERCHECKPOINT, $checkpointCallback));
array(CallbackManager::CB_TM_PLAYERCHECKPOINT, $checkpointCallback));
} }
/** /**
@ -97,7 +69,6 @@ class ShootManiaCallbacks implements CallbackListener {
} }
// Trigger trackmania player finish callback // Trigger trackmania player finish callback
$finishCallback = array($player->pid, $player->login, $time); $finishCallback = array($player->pid, $player->login, $time);
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERFINISH, $this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERFINISH, array(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback));
array(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback));
} }
} }

View File

@ -5,6 +5,7 @@ namespace ManiaControl\Maps;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Files\FileUtil; use ManiaControl\Files\FileUtil;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\ManiaExchange\ManiaExchangeList; use ManiaControl\ManiaExchange\ManiaExchangeList;
@ -30,7 +31,9 @@ class MapManager implements CallbackListener {
* Constants * Constants
*/ */
const TABLE_MAPS = 'mc_maps'; const TABLE_MAPS = 'mc_maps';
/** @deprecated CB_BEGINMAP */
const CB_BEGINMAP = 'MapManager.BeginMap'; const CB_BEGINMAP = 'MapManager.BeginMap';
/** @deprecated CB_ENDMAP */
const CB_ENDMAP = 'MapManager.EndMap'; const CB_ENDMAP = 'MapManager.EndMap';
const CB_MAPS_UPDATED = 'MapManager.MapsUpdated'; const CB_MAPS_UPDATED = 'MapManager.MapsUpdated';
const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated'; const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated';
@ -503,16 +506,18 @@ class MapManager implements CallbackListener {
// Update the mx of the map (for update checks, etc.) // Update the mx of the map (for update checks, etc.)
$this->mxManager->fetchManiaExchangeMapInformations($this->currentMap); $this->mxManager->fetchManiaExchangeMapInformations($this->currentMap);
// Trigger own BeginMap callback // Trigger own BeginMap callback (
//TODO remove deprecated callback later
$this->maniaControl->callbackManager->triggerCallback(self::CB_BEGINMAP, $this->currentMap); $this->maniaControl->callbackManager->triggerCallback(self::CB_BEGINMAP, $this->currentMap);
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINMAP, $this->currentMap);
} }
/** /**
* Handle Script BeginMap callback * Handle Script BeginMap callback
* *
* @param array $callback * @param int $mapNumber
*/ */
public function handleScriptBeginMap(array $callback) { public function handleScriptBeginMap($mapNumber) {
$this->handleBeginMap(array()); $this->handleBeginMap(array());
} }
@ -530,22 +535,17 @@ class MapManager implements CallbackListener {
// Trigger own EndMap callback // Trigger own EndMap callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_ENDMAP, $this->currentMap); $this->maniaControl->callbackManager->triggerCallback(self::CB_ENDMAP, $this->currentMap);
//TODO remove deprecated callback later
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDMAP, $this->currentMap);
} }
/** /**
* Handle Script EndMap Callback * Handle Script EndMap Callback
* *
* @param array $callback * @param int $mapNumber
*/ */
public function handleScriptEndMap(array $callback) { public function handleScriptEndMap($mapNumber) {
if ($this->mapEnded) { $this->handleEndMap(array());
return;
}
$this->mapEnded = true;
$this->mapBegan = false;
// Trigger own EndMap callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_ENDMAP, $this->currentMap);
} }
/** /**