TrackManiaControl/core/Admin/AuthenticationManager.php

542 lines
17 KiB
PHP
Raw Normal View History

2013-11-09 17:24:03 +01:00
<?php
namespace ManiaControl\Admin;
2013-11-09 17:24:03 +01:00
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\EchoListener;
2015-07-11 15:54:15 +02:00
use ManiaControl\Communication\CommunicationAnswer;
use ManiaControl\Communication\CommunicationListener;
use ManiaControl\Communication\CommunicationMethods;
use ManiaControl\General\UsageInformationAble;
use ManiaControl\General\UsageInformationTrait;
use ManiaControl\Logger;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
use ManiaControl\Plugins\Plugin;
2014-05-13 16:03:26 +02:00
use ManiaControl\Settings\Setting;
2013-11-09 17:24:03 +01:00
/**
2014-01-06 17:48:40 +01:00
* Class managing Authentication Levels
2014-05-02 17:31:10 +02:00
*
2017-04-07 23:38:18 +02:00
* @api
2014-05-02 17:31:10 +02:00
* @author ManiaControl Team <mail@maniacontrol.com>
2020-01-22 10:39:35 +01:00
* @copyright 2014-2020 ManiaControl Team
2014-05-02 17:31:10 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2013-11-09 17:24:03 +01:00
*/
class AuthenticationManager implements CallbackListener, EchoListener, CommunicationListener, UsageInformationAble {
use UsageInformationTrait;
/*
2013-11-09 17:24:03 +01:00
* Constants
*/
2014-05-02 17:31:10 +02:00
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;
2014-05-02 17:31:10 +02:00
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 ECHO_GRANT_LEVEL = 'ManiaControl.AuthenticationManager.GrandLevel';
const ECHO_REVOKE_LEVEL = 'ManiaControl.AuthenticationManager.RevokeLevel';
/*
* Private properties
2013-11-09 17:24:03 +01:00
*/
/** @var ManiaControl $maniaControl */
private $maniaControl = null;
/** @var AuthCommands $authCommands */
private $authCommands = null;
2013-11-09 17:24:03 +01:00
/**
* Construct a new Authentication Manager instance
2014-05-02 17:31:10 +02:00
*
* @param ManiaControl $maniaControl
2013-11-09 17:24:03 +01:00
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->authCommands = new AuthCommands($maniaControl);
2017-05-09 19:29:42 +02:00
// Callbacks
2014-08-13 11:05:52 +02:00
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
// Echo Grant Level Command (Usage: sendEcho json_encode("player" => "loginName", "level" => "AUTH_LEVEL_NUMBER")
$this->maniaControl->getEchoManager()->registerEchoListener(self::ECHO_GRANT_LEVEL, $this, function ($params) {
if (property_exists($params, 'level') && property_exists($params, 'player')) {
$player = $this->maniaControl->getPlayerManager()->getPlayer($params->player);
if ($player) {
$this->grantAuthLevel($player, $params->level);
}
}
});
// Echo Revoke Level Command (Usage: sendEcho json_encode("player" => "loginName")
$this->maniaControl->getEchoManager()->registerEchoListener(self::ECHO_REVOKE_LEVEL, $this, function ($params) {
if (property_exists($params, 'player')) {
$player = $this->maniaControl->getPlayerManager()->getPlayer($params->player);
if ($player) {
$this->maniaControl->getAuthenticationManager()->grantAuthLevel($player, self::AUTH_LEVEL_PLAYER);
}
}
});
2015-07-11 15:54:15 +02:00
//Communication Listenings
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::GRANT_AUTH_LEVEL, $this, function ($data) {
if (!is_object($data) || !property_exists($data, 'level') || !property_exists($data, 'login')) {
return new CommunicationAnswer("No valid level or player login provided!", true);
}
$player = $this->maniaControl->getPlayerManager()->getPlayer($data->login);
if ($player) {
$success = $this->grantAuthLevel($player, $data->level);
return new CommunicationAnswer(array("success" => $success));
} else {
return new CommunicationAnswer("Player not found!", true);
}
});
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::REVOKE_AUTH_LEVEL, $this, function ($data) {
if (!is_object($data) || !property_exists($data, 'login')) {
return new CommunicationAnswer("No valid player login provided!", true);
}
$player = $this->maniaControl->getPlayerManager()->getPlayer($data->login);
if ($player) {
$success = $this->maniaControl->getAuthenticationManager()->grantAuthLevel($player, self::AUTH_LEVEL_PLAYER);
return new CommunicationAnswer(array("success" => $success));
} else {
return new CommunicationAnswer("Player not found!", true);
}
});
2013-11-09 17:24:03 +01:00
}
2014-05-02 17:31:10 +02:00
/**
* Get Name of the Authentication Level from Level Int
*
2017-04-07 23:38:18 +02:00
* @api
2014-05-02 17:31:10 +02:00
* @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;
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
case self::AUTH_LEVEL_PLAYER:
return self::AUTH_NAME_PLAYER;
2014-05-02 17:31:10 +02:00
}
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
return '-';
2014-05-02 17:31:10 +02:00
}
/**
* Get the Authentication Level Int from the given Param
*
2017-04-07 23:38:18 +02:00
* @api
2014-05-02 17:31:10 +02:00
* @param mixed $authLevelParam
* @return int
*/
public static function getAuthLevelInt($authLevelParam) {
if (is_object($authLevelParam) && property_exists($authLevelParam, 'authLevel')) {
return (int) $authLevelParam->authLevel;
2014-05-02 17:31:10 +02:00
}
if (is_string($authLevelParam)) {
return self::getAuthLevel($authLevelParam);
}
return (int) $authLevelParam;
2014-05-02 17:31:10 +02:00
}
/**
* Get Authentication Level Int from Level Name
*
2017-04-07 23:38:18 +02:00
* @api
2014-05-02 17:31:10 +02:00
* @param string $authLevelName
* @return int
*/
public static function getAuthLevel($authLevelName) {
$authLevelName = (string) $authLevelName;
2014-05-02 17:31:10 +02:00
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;
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
case self::AUTH_NAME_PLAYER:
return self::AUTH_LEVEL_PLAYER;
2014-05-02 17:31:10 +02:00
}
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
return -1;
2014-05-02 17:31:10 +02:00
}
/**
* Get the Abbreviation of the Authentication Level from Level Int
*
2017-04-07 23:38:18 +02:00
* @api
2014-05-02 17:31:10 +02:00
* @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
2017-04-07 23:38:18 +02:00
*
* @internal
*/
public function handleOnInit() {
2014-01-09 22:13:25 +01:00
$this->updateMasterAdmins();
}
2014-01-09 18:45:39 +01:00
2013-11-09 17:24:03 +01:00
/**
2014-05-02 17:31:10 +02:00
* Update MasterAdmins based on Config
*
2013-11-09 17:24:03 +01:00
* @return bool
*/
2014-01-06 17:48:40 +01:00
private function updateMasterAdmins() {
2014-08-13 11:05:52 +02:00
$masterAdminsElements = $this->maniaControl->getConfig()->xpath('masteradmins');
2014-05-27 10:59:14 +02:00
if (!$masterAdminsElements) {
Logger::logError('Missing MasterAdmins configuration!');
2014-05-27 10:59:14 +02:00
return false;
}
$masterAdminsElement = $masterAdminsElements[0];
2014-08-13 11:05:52 +02:00
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
2014-05-02 17:31:10 +02:00
// Remove all MasterAdmins
2014-05-02 17:31:10 +02:00
$adminQuery = "UPDATE `" . PlayerManager::TABLE_PLAYERS . "`
SET `authLevel` = ?
WHERE `authLevel` = ?;";
$adminStatement = $mysqli->prepare($adminQuery);
2014-01-09 22:13:25 +01:00
if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR);
return false;
}
2014-05-02 17:31:10 +02:00
$adminLevel = self::AUTH_LEVEL_SUPERADMIN;
2014-01-06 14:22:48 +01:00
$masterAdminLevel = self::AUTH_LEVEL_MASTERADMIN;
$adminStatement->bind_param('ii', $adminLevel, $masterAdminLevel);
$adminStatement->execute();
2014-01-09 22:13:25 +01:00
if ($adminStatement->error) {
trigger_error($adminStatement->error);
}
$adminStatement->close();
2014-05-02 17:31:10 +02:00
2014-05-27 10:59:14 +02:00
// Set configured MasterAdmins
$loginElements = $masterAdminsElement->xpath('login');
2014-05-02 17:31:10 +02:00
$adminQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
`login`,
`authLevel`
) VALUES (
?, ?
) ON DUPLICATE KEY UPDATE
`authLevel` = VALUES(`authLevel`);";
$adminStatement = $mysqli->prepare($adminQuery);
2014-01-09 22:13:25 +01:00
if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR);
return false;
}
$success = true;
2014-05-27 10:59:14 +02:00
foreach ($loginElements as $loginElement) {
$login = (string) $loginElement;
2014-02-13 00:46:41 +01:00
$adminStatement->bind_param('si', $login, $masterAdminLevel);
$adminStatement->execute();
2014-01-09 22:13:25 +01:00
if ($adminStatement->error) {
trigger_error($adminStatement->error);
$success = false;
}
}
$adminStatement->close();
2014-05-27 10:59:14 +02:00
return $success;
2013-11-09 17:24:03 +01:00
}
/**
* Get all connected Players with at least the given Auth Level
*
2017-04-07 23:38:18 +02:00
* @api
* @param int $authLevel
* @return Player[]
*/
public function getConnectedAdmins($authLevel = self::AUTH_LEVEL_MODERATOR) {
2014-08-13 11:05:52 +02:00
$players = $this->maniaControl->getPlayerManager()->getPlayers();
$admins = array();
foreach ($players as $player) {
if (self::checkRight($player, $authLevel)) {
array_push($admins, $player);
}
}
return $admins;
}
2017-05-09 19:29:42 +02:00
/**
* Get all connected Players with less permission than the given Auth Level
*
* @api
* @param int $authLevel
* @return Player[]
*/
public function getConnectedPlayers($authLevel = self::AUTH_LEVEL_MODERATOR) {
$players = $this->maniaControl->getPlayerManager()->getPlayers();
$playerArray = array();
foreach ($players as $player) {
if (!self::checkRight($player, $authLevel)) {
array_push($playerArray, $player);
}
}
return $playerArray;
}
/**
* Check whether the Player has enough Rights
*
2017-04-07 23:38:18 +02:00
* @api
* @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
2014-05-02 17:31:10 +02:00
*
2017-04-07 23:38:18 +02:00
* @api
* @param int $authLevel
* @return Player[]
*/
public function getAdmins($authLevel = self::AUTH_LEVEL_MODERATOR) {
2014-08-13 11:05:52 +02:00
$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()) {
2014-08-13 11:05:52 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($row->login, false);
if ($player) {
array_push($admins, $player);
}
}
$result->free();
return $admins;
}
2013-11-09 17:24:03 +01:00
/**
2014-01-06 17:48:40 +01:00
* Grant the Auth Level to the Player
2014-05-02 17:31:10 +02:00
*
2017-04-07 23:38:18 +02:00
* @api
* @param Player $player
2014-05-02 17:31:10 +02:00
* @param int $authLevel
2013-11-09 17:24:03 +01:00
* @return bool
*/
2014-01-06 17:48:40 +01:00
public function grantAuthLevel(Player &$player, $authLevel) {
if (!$player || !is_numeric($authLevel)) {
return false;
}
$authLevel = (int) $authLevel;
2014-01-31 16:55:01 +01:00
if ($authLevel >= self::AUTH_LEVEL_MASTERADMIN) {
return false;
2014-01-31 16:55:01 +01:00
}
2014-05-02 17:31:10 +02:00
2014-08-13 11:05:52 +02:00
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
2014-05-02 17:31:10 +02:00
$authQuery = "INSERT INTO `" . PlayerManager::TABLE_PLAYERS . "` (
`login`,
2017-02-04 11:41:31 +01:00
`nickname`,
`authLevel`
) VALUES (
2017-02-04 11:41:31 +01:00
?, ?, ?
) ON DUPLICATE KEY UPDATE
`authLevel` = VALUES(`authLevel`);";
$authStatement = $mysqli->prepare($authQuery);
2014-01-09 22:13:25 +01:00
if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR);
2013-11-09 17:24:03 +01:00
return false;
}
2017-02-04 11:41:31 +01:00
$authStatement->bind_param('ssi', $player->login, $player->nickname, $authLevel);
2014-01-06 17:48:40 +01:00
$authStatement->execute();
2014-01-09 22:13:25 +01:00
if ($authStatement->error) {
trigger_error($authStatement->error);
$authStatement->close();
return false;
2013-11-09 17:24:03 +01:00
}
$authStatement->close();
2014-05-02 17:31:10 +02:00
2014-01-06 17:48:40 +01:00
$player->authLevel = $authLevel;
2014-08-13 11:05:52 +02:00
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_AUTH_LEVEL_CHANGED, $player);
2014-05-02 17:31:10 +02:00
$this->maniaControl->getActionsMenu()->rebuildAndShowAdminMenu();
2014-01-06 17:48:40 +01:00
return true;
2013-11-09 17:24:03 +01:00
}
/**
2014-01-06 17:48:40 +01:00
* Send an Error Message to the Player
2014-05-02 17:31:10 +02:00
*
2017-04-07 23:38:18 +02:00
* @api
* @param Player $player
* @return bool
2013-11-09 17:24:03 +01:00
*/
public function sendNotAllowed(Player $player) {
2014-01-31 16:55:01 +01:00
if (!$player) {
return false;
2014-01-31 16:55:01 +01:00
}
2014-08-13 11:05:52 +02:00
return $this->maniaControl->getChat()->sendError('You do not have the required Rights to perform this Action!', $player);
}
2013-11-09 17:24:03 +01:00
/**
2014-05-02 17:31:10 +02:00
* Checks the permission by a right name
*
2017-04-07 23:38:18 +02:00
* @api
* @param Player $player
2014-05-02 17:31:10 +02:00
* @param $rightName
* @return bool
2013-11-09 17:24:03 +01:00
*/
2014-05-02 17:31:10 +02:00
public function checkPermission(Player $player, $rightName) {
2014-08-13 11:05:52 +02:00
$right = $this->maniaControl->getSettingManager()->getSettingValue($this, $rightName);
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
return self::checkRight($player, self::getAuthLevel($right));
}
/**
* Checks the permission by a right name
*
* @api
* @param Plugin $plugin
* @param Player $player
* @param $rightName
* @return bool
*/
public function checkPluginPermission(Plugin $plugin, Player $player, $rightName) {
$right = $this->maniaControl->getSettingManager()->getSettingValue($plugin, $rightName);
return self::checkRight($player, self::getAuthLevel($right));
2013-11-09 17:24:03 +01:00
}
2014-01-09 18:45:39 +01:00
/**
* Define a Minimum Right Level needed for an Action
2014-05-02 17:31:10 +02:00
*
2017-04-07 23:38:18 +02:00
* @api
* @param string $rightName
* @param int $authLevelNeeded
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
* @param string $authLevelsAllowed
2014-01-09 18:45:39 +01:00
*/
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
public function definePermissionLevel($rightName, $authLevelNeeded, $authLevelsAllowed = self::AUTH_LEVEL_MODERATOR) {
$this->maniaControl->getSettingManager()->initSetting($this, $rightName, self::getPermissionLevelNameArray($authLevelNeeded, $authLevelsAllowed));
}
/**
* Define a Minimum Right Level needed for an Action
*
* @api
* @param Plugin $plugin
* @param string $rightName
* @param int $authLevelNeeded
* @param string $authLevelsAllowed
*/
public function definePluginPermissionLevel(Plugin $plugin, $rightName, $authLevelNeeded, $authLevelsAllowed = self::AUTH_LEVEL_MODERATOR) {
$this->maniaControl->getSettingManager()->initSetting($plugin, $rightName, self::getPermissionLevelNameArray($authLevelNeeded, $authLevelsAllowed));
2014-05-25 10:06:22 +02:00
}
/**
* Get the PermissionLevelNameArray
*
* @api
2014-05-25 10:06:22 +02:00
* @param $authLevelNeeded
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
* @param $authLevelsAllowed
* @return array[]
2014-05-25 10:06:22 +02:00
*/
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
public static function getPermissionLevelNameArray($authLevelNeeded, $authLevelsAllowed = self::AUTH_LEVEL_MODERATOR) {
assert($authLevelNeeded >= $authLevelsAllowed);
switch ($authLevelsAllowed) {
case self::AUTH_LEVEL_PLAYER:
switch ($authLevelNeeded) {
case self::AUTH_LEVEL_PLAYER:
return array(self::AUTH_NAME_PLAYER, self::AUTH_NAME_MODERATOR, self::AUTH_NAME_ADMIN, self::AUTH_NAME_SUPERADMIN, self::AUTH_NAME_MASTERADMIN);
case self::AUTH_LEVEL_MODERATOR:
return array(self::AUTH_NAME_MODERATOR, self::AUTH_NAME_ADMIN, self::AUTH_NAME_SUPERADMIN, self::AUTH_NAME_MASTERADMIN, self::AUTH_NAME_PLAYER);
case self::AUTH_LEVEL_ADMIN:
return array(self::AUTH_NAME_ADMIN, self::AUTH_NAME_SUPERADMIN, self::AUTH_NAME_MASTERADMIN, self::AUTH_NAME_PLAYER, self::AUTH_NAME_MODERATOR);
case self::AUTH_LEVEL_SUPERADMIN:
return array(self::AUTH_NAME_SUPERADMIN, self::AUTH_NAME_MASTERADMIN, self::AUTH_NAME_PLAYER, self::AUTH_NAME_MODERATOR, self::AUTH_NAME_ADMIN);
case self::AUTH_LEVEL_MASTERADMIN:
return array(self::AUTH_NAME_MASTERADMIN, self::AUTH_NAME_PLAYER, self::AUTH_NAME_MODERATOR, self::AUTH_NAME_ADMIN, self::AUTH_NAME_SUPERADMIN);
}
break;
2014-05-25 10:06:22 +02:00
case self::AUTH_LEVEL_MODERATOR:
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
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);
}
break;
2014-05-25 10:06:22 +02:00
case self::AUTH_LEVEL_ADMIN:
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
switch ($authLevelNeeded) {
case self::AUTH_LEVEL_ADMIN:
return array(self::AUTH_NAME_ADMIN, self::AUTH_NAME_SUPERADMIN, self::AUTH_NAME_MASTERADMIN);
case self::AUTH_LEVEL_SUPERADMIN:
return array(self::AUTH_NAME_SUPERADMIN, self::AUTH_NAME_MASTERADMIN, self::AUTH_NAME_ADMIN);
case self::AUTH_LEVEL_MASTERADMIN:
return array(self::AUTH_NAME_MASTERADMIN, self::AUTH_NAME_ADMIN, self::AUTH_NAME_SUPERADMIN);
}
break;
2014-05-25 10:06:22 +02:00
case self::AUTH_LEVEL_SUPERADMIN:
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
switch ($authLevelNeeded) {
case self::AUTH_LEVEL_SUPERADMIN:
return array(self::AUTH_NAME_SUPERADMIN, self::AUTH_NAME_MASTERADMIN);
case self::AUTH_LEVEL_MASTERADMIN:
return array(self::AUTH_NAME_MASTERADMIN, self::AUTH_NAME_SUPERADMIN);
}
break;
// just for completeness, should not be used this way
2014-05-25 10:06:22 +02:00
case self::AUTH_LEVEL_MASTERADMIN:
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
switch ($authLevelNeeded) {
case self::AUTH_LEVEL_MASTERADMIN:
return array(self::AUTH_NAME_MASTERADMIN);
}
break;
2014-05-25 10:06:22 +02:00
}
Multiple Features to improve ManiaControl usability (#234) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. * New CallQueue which runs once inbetween the MC-loops * Added important queued call to be executed earlier * ErrorMethod made optional, as in some cases, there might be nothing to fail * Clean up repository from unnecessary files * Added easy installation script for DB on Unix-like systems * Replaced deprecated is_real by is_float * Add milliseconds with dot instead of double colon * Resolved deprecated curly braces error * gitignore all hidden files (except git and gitignore) * Update MC-update-check-interval, so that a restart is not required * Update gitignore to not ignore changes in MCTeam-Plugins * Update gitignore again * And another try * fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting * Increase version number of local records plugin * Add Permission to delete any record * Reworked notifications of locals, removed private only, added private at rank * Fix formatting * Allow AuthenticationManager to store Plugin Permissions * Method to check, if a named function call is already queued * Added command disable feature * Reset timer if DeltaTime updated, so it does not try to catch up missed timings * Added private notification setting * To reduce load of multiple records (especially in rounds), queue call chat notifications * Added internal function to plugin manager to return plugin menu * restore .idea codestyle files * Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
2014-05-25 10:06:22 +02:00
return array("-");
2014-01-09 18:45:39 +01:00
}
2013-11-09 17:24:03 +01:00
}