applied common formatting
This commit is contained in:
parent
3857f332f7
commit
d52423b737
24
.idea/codeStyleSettings.xml
generated
24
.idea/codeStyleSettings.xml
generated
@ -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>
|
||||
|
@ -18,21 +18,21 @@ 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';
|
||||
|
||||
|
||||
/*
|
||||
* Private Properties
|
||||
*/
|
||||
@ -48,12 +48,12 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
|
||||
// Init settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 156.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, -17.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6.);
|
||||
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
|
||||
@ -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,22 +113,22 @@ 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;
|
||||
|
||||
|
||||
// If game is shootmania lower the icons position by 20
|
||||
if ($this->maniaControl->mapManager->getCurrentMap()->getGame() == 'sm') {
|
||||
$posY -= $shootManiaOffset;
|
||||
}
|
||||
|
||||
|
||||
$manialink = new ManiaLink(self::MLID_MENU);
|
||||
|
||||
|
||||
/*
|
||||
* Admin Menu
|
||||
*/
|
||||
@ -188,17 +137,17 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
||||
$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);
|
||||
@ -207,7 +156,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
||||
$descriptionLabel->setSize(40, 4);
|
||||
$descriptionLabel->setTextSize(1.4);
|
||||
$descriptionLabel->setTextColor('fff');
|
||||
|
||||
|
||||
// Admin Menu
|
||||
$popoutFrame = new Frame();
|
||||
$manialink->add($popoutFrame);
|
||||
@ -215,15 +164,15 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
||||
$popoutFrame->setHAlign(Control::RIGHT);
|
||||
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
||||
$popoutFrame->setVisible(false);
|
||||
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$popoutFrame->add($backgroundQuad);
|
||||
$backgroundQuad->setHAlign(Control::RIGHT);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
$backgroundQuad->setSize(count($this->adminMenuItems) * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY);
|
||||
|
||||
|
||||
$itemQuad->addToggleFeature($popoutFrame);
|
||||
|
||||
|
||||
// Add items
|
||||
$x = -1;
|
||||
foreach ($this->adminMenuItems as $menuItems) {
|
||||
@ -237,7 +186,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
||||
$menuQuad->setX($x);
|
||||
$menuQuad->setHAlign(Control::RIGHT);
|
||||
$x -= $itemSize * 1.05;
|
||||
|
||||
|
||||
if ($menuItem[1]) {
|
||||
$menuQuad->removeScriptFeatures();
|
||||
$description = '$s' . $menuItem[1];
|
||||
@ -246,7 +195,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Player Menu
|
||||
*/
|
||||
@ -254,17 +203,17 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
||||
$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);
|
||||
@ -273,7 +222,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
||||
$descriptionLabel->setSize(40, 4);
|
||||
$descriptionLabel->setTextSize(1.4);
|
||||
$descriptionLabel->setTextColor('fff');
|
||||
|
||||
|
||||
// Player Menu
|
||||
$popoutFrame = new Frame();
|
||||
$manialink->add($popoutFrame);
|
||||
@ -281,15 +230,15 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
||||
$popoutFrame->setHAlign(Control::RIGHT);
|
||||
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
|
||||
$popoutFrame->setVisible(false);
|
||||
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$popoutFrame->add($backgroundQuad);
|
||||
$backgroundQuad->setHAlign(Control::RIGHT);
|
||||
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||
$backgroundQuad->setSize(count($this->playerMenuItems) * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY);
|
||||
|
||||
|
||||
$itemQuad->addToggleFeature($popoutFrame);
|
||||
|
||||
|
||||
// Add items
|
||||
$x = -1;
|
||||
foreach ($this->playerMenuItems as $menuItems) {
|
||||
@ -303,7 +252,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
|
||||
$menuQuad->setX($x);
|
||||
$menuQuad->setHAlign(Control::RIGHT);
|
||||
$x -= $itemSize * 1.05;
|
||||
|
||||
|
||||
if ($menuItem[1]) {
|
||||
$menuQuad->removeScriptFeatures();
|
||||
$description = '$s' . $menuItem[1];
|
||||
@ -311,7 +260,56 @@ 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);
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,10 @@ 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 {
|
||||
/*
|
||||
@ -61,8 +61,8 @@ 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) {
|
||||
@ -71,7 +71,7 @@ class AdminLists implements ManialinkPageAnswerListener, CallbackListener {
|
||||
|
||||
/**
|
||||
* Show the Admin List
|
||||
*
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function showAdminLists(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) {
|
||||
|
@ -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 {
|
||||
/*
|
||||
@ -22,29 +22,29 @@ class AuthCommands implements CommandListener {
|
||||
/**
|
||||
* Create a new AuthCommands instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$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 Player $player
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_AddSuperAdmin(array $chatCallback, Player $player) {
|
||||
if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) {
|
||||
$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,18 +64,29 @@ 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 Player $player
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_AddAdmin(array $chatCallback, Player $player) {
|
||||
if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) {
|
||||
$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,18 +106,29 @@ 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 Player $player
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_AddModerator(array $chatCallback, Player $player) {
|
||||
if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
||||
$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,32 +148,10 @@ 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
|
||||
*
|
||||
* @param Player $player
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
private function sendAddModeratorUsageInfo(Player $player) {
|
||||
|
@ -10,32 +10,32 @@ 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
|
||||
*/
|
||||
public $authCommands = null;
|
||||
|
||||
|
||||
/*
|
||||
* Private Properties
|
||||
*/
|
||||
@ -43,196 +43,19 @@ class AuthenticationManager implements CallbackListener {
|
||||
|
||||
/**
|
||||
* Construct a new Authentication Manager
|
||||
*
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->authCommands = new AuthCommands($maniaControl);
|
||||
|
||||
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'handleOnInit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ManiaControl OnInit Callback
|
||||
*/
|
||||
public function handleOnInit() {
|
||||
$this->updateMasterAdmins();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update MasterAdmins based on config
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function updateMasterAdmins() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
// 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 MasterAdmins
|
||||
$masterAdmins = $this->maniaControl->config->masteradmins->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 ($masterAdmins as $masterAdmin) {
|
||||
$login = (string) $masterAdmin;
|
||||
$adminStatement->bind_param('si', $login, $masterAdminLevel);
|
||||
$adminStatement->execute();
|
||||
if ($adminStatement->error) {
|
||||
trigger_error($adminStatement->error);
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
$adminStatement->close();
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a List of all Admins
|
||||
*
|
||||
* @param $authLevel
|
||||
* @return array null
|
||||
*/
|
||||
public function getAdmins($authLevel = -1) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
if ($authLevel < 0) {
|
||||
$query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "` WHERE `authLevel` > 0 ORDER BY `authLevel` DESC;";
|
||||
}
|
||||
else {
|
||||
$query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "` WHERE `authLevel` = " . $authLevel . ";";
|
||||
}
|
||||
$result = $mysqli->query($query);
|
||||
if (!$result) {
|
||||
trigger_error($mysqli->error);
|
||||
return null;
|
||||
}
|
||||
$admins = array();
|
||||
while ($row = $result->fetch_object()) {
|
||||
array_push($admins, $row);
|
||||
}
|
||||
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->database->mysqli;
|
||||
$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->callbackManager->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->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
|
||||
* @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
|
||||
*
|
||||
*
|
||||
* @param mixed $authLevelInt
|
||||
* @return string
|
||||
*/
|
||||
@ -251,9 +74,46 @@ class AuthenticationManager implements CallbackListener {
|
||||
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
|
||||
*/
|
||||
@ -273,39 +133,178 @@ class AuthenticationManager implements CallbackListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Authentication Level Int from Level Name
|
||||
*
|
||||
* @param string $authLevelName
|
||||
* @return int
|
||||
* Handle ManiaControl OnInit Callback
|
||||
*/
|
||||
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;
|
||||
public function handleOnInit() {
|
||||
$this->updateMasterAdmins();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Authentication Level Int from the given Param
|
||||
*
|
||||
* @param mixed $authLevelParam
|
||||
* @return int
|
||||
* Update MasterAdmins based on Config
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function getAuthLevelInt($authLevelParam) {
|
||||
if (is_object($authLevelParam) && property_exists($authLevelParam, 'authLevel')) {
|
||||
return (int) $authLevelParam->authLevel;
|
||||
private function updateMasterAdmins() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
// 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;
|
||||
}
|
||||
if (is_string($authLevelParam)) {
|
||||
return self::getAuthLevel($authLevelParam);
|
||||
$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);
|
||||
}
|
||||
return (int) $authLevelParam;
|
||||
$adminStatement->close();
|
||||
|
||||
// Set MasterAdmins
|
||||
$masterAdmins = $this->maniaControl->config->masteradmins->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 ($masterAdmins as $masterAdmin) {
|
||||
$login = (string)$masterAdmin;
|
||||
$adminStatement->bind_param('si', $login, $masterAdminLevel);
|
||||
$adminStatement->execute();
|
||||
if ($adminStatement->error) {
|
||||
trigger_error($adminStatement->error);
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
$adminStatement->close();
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a List of all Admins
|
||||
*
|
||||
* @param $authLevel
|
||||
* @return array null
|
||||
*/
|
||||
public function getAdmins($authLevel = -1) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
if ($authLevel < 0) {
|
||||
$query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "` WHERE `authLevel` > 0 ORDER BY `authLevel` DESC;";
|
||||
} else {
|
||||
$query = "SELECT * FROM `" . PlayerManager::TABLE_PLAYERS . "` WHERE `authLevel` = " . $authLevel . ";";
|
||||
}
|
||||
$result = $mysqli->query($query);
|
||||
if (!$result) {
|
||||
trigger_error($mysqli->error);
|
||||
return null;
|
||||
}
|
||||
$admins = array();
|
||||
while ($row = $result->fetch_object()) {
|
||||
array_push($admins, $row);
|
||||
}
|
||||
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->database->mysqli;
|
||||
$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->callbackManager->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->chat->sendError('You do not have the required Rights to perform this Action!', $player->login);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param $rightName
|
||||
* @param $authLevelNeeded
|
||||
*/
|
||||
public function definePermissionLevel($rightName, $authLevelNeeded) {
|
||||
$this->maniaControl->settingManager->initSetting($this, $rightName, $authLevelNeeded);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user