applied common formatting

This commit is contained in:
Steffen Schröder 2014-05-02 17:31:10 +02:00
parent 3857f332f7
commit d52423b737
5 changed files with 393 additions and 378 deletions

View File

@ -3,6 +3,18 @@
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<option name="OTHER_INDENT_OPTIONS">
<value>
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="true" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
<option name="USE_RELATIVE_INDENTS" value="false" />
</value>
</option>
<PHPCodeStyleSettings>
<option name="ALIGN_PHPDOC_PARAM_NAMES" value="true" />
<option name="ALIGN_PHPDOC_COMMENTS" value="true" />
@ -16,6 +28,11 @@
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML>
<codeStyleSettings language="HTML">
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="PHP">
<option name="KEEP_LINE_BREAKS" value="false" />
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
@ -25,9 +42,10 @@
<option name="CLASS_BRACE_STYLE" value="1" />
<option name="METHOD_BRACE_STYLE" value="1" />
<option name="SPECIAL_ELSE_IF_TREATMENT" value="true" />
<option name="IF_BRACE_FORCE" value="1" />
<option name="DOWHILE_BRACE_FORCE" value="1" />
<option name="WHILE_BRACE_FORCE" value="1" />
<option name="IF_BRACE_FORCE" value="3" />
<option name="DOWHILE_BRACE_FORCE" value="3" />
<option name="WHILE_BRACE_FORCE" value="3" />
<option name="FOR_BRACE_FORCE" value="3" />
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
</indentOptions>

View File

@ -18,19 +18,19 @@ use ManiaControl\Players\PlayerManager;
/**
* Class managing Actions Menus
*
* @author steeffeen & kremsy
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
/*
* Constants
*/
const MLID_MENU = 'ActionsMenu.MLID';
const SETTING_MENU_POSX = 'Menu Position: X';
const SETTING_MENU_POSY = 'Menu Position: Y';
const SETTING_MENU_ITEMSIZE = 'Menu Item Size';
const ACTION_OPEN_ADMIN_MENU = 'ActionsMenu.OpenAdminMenu';
const MLID_MENU = 'ActionsMenu.MLID';
const SETTING_MENU_POSX = 'Menu Position: X';
const SETTING_MENU_POSY = 'Menu Position: Y';
const SETTING_MENU_ITEMSIZE = 'Menu Item Size';
const ACTION_OPEN_ADMIN_MENU = 'ActionsMenu.OpenAdminMenu';
const ACTION_OPEN_PLAYER_MENU = 'ActionsMenu.OpenPlayerMenu';
/*
@ -64,41 +64,24 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* Add a new Menu Item
*
* @param Control $control
* @param bool $playerAction
* @param int $order
* @param string $description
* @param bool $playerAction
* @param int $order
* @param string $description
*/
public function addMenuItem(Control $control, $playerAction = true, $order = 0, $description = null) {
if ($playerAction) {
$this->addPlayerMenuItem($control, $order, $description);
}
else {
} else {
$this->addAdminMenuItem($control, $order, $description);
}
}
/**
* Removes a Menu Item
*
* @param $order
* @param bool $playerAction
*/
public function removeMenuItem($order, $playerAction = true) {
if ($playerAction) {
unset($this->playerMenuItems[$order]);
}
else {
unset($this->adminMenuItems[$order]);
}
$this->rebuildAndShowMenu();
}
/**
* Add a new Player Menu Item
*
* @param Control $control
* @param int $order
* @param string $description
* @param int $order
* @param string $description
*/
public function addPlayerMenuItem(Control $control, $order = 0, $description = null) {
if (!isset($this->playerMenuItems[$order])) {
@ -109,30 +92,6 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
$this->rebuildAndShowMenu();
}
/**
* Add a new Admin Menu Item
*
* @param Control $control
* @param int $order
* @param string $description
*/
public function addAdminMenuItem(Control $control, $order = 0, $description = null) {
if (!isset($this->adminMenuItems[$order])) {
$this->adminMenuItems[$order] = array();
}
array_push($this->adminMenuItems[$order], array($control, $description));
krsort($this->adminMenuItems);
$this->rebuildAndShowMenu();
}
/**
* Handle ManiaControl AfterInit callback
*/
public function handleAfterInit() {
$this->initCompleted = true;
$this->rebuildAndShowMenu();
}
/**
* Build and show the menus to everyone (if a menu get made after the init)
*/
@ -147,16 +106,6 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
}
}
/**
* Handle PlayerJoined callback
*
* @param Player $player
*/
public function handlePlayerJoined(Player $player) {
$maniaLink = $this->buildMenuIconsManialink($player);
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $player->login);
}
/**
* Builds the Manialink
*
@ -164,12 +113,12 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* @return ManiaLink
*/
private function buildMenuIconsManialink(Player $player) {
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
$itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE);
$shootManiaOffset = $this->maniaControl->manialinkManager->styleManager->getDefaultIconOffsetSM();
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
$itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE);
$shootManiaOffset = $this->maniaControl->manialinkManager->styleManager->getDefaultIconOffsetSM();
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$itemMarginFactorX = 1.3;
$itemMarginFactorY = 1.2;
@ -314,4 +263,53 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
return $manialink;
}
/**
* Add a new Admin Menu Item
*
* @param Control $control
* @param int $order
* @param string $description
*/
public function addAdminMenuItem(Control $control, $order = 0, $description = null) {
if (!isset($this->adminMenuItems[$order])) {
$this->adminMenuItems[$order] = array();
}
array_push($this->adminMenuItems[$order], array($control, $description));
krsort($this->adminMenuItems);
$this->rebuildAndShowMenu();
}
/**
* Removes a Menu Item
*
* @param $order
* @param bool $playerAction
*/
public function removeMenuItem($order, $playerAction = true) {
if ($playerAction) {
unset($this->playerMenuItems[$order]);
} else {
unset($this->adminMenuItems[$order]);
}
$this->rebuildAndShowMenu();
}
/**
* Handle ManiaControl AfterInit callback
*/
public function handleAfterInit() {
$this->initCompleted = true;
$this->rebuildAndShowMenu();
}
/**
* Handle PlayerJoined callback
*
* @param Player $player
*/
public function handlePlayerJoined(Player $player) {
$maniaLink = $this->buildMenuIconsManialink($player);
$this->maniaControl->manialinkManager->sendManialink($maniaLink, $player->login);
}
}

