2013-11-25 00:19:37 +01:00
|
|
|
<?php
|
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use ManiaControl\Admin\AuthenticationManager;
|
2013-12-03 18:39:23 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2013-11-25 02:01:15 +01:00
|
|
|
use ManiaControl\Commands\CommandListener;
|
2013-11-25 00:19:37 +01:00
|
|
|
use ManiaControl\Players\Player;
|
|
|
|
use ManiaControl\Plugins\Plugin;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ManiaControl Obstacle Plugin
|
|
|
|
*
|
|
|
|
* @author steeffeen
|
|
|
|
*/
|
2013-12-03 18:39:23 +01:00
|
|
|
class ObstaclePlugin extends Plugin implements CallbackListener, CommandListener {
|
2013-11-25 00:19:37 +01:00
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
const VERSION = '1.0';
|
2013-12-03 18:39:23 +01:00
|
|
|
const CB_JUMPTO = 'Obstacle.JumpTo';
|
|
|
|
const SCB_ONFINISH = 'OnFinish';
|
|
|
|
const SCB_ONCHECKPOINT = 'OnCheckpoint';
|
|
|
|
const SETTING_JUMPTOAUTHLEVEL = 'Authentication level for JumpTo commands';
|
2013-11-25 00:19:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create new obstacle plugin
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
|
|
|
// Plugin details
|
2013-12-03 18:50:30 +01:00
|
|
|
self::$name = 'Obstacle Plugin';
|
|
|
|
self::$version = self::VERSION;
|
|
|
|
self::$author = 'steeffeen';
|
|
|
|
self::$description = 'Plugin offering various Commands for the ShootMania Obstacle Game Mode.';
|
2013-11-25 00:19:37 +01:00
|
|
|
|
2013-12-03 18:39:23 +01:00
|
|
|
// Init settings
|
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_JUMPTOAUTHLEVEL,
|
|
|
|
AuthenticationManager::AUTH_LEVEL_OPERATOR);
|
|
|
|
|
|
|
|
// Register for commands
|
2013-11-25 00:19:37 +01:00
|
|
|
$this->maniaControl->commandManager->registerCommandListener('jumpto', $this, 'command_JumpTo');
|
2013-12-03 18:39:23 +01:00
|
|
|
|
|
|
|
// Register for callbacks
|
|
|
|
$this->maniaControl->callbackManager->registerScriptCallbackListener(self::SCB_ONFINISH, $this, 'callback_OnFinish');
|
|
|
|
$this->maniaControl->callbackManager->registerScriptCallbackListener(self::SCB_ONCHECKPOINT, $this, 'callback_OnCheckpoint');
|
2013-11-25 00:19:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle JumpTo command
|
|
|
|
*
|
|
|
|
* @param array $chatCallback
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function command_JumpTo(array $chatCallback, Player $player) {
|
2013-12-03 18:39:23 +01:00
|
|
|
$authLevel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_JUMPTOAUTHLEVEL);
|
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, $authLevel)) {
|
2013-11-25 00:19:37 +01:00
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Send jump callback
|
|
|
|
$params = explode(' ', $chatCallback[1][2], 2);
|
|
|
|
$param = $player->login . ";" . $params[1] . ";";
|
|
|
|
if (!$this->maniaControl->client->query('TriggerModeScriptEvent', self::CB_JUMPTO, $param)) {
|
|
|
|
trigger_error("Couldn't send jump callback for '{$player->login}'. " . $this->maniaControl->getClientErrorText());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-03 18:39:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle OnFinish script callback
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function callback_OnFinish(array $callback) {
|
|
|
|
$data = json_decode($callback[1]);
|
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($data->Player->Login);
|
|
|
|
if (!$player) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$time = $data->Run->Time;
|
|
|
|
// Trigger trackmania player finish callback
|
|
|
|
$finishCallback = array($player->pid, $player->login, $time);
|
|
|
|
$finishCallback = array(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback);
|
|
|
|
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle OnCheckpoint script callback
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function callback_OnCheckpoint(array $callback) {
|
|
|
|
$data = json_decode($callback[1]);
|
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($data->Player->Login);
|
|
|
|
if (!$player) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$time = $data->Run->Time;
|
|
|
|
// Trigger trackmania player finish callback
|
|
|
|
$finishCallback = array($player->pid, $player->login, $time);
|
|
|
|
$finishCallback = array(CallbackManager::CB_TM_PLAYERCHECKPOINT, $finishCallback);
|
|
|
|
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERCHECKPOINT, $finishCallback);
|
|
|
|
}
|
2013-11-25 00:19:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|