fixed authentication manager

This commit is contained in:
Steffen Schröder 2014-01-09 22:13:25 +01:00
parent f9041748f6
commit 161ef44508

View File

@ -5,6 +5,8 @@ namespace ManiaControl\Admin;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
require_once __DIR__ . '/AuthCommands.php'; require_once __DIR__ . '/AuthCommands.php';
@ -13,7 +15,7 @@ require_once __DIR__ . '/AuthCommands.php';
* *
* @author steeffeen & kremsy * @author steeffeen & kremsy
*/ */
class AuthenticationManager { class AuthenticationManager implements CallbackListener {
/** /**
* Constants * Constants
*/ */
@ -35,20 +37,23 @@ class AuthenticationManager {
private $maniaControl = null; private $maniaControl = null;
/** /**
* Construct authentication manager * Construct a new Authentication Manager
* *
* @param \ManiaControl\ManiaControl $maniaControl * @param \ManiaControl\ManiaControl $maniaControl
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->updateMasterAdmins();
$this->authCommands = new AuthCommands($maniaControl); $this->authCommands = new AuthCommands($maniaControl);
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
} }
public function handleOnInit(array $callback) {
$this->updateMasterAdmins();
}
/** /**
* Set MasterAdmins * Update MasterAdmins based on config
* *
* @return bool * @return bool
*/ */
@ -109,13 +114,9 @@ class AuthenticationManager {
* @return bool * @return bool
*/ */
public function grantAuthLevel(Player &$player, $authLevel) { public function grantAuthLevel(Player &$player, $authLevel) {
if(!$player || !is_numeric($authLevel)) { if (!$player || !is_numeric($authLevel)) return false;
return false;
}
$authLevel = (int) $authLevel; $authLevel = (int) $authLevel;
if($authLevel >= self::AUTH_LEVEL_MASTERADMIN) { if ($authLevel >= self::AUTH_LEVEL_MASTERADMIN) return false;
return false;
}
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$authQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` ( $authQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
@ -152,9 +153,7 @@ class AuthenticationManager {
* @return bool * @return bool
*/ */
public function sendNotAllowed(Player $player) { public function sendNotAllowed(Player $player) {
if(!$player) { if (!$player) return false;
return false;
}
return $this->maniaControl->chat->sendError('You do not have the required Rights to perform this Command!', $player->login); return $this->maniaControl->chat->sendError('You do not have the required Rights to perform this Command!', $player->login);
} }
@ -191,7 +190,6 @@ class AuthenticationManager {
$this->maniaControl->settingManager->initSetting($this, $rightName, $authLevelNeeded); $this->maniaControl->settingManager->initSetting($this, $rightName, $authLevelNeeded);
} }
/** /**
* Get Name of the Authentication Level from Level Int * Get Name of the Authentication Level from Level Int
* *