definiations of permission levels

This commit is contained in:
kremsy 2014-01-09 18:45:39 +01:00
parent 6e4cf32a16
commit 4ab7f8ff49
4 changed files with 88 additions and 52 deletions

View File

@ -2,7 +2,6 @@
namespace ManiaControl\Admin;
use ManiaControl\FileUtil;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
@ -18,18 +17,18 @@ class AuthenticationManager {
/**
* Constants
*/
const AUTH_LEVEL_PLAYER = 0;
const AUTH_LEVEL_MODERATOR = 1;
const AUTH_LEVEL_ADMIN = 2;
const AUTH_LEVEL_SUPERADMIN = 3;
const AUTH_LEVEL_PLAYER = 0;
const AUTH_LEVEL_MODERATOR = 1;
const AUTH_LEVEL_ADMIN = 2;
const AUTH_LEVEL_SUPERADMIN = 3;
const AUTH_LEVEL_MASTERADMIN = 4;
const CB_AUTH_LEVEL_CHANGED = 'AuthenticationManager.AuthLevelChanged';
const CB_AUTH_LEVEL_CHANGED = 'AuthenticationManager.AuthLevelChanged';
/**
* Public Properties
*/
public $authCommands = null;
/**
* Private Properties
*/
@ -43,10 +42,11 @@ class AuthenticationManager {
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->updateMasterAdmins();
$this->authCommands = new AuthCommands($maniaControl);
}
/**
* Set MasterAdmins
*
@ -54,28 +54,28 @@ class AuthenticationManager {
*/
private function updateMasterAdmins() {
$mysqli = $this->maniaControl->database->mysqli;
// Remove all MasterAdmins
$adminQuery = "UPDATE `" . PlayerManager::TABLE_PLAYERS . "`
$adminQuery = "UPDATE `" . PlayerManager::TABLE_PLAYERS . "`
SET `authLevel` = ?
WHERE `authLevel` = ?;";
$adminStatement = $mysqli->prepare($adminQuery);
if ($mysqli->error) {
if($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR);
return false;
}
$adminLevel = self::AUTH_LEVEL_SUPERADMIN;
$adminLevel = self::AUTH_LEVEL_SUPERADMIN;
$masterAdminLevel = self::AUTH_LEVEL_MASTERADMIN;
$adminStatement->bind_param('ii', $adminLevel, $masterAdminLevel);
$adminStatement->execute();
if ($adminStatement->error) {
if($adminStatement->error) {
trigger_error($adminStatement->error);
}
$adminStatement->close();
// Set MasterAdmins
$masterAdmins = $this->maniaControl->config->masteradmins->xpath('login');
$adminQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
$masterAdmins = $this->maniaControl->config->masteradmins->xpath('login');
$adminQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
`login`,
`authLevel`
) VALUES (
@ -83,16 +83,16 @@ class AuthenticationManager {
) ON DUPLICATE KEY UPDATE
`authLevel` = VALUES(`authLevel`);";
$adminStatement = $mysqli->prepare($adminQuery);
if ($mysqli->error) {
if($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR);
return false;
}
$adminStatement->bind_param('si', $login, $masterAdminLevel);
$success = true;
foreach ($masterAdmins as $masterAdmin) {
$login = (string) $masterAdmin;
foreach($masterAdmins as $masterAdmin) {
$login = (string)$masterAdmin;
$adminStatement->execute();
if ($adminStatement->error) {
if($adminStatement->error) {
trigger_error($adminStatement->error);
$success = false;
}
@ -105,16 +105,20 @@ class AuthenticationManager {
* Grant the Auth Level to the Player
*
* @param Player $player
* @param int $authLevel
* @param int $authLevel
* @return bool
*/
public function grantAuthLevel(Player &$player, $authLevel) {
if (!$player || !is_numeric($authLevel)) return false;
$authLevel = (int) $authLevel;
if ($authLevel >= self::AUTH_LEVEL_MASTERADMIN) return false;
$mysqli = $this->maniaControl->database->mysqli;
$authQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
if(!$player || !is_numeric($authLevel)) {
return false;
}
$authLevel = (int)$authLevel;
if($authLevel >= self::AUTH_LEVEL_MASTERADMIN) {
return false;
}
$mysqli = $this->maniaControl->database->mysqli;
$authQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
`login`,
`authLevel`
) VALUES (
@ -122,22 +126,22 @@ class AuthenticationManager {
) ON DUPLICATE KEY UPDATE
`authLevel` = VALUES(`authLevel`);";
$authStatement = $mysqli->prepare($authQuery);
if ($mysqli->error) {
if($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR);
return false;
}
$authStatement->bind_param('si', $player->login, $authLevel);
$authStatement->execute();
if ($authStatement->error) {
if($authStatement->error) {
trigger_error($authStatement->error);
$authStatement->close();
return false;
}
$authStatement->close();
$player->authLevel = $authLevel;
$this->maniaControl->callbackManager->triggerCallback(self::CB_AUTH_LEVEL_CHANGED, array(self::CB_AUTH_LEVEL_CHANGED, $player));
return true;
}
@ -148,7 +152,9 @@ class AuthenticationManager {
* @return bool
*/
public function sendNotAllowed(Player $player) {
if (!$player) return false;
if(!$player) {
return false;
}
return $this->maniaControl->chat->sendError('You do not have the required Rights to perform this Command!', $player->login);
}
@ -156,13 +162,36 @@ class AuthenticationManager {
* Check if the Player has enough Rights
*
* @param Player $player
* @param int $neededAuthLevel
* @param int $neededAuthLevel
* @return bool
*/
public static function checkRight(Player $player, $neededAuthLevel) {
return ($player->authLevel >= $neededAuthLevel);
}
/**
* Checks the permission by a right name
*
* @param Player $player
* @param $rightName
* @return bool
*/
public function checkPermission(Player $player, $rightName) {
$right = $this->maniaControl->settingManager->getSetting($this, $rightName);
return $this->checkRight($player, $right);
}
/**
* Defines a Minimum Right Level needed for an action
*
* @param $rightName
* @param $authLevelNeeded
*/
public function definePermissionLevel($rightName, $authLevelNeeded) {
$this->maniaControl->settingManager->initSetting($this, $rightName, $authLevelNeeded);
}
/**
* Get Name of the Authentication Level from Level Int
*
@ -170,16 +199,16 @@ class AuthenticationManager {
* @return string
*/
public static function getAuthLevelName($authLevelInt) {
if ($authLevelInt == self::AUTH_LEVEL_MASTERADMIN) {
if($authLevelInt == self::AUTH_LEVEL_MASTERADMIN) {
return 'MasterAdmin';
}
if ($authLevelInt == self::AUTH_LEVEL_SUPERADMIN) {
if($authLevelInt == self::AUTH_LEVEL_SUPERADMIN) {
return 'SuperAdmin';
}
if ($authLevelInt == self::AUTH_LEVEL_ADMIN) {
if($authLevelInt == self::AUTH_LEVEL_ADMIN) {
return 'Admin';
}
if ($authLevelInt == self::AUTH_LEVEL_MODERATOR) {
if($authLevelInt == self::AUTH_LEVEL_MODERATOR) {
return 'Moderator';
}
return 'Player';
@ -192,16 +221,16 @@ class AuthenticationManager {
* @return string
*/
public static function getAuthLevelAbbreviation($authLevelInt) {
if ($authLevelInt == self::AUTH_LEVEL_MASTERADMIN) {
if($authLevelInt == self::AUTH_LEVEL_MASTERADMIN) {
return 'MA';
}
if ($authLevelInt == self::AUTH_LEVEL_SUPERADMIN) {
if($authLevelInt == self::AUTH_LEVEL_SUPERADMIN) {
return 'SA';
}
if ($authLevelInt == self::AUTH_LEVEL_ADMIN) {
if($authLevelInt == self::AUTH_LEVEL_ADMIN) {
return 'AD';
}
if ($authLevelInt == self::AUTH_LEVEL_MODERATOR) {
if($authLevelInt == self::AUTH_LEVEL_MODERATOR) {
return 'MOD';
}
return 'PL';
@ -215,16 +244,16 @@ class AuthenticationManager {
*/
public static function getAuthLevel($authLevelName) {
$authLevelName = strtolower($authLevelName);
if ($authLevelName == 'MasterAdmin') {
if($authLevelName == 'MasterAdmin') {
return self::AUTH_LEVEL_MASTERADMIN;
}
if ($authLevelName == 'SuperAdmin') {
if($authLevelName == 'SuperAdmin') {
return self::AUTH_LEVEL_SUPERADMIN;
}
if ($authLevelName == 'Admin') {
if($authLevelName == 'Admin') {
return self::AUTH_LEVEL_ADMIN;
}
if ($authLevelName == 'Moderator') {
if($authLevelName == 'Moderator') {
return self::AUTH_LEVEL_MODERATOR;
}
return self::AUTH_LEVEL_PLAYER;

View File

@ -140,7 +140,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
// Pagers
// Config
$pagerSize = 6.;
$pagesId = 'MapListPages';
$pagesId = 'MxListPages';
$pagerPrev = new Quad_Icons64x64_1();
$frame->add($pagerPrev);
@ -184,7 +184,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$i = 0;
$y -= 10;
$pageFrames = array();
foreach($maps as $map) { //TODO pagers, order possabilities
foreach($maps as $map) { //TODO order possabilities
if(!isset($pageFrame)) {
$pageFrame = new Frame();
$frame->add($pageFrame);
@ -372,7 +372,6 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$maniaLink->setScript($script);
// Pagers
// Config
$pagerSize = 6.;
$pagesId = 'MapListPages';

View File

@ -2,6 +2,7 @@
namespace ManiaControl\Maps;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\FileUtil;
@ -21,9 +22,11 @@ class MapManager implements CallbackListener {
/**
* Constants
*/
const TABLE_MAPS = 'mc_maps';
const CB_MAPS_UPDATED = 'MapManager.MapsUpdated';
const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated';
const TABLE_MAPS = 'mc_maps';
const CB_MAPS_UPDATED = 'MapManager.MapsUpdated';
const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated';
const SETTING_PERMISSION_ADD_MAP = 'Add Maps';
const SETTING_PERMISSION_REMOVE_MAP = 'Remove Maps';
/**
* Public Properties
@ -60,6 +63,10 @@ class MapManager implements CallbackListener {
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'handleBeginMap');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_MAPLISTMODIFIED, $this, 'mapsModified');
//Define Rights
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_ADD_MAP,AuthenticationManager::AUTH_LEVEL_ADMIN);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_REMOVE_MAP,AuthenticationManager::AUTH_LEVEL_ADMIN);
}
/**

View File

@ -17,6 +17,7 @@ class SettingManager {
const TYPE_REAL = 'real';
const TYPE_BOOL = 'bool';
const TYPE_ARRAY = 'array';
//const TYPE_AUTH_LEVEL = 'auth'; //TODO
/**
* Private properties