fixed small bug on authentification level changes + instant addition of the admin panel

This commit is contained in:
kremsy 2014-01-09 18:32:52 +01:00
parent 5452b99749
commit 6e4cf32a16

View File

@ -2,7 +2,6 @@
namespace ManiaControl\Players; namespace ManiaControl\Players;
use FML\Controls\Control;
use FML\Controls\Frame; use FML\Controls\Frame;
use FML\Controls\Labels\Label_Text; use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad; use FML\Controls\Quad;
@ -52,15 +51,17 @@ class PlayerActions {
*/ */
public function forcePlayerToPlay($adminLogin, $targetLogin, $type = 2) { public function forcePlayerToPlay($adminLogin, $targetLogin, $type = 2) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if(!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin); $this->maniaControl->authenticationManager->sendNotAllowed($admin);
return; return;
} }
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
if (!$target) return; if(!$target) {
return;
}
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, ($type != 1 ? 0 : 2)); $success = $this->maniaControl->client->query('ForceSpectator', $target->login, ($type != 1 ? 0 : 2));
if (!$success) { if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -79,36 +80,37 @@ class PlayerActions {
*/ */
public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId) { public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if(!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin); $this->maniaControl->authenticationManager->sendNotAllowed($admin);
return; return;
} }
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
if (!$target) return; if(!$target)
return;
if ($target->isSpectator) { if($target->isSpectator) {
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, self::SPECTATOR_PLAYER); $success = $this->maniaControl->client->query('ForceSpectator', $target->login, self::SPECTATOR_PLAYER);
if (!$success) { if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
} }
$success = $this->maniaControl->client->query('ForcePlayerTeam', $target->login, $teamId); $success = $this->maniaControl->client->query('ForcePlayerTeam', $target->login, $teamId);
if (!$success) { if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
$chatMessage = false; $chatMessage = false;
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if ($teamId == self::TEAM_BLUE) { if($teamId == self::TEAM_BLUE) {
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!'; $chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!';
} } else if($teamId == self::TEAM_RED) {
else if ($teamId == self::TEAM_RED) {
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!'; $chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!';
} }
if (!$chatMessage) return; if(!$chatMessage)
return;
$this->maniaControl->chat->sendInformation($chatMessage); $this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log($chatMessage, true); $this->maniaControl->log($chatMessage, true);
} }
@ -123,14 +125,14 @@ class PlayerActions {
*/ */
public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true) { public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if(!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin); $this->maniaControl->authenticationManager->sendNotAllowed($admin);
return; return;
} }
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, $spectatorState); $success = $this->maniaControl->client->query('ForceSpectator', $target->login, $spectatorState);
if (!$success) { if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -140,7 +142,7 @@ class PlayerActions {
$this->maniaControl->chat->sendInformation($chatMessage); $this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log($chatMessage, true); $this->maniaControl->log($chatMessage, true);
if ($releaseSlot) { if($releaseSlot) {
// Free player slot // Free player slot
$this->maniaControl->client->query('SpectatorReleasePlayerSlot', $target->login); $this->maniaControl->client->query('SpectatorReleasePlayerSlot', $target->login);
} }
@ -155,7 +157,7 @@ class PlayerActions {
*/ */
public function unMutePlayer($adminLogin, $targetLogin) { public function unMutePlayer($adminLogin, $targetLogin) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if(!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin); $this->maniaControl->authenticationManager->sendNotAllowed($admin);
return; return;
} }
@ -163,7 +165,7 @@ class PlayerActions {
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$success = $this->maniaControl->client->query('UnIgnore', $target->login); $success = $this->maniaControl->client->query('UnIgnore', $target->login);
if (!$success) { if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -183,7 +185,7 @@ class PlayerActions {
*/ */
public function mutePlayer($adminLogin, $targetLogin) { public function mutePlayer($adminLogin, $targetLogin) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if(!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin); $this->maniaControl->authenticationManager->sendNotAllowed($admin);
return; return;
} }
@ -191,7 +193,7 @@ class PlayerActions {
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$success = $this->maniaControl->client->query('Ignore', $targetLogin); $success = $this->maniaControl->client->query('Ignore', $targetLogin);
if (!$success) { if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -210,12 +212,13 @@ class PlayerActions {
*/ */
public function warnPlayer($adminLogin, $targetLogin) { public function warnPlayer($adminLogin, $targetLogin) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if(!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin); $this->maniaControl->authenticationManager->sendNotAllowed($admin);
return; return;
} }
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
if (!$target) return; if(!$target)
return;
// Display warning message // Display warning message
$message = '$s$f00This is an administrative warning.{br}{br}$gWhatever you wrote or you have done is against {br} our server\'s policy. $message = '$s$f00This is an administrative warning.{br}{br}$gWhatever you wrote or you have done is against {br} our server\'s policy.
@ -258,7 +261,7 @@ class PlayerActions {
$label->setTextColor('f00'); $label->setTextColor('f00');
$y = $height / 2 - 15; $y = $height / 2 - 15;
foreach ($message as $line) { foreach($message as $line) {
// Message lines // Message lines
$label = new Label_Text(); $label = new Label_Text();
$frame->add($label); $frame->add($label);
@ -288,20 +291,20 @@ class PlayerActions {
*/ */
public function kickPlayer($adminLogin, $targetLogin, $message = '') { public function kickPlayer($adminLogin, $targetLogin, $message = '') {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if(!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin); $this->maniaControl->authenticationManager->sendNotAllowed($admin);
return; return;
} }
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
if (!$target) return; if(!$target)
return;
if ($target->isFakePlayer()) { if($target->isFakePlayer()) {
$success = $this->maniaControl->client->query('DisconnectFakePlayer', $target->login); $success = $this->maniaControl->client->query('DisconnectFakePlayer', $target->login);
} } else {
else {
$success = $this->maniaControl->client->query('Kick', $target->login, $message); $success = $this->maniaControl->client->query('Kick', $target->login, $message);
} }
if (!$success) { if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -322,15 +325,16 @@ class PlayerActions {
*/ */
public function banPlayer($adminLogin, $targetLogin, $message = '') { public function banPlayer($adminLogin, $targetLogin, $message = '') {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_ADMIN)) { if(!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin); $this->maniaControl->authenticationManager->sendNotAllowed($admin);
return; return;
} }
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
if (!$target) return; if(!$target)
return;
$success = $this->maniaControl->client->query('Ban', $target->login, $message); $success = $this->maniaControl->client->query('Ban', $target->login, $message);
if (!$success) { if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -352,20 +356,22 @@ class PlayerActions {
public function grandAuthLevel($adminLogin, $targetLogin, $authLevel) { public function grandAuthLevel($adminLogin, $targetLogin, $authLevel) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
if (!$admin || !$target) return; if(!$admin || !$target)
return;
$authLevelName = $this->maniaControl->authenticationManager->getAuthLevelName($authLevel); $authLevelName = $this->maniaControl->authenticationManager->getAuthLevelName($authLevel);
if ($this->maniaControl->authenticationManager->checkRight($admin, $authLevel + 1)) { if(!$this->maniaControl->authenticationManager->checkRight($admin, $authLevel + 1)) {
$this->maniaControl->chat->sendError("You don't have the permission to add a {$authLevelName}!", $admin->login); $this->maniaControl->chat->sendError("You don't have the permission to add a {$authLevelName}!", $admin->login);
return;
} }
if ($this->maniaControl->authenticationManager->checkRight($target, $authLevel)) { if($this->maniaControl->authenticationManager->checkRight($target, $authLevel)) {
$this->maniaControl->chat->sendError("This Player is already {$authLevelName}!", $admin->login); $this->maniaControl->chat->sendError("This Player is already {$authLevelName}!", $admin->login);
return; return;
} }
$success = $this->maniaControl->authenticationManager->grantAuthLevel($target, $authLevel); $success = $this->maniaControl->authenticationManager->grantAuthLevel($target, $authLevel);
if (!$success) { if(!$success) {
$this->maniaControl->chat->sendError('Error occurred.', $admin->login); $this->maniaControl->chat->sendError('Error occurred.', $admin->login);
return; return;
} }
@ -386,21 +392,22 @@ class PlayerActions {
public function revokeAuthLevel($adminLogin, $targetLogin) { public function revokeAuthLevel($adminLogin, $targetLogin) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
if (!$admin || !$target) return; if(!$admin || !$target)
return;
if ($this->maniaControl->authenticationManager->checkRight($admin, $target->authLevel + 1)) { if(!$this->maniaControl->authenticationManager->checkRight($admin, $target->authLevel + 1)) {
$title = $this->maniaControl->authenticationManager->getAuthLevelName($target->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($target->authLevel);
$this->maniaControl->chat->sendError("You can't revoke the Rights of a {$title}!", $admin->login); $this->maniaControl->chat->sendError("You can't revoke the Rights of a {$title}!", $admin->login);
return; return;
} }
if ($this->maniaControl->authenticationManager->checkRight($target, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) { if($this->maniaControl->authenticationManager->checkRight($target, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) {
$this->maniaControl->chat->sendError("MasterAdmins can't be removed!", $admin->login); $this->maniaControl->chat->sendError("MasterAdmins can't be removed!", $admin->login);
return; return;
} }
$success = $this->maniaControl->authenticationManager->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_PLAYER); $success = $this->maniaControl->authenticationManager->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_PLAYER);
if (!$success) { if(!$success) {
$this->maniaControl->chat->sendError('Error occurred.', $admin->login); $this->maniaControl->chat->sendError('Error occurred.', $admin->login);
return; return;
} }
@ -420,8 +427,9 @@ class PlayerActions {
*/ */
public function isPlayerMuted($login) { public function isPlayerMuted($login) {
$this->maniaControl->client->query('GetIgnoreList', 100, 0); $this->maniaControl->client->query('GetIgnoreList', 100, 0);
foreach ($this->maniaControl->client->getResponse() as $ignoredPlayers) { foreach($this->maniaControl->client->getResponse() as $ignoredPlayers) {
if ($ignoredPlayers["Login"] == $login) return true; if($ignoredPlayers["Login"] == $login)
return true;
} }
return false; return false;
} }