View File

@ -21,9 +21,9 @@ use ManiaControl\Players\Player;
/**
* Widget Class listing Authorized Players
*
* @author kremsy
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
/*
@ -62,7 +62,7 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
/**
* Open Admin List Action
*
* @param array $callback
* @param array $callback
* @param Player $player
*/
public function openAdminList(array $callback, Player $player) {
@ -90,8 +90,8 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
//Create ManiaLink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript();
$paging = new Paging();
$script->addFeature($paging);
$paging = new Paging();
$script->addFeature($paging);
// Main frame
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $pagesId);
@ -115,7 +115,7 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
$i = 1;
$y = $y - 10;
$pageFrames = array();
foreach($admins as $admin) {
foreach ($admins as $admin) {
if (!isset($pageFrame)) {
$pageFrame = new Frame();
$frame->add($pageFrame);
@ -124,7 +124,7 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
}
array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10;
$paging->addPage($pageFrame);
$paging->addPage($pageFrame);
}
@ -158,8 +158,8 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
$rightLabel->setTextSize(0.8);
$rightLabel->setZ(10);
$rightLabel->setText($this->maniaControl->authenticationManager->getAuthLevelAbbreviation($admin));
$description = $this->maniaControl->authenticationManager->getAuthLevelName($admin) . " " . $admin->nickname;
$rightLabel->addTooltipLabelFeature($descriptionLabel, $description);
$description = $this->maniaControl->authenticationManager->getAuthLevelName($admin) . " " . $admin->nickname;
$rightLabel->addTooltipLabelFeature($descriptionLabel, $description);
//Revoke Button
if ($admin->authLevel > 0 && $this->maniaControl->authenticationManager->checkRight($player, $admin->authLevel + 1)) {
@ -217,7 +217,7 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
$adminLogin = $callback[1][1];
$targetLogin = $actionArray[2];
switch($action) {
switch ($action) {
case self::ACTION_REVOKE_RIGHTS:
$this->maniaControl->playerManager->playerActions->revokeAuthLevel($adminLogin, $targetLogin);
break;
@ -230,7 +230,7 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
* @param Player $player
*/
public function updateWidget(Player $player) {
foreach($this->adminListShown as $login => $shown) {
foreach ($this->adminListShown as $login => $shown) {
if ($shown) {
$player = $this->maniaControl->playerManager->getPlayer($login);
if ($player) {

View File

@ -2,16 +2,16 @@
namespace ManiaControl\Admin;
use ManiaControl\ManiaControl;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
/**
* Class offering Commands to grant Authorizations to Players
*
* @author steeffeen & kremsy
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class AuthCommands implements CommandListener {
/*
@ -28,15 +28,15 @@ class AuthCommands implements CommandListener {
$this->maniaControl = $maniaControl;
// Register for commands
$this->maniaControl->commandManager->registerCommandListener('addsuperadmin', $this, 'command_AddSuperAdmin',true, 'Add Player to the AdminList as SuperAdmin.');
$this->maniaControl->commandManager->registerCommandListener('addadmin', $this, 'command_AddAdmin',true, 'Add Player to the AdminList as Admin.');
$this->maniaControl->commandManager->registerCommandListener('addmod', $this, 'command_AddModerator',true, 'Add Player to the AdminList as Moderator.');
$this->maniaControl->commandManager->registerCommandListener('addsuperadmin', $this, 'command_AddSuperAdmin', true, 'Add Player to the AdminList as SuperAdmin.');
$this->maniaControl->commandManager->registerCommandListener('addadmin', $this, 'command_AddAdmin', true, 'Add Player to the AdminList as Admin.');
$this->maniaControl->commandManager->registerCommandListener('addmod', $this, 'command_AddModerator', true, 'Add Player to the AdminList as Moderator.');
}
/**
* Handle //addsuperadmin command
*
* @param array $chatCallback
* @param array $chatCallback
* @param Player $player
*/
public function command_AddSuperAdmin(array $chatCallback, Player $player) {
@ -44,7 +44,7 @@ class AuthCommands implements CommandListener {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
$text = $chatCallback[1][2];
$text = $chatCallback[1][2];
$commandParts = explode(' ', $text);
if (!array_key_exists(1, $commandParts)) {
$this->sendAddSuperAdminUsageInfo($player);
@ -64,10 +64,21 @@ class AuthCommands implements CommandListener {
$this->maniaControl->chat->sendSuccess($message);
}
/**
* Send usage example for //addsuperadmin command
*
* @param Player $player
* @return bool
*/
private function sendAddSuperAdminUsageInfo(Player $player) {
$message = "Usage Example: '//addsuperadmin login'";
return $this->maniaControl->chat->sendUsageInfo($message, $player->login);
}
/**
* Handle //addadmin command
*
* @param array $chatCallback
* @param array $chatCallback
* @param Player $player
*/
public function command_AddAdmin(array $chatCallback, Player $player) {
@ -75,7 +86,7 @@ class AuthCommands implements CommandListener {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
$text = $chatCallback[1][2];
$text = $chatCallback[1][2];
$commandParts = explode(' ', $text);
if (!array_key_exists(1, $commandParts)) {
$this->sendAddAdminUsageInfo($player);
@ -95,10 +106,21 @@ class AuthCommands implements CommandListener {
$this->maniaControl->chat->sendSuccess($message);
}
/**
* Send usage example for //addadmin command
*
* @param Player $player
* @return bool
*/
private function sendAddAdminUsageInfo(Player $player) {
$message = "Usage Example: '//addadmin login'";
return $this->maniaControl->chat->sendUsageInfo($message, $player->login);
}
/**
* Handle //addmod command
*
* @param array $chatCallback
* @param array $chatCallback
* @param Player $player
*/
public function command_AddModerator(array $chatCallback, Player $player) {
@ -106,7 +128,7 @@ class AuthCommands implements CommandListener {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
$text = $chatCallback[1][2];
$text = $chatCallback[1][2];
$commandParts = explode(' ', $text);
if (!array_key_exists(1, $commandParts)) {
$this->sendAddModeratorUsageInfo($player);
@ -126,28 +148,6 @@ class AuthCommands implements CommandListener {
$this->maniaControl->chat->sendSuccess($message);
}
/**
* Send usage example for //addsuperadmin command
*
* @param Player $player
* @return bool
*/
private function sendAddSuperAdminUsageInfo(Player $player) {
$message = "Usage Example: '//addsuperadmin login'";
return $this->maniaControl->chat->sendUsageInfo($message, $player->login);
}
/**
* Send usage example for //addadmin command
*
* @param Player $player
* @return bool
*/
private function sendAddAdminUsageInfo(Player $player) {
$message = "Usage Example: '//addadmin login'";
return $this->maniaControl->chat->sendUsageInfo($message, $player->login);
}
/**
* Send usage example for //addop command
*

View File

@ -11,25 +11,25 @@ use ManiaControl\Players\PlayerManager;
/**
* Class managing Authentication Levels
*
* @author steeffeen & kremsy
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class AuthenticationManager implements CallbackListener {
/*
* 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 AUTH_NAME_PLAYER = 'Player';
const AUTH_NAME_MODERATOR = 'Moderator';
const AUTH_NAME_ADMIN = 'Admin';
const AUTH_NAME_SUPERADMIN = 'SuperAdmin';
const AUTH_NAME_MASTERADMIN = 'MasterAdmin';
const CB_AUTH_LEVEL_CHANGED = 'AuthenticationManager.AuthLevelChanged';
const AUTH_NAME_PLAYER = 'Player';
const AUTH_NAME_MODERATOR = 'Moderator';
const AUTH_NAME_ADMIN = 'Admin';
const AUTH_NAME_SUPERADMIN = 'SuperAdmin';
const AUTH_NAME_MASTERADMIN = 'MasterAdmin';
const CB_AUTH_LEVEL_CHANGED = 'AuthenticationManager.AuthLevelChanged';
/*
* Public Properties
@ -53,6 +53,85 @@ class AuthenticationManager implements CallbackListener {
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'handleOnInit');
}
/**
* Get Name of the Authentication Level from Level Int
*
* @param mixed $authLevelInt
* @return string
*/
public static function getAuthLevelName($authLevelInt) {
$authLevelInt = self::getAuthLevelInt($authLevelInt);
switch ($authLevelInt) {
case self::AUTH_LEVEL_MASTERADMIN:
return self::AUTH_NAME_MASTERADMIN;
case self::AUTH_LEVEL_SUPERADMIN:
return self::AUTH_NAME_SUPERADMIN;
case self::AUTH_LEVEL_ADMIN:
return self::AUTH_NAME_ADMIN;
case self::AUTH_LEVEL_MODERATOR:
return self::AUTH_NAME_MODERATOR;
}
return self::AUTH_NAME_PLAYER;
}
/**
* Get the Authentication Level Int from the given Param
*
* @param mixed $authLevelParam
* @return int
*/
public static function getAuthLevelInt($authLevelParam) {
if (is_object($authLevelParam) && property_exists($authLevelParam, 'authLevel')) {
return (int)$authLevelParam->authLevel;
}
if (is_string($authLevelParam)) {
return self::getAuthLevel($authLevelParam);
}
return (int)$authLevelParam;
}
/**
* Get Authentication Level Int from Level Name
*
* @param string $authLevelName
* @return int
*/
public static function getAuthLevel($authLevelName) {
$authLevelName = (string)$authLevelName;
switch ($authLevelName) {
case self::AUTH_NAME_MASTERADMIN:
return self::AUTH_LEVEL_MASTERADMIN;
case self::AUTH_NAME_SUPERADMIN:
return self::AUTH_LEVEL_SUPERADMIN;
case self::AUTH_NAME_ADMIN:
return self::AUTH_LEVEL_ADMIN;
case self::AUTH_NAME_MODERATOR:
return self::AUTH_LEVEL_MODERATOR;
}
return self::AUTH_LEVEL_PLAYER;
}
/**
* Get the Abbreviation of the Authentication Level from Level Int
*
* @param mixed $authLevelInt
* @return string
*/
public static function getAuthLevelAbbreviation($authLevelInt) {
$authLevelInt = self::getAuthLevelInt($authLevelInt);
switch ($authLevelInt) {
case self::AUTH_LEVEL_MASTERADMIN:
return 'MA';
case self::AUTH_LEVEL_SUPERADMIN:
return 'SA';
case self::AUTH_LEVEL_ADMIN:
return 'AD';
case self::AUTH_LEVEL_MODERATOR:
return 'MOD';
}
return '';
}
/**
* Handle ManiaControl OnInit Callback
*/
@ -61,7 +140,7 @@ class AuthenticationManager implements CallbackListener {
}
/**
* Update MasterAdmins based on config
* Update MasterAdmins based on Config
*
* @return bool
*/
@ -69,7 +148,7 @@ class AuthenticationManager implements CallbackListener {
$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);
@ -77,7 +156,7 @@ class AuthenticationManager implements CallbackListener {
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();
@ -87,8 +166,8 @@ class AuthenticationManager implements CallbackListener {
$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 (
@ -102,7 +181,7 @@ class AuthenticationManager implements CallbackListener {
}
$success = true;
foreach ($masterAdmins as $masterAdmin) {
$login = (string) $masterAdmin;
$login = (string)$masterAdmin;
$adminStatement->bind_param('si', $login, $masterAdminLevel);
$adminStatement->execute();
if ($adminStatement->error) {
@ -124,8 +203,7 @@ class AuthenticationManager implements CallbackListener {
$mysqli = $this->maniaControl->database->mysqli;
if ($authLevel < 0) {
$query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "` WHERE `authLevel` > 0 ORDER BY `authLevel` DESC;";
}
else {
} else {
$query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "` WHERE `authLevel` = " . $authLevel . ";";
}
$result = $mysqli->query($query);
@ -144,20 +222,20 @@ class AuthenticationManager implements CallbackListener {
* 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;
$authLevel = (int)$authLevel;
if ($authLevel >= self::AUTH_LEVEL_MASTERADMIN) {
return false;
}
$mysqli = $this->maniaControl->database->mysqli;
$authQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
$mysqli = $this->maniaControl->database->mysqli;
$authQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
`login`,
`authLevel`
) VALUES (
@ -197,22 +275,11 @@ class AuthenticationManager implements CallbackListener {
return $this->maniaControl->chat->sendError('You do not have the required Rights to perform this Action!', $player->login);
}
/**
* Check if the Player has enough Rights
*
* @param Player $player
* @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
* @param $rightName
* @return bool
*/
public function checkPermission(Player $player, $rightName) {
@ -220,6 +287,17 @@ class AuthenticationManager implements CallbackListener {
return $this->checkRight($player, $right);
}
/**
* Check if the Player has enough Rights
*
* @param Player $player
* @param int $neededAuthLevel
* @return bool
*/
public static function checkRight(Player $player, $neededAuthLevel) {
return ($player->authLevel >= $neededAuthLevel);
}
/**
* Defines a Minimum Right Level needed for an action
*
@ -229,83 +307,4 @@ class AuthenticationManager implements CallbackListener {
public function definePermissionLevel($rightName, $authLevelNeeded) {
$this->maniaControl->settingManager->initSetting($this, $rightName, $authLevelNeeded);
}
/**
* Get Name of the Authentication Level from Level Int
*
* @param mixed $authLevelInt
* @return string
*/
public static function getAuthLevelName($authLevelInt) {
$authLevelInt = self::getAuthLevelInt($authLevelInt);
switch ($authLevelInt) {
case self::AUTH_LEVEL_MASTERADMIN:
return self::AUTH_NAME_MASTERADMIN;
case self::AUTH_LEVEL_SUPERADMIN:
return self::AUTH_NAME_SUPERADMIN;
case self::AUTH_LEVEL_ADMIN:
return self::AUTH_NAME_ADMIN;
case self::AUTH_LEVEL_MODERATOR:
return self::AUTH_NAME_MODERATOR;
}
return self::AUTH_NAME_PLAYER;
}
/**
* Get the Abbreviation of the Authentication Level from Level Int
*
* @param mixed $authLevelInt
* @return string
*/
public static function getAuthLevelAbbreviation($authLevelInt) {
$authLevelInt = self::getAuthLevelInt($authLevelInt);
switch ($authLevelInt) {
case self::AUTH_LEVEL_MASTERADMIN:
return 'MA';
case self::AUTH_LEVEL_SUPERADMIN:
return 'SA';
case self::AUTH_LEVEL_ADMIN:
return 'AD';
case self::AUTH_LEVEL_MODERATOR:
return 'MOD';
}
return '';
}
/**
* Get Authentication Level Int from Level Name
*
* @param string $authLevelName
* @return int
*/
public static function getAuthLevel($authLevelName) {
$authLevelName = (string) $authLevelName;
switch ($authLevelName) {
case self::AUTH_NAME_MASTERADMIN:
return self::AUTH_LEVEL_MASTERADMIN;
case self::AUTH_NAME_SUPERADMIN:
return self::AUTH_LEVEL_SUPERADMIN;
case self::AUTH_NAME_ADMIN:
return self::AUTH_LEVEL_ADMIN;
case self::AUTH_NAME_MODERATOR:
return self::AUTH_LEVEL_MODERATOR;
}
return self::AUTH_LEVEL_PLAYER;
}
/**
* Get the Authentication Level Int from the given Param
*
* @param mixed $authLevelParam
* @return int
*/
public static function getAuthLevelInt($authLevelParam) {
if (is_object($authLevelParam) && property_exists($authLevelParam, 'authLevel')) {
return (int) $authLevelParam->authLevel;
}
if (is_string($authLevelParam)) {
return self::getAuthLevel($authLevelParam);
}
return (int) $authLevelParam;
}
}