2013-11-25 00:19:37 +01:00
|
|
|
<?php
|
2014-04-27 16:22:12 +02:00
|
|
|
|
|
|
|
namespace steeffeen;
|
|
|
|
|
2013-11-25 00:19:37 +01:00
|
|
|
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;
|
2014-02-13 14:21:25 +01:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
2013-11-25 00:19:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ManiaControl Obstacle Plugin
|
|
|
|
*
|
|
|
|
* @author steeffeen
|
|
|
|
*/
|
2013-12-03 22:21:17 +01:00
|
|
|
class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
2013-11-25 00:19:37 +01:00
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
2014-02-26 10:36:22 +01:00
|
|
|
const ID = 24;
|
2013-12-09 10:04:22 +01:00
|
|
|
const VERSION = 0.1;
|
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-12-14 23:29:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private Properties
|
|
|
|
*/
|
2014-03-19 22:07:05 +01:00
|
|
|
/**
|
|
|
|
* @var maniaControl $maniaControl
|
|
|
|
*/
|
2013-12-14 23:29:17 +01:00
|
|
|
private $maniaControl = null;
|
2013-11-25 00:19:37 +01:00
|
|
|
|
2014-01-27 20:39:10 +01:00
|
|
|
/**
|
|
|
|
* Prepares the Plugin
|
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public static function prepare(ManiaControl $maniaControl) {
|
2014-03-19 22:07:05 +01:00
|
|
|
// do nothing
|
2014-01-27 20:39:10 +01:00
|
|
|
}
|
|
|
|
|
2013-11-25 00:19:37 +01:00
|
|
|
/**
|
2013-12-14 23:29:17 +01:00
|
|
|
*
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::load()
|
2013-11-25 00:19:37 +01:00
|
|
|
*/
|
2013-12-14 23:29:17 +01:00
|
|
|
public function load(ManiaControl $maniaControl) {
|
2013-11-25 00:19:37 +01:00
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
2013-12-03 18:39:23 +01:00
|
|
|
// Init settings
|
2014-03-19 22:07:05 +01:00
|
|
|
$this->maniaControl->settingManager->initSetting($this, self::SETTING_JUMPTOAUTHLEVEL, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
2013-12-03 18:39:23 +01:00
|
|
|
|
|
|
|
// 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-12-14 23:29:17 +01:00
|
|
|
|
|
|
|
return true;
|
2013-11-25 00:19:37 +01:00
|
|
|
}
|
|
|
|
|
2013-12-14 23:29:17 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::unload()
|
|
|
|
*/
|
|
|
|
public function unload() {
|
|
|
|
$this->maniaControl->commandManager->unregisterCommandListener($this);
|
|
|
|
$this->maniaControl->callbackManager->unregisterScriptCallbackListener($this);
|
|
|
|
unset($this->maniaControl);
|
|
|
|
}
|
2013-12-09 10:04:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getId()
|
|
|
|
*/
|
|
|
|
public static function getId() {
|
|
|
|
return self::ID;
|
|
|
|
}
|
2013-12-14 23:29:17 +01:00
|
|
|
|
2013-12-03 22:21:17 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getName()
|
|
|
|
*/
|
|
|
|
public static function getName() {
|
|
|
|
return 'Obstacle Plugin';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getVersion()
|
|
|
|
*/
|
|
|
|
public static function getVersion() {
|
|
|
|
return self::VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getAuthor()
|
|
|
|
*/
|
|
|
|
public static function getAuthor() {
|
|
|
|
return 'steeffeen';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
|
|
|
*/
|
|
|
|
public static function getDescription() {
|
2014-02-26 10:36:22 +01:00
|
|
|
return "Plugin offering CP Jumping and Local Records Support for the ShootManie Gamemode 'Obstacle'.";
|
2013-12-03 22:21:17 +01:00
|
|
|
}
|
|
|
|
|
2013-11-25 00:19:37 +01:00
|
|
|
/**
|
|
|
|
* Handle JumpTo command
|
|
|
|
*
|
2014-03-19 22:07:05 +01:00
|
|
|
* @param array $chatCallback
|
|
|
|
* @param Player $player
|
2013-11-25 00:19:37 +01:00
|
|
|
* @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);
|
2013-12-03 22:21:17 +01:00
|
|
|
return;
|
2013-11-25 00:19:37 +01:00
|
|
|
}
|
|
|
|
// Send jump callback
|
|
|
|
$params = explode(' ', $chatCallback[1][2], 2);
|
|
|
|
$param = $player->login . ";" . $params[1] . ";";
|
2014-03-19 22:07:05 +01:00
|
|
|
try {
|
2014-02-08 15:00:21 +01:00
|
|
|
$this->maniaControl->client->triggerModeScriptEvent(self::CB_JUMPTO, $param);
|
2014-03-19 22:07:05 +01:00
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
2014-02-13 14:21:25 +01:00
|
|
|
if ($e->getMessage() == 'Not in script mode.') {
|
|
|
|
trigger_error("Couldn't send jump callback for '{$player->login}'. " . $e->getMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
throw $e;
|
2013-11-25 00:19:37 +01:00
|
|
|
}
|
|
|
|
}
|
2013-12-03 18:39:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle OnFinish script callback
|
|
|
|
*
|
2014-03-19 22:07:05 +01:00
|
|
|
* @param array $callback
|
2013-12-03 18:39:23 +01:00
|
|
|
*/
|
|
|
|
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);
|
2014-03-19 22:07:05 +01:00
|
|
|
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERFINISH,
|
|
|
|
array(CallbackManager::CB_TM_PLAYERFINISH, $finishCallback));
|
2013-12-03 18:39:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle OnCheckpoint script callback
|
|
|
|
*
|
2014-03-19 22:07:05 +01:00
|
|
|
* @param array $callback
|
2013-12-03 18:39:23 +01:00
|
|
|
*/
|
|
|
|
public function callback_OnCheckpoint(array $callback) {
|
|
|
|
$data = json_decode($callback[1]);
|
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($data->Player->Login);
|
2014-03-19 22:07:05 +01:00
|
|
|
$time = $data->Run->Time;
|
|
|
|
if (!$player || $time <= 0) {
|
2013-12-03 18:39:23 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-12-16 08:38:11 +01:00
|
|
|
// Trigger Trackmania player checkpoint callback
|
|
|
|
$checkpointCallback = array($player->pid, $player->login, $time, 0, 0);
|
2014-03-19 22:07:05 +01:00
|
|
|
$this->maniaControl->callbackManager->triggerCallback(CallbackManager::CB_TM_PLAYERCHECKPOINT,
|
|
|
|
array(CallbackManager::CB_TM_PLAYERCHECKPOINT, $checkpointCallback));
|
2013-12-03 18:39:23 +01:00
|
|
|
}
|
2013-11-25 00:19:37 +01:00
|
|
|
}
|