removed 'application' folder to have everything in the root directory
This commit is contained in:
318
core/Admin/ActionsMenu.php
Normal file
318
core/Admin/ActionsMenu.php
Normal file
@ -0,0 +1,318 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Admin;
|
||||
|
||||
use FML\Controls\Control;
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Label;
|
||||
use FML\Controls\Quad;
|
||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||
use FML\ManiaLink;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\Callbacks;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
|
||||
/**
|
||||
* Class managing Actions Menus
|
||||
*
|
||||
* @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 ACTION_OPEN_PLAYER_MENU = 'ActionsMenu.OpenPlayerMenu';
|
||||
|
||||
/*
|
||||
* Private properties
|
||||
*/
|
||||
/** @var ManiaControl $maniaControl */
|
||||
private $maniaControl = null;
|
||||
private $adminMenuItems = array();
|
||||
private $playerMenuItems = array();
|
||||
private $initCompleted = false;
|
||||
|
||||
/**
|
||||
* Construct a new Actions Menu instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Settings
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_POSX, 156.);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_POSY, -17.);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6.);
|
||||
|
||||
// Callbacks
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'handlePlayerJoined');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new Menu Item
|
||||
*
|
||||
* @param Control $control
|
||||
* @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 {
|
||||
$this->addAdminMenuItem($control, $order, $description);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new Player Menu Item
|
||||
*
|
||||
* @param Control $control
|
||||
* @param int $order
|
||||
* @param string $description
|
||||
*/
|
||||
public function addPlayerMenuItem(Control $control, $order = 0, $description = null) {
|
||||
if (!isset($this->playerMenuItems[$order])) {
|
||||
$this->playerMenuItems[$order] = array();
|
||||
}
|
||||
array_push($this->playerMenuItems[$order], array($control, $description));
|
||||
krsort($this->playerMenuItems);
|
||||
$this->rebuildAndShowMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and show the menus to everyone (if a menu get made after the init)
|
||||
*/
|
||||
public function rebuildAndShowMenu() {
|
||||
if (!$this->initCompleted) {
|
||||
return;
|
||||
}
|
||||
$players = $this->maniaControl->getPlayerManager()->getPlayers();
|
||||
foreach ($players as $player) {
|
||||
$manialink = $this->buildMenuIconsManialink($player);
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($manialink, $player->login);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Manialink
|
||||
*
|
||||
* @param Player $player
|
||||
* @return ManiaLink
|
||||
*/
|
||||
private function buildMenuIconsManialink(Player $player) {
|
||||
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSX);
|
||||
$posY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSY);
|
||||
$itemSize = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_ITEMSIZE);
|
||||
$shootManiaOffset = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultIconOffsetSM();
|
||||
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
|
||||
$itemMarginFactorX = 1.3;
|
||||
$itemMarginFactorY = 1.2;
|
||||
|
||||
// If game is shootmania lower the icons position by 20
|
||||
if ($this->maniaControl->getMapManager()->getCurrentMap()->getGame() === 'sm'
|
||||
) {
|
||||
$posY -= $shootManiaOffset;
|
||||
}
|
||||
|
||||
$manialink = new ManiaLink(self::MLID_MENU);
|
||||
|
||||
/*
|
||||
* Admin Menu
|
||||
*/
|
||||
if ($this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)
|
||||
) {
|
||||
// Admin Menu Icon Frame
|
||||
$iconFrame = new Frame();
|
||||
$manialink->add($iconFrame);
|
||||
$iconFrame->setPosition($posX, $posY);
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$iconFrame->add($backgroundQuad);
|
||||
$backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$itemQuad = new Quad_Icons64x64_1();
|
||||
$iconFrame->add($itemQuad);
|
||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconServers);
|
||||
$itemQuad->setSize($itemSize, $itemSize);
|
||||
|
||||
// Admin Menu Description
|
||||
$descriptionLabel = new Label();
|
||||
$manialink->add($descriptionLabel);
|
||||
$descriptionLabel->setPosition($posX - count($this->adminMenuItems) * $itemSize * 1.15 - 6, $posY);
|
||||
$descriptionLabel->setAlign($descriptionLabel::RIGHT, $descriptionLabel::TOP);
|
||||
$descriptionLabel->setSize(40, 4);
|
||||
$descriptionLabel->setTextSize(1.4);
|
||||
$descriptionLabel->setTextColor('fff');
|
||||
|
||||
// Admin Menu
|
||||
$popoutFrame = new Frame();
|
||||
$manialink->add($popoutFrame);
|
||||
$popoutFrame->setPosition($posX - $itemSize * 0.5, $posY);
|
||||
$popoutFrame->setHAlign($popoutFrame::RIGHT);
|
||||
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
||||
$popoutFrame->setVisible(false);
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$popoutFrame->add($backgroundQuad);
|
||||
$backgroundQuad->setHAlign($backgroundQuad::RIGHT);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
$backgroundQuad->setSize(count($this->adminMenuItems) * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY);
|
||||
|
||||
$itemQuad->addToggleFeature($popoutFrame);
|
||||
|
||||
// Add items
|
||||
$itemPosX = -1;
|
||||
foreach ($this->adminMenuItems as $menuItems) {
|
||||
foreach ($menuItems as $menuItem) {
|
||||
$menuQuad = $menuItem[0];
|
||||
/** @var Quad $menuQuad */
|
||||
$popoutFrame->add($menuQuad);
|
||||
$menuQuad->setSize($itemSize, $itemSize);
|
||||
$menuQuad->setX($itemPosX);
|
||||
$menuQuad->setHAlign($menuQuad::RIGHT);
|
||||
$itemPosX -= $itemSize * 1.05;
|
||||
|
||||
if ($menuItem[1]) {
|
||||
$menuQuad->removeScriptFeatures();
|
||||
$description = '$s' . $menuItem[1];
|
||||
$menuQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Player Menu
|
||||
*/
|
||||
// Player Menu Icon Frame
|
||||
$iconFrame = new Frame();
|
||||
$manialink->add($iconFrame);
|
||||
$iconFrame->setPosition($posX, $posY - $itemSize * $itemMarginFactorY);
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$iconFrame->add($backgroundQuad);
|
||||
$backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$itemQuad = new Quad_Icons64x64_1();
|
||||
$iconFrame->add($itemQuad);
|
||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconPlayers);
|
||||
$itemQuad->setSize($itemSize, $itemSize);
|
||||
|
||||
// Player Menu Description
|
||||
$descriptionLabel = new Label();
|
||||
$manialink->add($descriptionLabel);
|
||||
$descriptionLabel->setPosition($posX - count($this->playerMenuItems) * $itemSize * 1.15 - 6, $posY - $itemSize * $itemMarginFactorY);
|
||||
$descriptionLabel->setAlign($descriptionLabel::RIGHT, $descriptionLabel::TOP);
|
||||
$descriptionLabel->setSize(40, 4);
|
||||
$descriptionLabel->setTextSize(1.4);
|
||||
$descriptionLabel->setTextColor('fff');
|
||||
|
||||
// Player Menu
|
||||
$popoutFrame = new Frame();
|
||||
$manialink->add($popoutFrame);
|
||||
$popoutFrame->setPosition($posX - $itemSize * 0.5, $posY - $itemSize * $itemMarginFactorY);
|
||||
$popoutFrame->setHAlign($popoutFrame::RIGHT);
|
||||
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
||||
$popoutFrame->setVisible(false);
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$popoutFrame->add($backgroundQuad);
|
||||
$backgroundQuad->setHAlign($backgroundQuad::RIGHT);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
$backgroundQuad->setSize(count($this->playerMenuItems) * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY);
|
||||
|
||||
$itemQuad->addToggleFeature($popoutFrame);
|
||||
|
||||
// Add items
|
||||
$itemPosX = -1;
|
||||
foreach ($this->playerMenuItems as $menuItems) {
|
||||
foreach ($menuItems as $menuItem) {
|
||||
$menuQuad = $menuItem[0];
|
||||
/** @var Quad $menuQuad */
|
||||
$popoutFrame->add($menuQuad);
|
||||
$menuQuad->setSize($itemSize, $itemSize);
|
||||
$menuQuad->setX($itemPosX);
|
||||
$menuQuad->setHAlign($menuQuad::RIGHT);
|
||||
$itemPosX -= $itemSize * 1.05;
|
||||
|
||||
if ($menuItem[1]) {
|
||||
$menuQuad->removeScriptFeatures();
|
||||
$description = '$s' . $menuItem[1];
|
||||
$menuQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 int $order
|
||||
* @param bool $playerAction
|
||||
*/
|
||||
public function removeMenuItem($order, $playerAction = true) {
|
||||
if ($playerAction) {
|
||||
if ($this->playerMenuItems[$order]) {
|
||||
unset($this->playerMenuItems[$order]);
|
||||
}
|
||||
} else {
|
||||
if ($this->playerMenuItems[$order]) {
|
||||
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->getManialinkManager()->sendManialink($maniaLink, $player);
|
||||
}
|
||||
}
|
257
core/Admin/AdminLists.php
Normal file
257
core/Admin/AdminLists.php
Normal file
@ -0,0 +1,257 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Admin;
|
||||
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Labels\Label_Button;
|
||||
use FML\Controls\Labels\Label_Text;
|
||||
use FML\Controls\Quads\Quad_BgRaceScore2;
|
||||
use FML\Controls\Quads\Quad_BgsPlayerCard;
|
||||
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
||||
use FML\ManiaLink;
|
||||
use FML\Script\Features\Paging;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Players\Player;
|
||||
|
||||
/**
|
||||
* Widget Class listing Authorized Players
|
||||
*
|
||||
* @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 {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const ACTION_OPEN_ADMIN_LIST = 'AdminList.OpenAdminList';
|
||||
const ACTION_REVOKE_RIGHTS = 'AdminList.RevokeRights';
|
||||
const MAX_PLAYERS_PER_PAGE = 15;
|
||||
|
||||
/*
|
||||
* Private Properties
|
||||
*/
|
||||
private $adminListShown = array();
|
||||
|
||||
/**
|
||||
* Construct a new PlayerList instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Callbacks
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'updateWidget');
|
||||
|
||||
// Menu Entry AdminList
|
||||
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_OPEN_ADMIN_LIST, $this, 'openAdminList');
|
||||
$itemQuad = new Quad_UIConstruction_Buttons();
|
||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Author);
|
||||
$itemQuad->setAction(self::ACTION_OPEN_ADMIN_LIST);
|
||||
$this->maniaControl->getActionsMenu()->addMenuItem($itemQuad, false, 50, 'Open AdminList');
|
||||
}
|
||||
|
||||
/**
|
||||
* Open Admin List Action
|
||||
*
|
||||
* @param array $callback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function openAdminList(array $callback, Player $player) {
|
||||
$this->showAdminLists($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the Admin List
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function showAdminLists(Player $player) {
|
||||
$this->adminListShown[$player->login] = true;
|
||||
|
||||
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
|
||||
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
|
||||
|
||||
// get Admins
|
||||
$admins = $this->maniaControl->getAuthenticationManager()->getAdmins();
|
||||
|
||||
//Create ManiaLink
|
||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||
$script = $maniaLink->getScript();
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
|
||||
// Main frame
|
||||
$frame = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultListFrame($script, $paging);
|
||||
$maniaLink->add($frame);
|
||||
|
||||
// Start offsets
|
||||
$posX = -$width / 2;
|
||||
$posY = $height / 2;
|
||||
|
||||
//Predefine description Label
|
||||
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
|
||||
$frame->add($descriptionLabel);
|
||||
|
||||
// Headline
|
||||
$headFrame = new Frame();
|
||||
$frame->add($headFrame);
|
||||
$headFrame->setY($posY - 5);
|
||||
$array = array('Id' => $posX + 5, 'Nickname' => $posX + 18, 'Login' => $posX + 70, 'Actions' => $posX + 120);
|
||||
$this->maniaControl->getManialinkManager()->labelLine($headFrame, $array);
|
||||
|
||||
$index = 1;
|
||||
$posY -= 10;
|
||||
$pageFrame = null;
|
||||
|
||||
foreach ($admins as $admin) {
|
||||
if ($index % self::MAX_PLAYERS_PER_PAGE === 1) {
|
||||
$pageFrame = new Frame();
|
||||
$frame->add($pageFrame);
|
||||
|
||||
$paging->addPage($pageFrame);
|
||||
$posY = $height / 2 - 10;
|
||||
}
|
||||
|
||||
$playerFrame = new Frame();
|
||||
$pageFrame->add($playerFrame);
|
||||
$playerFrame->setY($posY);
|
||||
|
||||
if ($index % 2 !== 0) {
|
||||
$lineQuad = new Quad_BgsPlayerCard();
|
||||
$playerFrame->add($lineQuad);
|
||||
$lineQuad->setSize($width, 4);
|
||||
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
|
||||
$lineQuad->setZ(0.001);
|
||||
}
|
||||
|
||||
$array = array($index => $posX + 5, $admin->nickname => $posX + 18, $admin->login => $posX + 70);
|
||||
$this->maniaControl->getManialinkManager()->labelLine($playerFrame, $array);
|
||||
|
||||
|
||||
// Level Quad
|
||||
$rightQuad = new Quad_BgRaceScore2();
|
||||
$playerFrame->add($rightQuad);
|
||||
$rightQuad->setX($posX + 13);
|
||||
$rightQuad->setZ(5);
|
||||
$rightQuad->setSubStyle($rightQuad::SUBSTYLE_CupFinisher);
|
||||
$rightQuad->setSize(7, 3.5);
|
||||
|
||||
$rightLabel = new Label_Text();
|
||||
$playerFrame->add($rightLabel);
|
||||
$rightLabel->setX($posX + 13.9);
|
||||
$rightLabel->setTextSize(0.8);
|
||||
$rightLabel->setZ(10);
|
||||
$rightLabel->setText($this->maniaControl->getAuthenticationManager()->getAuthLevelAbbreviation($admin));
|
||||
$description = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin) . " " . $admin->nickname;
|
||||
$rightLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
|
||||
//Revoke Button
|
||||
if ($admin->authLevel > 0
|
||||
&& $this->maniaControl->getAuthenticationManager()->checkRight($player, $admin->authLevel + 1)
|
||||
) {
|
||||
//Settings
|
||||
$style = Label_Text::STYLE_TextCardSmall;
|
||||
$textColor = 'FFF';
|
||||
$quadWidth = 24;
|
||||
$quadHeight = 3.4;
|
||||
|
||||
// Quad
|
||||
$quad = new Quad_BgsPlayerCard();
|
||||
$playerFrame->add($quad);
|
||||
$quad->setZ(11);
|
||||
$quad->setX($posX + 130);
|
||||
$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig);
|
||||
$quad->setSize($quadWidth, $quadHeight);
|
||||
$quad->setAction(self::ACTION_REVOKE_RIGHTS . "." . $admin->login);
|
||||
|
||||
//Label
|
||||
$label = new Label_Button();
|
||||
$playerFrame->add($label);
|
||||
$label->setX($posX + 130);
|
||||
$quad->setZ(12);
|
||||
$label->setStyle($style);
|
||||
$label->setTextSize(1);
|
||||
$label->setTextColor($textColor);
|
||||
$label->setText("Revoke Rights");
|
||||
}
|
||||
|
||||
$posY -= 4;
|
||||
$index++;
|
||||
}
|
||||
|
||||
// Render and display xml
|
||||
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'AdminList');
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on ManialinkPageAnswer
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleManialinkPageAnswer(array $callback) {
|
||||
$actionId = $callback[1][2];
|
||||
$actionArray = explode('.', $actionId, 3);
|
||||
if (count($actionArray) <= 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$action = $actionArray[0] . '.' . $actionArray[1];
|
||||
$adminLogin = $callback[1][1];
|
||||
$targetLogin = $actionArray[2];
|
||||
|
||||
switch ($action) {
|
||||
case self::ACTION_REVOKE_RIGHTS:
|
||||
$this->maniaControl->getPlayerManager()->getPlayerActions()->revokeAuthLevel($adminLogin, $targetLogin);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reopen the widget on Map Begin, MapListChanged, etc.
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function updateWidget(Player $player) {
|
||||
foreach ($this->adminListShown as $login => $shown) {
|
||||
if ($shown) {
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
if ($player) {
|
||||
$this->showAdminLists($player);
|
||||
} else {
|
||||
unset($this->adminListShown[$login]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the widget
|
||||
*
|
||||
* @param \ManiaControl\Players\Player $player
|
||||
*/
|
||||
public function closeWidget(Player $player) {
|
||||
unset($this->adminListShown[$player->login]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset the player if he opened another Main Widget
|
||||
*
|
||||
* @param Player $player
|
||||
* @param $openedWidget
|
||||
*/
|
||||
public function handleWidgetOpened(Player $player, $openedWidget) {
|
||||
//unset when another main widget got opened
|
||||
if ($openedWidget !== 'AdminList') {
|
||||
unset($this->adminListShown[$player->login]);
|
||||
}
|
||||
}
|
||||
}
|
162
core/Admin/AuthCommands.php
Normal file
162
core/Admin/AuthCommands.php
Normal file
@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Admin;
|
||||
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
|
||||
/**
|
||||
* Class offering Commands to grant Authorizations to Players
|
||||
*
|
||||
* @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 {
|
||||
/*
|
||||
* Private properties
|
||||
*/
|
||||
/** @var ManiaControl $maniaControl */
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Construct a new AuthCommands instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Commands
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener('addsuperadmin', $this, 'command_AddSuperAdmin', true, 'Add Player to the AdminList as SuperAdmin.');
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener('addadmin', $this, 'command_AddAdmin', true, 'Add Player to the AdminList as Admin.');
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener('addmod', $this, 'command_AddModerator', true, 'Add Player to the AdminList as Moderator.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle //addsuperadmin command
|
||||
*
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_AddSuperAdmin(array $chatCallback, Player $player) {
|
||||
if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) {
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
$text = $chatCallback[1][2];
|
||||
$commandParts = explode(' ', $text);
|
||||
if (!array_key_exists(1, $commandParts)) {
|
||||
$this->sendAddSuperAdminUsageInfo($player);
|
||||
return;
|
||||
}
|
||||
$target = $this->maniaControl->getPlayerManager()->getPlayer($commandParts[1]);
|
||||
if (!$target) {
|
||||
$this->maniaControl->getChat()->sendError("Player '{$commandParts[1]}' not found!", $player);
|
||||
return;
|
||||
}
|
||||
$success = $this->maniaControl->getAuthenticationManager()->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
|
||||
if (!$success) {
|
||||
$this->maniaControl->getChat()->sendError('Error occurred.', $player);
|
||||
return;
|
||||
}
|
||||
$message = $player->getEscapedNickname() . ' added ' . $target->getEscapedNickname() . ' as SuperAdmin!';
|
||||
$this->maniaControl->getChat()->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->getChat()->sendUsageInfo($message, $player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle //addadmin command
|
||||
*
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_AddAdmin(array $chatCallback, Player $player) {
|
||||
if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) {
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
$text = $chatCallback[1][2];
|
||||
$commandParts = explode(' ', $text);
|
||||
if (!array_key_exists(1, $commandParts)) {
|
||||
$this->sendAddAdminUsageInfo($player);
|
||||
return;
|
||||
}
|
||||
$target = $this->maniaControl->getPlayerManager()->getPlayer($commandParts[1]);
|
||||
if (!$target) {
|
||||
$this->maniaControl->getChat()->sendError("Player '{$commandParts[1]}' not found!", $player);
|
||||
return;
|
||||
}
|
||||
$success = $this->maniaControl->getAuthenticationManager()->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
if (!$success) {
|
||||
$this->maniaControl->getChat()->sendError('Error occurred.', $player);
|
||||
return;
|
||||
}
|
||||
$message = $player->getEscapedNickname() . ' added ' . $target->getEscapedNickname() . ' as Admin!';
|
||||
$this->maniaControl->getChat()->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->getChat()->sendUsageInfo($message, $player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle //addmod command
|
||||
*
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_AddModerator(array $chatCallback, Player $player) {
|
||||
if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
$text = $chatCallback[1][2];
|
||||
$commandParts = explode(' ', $text);
|
||||
if (!array_key_exists(1, $commandParts)) {
|
||||
$this->sendAddModeratorUsageInfo($player);
|
||||
return;
|
||||
}
|
||||
$target = $this->maniaControl->getPlayerManager()->getPlayer($commandParts[1]);
|
||||
if (!$target) {
|
||||
$this->maniaControl->getChat()->sendError("Player '{$commandParts[1]}' not found!", $player);
|
||||
return;
|
||||
}
|
||||
$success = $this->maniaControl->getAuthenticationManager()->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||
if (!$success) {
|
||||
$this->maniaControl->getChat()->sendError('Error occurred.', $player);
|
||||
return;
|
||||
}
|
||||
$message = $player->getEscapedNickname() . ' added ' . $target->getEscapedNickname() . ' as Moderator!';
|
||||
$this->maniaControl->getChat()->sendSuccess($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send usage example for //addmod command
|
||||
*
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
private function sendAddModeratorUsageInfo(Player $player) {
|
||||
$message = "Usage Example: '//addmod login'";
|
||||
return $this->maniaControl->getChat()->sendUsageInfo($message, $player);
|
||||
}
|
||||
}
|
361
core/Admin/AuthenticationManager.php
Normal file
361
core/Admin/AuthenticationManager.php
Normal file
@ -0,0 +1,361 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Admin;
|
||||
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\Callbacks;
|
||||
use ManiaControl\Logger;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
use ManiaControl\Settings\Setting;
|
||||
|
||||
/**
|
||||
* Class managing Authentication Levels
|
||||
*
|
||||
* @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_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';
|
||||
|
||||
/*
|
||||
* Private properties
|
||||
*/
|
||||
/** @var ManiaControl $maniaControl */
|
||||
private $maniaControl = null;
|
||||
/** @var AuthCommands $authCommands */
|
||||
private $authCommands = null;
|
||||
|
||||
/**
|
||||
* Construct a new Authentication Manager instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->authCommands = new AuthCommands($maniaControl);
|
||||
|
||||
// Callbacks
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::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
|
||||
*/
|
||||
public function handleOnInit() {
|
||||
$this->updateMasterAdmins();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update MasterAdmins based on Config
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function updateMasterAdmins() {
|
||||
$masterAdminsElements = $this->maniaControl->getConfig()->xpath('masteradmins');
|
||||
if (!$masterAdminsElements) {
|
||||
Logger::logError('Missing MasterAdmins configuration!');
|
||||
return false;
|
||||
}
|
||||
$masterAdminsElement = $masterAdminsElements[0];
|
||||
|
||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||
|
||||
// Remove all MasterAdmins
|
||||
$adminQuery = "UPDATE `" . PlayerManager::TABLE_PLAYERS . "`
|
||||
SET `authLevel` = ?
|
||||
WHERE `authLevel` = ?;";
|
||||
$adminStatement = $mysqli->prepare($adminQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$adminLevel = self::AUTH_LEVEL_SUPERADMIN;
|
||||
$masterAdminLevel = self::AUTH_LEVEL_MASTERADMIN;
|
||||
$adminStatement->bind_param('ii', $adminLevel, $masterAdminLevel);
|
||||
$adminStatement->execute();
|
||||
if ($adminStatement->error) {
|
||||
trigger_error($adminStatement->error);
|
||||
}
|
||||
$adminStatement->close();
|
||||
|
||||
// Set configured MasterAdmins
|
||||
$loginElements = $masterAdminsElement->xpath('login');
|
||||
$adminQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
|
||||
`login`,
|
||||
`authLevel`
|
||||
) VALUES (
|
||||
?, ?
|
||||
) ON DUPLICATE KEY UPDATE
|
||||
`authLevel` = VALUES(`authLevel`);";
|
||||
$adminStatement = $mysqli->prepare($adminQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$success = true;
|
||||
foreach ($loginElements as $loginElement) {
|
||||
$login = (string)$loginElement;
|
||||
$adminStatement->bind_param('si', $login, $masterAdminLevel);
|
||||
$adminStatement->execute();
|
||||
if ($adminStatement->error) {
|
||||
trigger_error($adminStatement->error);
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
$adminStatement->close();
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all connected Players with at least the given Auth Level
|
||||
*
|
||||
* @param int $authLevel
|
||||
* @return Player[]
|
||||
*/
|
||||
public function getConnectedAdmins($authLevel = self::AUTH_LEVEL_MODERATOR) {
|
||||
$players = $this->maniaControl->getPlayerManager()->getPlayers();
|
||||
$admins = array();
|
||||
foreach ($players as $player) {
|
||||
if (self::checkRight($player, $authLevel)) {
|
||||
array_push($admins, $player);
|
||||
}
|
||||
}
|
||||
return $admins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the Player has enough Rights
|
||||
*
|
||||
* @param Player $player
|
||||
* @param int|Setting $neededAuthLevel
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkRight(Player $player, $neededAuthLevel) {
|
||||
if ($neededAuthLevel instanceof Setting) {
|
||||
$neededAuthLevel = $neededAuthLevel->value;
|
||||
}
|
||||
return ($player->authLevel >= $neededAuthLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a List of all Admins
|
||||
*
|
||||
* @param int $authLevel
|
||||
* @return Player[]
|
||||
*/
|
||||
public function getAdmins($authLevel = self::AUTH_LEVEL_MODERATOR) {
|
||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||
$query = "SELECT `login` FROM `" . PlayerManager::TABLE_PLAYERS . "`
|
||||
WHERE `authLevel` > " . $authLevel . "
|
||||
ORDER BY `authLevel` DESC;";
|
||||
$result = $mysqli->query($query);
|
||||
if (!$result) {
|
||||
trigger_error($mysqli->error);
|
||||
return null;
|
||||
}
|
||||
$admins = array();
|
||||
while ($row = $result->fetch_object()) {
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($row->login, false);
|
||||
if ($player) {
|
||||
array_push($admins, $player);
|
||||
}
|
||||
}
|
||||
$result->free();
|
||||
return $admins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grant the Auth Level to the Player
|
||||
*
|
||||
* @param Player $player
|
||||
* @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->getDatabase()->getMysqli();
|
||||
$authQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
|
||||
`login`,
|
||||
`authLevel`
|
||||
) VALUES (
|
||||
?, ?
|
||||
) ON DUPLICATE KEY UPDATE
|
||||
`authLevel` = VALUES(`authLevel`);";
|
||||
$authStatement = $mysqli->prepare($authQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$authStatement->bind_param('si', $player->login, $authLevel);
|
||||
$authStatement->execute();
|
||||
if ($authStatement->error) {
|
||||
trigger_error($authStatement->error);
|
||||
$authStatement->close();
|
||||
return false;
|
||||
}
|
||||
$authStatement->close();
|
||||
|
||||
$player->authLevel = $authLevel;
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_AUTH_LEVEL_CHANGED, $player);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an Error Message to the Player
|
||||
*
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function sendNotAllowed(Player $player) {
|
||||
if (!$player) {
|
||||
return false;
|
||||
}
|
||||
return $this->maniaControl->getChat()->sendError('You do not have the required Rights to perform this Action!', $player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the permission by a right name
|
||||
*
|
||||
* @param Player $player
|
||||
* @param $rightName
|
||||
* @return bool
|
||||
*/
|
||||
public function checkPermission(Player $player, $rightName) {
|
||||
$right = $this->maniaControl->getSettingManager()->getSettingValue($this, $rightName);
|
||||
return $this->checkRight($player, $this->getAuthLevel($right));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define a Minimum Right Level needed for an Action
|
||||
*
|
||||
* @param string $rightName
|
||||
* @param int $authLevelNeeded
|
||||
*/
|
||||
public function definePermissionLevel($rightName, $authLevelNeeded) {
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, $rightName, $this->getPermissionLevelNameArray($authLevelNeeded));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PermissionLevelNameArray
|
||||
*
|
||||
* @param $authLevelNeeded
|
||||
* @return array[]
|
||||
*/
|
||||
private function getPermissionLevelNameArray($authLevelNeeded) {
|
||||
switch ($authLevelNeeded) {
|
||||
case self::AUTH_LEVEL_MODERATOR:
|
||||
return array(self::AUTH_NAME_MODERATOR, self::AUTH_NAME_ADMIN, self::AUTH_NAME_SUPERADMIN, self::AUTH_NAME_MASTERADMIN);
|
||||
case self::AUTH_LEVEL_ADMIN:
|
||||
return array(self::AUTH_NAME_ADMIN, self::AUTH_NAME_SUPERADMIN, self::AUTH_NAME_MASTERADMIN, self::AUTH_NAME_MODERATOR);
|
||||
case self::AUTH_LEVEL_SUPERADMIN:
|
||||
return array(self::AUTH_NAME_SUPERADMIN, self::AUTH_NAME_MASTERADMIN, self::AUTH_NAME_MODERATOR, self::AUTH_NAME_ADMIN);
|
||||
case self::AUTH_LEVEL_MASTERADMIN:
|
||||
return array(self::AUTH_NAME_MASTERADMIN, self::AUTH_NAME_MODERATOR, self::AUTH_NAME_ADMIN, self::AUTH_NAME_SUPERADMIN);
|
||||
}
|
||||
return array("-");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user