Changed 'Operator' Level to 'Moderator'

This commit is contained in:
Steffen Schröder 2013-12-31 17:17:11 +01:00
parent 6f4320ff75
commit dcb4e3f951
9 changed files with 69 additions and 45 deletions

View File

@ -8,6 +8,6 @@
<login>kremsy</login>
</masteradmins>
<!-- You can add other admins and operators ingame -->
<!-- You can add other admins and moderators ingame -->
</authentication-config>

View File

@ -28,7 +28,7 @@ class AuthCommands implements CommandListener {
// Register for commands
$this->maniaControl->commandManager->registerCommandListener('addsuperadmin', $this, 'command_AddSuperAdmin',true);
$this->maniaControl->commandManager->registerCommandListener('addadmin', $this, 'command_AddAdmin',true);
$this->maniaControl->commandManager->registerCommandListener('addop', $this, 'command_AddOperator',true);
$this->maniaControl->commandManager->registerCommandListener('addmod', $this, 'command_AddModerator',true);
}
/**
@ -94,12 +94,12 @@ class AuthCommands implements CommandListener {
}
/**
* Handle //addop command
* Handle //addmod command
*
* @param array $chatCallback
* @param Player $player
*/
public function command_AddOperator(array $chatCallback, Player $player) {
public function command_AddModerator(array $chatCallback, Player $player) {
if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
@ -107,7 +107,7 @@ class AuthCommands implements CommandListener {
$text = $chatCallback[1][2];
$commandParts = explode(' ', $text);
if (!array_key_exists(1, $commandParts)) {
$this->sendAddOperatorUsageInfo($player);
$this->sendAddModeratorUsageInfo($player);
return;
}
$target = $this->maniaControl->playerManager->getPlayer($commandParts[1]);
@ -115,12 +115,12 @@ class AuthCommands implements CommandListener {
$this->maniaControl->chat->sendError("Player '{$commandParts[1]}' not found!", $player->login);
return;
}
$success = $this->maniaControl->authenticationManager->grantAuthLevel($player, AuthenticationManager::AUTH_LEVEL_OPERATOR);
$success = $this->maniaControl->authenticationManager->grantAuthLevel($player, AuthenticationManager::AUTH_LEVEL_MODERATOR);
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred.', $player->login);
return;
}
$message = '$<' . $player->nickname . '$> added $<' . $target->nickname . '$> as Operator!';
$message = '$<' . $player->nickname . '$> added $<' . $target->nickname . '$> as Moderator!';
$this->maniaControl->chat->sendSuccess($message);
}
@ -152,8 +152,8 @@ class AuthCommands implements CommandListener {
* @param Player $player
* @return bool
*/
private function sendAddOperatorUsageInfo(Player $player) {
$message = "Usage Example: '//addop login'";
private function sendAddModeratorUsageInfo(Player $player) {
$message = "Usage Example: '//addmod login'";
return $this->maniaControl->chat->sendUsageInfo($message, $player->login);
}
}

View File

@ -19,12 +19,11 @@ class AuthenticationManager {
* Constants
*/
const AUTH_LEVEL_PLAYER = 0;
const AUTH_LEVEL_OPERATOR = 1;
const AUTH_LEVEL_MODERATOR = 1;
const AUTH_LEVEL_ADMIN = 2;
const AUTH_LEVEL_SUPERADMIN = 3;
const AUTH_LEVEL_MASTERADMIN = 4;
const CB_AUTH_LEVEL_CHANGED = 'AuthenticationManager.AuthLevelChanged';
const CB_AUTH_LEVEL_CHANGED = 'AuthenticationManager.AuthLevelChanged';
/**
* Private properties
*/
@ -34,7 +33,7 @@ class AuthenticationManager {
/**
* Construct authentication manager
*
* @param \ManiaControl\ManiaControl $maniaControl
* @param \ManiaControl\ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
@ -87,8 +86,10 @@ class AuthenticationManager {
$adminStatement->bind_param('si', $login, $xAdminLevel);
$success = true;
foreach ($xAdmins as $xAdmin) {
/** @noinspection PhpUnusedLocalVariableInspection */
$login = (string) $xAdmin;
/**
* @noinspection PhpUnusedLocalVariableInspection
*/
$login = (string) $xAdmin;
$adminStatement->execute();
if ($adminStatement->error) {
trigger_error($adminStatement->error);
@ -102,8 +103,8 @@ class AuthenticationManager {
/**
* Grant the auth level to the player
*
* @param Player $player
* @param int $authLevel
* @param Player $player
* @param int $authLevel
* @return bool
*/
public function grantAuthLevel(Player $player, $authLevel) {
@ -131,13 +132,14 @@ class AuthenticationManager {
return false;
}
$authStatement->close();
if($success){
if ($success) {
// Trigger callback
$player->authLevel = $authLevel;
$this->maniaControl->callbackManager->triggerCallback(self::CB_AUTH_LEVEL_CHANGED, array(self::CB_AUTH_LEVEL_CHANGED, $player));
$this->maniaControl->callbackManager->triggerCallback(self::CB_AUTH_LEVEL_CHANGED,
array(self::CB_AUTH_LEVEL_CHANGED, $player));
}
return $success;
}
@ -158,7 +160,7 @@ class AuthenticationManager {
* Check if the player has enough rights
*
* @param Player $player
* @param int $neededAuthLevel
* @param int $neededAuthLevel
* @return bool
*/
public static function checkRight(Player $player, $neededAuthLevel) {
@ -168,7 +170,7 @@ class AuthenticationManager {
/**
* Get Name of the Authentication Level from Level Int
*
* @param int $authLevelInt
* @param int $authLevelInt
* @return string
*/
public static function getAuthLevelName($authLevelInt) {
@ -181,16 +183,38 @@ class AuthenticationManager {
if ($authLevelInt == self::AUTH_LEVEL_ADMIN) {
return 'Admin';
}
if ($authLevelInt == self::AUTH_LEVEL_OPERATOR) {
return 'Operator';
if ($authLevelInt == self::AUTH_LEVEL_MODERATOR) {
return 'Moderator';
}
return 'Player';
}
/**
* Get the Abbreviation of the Authentication Level from Level Int
*
* @param int $authLevelInt
* @return string
*/
public static function getAuthLevelAbbreviation($authLevelInt) {
if ($authLevelInt == self::AUTH_LEVEL_MASTERADMIN) {
return 'MA';
}
if ($authLevelInt == self::AUTH_LEVEL_SUPERADMIN) {
return 'SA';
}
if ($authLevelInt == self::AUTH_LEVEL_ADMIN) {
return 'AD';
}
if ($authLevelInt == self::AUTH_LEVEL_MODERATOR) {
return 'MOD';
}
return 'PL';
}
/**
* Get Authentication Level Int from Level Name
*
* @param string $authLevelName
* @param string $authLevelName
* @return int
*/
public static function getAuthLevel($authLevelName) {
@ -204,8 +228,8 @@ class AuthenticationManager {
if ($authLevelName == 'Admin') {
return self::AUTH_LEVEL_ADMIN;
}
if ($authLevelName == 'Operator') {
return self::AUTH_LEVEL_OPERATOR;
if ($authLevelName == 'Moderator') {
return self::AUTH_LEVEL_MODERATOR;
}
return self::AUTH_LEVEL_PLAYER;
}

View File

@ -50,7 +50,7 @@ class MapCommands implements CommandListener {
* @param \ManiaControl\Players\Player $player
*/
public function command_RemoveMap(array $chat, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
@ -76,7 +76,7 @@ class MapCommands implements CommandListener {
* @param \ManiaControl\Players\Player $player
*/
public function command_AddMap(array $chatCallback, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
@ -98,7 +98,7 @@ class MapCommands implements CommandListener {
* @param \ManiaControl\Players\Player $player
*/
public function command_NextMap(array $chat, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
@ -112,7 +112,7 @@ class MapCommands implements CommandListener {
* @param \ManiaControl\Players\Player $player
*/
public function command_RestartMap(array $chat, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}

View File

@ -358,7 +358,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$descriptionLabel->setText("Remove Map: {$map->name}");
$script->addTooltip($eraseQuad, $descriptionLabel);
}
if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)){ //TODO SET as setting who can add maps
if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)){ //TODO SET as setting who can add maps
//switch to map quad
//$switchToQuad = new Quad_Icons64x64_1(); //TODO change name to label
$switchToQuad = new Label_Button();

View File

@ -54,7 +54,7 @@ class PlayerCommands implements CommandListener {
* @param Player $player
*/
public function command_TeamBalance(array $chatCallback, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
@ -73,7 +73,7 @@ class PlayerCommands implements CommandListener {
* @param Player $player
*/
public function command_Kick(array $chat, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
@ -103,7 +103,7 @@ class PlayerCommands implements CommandListener {
* @param Player $player
*/
public function command_ForceSpectator(array $chat, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
@ -140,7 +140,7 @@ class PlayerCommands implements CommandListener {
* @param Player $player
*/
public function command_ForcePlayer(array $chat, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}

View File

@ -126,7 +126,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
$frame->add($headFrame);
$headFrame->setY($y - 5);
// $array = array("Id" => $x + 5, "Nickname" => $x + 10, "Login" => $x + 40, "Ladder" => $x + 60,"Zone" => $x + 85);
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$array = array("Id" => $x + 5, "Nickname" => $x + 18, "Login" => $x + 60, "Location" => $x + 91, "Actions" => $x + 135);
}
else {
@ -270,13 +270,13 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
case authenticationManager::AUTH_LEVEL_ADMIN:
$rightLabel->setText("AD");
break;
case authenticationManager::AUTH_LEVEL_OPERATOR:
case authenticationManager::AUTH_LEVEL_MODERATOR:
$rightLabel->setText("MOD");
}
$rightLabel->setTextColor("fff");
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
// Further Player actions Quad
$playerQuad = new Quad_Icons64x64_1();
$playerFrame->add($playerQuad);
@ -567,7 +567,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
$label->setText("Set Moderator");
$label->setTextColor($textColor);
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$y -= 5;
// Revoke Rights
$quad = new Quad_BgsPlayerCard();
@ -664,7 +664,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
break;
case self::ACTION_ADD_AS_MOD:
$this->maniaControl->playerManager->playerActions->grandAuthLevel($adminLogin, $targetLogin,
AuthenticationManager::AUTH_LEVEL_OPERATOR);
AuthenticationManager::AUTH_LEVEL_MODERATOR);
break;
case self::ACTION_REVOKE_RIGHTS:
$this->maniaControl->playerManager->playerActions->revokeAuthLevel($adminLogin, $targetLogin);

View File

@ -368,7 +368,7 @@ class ServerCommands implements CallbackListener, CommandListener {
* @param Player $player
*/
public function command_EnableHorns(array $chatCallback, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
@ -387,7 +387,7 @@ class ServerCommands implements CallbackListener, CommandListener {
* @param Player $player
*/
public function command_DisableHorns(array $chatCallback, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}

View File

@ -38,7 +38,7 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
// Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_JUMPTOAUTHLEVEL,
AuthenticationManager::AUTH_LEVEL_OPERATOR);
AuthenticationManager::AUTH_LEVEL_MODERATOR);
// Register for commands
$this->maniaControl->commandManager->registerCommandListener('jumpto', $this, 'command_JumpTo');