fixed small bug on authentification level changes + instant addition of the admin panel
This commit is contained in:
parent
5452b99749
commit
6e4cf32a16
@ -2,7 +2,6 @@
|
||||
|
||||
namespace ManiaControl\Players;
|
||||
|
||||
use FML\Controls\Control;
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Labels\Label_Text;
|
||||
use FML\Controls\Quad;
|
||||
@ -22,11 +21,11 @@ class PlayerActions {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const TEAM_BLUE = 0;
|
||||
const TEAM_RED = 1;
|
||||
const SPECTATOR_USER_SELECTABLE = 0;
|
||||
const SPECTATOR_SPECTATOR = 1;
|
||||
const SPECTATOR_PLAYER = 2;
|
||||
const TEAM_BLUE = 0;
|
||||
const TEAM_RED = 1;
|
||||
const SPECTATOR_USER_SELECTABLE = 0;
|
||||
const SPECTATOR_SPECTATOR = 1;
|
||||
const SPECTATOR_PLAYER = 2;
|
||||
const SPECTATOR_BUT_KEEP_SELECTABLE = 3;
|
||||
|
||||
/**
|
||||
@ -48,19 +47,21 @@ class PlayerActions {
|
||||
*
|
||||
* @param string $adminLogin
|
||||
* @param string $targetLogin
|
||||
* @param int $type
|
||||
* @param int $type
|
||||
*/
|
||||
public function forcePlayerToPlay($adminLogin, $targetLogin, $type = 2) {
|
||||
$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);
|
||||
return;
|
||||
}
|
||||
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
|
||||
if (!$target) return;
|
||||
if(!$target) {
|
||||
return;
|
||||
}
|
||||
|
||||
$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);
|
||||
return;
|
||||
}
|
||||
@ -75,40 +76,41 @@ class PlayerActions {
|
||||
*
|
||||
* @param string $adminLogin
|
||||
* @param string $targetLogin
|
||||
* @param int $teamId
|
||||
* @param int $teamId
|
||||
*/
|
||||
public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId) {
|
||||
$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);
|
||||
return;
|
||||
}
|
||||
$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);
|
||||
if (!$success) {
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$success = $this->maniaControl->client->query('ForcePlayerTeam', $target->login, $teamId);
|
||||
if (!$success) {
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
|
||||
return;
|
||||
}
|
||||
|
||||
$chatMessage = false;
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
if ($teamId == self::TEAM_BLUE) {
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
if($teamId == self::TEAM_BLUE) {
|
||||
$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!';
|
||||
}
|
||||
if (!$chatMessage) return;
|
||||
if(!$chatMessage)
|
||||
return;
|
||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||
$this->maniaControl->log($chatMessage, true);
|
||||
}
|
||||
@ -118,29 +120,29 @@ class PlayerActions {
|
||||
*
|
||||
* @param string $adminLogin
|
||||
* @param string $targetLogin
|
||||
* @param int $spectatorState
|
||||
* @param bool $releaseSlot
|
||||
* @param int $spectatorState
|
||||
* @param bool $releaseSlot
|
||||
*/
|
||||
public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true) {
|
||||
$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);
|
||||
return;
|
||||
}
|
||||
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
|
||||
|
||||
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, $spectatorState);
|
||||
if (!$success) {
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
|
||||
return;
|
||||
}
|
||||
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to Spectator!';
|
||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||
$this->maniaControl->log($chatMessage, true);
|
||||
|
||||
if ($releaseSlot) {
|
||||
if($releaseSlot) {
|
||||
// Free player slot
|
||||
$this->maniaControl->client->query('SpectatorReleasePlayerSlot', $target->login);
|
||||
}
|
||||
@ -151,11 +153,11 @@ class PlayerActions {
|
||||
*
|
||||
* @param string $adminLogin
|
||||
* @param string $targetLogin
|
||||
* @param int $spectatorState
|
||||
* @param int $spectatorState
|
||||
*/
|
||||
public function unMutePlayer($adminLogin, $targetLogin) {
|
||||
$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);
|
||||
return;
|
||||
}
|
||||
@ -163,12 +165,12 @@ class PlayerActions {
|
||||
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
|
||||
|
||||
$success = $this->maniaControl->client->query('UnIgnore', $target->login);
|
||||
if (!$success) {
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
|
||||
return;
|
||||
}
|
||||
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$chatMessage = $title . ' $<' . $admin->nickname . '$> un-muted $<' . $target->nickname . '$>!';
|
||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||
$this->maniaControl->log($chatMessage, true);
|
||||
@ -179,11 +181,11 @@ class PlayerActions {
|
||||
*
|
||||
* @param string $adminLogin
|
||||
* @param string $targetLogin
|
||||
* @param int $spectatorState
|
||||
* @param int $spectatorState
|
||||
*/
|
||||
public function mutePlayer($adminLogin, $targetLogin) {
|
||||
$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);
|
||||
return;
|
||||
}
|
||||
@ -191,12 +193,12 @@ class PlayerActions {
|
||||
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
|
||||
|
||||
$success = $this->maniaControl->client->query('Ignore', $targetLogin);
|
||||
if (!$success) {
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
|
||||
return;
|
||||
}
|
||||
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$chatMessage = $title . ' $<' . $admin->nickname . '$> muted $<' . $target->nickname . '$>!';
|
||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||
$this->maniaControl->log($chatMessage, true);
|
||||
@ -210,12 +212,13 @@ class PlayerActions {
|
||||
*/
|
||||
public function warnPlayer($adminLogin, $targetLogin) {
|
||||
$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);
|
||||
return;
|
||||
}
|
||||
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
|
||||
if (!$target) return;
|
||||
if(!$target)
|
||||
return;
|
||||
|
||||
// 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.
|
||||
@ -224,13 +227,13 @@ class PlayerActions {
|
||||
$message = preg_split('/{br}/', $message);
|
||||
|
||||
// Build Manialink
|
||||
$width = 80;
|
||||
$height = 50;
|
||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
|
||||
$width = 80;
|
||||
$height = 50;
|
||||
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
|
||||
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
|
||||
|
||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||
$frame = new Frame();
|
||||
$frame = new Frame();
|
||||
$maniaLink->add($frame);
|
||||
$frame->setPosition(0, 10);
|
||||
|
||||
@ -258,7 +261,7 @@ class PlayerActions {
|
||||
$label->setTextColor('f00');
|
||||
|
||||
$y = $height / 2 - 15;
|
||||
foreach ($message as $line) {
|
||||
foreach($message as $line) {
|
||||
// Message lines
|
||||
$label = new Label_Text();
|
||||
$frame->add($label);
|
||||
@ -273,7 +276,7 @@ class PlayerActions {
|
||||
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $target);
|
||||
|
||||
// Announce warning
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$chatMessage = $title . ' $<' . $admin->nickname . '$> warned $<' . $target->nickname . '$>!';
|
||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||
$this->maniaControl->log($chatMessage, true);
|
||||
@ -288,26 +291,26 @@ class PlayerActions {
|
||||
*/
|
||||
public function kickPlayer($adminLogin, $targetLogin, $message = '') {
|
||||
$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);
|
||||
return;
|
||||
}
|
||||
$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);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$success = $this->maniaControl->client->query('Kick', $target->login, $message);
|
||||
}
|
||||
if (!$success) {
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
|
||||
return;
|
||||
}
|
||||
|
||||
// Announce kick
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$chatMessage = $title . ' $<' . $admin->nickname . '$> kicked $<' . $target->nickname . '$>!';
|
||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
|
||||
@ -322,21 +325,22 @@ class PlayerActions {
|
||||
*/
|
||||
public function banPlayer($adminLogin, $targetLogin, $message = '') {
|
||||
$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);
|
||||
return;
|
||||
}
|
||||
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
|
||||
if (!$target) return;
|
||||
if(!$target)
|
||||
return;
|
||||
|
||||
$success = $this->maniaControl->client->query('Ban', $target->login, $message);
|
||||
if (!$success) {
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
|
||||
return;
|
||||
}
|
||||
|
||||
// Announce ban
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$chatMessage = $title . ' $<' . $admin->nickname . '$> banned $<' . $target->nickname . '$>!';
|
||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||
$this->maniaControl->log($chatMessage, true);
|
||||
@ -347,31 +351,33 @@ class PlayerActions {
|
||||
*
|
||||
* @param string $adminLogin
|
||||
* @param string $targetLogin
|
||||
* @param int $authLevel
|
||||
* @param int $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);
|
||||
if (!$admin || !$target) return;
|
||||
if(!$admin || !$target)
|
||||
return;
|
||||
|
||||
$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);
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
$success = $this->maniaControl->authenticationManager->grantAuthLevel($target, $authLevel);
|
||||
if (!$success) {
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred.', $admin->login);
|
||||
return;
|
||||
}
|
||||
|
||||
// Announce granting
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$chatMessage = $title . ' $<' . $admin->nickname . '$> added $<' . $target->nickname . '$> as $< ' . $authLevelName . '$>!';
|
||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||
$this->maniaControl->log($chatMessage, true);
|
||||
@ -384,29 +390,30 @@ class PlayerActions {
|
||||
* @param string $targetLogin
|
||||
*/
|
||||
public function revokeAuthLevel($adminLogin, $targetLogin) {
|
||||
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
|
||||
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
|
||||
$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);
|
||||
$this->maniaControl->chat->sendError("You can't revoke the Rights of a {$title}!", $admin->login);
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
$success = $this->maniaControl->authenticationManager->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_PLAYER);
|
||||
if (!$success) {
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred.', $admin->login);
|
||||
return;
|
||||
}
|
||||
|
||||
// Announce revoke
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
$chatMessage = $title . ' $<' . $admin->nickname . '$> revoked the Rights of $<' . $target->nickname . '$>!';
|
||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||
$this->maniaControl->log($chatMessage, true);
|
||||
@ -420,8 +427,9 @@ class PlayerActions {
|
||||
*/
|
||||
public function isPlayerMuted($login) {
|
||||
$this->maniaControl->client->query('GetIgnoreList', 100, 0);
|
||||
foreach ($this->maniaControl->client->getResponse() as $ignoredPlayers) {
|
||||
if ($ignoredPlayers["Login"] == $login) return true;
|
||||
foreach($this->maniaControl->client->getResponse() as $ignoredPlayers) {
|
||||
if($ignoredPlayers["Login"] == $login)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user