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

@ -118,8 +118,8 @@ class CallbackManager {
*/
public function unregisterCallbackListener(CallbackListener $listener) {
$removed = false;
foreach ($this->callbackListeners as &$listeners) {
foreach ($listeners as $key => &$listenerCallback) {
foreach($this->callbackListeners as &$listeners) {
foreach($listeners as $key => &$listenerCallback) {
if ($listenerCallback[0] != $listener) {
continue;
}
@ -138,8 +138,8 @@ class CallbackManager {
*/
public function unregisterScriptCallbackListener(CallbackListener $listener) {
$removed = false;
foreach ($this->scriptCallbackListener as &$listeners) {
foreach ($listeners as $key => &$listenerCallback) {
foreach($this->scriptCallbackListener as &$listeners) {
foreach($listeners as $key => &$listenerCallback) {
if ($listenerCallback[0] != $listener) {
continue;
}
@ -161,7 +161,7 @@ class CallbackManager {
}
$params = func_get_args();
$params = array_slice($params, 1, count($params), true);
foreach ($this->callbackListeners[$callbackName] as $listener) {
foreach($this->callbackListeners[$callbackName] as $listener) {
call_user_func_array(array($listener[0], $listener[1]), $params);
}
}
@ -177,7 +177,7 @@ class CallbackManager {
}
$params = func_get_args();
$params = array_slice($params, 1, count($params), true);
foreach ($this->scriptCallbackListener[$callbackName] as $listener) {
foreach($this->scriptCallbackListener[$callbackName] as $listener) {
call_user_func_array(array($listener[0], $listener[1]), $params);
}
}
@ -197,7 +197,7 @@ class CallbackManager {
$callbacks = $this->maniaControl->client->executeCallbacks();
// Handle callbacks
foreach ($callbacks as $callback) {
foreach($callbacks as $callback) {
$this->handleCallback($callback);
}
}
@ -209,7 +209,7 @@ class CallbackManager {
*/
private function handleCallback(array $callback) {
$callbackName = $callback[0];
switch ($callbackName) {
switch($callbackName) {
case 'ManiaPlanet.BeginMatch':
if ($this->maniaControl->mapManager->getCurrentMap()->getGame() == 'sm') {
$this->triggerCallback($callbackName, $callback);
@ -251,6 +251,6 @@ class CallbackManager {
$scriptCallbackData = $callback[1];
$scriptCallbackName = $scriptCallbackData[0];
$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
*/
interface Callbacks {
const ScriptCallback = 'Callbacks.ScriptCallback';
/** BeginMatch Callback, param1 MapNumber */
const BeginMatch = "Callbacks.BeginMatch";
/** LoadingMap Callback, param1 MapNumber */
const LoadingMap = "Callbacks.LoadingMap";
/** BeginMap Callback, param1 MapNumber */
const BeginMap = "Callbacks.BeginMap";
const SCRIPTCALLBACK = 'Callbacks.ScriptCallback';
/** BeginMatch Callback, param1 MatchNumber */
const BEGINMATCH = "Callbacks.BeginMatch";
/** LoadingMap Callback, Number of Map */
const LOADINGMAP = "Callbacks.LoadingMap";
/** BeginMap Callback, triggered by MapManager, param1 Map Object */
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,51 +1,66 @@
<?php
/**
* Created by PhpStorm.
* User: Lukas
* Date: 24.04.14
* Time: 16:57
*/
namespace ManiaControl\Callbacks;
use ManiaControl\ManiaControl;
class LibXmlRpcCallbackManager implements CallbackListener{
class LibXmlRpcCallbackManager implements CallbackListener {
/*
* Private Properties
*/
private $maniaControl = null;
/**
* Create a new ShootMania Callbacks Instance
* Create a new LibXmlRpc Callbacks Instance
*
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
$this->maniaControl = $maniaControl;
$callbackManager->registerCallbackListener(Callbacks::ScriptCallback, $this, 'handleScriptCallbacks');
$callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallbacks');
}
public function handleScriptCallbacks($name, $data){
switch($name){
public function handleScriptCallbacks($name, $data) {
switch($name) {
case 'LibXmlRpc_BeginMatch':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BeginMatch, $data[0]);
$this->maniaControl->callbackManager->triggerCallback(Callbacks::BEGINMATCH, $data[0]);
break;
case 'LibXmlRpc_LoadingMap':
$this->maniaControl->callbackManager->triggerCallback(Callbacks::LoadingMap, $data[0]);
$this->maniaControl->callbackManager->triggerCallback(Callbacks::LOADINGMAP, $data[0]);
break;
case 'BeginMap':
case 'LibXmlRpc_BeginMap':
//$this->maniaControl->callbackManager->triggerCallback(Callbacks::BeginMap, $data[0]);
$this->maniaControl->mapManager->handleScriptBeginMap($data[0]);
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
*/
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_ONRESTART = 'TimeAttack_OnRestart';
const SCB_TIMEATTACK_ONCHECKPOINT = 'TimeAttack_OnCheckpoint';
@ -38,33 +34,10 @@ class ShootManiaCallbacks implements CallbackListener {
$this->maniaControl = $maniaControl;
// 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_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
*
@ -72,15 +45,14 @@ class ShootManiaCallbacks implements CallbackListener {
*/
public function callback_TimeAttack_OnCheckpoint(array $callback) {
$login = $callback[1][0];
$time = (int) $callback[1][1];
$time = (int)$callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login);
if (!$player || $time <= 0) {
return;
}
// Trigger trackmania player checkpoint callback
$checkpointCallback = array($player->pid, $player->login, $time, 0, 0);
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERCHECKPOINT,
array(CallbackManager::CB_TM_PLAYERCHECKPOINT, $checkpointCallback));
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERCHECKPOINT, array(CallbackManager::CB_TM_PLAYERCHECKPOINT, $checkpointCallback));
}
/**
@ -90,14 +62,13 @@ class ShootManiaCallbacks implements CallbackListener {
*/
public function callback_TimeAttack_OnFinish(array $callback) {
$login = $callback[1][0];
$time = (int) $callback[1][1];
$time = (int)$callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login);
if (!$player || $time <= 0) {
return;
}
// Trigger trackmania player finish callback
$finishCallback = array($player->pid, $player->login, $time);
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERFINISH,
array(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback));
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERFINISH, array(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback));
}
}

View File

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