- added auth level util methods

- added obstacle plugin
This commit is contained in:
Steffen Schröder 2013-11-25 00:19:37 +01:00
parent 835744b0e6
commit c8d879fe60
2 changed files with 102 additions and 0 deletions

View File

@ -190,6 +190,51 @@ class AuthenticationManager implements CommandListener {
}
return ($player->authLevel >= $neededAuthLevel);
}
/**
* Get Name of the Authentication Level from Level Int
*
* @param int $authLevelInt
* @return string
*/
public static function getAuthLevelName($authLevelInt) {
if ($authLevelInt == self::AUTH_LEVEL_MASTERADMIN) {
return 'MasterAdmin';
}
if ($authLevelInt == self::AUTH_LEVEL_SUPERADMIN) {
return 'SuperAdmin';
}
if ($authLevelInt == self::AUTH_LEVEL_ADMIN) {
return 'Admin';
}
if ($authLevelInt == self::AUTH_LEVEL_OPERATOR) {
return 'Operator';
}
return 'Player';
}
/**
* Get Authentication Level Int from Level Name
*
* @param string $authLevelName
* @return int
*/
public static function getAuthLevel($authLevelName) {
$authLevelName = strtolower($authLevelName);
if ($authLevelName == 'MasterAdmin') {
return self::AUTH_LEVEL_MASTERADMIN;
}
if ($authLevelName == 'SuperAdmin') {
return self::AUTH_LEVEL_SUPERADMIN;
}
if ($authLevelName == 'Admin') {
return self::AUTH_LEVEL_ADMIN;
}
if ($authLevelName == 'Operator') {
return self::AUTH_LEVEL_OPERATOR;
}
return self::AUTH_LEVEL_PLAYER;
}
}
?>

View File

@ -0,0 +1,57 @@
<?php
use ManiaControl\ManiaControl;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Players\Player;
use ManiaControl\Plugins\Plugin;
/**
* ManiaControl Obstacle Plugin
*
* @author steeffeen
*/
class ObstaclePlugin extends Plugin {
/**
* Constants
*/
const CB_JUMPTO = 'Obstacle.JumpTo';
const VERSION = '1.0';
/**
* Create new obstacle plugin
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
// Plugin details
$this->name = 'Obstacle Plugin';
$this->version = self::VERSION;
$this->author = 'steeffeen';
$this->description = 'Plugin offering various Commands for the ShootMania Obstacle Game Mode.';
// Register for jump command
$this->maniaControl->commandManager->registerCommandListener('jumpto', $this, 'command_JumpTo');
}
/**
* Handle JumpTo command
*
* @param array $chatCallback
* @return bool
*/
public function command_JumpTo(array $chatCallback, Player $player) {
// $rightLevel =
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
$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;
}
}
?>