2014-03-19 21:58:11 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Callbacks;
|
|
|
|
|
2014-05-24 17:22:48 +02:00
|
|
|
use ManiaControl\Callbacks\Models\RecordCallback;
|
2014-03-19 21:58:11 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class handling and parsing ShootMania Callbacks
|
|
|
|
*
|
2014-05-02 17:50:30 +02:00
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
|
|
|
* @copyright 2014 ManiaControl Team
|
2014-04-24 21:55:47 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-03-19 21:58:11 +01:00
|
|
|
*/
|
|
|
|
class ShootManiaCallbacks implements CallbackListener {
|
|
|
|
/*
|
|
|
|
* Constants
|
|
|
|
*/
|
2014-05-24 17:22:48 +02:00
|
|
|
const CB_TIMEATTACK_ONSTART = 'TimeAttack_OnStart';
|
|
|
|
const CB_TIMEATTACK_ONRESTART = 'TimeAttack_OnRestart';
|
|
|
|
const CB_TIMEATTACK_ONCHECKPOINT = 'TimeAttack_OnCheckpoint';
|
|
|
|
const CB_TIMEATTACK_ONFINISH = 'TimeAttack_OnFinish';
|
2014-04-24 21:55:47 +02:00
|
|
|
|
2014-03-19 21:58:11 +01:00
|
|
|
/*
|
2014-04-12 12:14:37 +02:00
|
|
|
* Private Properties
|
2014-03-19 21:58:11 +01:00
|
|
|
*/
|
|
|
|
private $maniaControl = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new ShootMania Callbacks Instance
|
|
|
|
*
|
2014-05-02 17:50:30 +02:00
|
|
|
* @param ManiaControl $maniaControl
|
2014-05-02 16:13:45 +02:00
|
|
|
* @param CallbackManager $callbackManager
|
2014-03-19 21:58:11 +01:00
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl, CallbackManager $callbackManager) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2014-04-24 21:55:47 +02:00
|
|
|
|
2014-03-19 21:58:11 +01:00
|
|
|
// Register for script callbacks
|
2014-04-24 23:11:09 +02:00
|
|
|
$callbackManager->registerCallbackListener(Callbacks::SCRIPTCALLBACK, $this, 'handleScriptCallbacks');
|
2014-03-19 21:58:11 +01:00
|
|
|
}
|
|
|
|
|
2014-04-24 23:11:09 +02:00
|
|
|
/**
|
|
|
|
* Handle Script Callbacks
|
|
|
|
*
|
2014-05-02 17:50:30 +02:00
|
|
|
* @param string $name
|
2014-05-13 01:18:47 +02:00
|
|
|
* @param mixed $data
|
2014-04-24 23:11:09 +02:00
|
|
|
*/
|
|
|
|
public function handleScriptCallbacks($name, $data) {
|
2014-05-02 17:50:30 +02:00
|
|
|
switch ($name) {
|
2014-04-24 23:11:09 +02:00
|
|
|
case 'LibXmlRpc_Rankings':
|
|
|
|
$this->maniaControl->server->rankingManager->updateRankings($data[0]);
|
|
|
|
break;
|
|
|
|
case 'LibXmlRpc_Scores':
|
2014-05-24 17:22:48 +02:00
|
|
|
$this->maniaControl->callbackManager->triggerCallback(Callbacks::SCORES, $data[0]);
|
2014-04-24 23:11:09 +02:00
|
|
|
break;
|
|
|
|
case 'LibAFK_IsAFK':
|
|
|
|
$this->triggerAfkStatus($data[0]);
|
|
|
|
break;
|
2014-07-04 18:25:09 +02:00
|
|
|
case 'WarmUp_Status':
|
|
|
|
$this->maniaControl->callbackManager->triggerCallback(Callbacks::WARMUPSTATUS, $data[0]);
|
|
|
|
break;
|
2014-05-24 17:22:48 +02:00
|
|
|
case self::CB_TIMEATTACK_ONCHECKPOINT:
|
|
|
|
$this->handleTimeAttackOnCheckpoint($name, $data);
|
|
|
|
break;
|
|
|
|
case self::CB_TIMEATTACK_ONFINISH:
|
|
|
|
$this->handleTimeAttackOnFinish($name, $data);
|
|
|
|
break;
|
2014-04-24 23:11:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggers the AFK Status of an Player
|
|
|
|
*
|
2014-05-02 17:50:30 +02:00
|
|
|
* @param string $login
|
2014-04-24 23:11:09 +02:00
|
|
|
*/
|
|
|
|
private function triggerAfkStatus($login) {
|
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
|
|
$this->maniaControl->callbackManager->triggerCallback(Callbacks::AFKSTATUS, $player);
|
|
|
|
}
|
|
|
|
|
2014-03-19 21:58:11 +01:00
|
|
|
/**
|
2014-05-24 17:22:48 +02:00
|
|
|
* Handle TimeAttack OnCheckpoint Callback
|
2014-03-19 21:58:11 +01:00
|
|
|
*
|
2014-05-24 17:22:48 +02:00
|
|
|
* @param string $name
|
|
|
|
* @param array $data
|
2014-03-19 21:58:11 +01:00
|
|
|
*/
|
2014-05-24 17:22:48 +02:00
|
|
|
public function handleTimeAttackOnCheckpoint($name, array $data) {
|
|
|
|
$login = $data[0];
|
2014-03-19 21:58:11 +01:00
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
2014-05-24 17:22:48 +02:00
|
|
|
if (!$player) {
|
2014-03-19 21:58:11 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-05-24 17:22:48 +02:00
|
|
|
|
|
|
|
// Trigger checkpoint callback
|
|
|
|
$checkpointCallback = new RecordCallback();
|
|
|
|
$checkpointCallback->rawCallback = array($name, $data);
|
|
|
|
$checkpointCallback->name = $checkpointCallback::CHECKPOINT;
|
|
|
|
$checkpointCallback->setPlayer($player);
|
|
|
|
$checkpointCallback->time = (int)$data[1];
|
|
|
|
|
|
|
|
$this->maniaControl->callbackManager->triggerCallback($checkpointCallback);
|
2014-03-19 21:58:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-24 17:22:48 +02:00
|
|
|
* Handle TimeAttack OnFinish Callback
|
2014-03-19 21:58:11 +01:00
|
|
|
*
|
2014-05-24 17:22:48 +02:00
|
|
|
* @param string $name
|
|
|
|
* @param array $data
|
2014-03-19 21:58:11 +01:00
|
|
|
*/
|
2014-05-24 17:22:48 +02:00
|
|
|
public function handleTimeAttackOnFinish($name, array $data) {
|
|
|
|
$login = $data[0];
|
2014-03-19 21:58:11 +01:00
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
2014-05-24 17:22:48 +02:00
|
|
|
if (!$player) {
|
2014-03-19 21:58:11 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-05-24 17:22:48 +02:00
|
|
|
|
|
|
|
// Trigger finish callback
|
|
|
|
$finishCallback = new RecordCallback();
|
|
|
|
$finishCallback->rawCallback = array($name, $data);
|
|
|
|
$finishCallback->name = $finishCallback::FINISH;
|
|
|
|
$finishCallback->setPlayer($player);
|
|
|
|
$finishCallback->time = (int)$data[1];
|
|
|
|
|
|
|
|
$this->maniaControl->callbackManager->triggerCallback($finishCallback);
|
2014-03-19 21:58:11 +01:00
|
|
|
}
|
|
|
|
}
|