TrackManiaControl/application/core/Players/PlayerActions.php

523 lines
18 KiB
PHP
Raw Normal View History

2013-12-23 20:57:50 +01:00
<?php
namespace ManiaControl\Players;
2013-12-24 12:49:53 +01:00
use FML\Controls\Frame;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink;
2013-12-23 21:47:39 +01:00
use ManiaControl\Admin\AuthenticationManager;
2013-12-24 12:49:53 +01:00
use ManiaControl\Formatter;
2013-12-23 20:57:50 +01:00
use ManiaControl\ManiaControl;
2013-12-24 12:49:53 +01:00
use ManiaControl\Manialinks\ManialinkManager;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
2013-12-23 20:57:50 +01:00
2013-12-24 13:09:39 +01:00
/**
* Player Actions Class
2013-12-24 13:09:39 +01:00
*
2014-04-13 12:25:39 +02:00
* @author steeffeen & kremsy
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
2014-04-13 12:25:39 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2013-12-24 13:09:39 +01:00
*/
2013-12-23 20:57:50 +01:00
class PlayerActions {
/*
2013-12-23 20:57:50 +01:00
* Constants
*/
const TEAM_BLUE = 0;
const TEAM_RED = 1;
const SPECTATOR_USER_SELECTABLE = 0;
const SPECTATOR_SPECTATOR = 1;
const SPECTATOR_PLAYER = 2;
2013-12-23 20:57:50 +01:00
const SPECTATOR_BUT_KEEP_SELECTABLE = 3;
/*
2014-01-09 19:08:29 +01:00
* Permission Setting Constants
*/
const SETTING_PERMISSION_FORCE_PLAYER_PLAY = 'Force Player to Play';
const SETTING_PERMISSION_FORCE_PLAYER_TEAM = 'Force Player to Team';
const SETTING_PERMISSION_FORCE_PLAYER_SPEC = 'Force Player to Spec';
2014-01-09 19:15:06 +01:00
const SETTING_PERMISSION_MUTE_PLAYER = 'Mute Player';
const SETTING_PERMISSION_WARN_PLAYER = 'Warn Player';
const SETTING_PERMISSION_KICK_PLAYER = 'Kick Player';
const SETTING_PERMISSION_BAN_PLAYER = 'Ban Player';
2014-01-09 19:08:29 +01:00
/*
2013-12-31 16:01:22 +01:00
* Private Properties
2013-12-23 20:57:50 +01:00
*/
private $maniaControl = null;
2013-12-31 16:01:22 +01:00
/**
* Create a PlayerActions Instance
*
* @param ManiaControl $maniaControl
*/
2013-12-23 20:57:50 +01:00
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
2014-01-09 19:08:29 +01:00
//Define Rights
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_BAN_PLAYER, AuthenticationManager::AUTH_LEVEL_ADMIN);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_KICK_PLAYER, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_WARN_PLAYER, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_MUTE_PLAYER, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_PLAY, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_TEAM, AuthenticationManager::AUTH_LEVEL_MODERATOR);
2014-01-09 19:15:06 +01:00
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_SPEC, AuthenticationManager::AUTH_LEVEL_MODERATOR);
2013-12-23 20:57:50 +01:00
}
2014-01-06 18:09:47 +01:00
/**
* Force a Player to Play
*
* @param string $adminLogin
* @param string $targetLogin
2014-01-14 14:37:31 +01:00
* @param bool $userIsAbleToSelect
* @param bool $displayAnnouncement
* @internal param int $type
2014-01-06 18:09:47 +01:00
*/
2014-01-14 14:37:31 +01:00
public function forcePlayerToPlay($adminLogin, $targetLogin, $userIsAbleToSelect = true, $displayAnnouncement = true) {
2014-01-06 18:09:47 +01:00
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
2014-02-27 13:25:11 +01:00
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_PLAY)) {
2014-01-06 18:09:47 +01:00
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
2014-02-27 13:25:11 +01:00
if (!$target) {
return;
}
2014-01-16 21:51:25 +01:00
try {
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_PLAYER);
} catch(Exception $e) {
2014-03-13 18:47:40 +01:00
if ($e->getMessage() == 'There are too many players') {
$this->maniaControl->chat->sendError("Too many Spectators");
return;
} else {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerActions Debug Line 90: " . $e->getMessage());
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
}
2014-01-06 18:09:47 +01:00
return;
}
2014-02-27 13:25:11 +01:00
if ($userIsAbleToSelect) {
2014-01-16 21:51:25 +01:00
try {
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE);
} catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
2014-03-01 11:11:50 +01:00
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerActions Debug Line 100: " . $e->getMessage());
2014-01-20 20:51:03 +01:00
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
2014-01-14 14:37:31 +01:00
return;
}
}
2014-01-06 18:09:47 +01:00
// Announce force
2014-02-27 13:25:11 +01:00
if ($displayAnnouncement) {
2014-01-14 14:37:31 +01:00
$chatMessage = '$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to Play!';
$this->maniaControl->chat->sendInformation($chatMessage);
}
2014-01-06 18:09:47 +01:00
}
2013-12-23 20:57:50 +01:00
/**
2013-12-31 16:01:22 +01:00
* Force a Player to a certain Team
*
* @param string $adminLogin
* @param string $targetLogin
* @param int $teamId
2013-12-23 20:57:50 +01:00
*/
2013-12-31 16:01:22 +01:00
public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
2014-02-27 13:25:11 +01:00
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_TEAM)) {
2014-01-06 18:09:47 +01:00
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
2013-12-23 21:47:39 +01:00
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
2014-02-27 13:25:11 +01:00
if (!$target || !$admin) {
return;
2014-01-09 19:08:29 +01:00
}
2014-02-27 13:25:11 +01:00
if ($target->isSpectator) {
2014-01-14 14:37:31 +01:00
$this->forcePlayerToPlay($adminLogin, $targetLogin, true, false);
2013-12-23 21:47:39 +01:00
}
2014-03-13 18:25:29 +01:00
try {
$this->maniaControl->client->forcePlayerTeam($target->login, $teamId);
} catch(Exception $e) {
if ($e->getMessage() == "Not in Team mode.") {
$this->forcePlayerToPlay($adminLogin, $targetLogin);
return;
} else {
throw $e;
}
}
2013-12-31 16:01:22 +01:00
$chatMessage = false;
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
2014-02-27 13:25:11 +01:00
if ($teamId == self::TEAM_BLUE) {
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!';
2014-02-27 13:25:11 +01:00
} else if ($teamId == self::TEAM_RED) {
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!';
2013-12-24 12:49:53 +01:00
}
2014-02-27 13:25:11 +01:00
if (!$chatMessage) {
return;
2014-01-09 19:08:29 +01:00
}
2013-12-31 16:01:22 +01:00
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log($chatMessage, true);
2013-12-23 20:57:50 +01:00
}
/**
2013-12-31 16:01:22 +01:00
* Force a Player to Spectator
*
* @param string $adminLogin
* @param string $targetLogin
* @param int $spectatorState
* @param bool $releaseSlot
2013-12-23 20:57:50 +01:00
*/
2014-01-02 19:37:52 +01:00
public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
2014-02-27 13:25:11 +01:00
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_SPEC)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
2013-12-23 21:47:39 +01:00
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
2014-03-01 19:54:44 +01:00
if (!$admin || !$target || $target->isSpectator) {
2013-12-23 21:47:39 +01:00
return;
}
2014-04-13 12:25:39 +02:00
try {
$this->maniaControl->client->forceSpectator($target->login, $spectatorState);
} catch(Exception $e) {
if ($e->getMessage() == "There are too many spectators") {
$this->maniaControl->chat->sendError($e->getMessage(), $adminLogin);
return;
}
throw $e;
}
2014-02-27 13:24:55 +01:00
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to Spectator!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log($chatMessage, true);
2014-02-27 13:25:11 +01:00
if ($releaseSlot) {
// Free player slot
2014-01-16 21:51:25 +01:00
try {
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
} catch(Exception $e) {
2014-03-19 19:54:40 +01:00
//if ($e->getMessage() == 'The player is not a spectator') {
2014-04-13 12:25:39 +02:00
//$this->kickPlayer($adminLogin, $targetLogin, 'Disconnect');
//$this->maniaControl->errorHandler->triggerDebugNotice("inaktiv spec player kicked " . $e->getMessage());
2014-03-19 19:54:40 +01:00
//} else {
2014-04-13 12:25:39 +02:00
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerActions Debug Line 183: " . $e->getMessage());
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
//do nothing
2014-03-19 19:54:40 +01:00
//}
2014-01-16 21:51:25 +01:00
}
}
2013-12-23 20:57:50 +01:00
}
2014-01-02 16:37:52 +01:00
/**
* UnMute a Player
2014-01-02 16:37:52 +01:00
*
* @param string $adminLogin
* @param string $targetLogin
* @param int $spectatorState
2014-01-02 16:37:52 +01:00
*/
public function unMutePlayer($adminLogin, $targetLogin) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
2014-02-27 13:25:11 +01:00
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_MUTE_PLAYER)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
2014-02-27 13:25:11 +01:00
if (!$target) {
2014-01-02 16:37:52 +01:00
return;
}
2014-02-27 13:25:11 +01:00
$this->maniaControl->client->unIgnore($targetLogin);
2014-02-27 13:24:55 +01:00
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
2014-01-02 16:37:52 +01:00
$chatMessage = $title . ' $<' . $admin->nickname . '$> un-muted $<' . $target->nickname . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log($chatMessage, true);
2014-01-02 16:37:52 +01:00
}
/**
* Mute a Player
2014-01-02 16:37:52 +01:00
*
* @param string $adminLogin
* @param string $targetLogin
* @param int $spectatorState
2014-01-02 16:37:52 +01:00
*/
public function mutePlayer($adminLogin, $targetLogin) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
2014-02-27 13:25:11 +01:00
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_MUTE_PLAYER)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
2014-01-02 16:37:52 +01:00
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
2014-02-27 13:25:11 +01:00
if (!$target) {
2014-02-27 13:24:55 +01:00
return;
}
$this->maniaControl->client->ignore($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
2014-01-02 16:37:52 +01:00
$chatMessage = $title . ' $<' . $admin->nickname . '$> muted $<' . $target->nickname . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log($chatMessage, true);
2014-01-02 16:37:52 +01:00
}
2013-12-23 21:47:39 +01:00
/**
* Warn a Player
2013-12-31 16:01:22 +01:00
*
* @param string $adminLogin
* @param string $targetLogin
2013-12-23 21:47:39 +01:00
*/
2013-12-31 16:01:22 +01:00
public function warnPlayer($adminLogin, $targetLogin) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
2014-02-27 13:25:11 +01:00
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_WARN_PLAYER)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
2014-02-27 13:24:55 +01:00
2013-12-24 12:49:53 +01:00
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
2014-02-27 13:24:55 +01:00
2014-02-27 13:25:11 +01:00
if (!$target) {
return;
2014-01-09 19:08:29 +01:00
}
// Display warning message
2013-12-24 12:49:53 +01:00
$message = '$s$f00This is an administrative warning.{br}{br}$gWhatever you wrote or you have done is against {br} our server\'s policy.
{br}Not respecting other players, or{br}using offensive language might result in a{br}$f00kick, or ban $ff0the next time.
{br}{br}$gThe server administrators.';
$message = preg_split('/{br}/', $message);
// Build Manialink
$width = 80;
$height = 50;
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
2013-12-29 10:19:39 +01:00
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
2013-12-24 12:49:53 +01:00
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$frame = new Frame();
2013-12-24 12:49:53 +01:00
$maniaLink->add($frame);
$frame->setPosition(0, 10);
// Background
2013-12-24 12:49:53 +01:00
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
2013-12-31 16:01:22 +01:00
$backgroundQuad->setSize($width, $height);
2013-12-24 12:49:53 +01:00
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
// Close Quad (X)
2013-12-24 12:49:53 +01:00
$closeQuad = new Quad_Icons64x64_1();
$frame->add($closeQuad);
$closeQuad->setPosition($width * 0.473, $height * 0.457, 3);
$closeQuad->setSize(6, 6);
$closeQuad->setSubStyle($closeQuad::SUBSTYLE_QuitRace);
2013-12-24 12:49:53 +01:00
$closeQuad->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
// Headline
2013-12-24 12:49:53 +01:00
$label = new Label_Text();
$frame->add($label);
$label->setY($height / 2 - 5);
$label->setStyle($label::STYLE_TextCardMedium);
2013-12-24 12:49:53 +01:00
$label->setTextSize(4);
$label->setText('Administrative Warning');
$label->setTextColor('f00');
2013-12-24 12:49:53 +01:00
$y = $height / 2 - 15;
foreach($message as $line) {
// Message lines
2013-12-24 12:49:53 +01:00
$label = new Label_Text();
$frame->add($label);
$label->setY($y);
$label->setStyle(Label_Text::STYLE_TextCardMedium);
$label->setText($line);
$label->setTextColor('ff0');
2014-01-10 15:58:27 +01:00
$label->setTextSize(1.3);
2013-12-24 12:49:53 +01:00
$y -= 4;
}
2013-12-31 16:01:22 +01:00
// Display manialink
2013-12-24 12:49:53 +01:00
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $target);
// Announce warning
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin->nickname . '$> warned $<' . $target->nickname . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log($chatMessage, true);
2013-12-23 20:57:50 +01:00
}
2013-12-23 21:47:39 +01:00
/**
* Kick a Player
2013-12-31 16:01:22 +01:00
*
* @param string $adminLogin
* @param string $targetLogin
2013-12-23 21:47:39 +01:00
* @param string $message
*/
2013-12-31 16:01:22 +01:00
public function kickPlayer($adminLogin, $targetLogin, $message = '') {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
2014-02-27 13:25:11 +01:00
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_KICK_PLAYER)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
2013-12-23 21:47:39 +01:00
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
2014-02-27 13:25:11 +01:00
if (!$target) {
return;
2014-01-09 19:08:29 +01:00
}
2014-01-20 20:51:03 +01:00
try {
2014-02-27 13:25:11 +01:00
if ($target->isFakePlayer()) {
2014-01-20 20:51:03 +01:00
$this->maniaControl->client->disconnectFakePlayer($target->login);
} else {
$this->maniaControl->client->kick($target->login, $message);
}
} catch(Exception $e) {
2014-04-13 12:25:39 +02:00
if ($e == "Login unknown.") {
2014-04-09 10:42:56 +02:00
return;
}
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
2014-03-01 11:11:50 +01:00
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerActions Debug Line 354: " . $e->getMessage());
2014-01-20 20:51:03 +01:00
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
2013-12-23 21:47:39 +01:00
return;
}
// Announce kick
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin->nickname . '$> kicked $<' . $target->nickname . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
2013-12-23 20:57:50 +01:00
}
2013-12-23 21:47:39 +01:00
/**
* Ban a Player
2013-12-31 16:01:22 +01:00
*
* @param string $adminLogin
* @param string $targetLogin
2013-12-23 21:47:39 +01:00
* @param string $message
*/
2013-12-31 16:01:22 +01:00
public function banPlayer($adminLogin, $targetLogin, $message = '') {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
2014-02-27 13:25:11 +01:00
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_BAN_PLAYER)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
2013-12-23 21:47:39 +01:00
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
2014-02-27 13:25:11 +01:00
if (!$target) {
return;
2014-01-09 19:08:29 +01:00
}
2014-02-27 13:25:11 +01:00
if ($target->isFakePlayer()) {
2014-01-16 19:49:36 +01:00
$this->maniaControl->chat->sendError('It is not possible to Ban a bot', $admin->login);
return;
}
$this->maniaControl->client->ban($target->login, $message);
// Announce ban
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin->nickname . '$> banned $<' . $target->nickname . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log($chatMessage, true);
2013-12-23 20:57:50 +01:00
}
2013-12-26 11:25:10 +01:00
/**
2013-12-31 16:01:22 +01:00
* Grands the Player an Authorization Level
*
* @param string $adminLogin
* @param string $targetLogin
* @param int $authLevel
2013-12-26 11:25:10 +01:00
*/
2013-12-31 16:01:22 +01:00
public function grandAuthLevel($adminLogin, $targetLogin, $authLevel) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
2013-12-26 11:25:10 +01:00
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
2014-02-27 13:25:11 +01:00
if (!$admin || !$target) {
return;
2014-01-09 19:08:29 +01:00
}
$authLevelName = $this->maniaControl->authenticationManager->getAuthLevelName($authLevel);
2014-02-27 13:25:11 +01:00
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;
}
2014-02-27 13:25:11 +01:00
if ($this->maniaControl->authenticationManager->checkRight($target, $authLevel)) {
$this->maniaControl->chat->sendError("This Player is already {$authLevelName}!", $admin->login);
return;
}
2013-12-26 11:25:10 +01:00
$success = $this->maniaControl->authenticationManager->grantAuthLevel($target, $authLevel);
2014-02-27 13:25:11 +01:00
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred.', $admin->login);
2013-12-26 11:25:10 +01:00
return;
}
// Announce granting
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin->nickname . '$> added $<' . $target->nickname . '$> as $< ' . $authLevelName . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log($chatMessage, true);
2013-12-26 11:25:10 +01:00
}
/**
2013-12-31 16:01:22 +01:00
* Revokes all Rights from the Player
*
* @param string $adminLogin
* @param string $targetLogin
2013-12-26 11:25:10 +01:00
*/
2013-12-31 16:01:22 +01:00
public function revokeAuthLevel($adminLogin, $targetLogin) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
2013-12-26 11:25:10 +01:00
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
2014-02-27 13:25:11 +01:00
if (!$admin || !$target) {
return;
2014-01-09 19:08:29 +01:00
}
2014-02-27 13:25:11 +01:00
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;
}
2014-02-27 13:25:11 +01:00
if ($this->maniaControl->authenticationManager->checkRight($target, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) {
$this->maniaControl->chat->sendError("MasterAdmins can't be removed!", $admin->login);
2013-12-26 11:25:10 +01:00
return;
}
2013-12-26 11:25:10 +01:00
$success = $this->maniaControl->authenticationManager->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_PLAYER);
2014-02-27 13:25:11 +01:00
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred.', $admin->login);
2013-12-26 11:25:10 +01:00
return;
}
// Announce revoke
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' $<' . $admin->nickname . '$> revoked the Rights of $<' . $target->nickname . '$>!';
2013-12-31 16:01:22 +01:00
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log($chatMessage, true);
2013-12-26 11:25:10 +01:00
}
2014-01-02 16:37:52 +01:00
/**
* Check if a Player is muted
2014-01-02 16:37:52 +01:00
*
* @param string $login
2014-01-02 16:37:52 +01:00
* @return bool
*/
public function isPlayerMuted($login) {
2014-01-16 19:07:00 +01:00
$ignoreList = $this->maniaControl->client->getIgnoreList(100, 0);
foreach($ignoreList as $ignoredPlayers) {
2014-02-27 13:25:11 +01:00
if ($ignoredPlayers->login == $login) {
return true;
2014-01-09 19:08:29 +01:00
}
2014-01-02 16:37:52 +01:00
}
return false;
}
2013-12-31 16:01:22 +01:00
}