- extra shootmania callback class for parsing script callbacks
- timeattack local records support
This commit is contained in:
parent
06907825ed
commit
87549fdf9b
@ -43,8 +43,13 @@ class CallbackManager {
|
||||
const CB_TM_PLAYERFINISH = 'TrackMania.PlayerFinish';
|
||||
const CB_TM_PLAYERINCOHERENCE = 'TrackMania.PlayerIncoherence';
|
||||
|
||||
/**
|
||||
* Private Properties
|
||||
/*
|
||||
* Public proeprties
|
||||
*/
|
||||
public $shootManiaCallbacks = null;
|
||||
|
||||
/*
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $callbackListeners = array();
|
||||
@ -57,6 +62,8 @@ class CallbackManager {
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
$this->shootManiaCallbacks = new ShootManiaCallbacks($maniaControl, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,6 +194,16 @@ class CallbackManager {
|
||||
|
||||
// Handle callbacks
|
||||
foreach ($callbacks as $callback) {
|
||||
$this->handleCallback($callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the given Callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
private function handleCallback(array $callback) {
|
||||
$callbackName = $callback[0];
|
||||
switch ($callbackName) {
|
||||
case 'ManiaPlanet.BeginMatch':
|
||||
@ -220,7 +237,6 @@ class CallbackManager {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the given Script Callback
|
||||
@ -230,20 +246,6 @@ class CallbackManager {
|
||||
private function handleScriptCallback(array $callback) {
|
||||
$scriptCallbackData = $callback[1];
|
||||
$scriptCallbackName = $scriptCallbackData[0];
|
||||
switch($scriptCallbackName) {
|
||||
case 'BeginMap':
|
||||
case 'LibXmlRpc_BeginMap':
|
||||
$this->maniaControl->mapManager->handleScriptBeginMap($callback);
|
||||
$this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData);
|
||||
break;
|
||||
case 'EndMap':
|
||||
case 'LibXmlRpc_EndMap':
|
||||
$this->maniaControl->mapManager->handleScriptEndMap($callback);
|
||||
$this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData);
|
||||
break;
|
||||
default:
|
||||
$this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
101
application/core/Callbacks/ShootManiaCallbacks.php
Normal file
101
application/core/Callbacks/ShootManiaCallbacks.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Callbacks;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Class handling and parsing ShootMania Callbacks
|
||||
*
|
||||
* @author steeffeen
|
||||
*/
|
||||
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';
|
||||
const SCB_TIMEATTACK_ONFINISH = 'TimeAttack_OnFinish';
|
||||
|
||||
/*
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Create a new ShootMania Callbacks Instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
|
||||
$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
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function callback_TimeAttack_OnCheckpoint(array $callback) {
|
||||
$login = $callback[1][0];
|
||||
$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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle TimeAttack OnFinish Script Callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function callback_TimeAttack_OnFinish(array $callback) {
|
||||
$login = $callback[1][0];
|
||||
$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));
|
||||
}
|
||||
}
|
@ -32,7 +32,6 @@ require_once __DIR__ . '/Libs/FML/autoload.php';
|
||||
require_once __DIR__ . '/Libs/Symfony/autoload.php';
|
||||
require_once __DIR__ . '/Libs/curl-easy/autoload.php';
|
||||
|
||||
|
||||
/**
|
||||
* ManiaControl Server Controller for ManiaPlanet Server
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user