added records support to obstacle plugin

This commit is contained in:
Steffen Schröder 2013-12-03 18:39:23 +01:00
parent a0d8f4f0a4
commit ad6574b523

View File

@ -1,6 +1,8 @@
<?php <?php
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
@ -10,12 +12,15 @@ use ManiaControl\Plugins\Plugin;
* *
* @author steeffeen * @author steeffeen
*/ */
class ObstaclePlugin extends Plugin implements CommandListener { class ObstaclePlugin extends Plugin implements CallbackListener, CommandListener {
/** /**
* Constants * Constants
*/ */
const CB_JUMPTO = 'Obstacle.JumpTo';
const VERSION = '1.0'; const VERSION = '1.0';
const CB_JUMPTO = 'Obstacle.JumpTo';
const SCB_ONFINISH = 'OnFinish';
const SCB_ONCHECKPOINT = 'OnCheckpoint';
const SETTING_JUMPTOAUTHLEVEL = 'Authentication level for JumpTo commands';
/** /**
* Create new obstacle plugin * Create new obstacle plugin
@ -29,8 +34,16 @@ class ObstaclePlugin extends Plugin implements CommandListener {
$this->author = 'steeffeen'; $this->author = 'steeffeen';
$this->description = 'Plugin offering various Commands for the ShootMania Obstacle Game Mode.'; $this->description = 'Plugin offering various Commands for the ShootMania Obstacle Game Mode.';
// Register for jump command // Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_JUMPTOAUTHLEVEL,
AuthenticationManager::AUTH_LEVEL_OPERATOR);
// Register for commands
$this->maniaControl->commandManager->registerCommandListener('jumpto', $this, 'command_JumpTo'); $this->maniaControl->commandManager->registerCommandListener('jumpto', $this, 'command_JumpTo');
// Register for callbacks
$this->maniaControl->callbackManager->registerScriptCallbackListener(self::SCB_ONFINISH, $this, 'callback_OnFinish');
$this->maniaControl->callbackManager->registerScriptCallbackListener(self::SCB_ONCHECKPOINT, $this, 'callback_OnCheckpoint');
} }
/** /**
@ -40,8 +53,8 @@ class ObstaclePlugin extends Plugin implements CommandListener {
* @return bool * @return bool
*/ */
public function command_JumpTo(array $chatCallback, Player $player) { public function command_JumpTo(array $chatCallback, Player $player) {
// $rightLevel = $authLevel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_JUMPTOAUTHLEVEL);
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) { if (!$this->maniaControl->authenticationManager->checkRight($player, $authLevel)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return false; return false;
} }
@ -53,6 +66,42 @@ class ObstaclePlugin extends Plugin implements CommandListener {
} }
return true; return true;
} }
/**
* 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);
}
} }
?> ?>