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;
|
2015-06-23 21:20:44 +02:00
|
|
|
use ManiaControl\Callbacks\EchoListener;
|
2015-06-26 11:48:21 +02:00
|
|
|
use ManiaControl\Communication\CommunicationAnswer;
|
2015-06-23 21:20:44 +02:00
|
|
|
use ManiaControl\Communication\CommunicationListener;
|
|
|
|
use ManiaControl\Communication\CommunicationMethods;
|
2017-03-26 19:44:55 +02:00
|
|
|
use ManiaControl\General\UsageInformationAble;
|
|
|
|
use ManiaControl\General\UsageInformationTrait;
|
2014-08-05 01:49:13 +02:00
|
|
|
use ManiaControl\Logger;
|
2013-12-23 20:57:50 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
2013-12-24 12:49:53 +01:00
|
|
|
use ManiaControl\Manialinks\ManialinkManager;
|
2014-05-13 17:59:37 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\AlreadyInListException;
|
2014-04-28 20:58:21 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\FaultException;
|
2014-08-10 00:09:46 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
2014-05-13 17:59:37 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\NotInListException;
|
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\PlayerStateException;
|
2014-07-19 23:39:25 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\ServerOptionsException;
|
2014-05-13 17:59:37 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\UnknownPlayerException;
|
2013-12-23 20:57:50 +01:00
|
|
|
|
2013-12-24 13:09:39 +01:00
|
|
|
/**
|
2014-04-12 12:14:37 +02:00
|
|
|
* Player Actions Class
|
2013-12-24 13:09:39 +01:00
|
|
|
*
|
2017-04-14 19:23:09 +02:00
|
|
|
* @api
|
2014-05-02 17:50:30 +02:00
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2017-02-04 11:49:23 +01:00
|
|
|
* @copyright 2014-2017 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
|
|
|
*/
|
2017-03-26 19:44:55 +02:00
|
|
|
class PlayerActions implements EchoListener, CommunicationListener, UsageInformationAble {
|
|
|
|
use UsageInformationTrait;
|
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2013-12-23 20:57:50 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
2014-01-09 18:32:52 +01:00
|
|
|
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;
|
2015-06-23 21:20:44 +02:00
|
|
|
const ECHO_WARN_PLAYER = 'ManiaControl.PlayerManager.WarnPlayer';
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
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
|
|
|
|
2015-06-23 21:20:44 +02:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-08-02 22:31:46 +02:00
|
|
|
* Private properties
|
2013-12-23 20:57:50 +01:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2013-12-23 20:57:50 +01:00
|
|
|
private $maniaControl = null;
|
|
|
|
|
2013-12-31 16:01:22 +01:00
|
|
|
/**
|
2014-08-03 01:34:18 +02:00
|
|
|
* Construct a new PlayerActions instance
|
2013-12-31 16:01:22 +01:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Permissions
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_BAN_PLAYER, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
|
|
|
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_KICK_PLAYER, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
|
|
|
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_WARN_PLAYER, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
|
|
|
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_MUTE_PLAYER, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
|
|
|
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_PLAY, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
|
|
|
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_TEAM, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
|
|
|
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_SPEC, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
2015-06-23 21:20:44 +02:00
|
|
|
|
|
|
|
// Echo Warn Command (Usage: sendEcho json_encode("player" => "loginName")
|
|
|
|
$this->maniaControl->getEchoManager()->registerEchoListener(self::ECHO_WARN_PLAYER, $this, function ($params) {
|
|
|
|
$this->warnPlayer(null, $params->player, false);
|
|
|
|
});
|
|
|
|
|
|
|
|
//Communication Manager Methods
|
|
|
|
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::WARN_PLAYER, $this, function ($data) {
|
|
|
|
if (!is_object($data) || !property_exists($data, "login")) {
|
2015-06-26 11:48:21 +02:00
|
|
|
return new CommunicationAnswer("You have to provide a valid player Login", true);
|
2015-06-23 21:20:44 +02:00
|
|
|
}
|
|
|
|
$success = $this->warnPlayer(null, $data->login, false);
|
2015-06-26 11:48:21 +02:00
|
|
|
return new CommunicationAnswer(array("success" => $success));
|
2015-06-23 21:20:44 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::MUTE_PLAYER, $this, function ($data) {
|
|
|
|
if (!is_object($data) || !property_exists($data, "login")) {
|
2015-06-26 11:48:21 +02:00
|
|
|
return new CommunicationAnswer("You have to provide a valid player Login", true);
|
2015-06-23 21:20:44 +02:00
|
|
|
}
|
|
|
|
$success = $this->mutePlayer(null, $data->login, false);
|
2015-06-26 11:48:21 +02:00
|
|
|
return new CommunicationAnswer(array("success" => $success));
|
2015-06-23 21:20:44 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::UNMUTE_PLAYER, $this, function ($data) {
|
|
|
|
if (!is_object($data) || !property_exists($data, "login")) {
|
2015-06-26 11:48:21 +02:00
|
|
|
return new CommunicationAnswer("You have to provide a valid player Login", true);
|
2015-06-23 21:20:44 +02:00
|
|
|
}
|
|
|
|
$success = $this->unMutePlayer(null, $data->login, false);
|
2015-06-26 11:48:21 +02:00
|
|
|
return new CommunicationAnswer(array("success" => $success));
|
2015-06-23 21:20:44 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::KICK_PLAYER, $this, function ($data) {
|
|
|
|
if (!is_object($data) || !property_exists($data, "login")) {
|
2015-06-26 11:48:21 +02:00
|
|
|
return new CommunicationAnswer("You have to provide a valid player Login", true);
|
2015-06-23 21:20:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$message = "";
|
|
|
|
if (property_exists($data, "message")) {
|
|
|
|
$message = $data->message;
|
|
|
|
}
|
|
|
|
|
|
|
|
$success = $this->kickPlayer(null, $data->login, $message, false);
|
2015-06-26 11:48:21 +02:00
|
|
|
|
|
|
|
return new CommunicationAnswer(array("success" => $success));
|
2015-06-23 21:20:44 +02:00
|
|
|
});
|
2015-06-26 13:06:05 +02:00
|
|
|
|
|
|
|
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::FORCE_PLAYER_TO_SPEC, $this, function ($data) {
|
|
|
|
if (!is_object($data) || !property_exists($data, "login")) {
|
|
|
|
return new CommunicationAnswer("You have to provide a valid player Login", true);
|
|
|
|
}
|
|
|
|
//TODO allow parameters like spectator state
|
|
|
|
$success = $this->forcePlayerToSpectator(null, $data->login, self::SPECTATOR_BUT_KEEP_SELECTABLE, true, false);
|
|
|
|
return new CommunicationAnswer(array("success" => $success));
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::FORCE_PLAYER_TO_PLAY, $this, function ($data) {
|
|
|
|
if (!is_object($data) || !property_exists($data, "login")) {
|
|
|
|
return new CommunicationAnswer("You have to provide a valid player Login", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO allow parameters like spectator state
|
|
|
|
if (property_exists($data, "teamId")) {
|
|
|
|
$success = $this->forcePlayerToTeam(null, $data->login, $data->teamId, false);
|
|
|
|
} else {
|
|
|
|
$success = $this->forcePlayerToPlay(null, $data->login, true, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new CommunicationAnswer(array("success" => $success));
|
|
|
|
});
|
2013-12-23 20:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-31 16:01:22 +01:00
|
|
|
* Force a Player to a certain Team
|
|
|
|
*
|
2017-04-14 19:23:09 +02:00
|
|
|
* @api
|
2013-12-31 16:01:22 +01:00
|
|
|
* @param string $adminLogin
|
|
|
|
* @param string $targetLogin
|
2014-01-09 18:32:52 +01:00
|
|
|
* @param int $teamId
|
2015-06-26 13:06:05 +02:00
|
|
|
* @param bool $calledByAdmin
|
|
|
|
* @return bool
|
2013-12-23 20:57:50 +01:00
|
|
|
*/
|
2015-06-26 13:06:05 +02:00
|
|
|
public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId, $calledByAdmin = true) {
|
|
|
|
if ($calledByAdmin) {
|
|
|
|
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
2015-07-29 22:07:52 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_TEAM)) {
|
2015-06-26 13:06:05 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!$admin) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-06 18:09:47 +01:00
|
|
|
}
|
2014-08-13 11:05:52 +02:00
|
|
|
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
|
2015-06-26 13:06:05 +02:00
|
|
|
if (!$target) {
|
|
|
|
return false;
|
2014-01-09 19:08:29 +01:00
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-06-22 19:23:54 +02:00
|
|
|
if ($target->isSpectator) {
|
|
|
|
try {
|
2015-06-26 13:06:05 +02:00
|
|
|
if (!$this->forcePlayerToPlay($adminLogin, $targetLogin, true, false, $calledByAdmin)) {
|
|
|
|
return false;
|
2014-06-22 19:23:54 +02:00
|
|
|
}
|
|
|
|
} catch (FaultException $exception) {
|
2015-06-26 13:06:05 +02:00
|
|
|
if ($calledByAdmin) {
|
|
|
|
$this->maniaControl->getChat()->sendException($exception, $admin);
|
|
|
|
}
|
2014-06-22 19:23:54 +02:00
|
|
|
}
|
2013-12-23 21:47:39 +01:00
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-03-13 18:25:29 +01:00
|
|
|
try {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getClient()->forcePlayerTeam($target->login, $teamId);
|
2014-08-05 01:49:13 +02:00
|
|
|
} catch (ServerOptionsException $exception) {
|
2014-04-19 23:47:46 +02:00
|
|
|
$this->forcePlayerToPlay($adminLogin, $targetLogin);
|
2015-06-26 13:06:05 +02:00
|
|
|
return false;
|
2014-12-25 12:20:27 +01:00
|
|
|
} catch (UnknownPlayerException $exception) {
|
2015-06-26 13:06:05 +02:00
|
|
|
if ($calledByAdmin) {
|
|
|
|
$this->maniaControl->getChat()->sendException($exception, $admin);
|
|
|
|
}
|
|
|
|
return false;
|
2014-08-10 00:09:46 +02:00
|
|
|
} catch (GameModeException $exception) {
|
2015-06-26 13:06:05 +02:00
|
|
|
if ($calledByAdmin) {
|
|
|
|
$this->maniaControl->getChat()->sendException($exception, $admin);
|
|
|
|
}
|
|
|
|
return false;
|
2014-03-13 18:25:29 +01:00
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2013-12-31 16:01:22 +01:00
|
|
|
$chatMessage = false;
|
2015-06-26 13:06:05 +02:00
|
|
|
|
|
|
|
if ($calledByAdmin) {
|
|
|
|
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
|
|
|
|
if ($teamId === self::TEAM_BLUE) {
|
|
|
|
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' into the Blue-Team!';
|
|
|
|
} else if ($teamId === self::TEAM_RED) {
|
|
|
|
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' into the Red-Team!';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($teamId === self::TEAM_BLUE) {
|
|
|
|
$chatMessage = $target->getEscapedNickname() . ' got forced into the Blue-Team!';
|
|
|
|
} else if ($teamId === self::TEAM_RED) {
|
|
|
|
$chatMessage = $target->getEscapedNickname() . ' got forced into the Red-Team!';
|
|
|
|
}
|
2013-12-24 12:49:53 +01:00
|
|
|
}
|
2015-06-26 13:06:05 +02:00
|
|
|
|
2014-02-27 13:25:11 +01:00
|
|
|
if (!$chatMessage) {
|
2015-06-26 13:06:05 +02:00
|
|
|
return false;
|
2014-01-09 19:08:29 +01:00
|
|
|
}
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
2014-08-05 02:08:41 +02:00
|
|
|
Logger::logInfo($chatMessage, true);
|
2015-06-26 13:06:05 +02:00
|
|
|
|
|
|
|
return true;
|
2013-12-23 20:57:50 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
/**
|
|
|
|
* Force a Player to Play
|
|
|
|
*
|
2017-04-14 19:23:09 +02:00
|
|
|
* @api
|
2014-05-02 17:50:30 +02:00
|
|
|
* @param string $adminLogin
|
|
|
|
* @param string $targetLogin
|
|
|
|
* @param bool $userIsAbleToSelect
|
|
|
|
* @param bool $displayAnnouncement
|
2015-06-26 13:06:05 +02:00
|
|
|
* @param bool $calledByAdmin
|
2014-06-22 16:13:19 +02:00
|
|
|
* @return bool
|
2014-05-02 17:50:30 +02:00
|
|
|
*/
|
2015-06-26 13:06:05 +02:00
|
|
|
public function forcePlayerToPlay($adminLogin, $targetLogin, $userIsAbleToSelect = true, $displayAnnouncement = true, $calledByAdmin = true) {
|
|
|
|
if ($calledByAdmin) {
|
|
|
|
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
2015-07-29 22:07:52 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_PLAY)) {
|
2015-06-26 13:06:05 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
}
|
2015-06-26 13:06:05 +02:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
|
2014-05-02 17:50:30 +02:00
|
|
|
if (!$target) {
|
2014-06-22 16:13:19 +02:00
|
|
|
return false;
|
2014-05-02 17:50:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getClient()->forceSpectator($target->login, self::SPECTATOR_PLAYER);
|
2014-08-03 01:34:18 +02:00
|
|
|
} catch (ServerOptionsException $exception) {
|
2015-06-26 13:06:05 +02:00
|
|
|
if ($calledByAdmin) {
|
|
|
|
$this->maniaControl->getChat()->sendException($exception, $admin);
|
|
|
|
}
|
2014-06-22 16:13:19 +02:00
|
|
|
return false;
|
2017-02-11 23:26:28 +01:00
|
|
|
} catch (UnknownPlayerException $exception) {
|
|
|
|
if ($calledByAdmin) {
|
|
|
|
$this->maniaControl->getChat()->sendException($exception, $admin);
|
|
|
|
}
|
|
|
|
return false;
|
2014-05-02 17:50:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($userIsAbleToSelect) {
|
|
|
|
try {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getClient()->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE);
|
2014-08-03 01:34:18 +02:00
|
|
|
} catch (ServerOptionsException $exception) {
|
2015-06-26 13:06:05 +02:00
|
|
|
if ($calledByAdmin) {
|
|
|
|
$this->maniaControl->getChat()->sendException($exception, $admin);
|
|
|
|
}
|
2014-06-27 01:18:55 +02:00
|
|
|
return false;
|
2014-05-02 17:50:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Announce force
|
|
|
|
if ($displayAnnouncement) {
|
2015-06-26 13:06:05 +02:00
|
|
|
if ($calledByAdmin) {
|
|
|
|
$chatMessage = $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' to Play!';
|
|
|
|
} else {
|
|
|
|
$chatMessage = $target->getEscapedNickname() . ' got forced to Play!';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
2014-05-02 17:50:30 +02:00
|
|
|
}
|
2014-06-22 16:13:19 +02:00
|
|
|
|
|
|
|
return true;
|
2014-05-02 17:50:30 +02:00
|
|
|
}
|
|
|
|
|
2013-12-23 20:57:50 +01:00
|
|
|
/**
|
2013-12-31 16:01:22 +01:00
|
|
|
* Force a Player to Spectator
|
|
|
|
*
|
2017-04-14 19:23:09 +02:00
|
|
|
* @api
|
2013-12-31 16:01:22 +01:00
|
|
|
* @param string $adminLogin
|
|
|
|
* @param string $targetLogin
|
2014-01-09 18:32:52 +01:00
|
|
|
* @param int $spectatorState
|
|
|
|
* @param bool $releaseSlot
|
2015-06-26 13:06:05 +02:00
|
|
|
* @param bool $calledByAdmin
|
|
|
|
* @return bool
|
2013-12-23 20:57:50 +01:00
|
|
|
*/
|
2015-06-26 13:06:05 +02:00
|
|
|
public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true, $calledByAdmin = true) {
|
|
|
|
if ($calledByAdmin) {
|
|
|
|
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
2015-07-29 22:07:52 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_SPEC)) {
|
2015-06-26 13:06:05 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$admin) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-06 17:33:45 +01:00
|
|
|
}
|
2015-06-26 13:06:05 +02:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2015-06-26 13:06:05 +02:00
|
|
|
if (!$target || $target->isSpectator) {
|
|
|
|
return false;
|
2013-12-23 21:47:39 +01:00
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-04-13 12:25:39 +02:00
|
|
|
try {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getClient()->forceSpectator($target->login, $spectatorState);
|
2014-07-19 23:39:25 +02:00
|
|
|
} catch (ServerOptionsException $exception) {
|
2015-06-26 13:06:05 +02:00
|
|
|
if ($calledByAdmin) {
|
|
|
|
$this->maniaControl->getChat()->sendException($exception, $admin->login);
|
|
|
|
}
|
|
|
|
return false;
|
2014-04-13 12:25:39 +02:00
|
|
|
}
|
|
|
|
|
2015-06-26 13:06:05 +02:00
|
|
|
if ($calledByAdmin) {
|
|
|
|
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
|
|
|
|
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' to Spectator!';
|
|
|
|
} else {
|
|
|
|
$chatMessage = $target->getEscapedNickname() . ' got forced to Spectator!';
|
|
|
|
}
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
2014-08-05 02:08:41 +02:00
|
|
|
Logger::logInfo($chatMessage, true);
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-02-27 13:25:11 +01:00
|
|
|
if ($releaseSlot) {
|
2014-01-06 17:33:45 +01:00
|
|
|
// Free player slot
|
2014-01-16 21:51:25 +01:00
|
|
|
try {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getClient()->spectatorReleasePlayerSlot($target->login);
|
2014-05-13 17:59:37 +02:00
|
|
|
} catch (PlayerStateException $e) {
|
2014-07-19 23:39:25 +02:00
|
|
|
} catch (UnknownPlayerException $e) {
|
2014-01-16 21:51:25 +01:00
|
|
|
}
|
2014-01-06 17:33:45 +01:00
|
|
|
}
|
2015-06-26 13:06:05 +02:00
|
|
|
|
|
|
|
return true;
|
2013-12-23 20:57:50 +01:00
|
|
|
}
|
|
|
|
|
2014-01-02 16:37:52 +01:00
|
|
|
/**
|
2014-01-06 17:33:45 +01:00
|
|
|
* UnMute a Player
|
2014-01-02 16:37:52 +01:00
|
|
|
*
|
2017-04-14 19:23:09 +02:00
|
|
|
* @api
|
2015-06-23 21:20:44 +02:00
|
|
|
* @param $adminLogin
|
|
|
|
* @param $targetLogin
|
|
|
|
* @param bool $calledByAdmin
|
|
|
|
* @return bool
|
2014-01-02 16:37:52 +01:00
|
|
|
*/
|
2015-06-23 21:20:44 +02:00
|
|
|
public function unMutePlayer($adminLogin, $targetLogin, $calledByAdmin = true) {
|
|
|
|
if ($calledByAdmin) {
|
|
|
|
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
2015-07-29 22:07:52 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_MUTE_PLAYER)) {
|
2015-06-23 21:20:44 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-06 17:33:45 +01:00
|
|
|
}
|
2014-08-13 11:05:52 +02:00
|
|
|
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-02-27 13:25:11 +01:00
|
|
|
if (!$target) {
|
2015-06-23 21:20:44 +02:00
|
|
|
return false;
|
2014-01-02 16:37:52 +01:00
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
try {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getClient()->unIgnore($targetLogin);
|
2014-05-13 17:59:37 +02:00
|
|
|
} catch (NotInListException $e) {
|
2014-08-14 19:08:23 +02:00
|
|
|
$this->maniaControl->getChat()->sendError('Player is not ignored!', $adminLogin);
|
2015-06-23 21:20:44 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($calledByAdmin) {
|
|
|
|
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
|
|
|
|
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' un-muted ' . $target->getEscapedNickname() . '!';
|
|
|
|
} else {
|
|
|
|
$chatMessage = $target->getEscapedNickname() . ' got un-muted!';
|
2014-04-24 10:38:50 +02:00
|
|
|
}
|
2014-02-27 13:24:55 +01:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
2014-08-05 02:08:41 +02:00
|
|
|
Logger::logInfo($chatMessage, true);
|
2015-06-23 21:20:44 +02:00
|
|
|
|
|
|
|
return true;
|
2014-01-02 16:37:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-01-06 17:33:45 +01:00
|
|
|
* Mute a Player
|
2014-01-02 16:37:52 +01:00
|
|
|
*
|
2017-04-14 19:23:09 +02:00
|
|
|
* @api
|
2014-01-02 16:37:52 +01:00
|
|
|
* @param string $adminLogin
|
|
|
|
* @param string $targetLogin
|
2015-06-23 21:20:44 +02:00
|
|
|
* @param bool $calledByAdmin
|
|
|
|
* @return bool
|
2014-01-02 16:37:52 +01:00
|
|
|
*/
|
2015-06-23 21:20:44 +02:00
|
|
|
public function mutePlayer($adminLogin, $targetLogin, $calledByAdmin = true) {
|
|
|
|
if ($calledByAdmin) {
|
|
|
|
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
2015-07-29 22:07:52 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_MUTE_PLAYER)) {
|
2015-06-23 21:20:44 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-06 17:33:45 +01:00
|
|
|
}
|
2014-08-13 11:05:52 +02:00
|
|
|
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-02-27 13:25:11 +01:00
|
|
|
if (!$target) {
|
2015-06-23 21:20:44 +02:00
|
|
|
return false;
|
2014-02-27 13:24:55 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
try {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getClient()->ignore($targetLogin);
|
2014-05-13 17:59:37 +02:00
|
|
|
} catch (AlreadyInListException $e) {
|
2014-08-14 19:08:23 +02:00
|
|
|
$this->maniaControl->getChat()->sendError("Player already ignored!", $adminLogin);
|
2015-06-23 21:20:44 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Announce warning
|
|
|
|
if ($calledByAdmin) {
|
|
|
|
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
|
|
|
|
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' muted ' . $target->getEscapedNickname() . '!';
|
|
|
|
} else {
|
|
|
|
$chatMessage = $target->getEscapedNickname() . ' got muted!';
|
2014-04-24 10:33:47 +02:00
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
2014-08-05 02:08:41 +02:00
|
|
|
Logger::logInfo($chatMessage, true);
|
2015-06-23 21:20:44 +02:00
|
|
|
|
|
|
|
return 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
|
|
|
*
|
2017-04-14 19:23:09 +02:00
|
|
|
* @api
|
2013-12-31 16:01:22 +01:00
|
|
|
* @param string $adminLogin
|
|
|
|
* @param string $targetLogin
|
2015-06-19 18:30:44 +02:00
|
|
|
* @param bool $calledByAdmin
|
2015-06-23 21:20:44 +02:00
|
|
|
* @return bool
|
2013-12-23 21:47:39 +01:00
|
|
|
*/
|
2015-06-19 18:30:44 +02:00
|
|
|
public function warnPlayer($adminLogin, $targetLogin, $calledByAdmin = true) {
|
|
|
|
if ($calledByAdmin) {
|
2015-06-19 01:37:31 +02:00
|
|
|
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
2015-07-29 22:07:52 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_WARN_PLAYER)) {
|
2015-06-19 01:37:31 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
|
2015-06-23 21:20:44 +02:00
|
|
|
return false;
|
2015-06-19 01:37:31 +02:00
|
|
|
}
|
2014-01-06 17:33:45 +01:00
|
|
|
}
|
2014-02-27 13:24:55 +01:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
|
2014-02-27 13:24:55 +01:00
|
|
|
|
2014-02-27 13:25:11 +01:00
|
|
|
if (!$target) {
|
2015-06-23 21:20:44 +02:00
|
|
|
return false;
|
2014-01-09 19:08:29 +01:00
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-01-06 17:33:45 +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);
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-01-06 17:33:45 +01:00
|
|
|
// Build Manialink
|
2014-01-09 18:32:52 +01:00
|
|
|
$width = 80;
|
|
|
|
$height = 50;
|
2014-08-13 11:05:52 +02:00
|
|
|
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowStyle();
|
|
|
|
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultMainWindowSubStyle();
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2013-12-24 12:49:53 +01:00
|
|
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
2014-01-09 18:32:52 +01:00
|
|
|
$frame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$maniaLink->addChild($frame);
|
2013-12-24 12:49:53 +01:00
|
|
|
$frame->setPosition(0, 10);
|
2017-05-07 19:35:53 +02:00
|
|
|
$frame->setZ(ManialinkManager::MAIN_MANIALINK_Z_VALUE);
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-01-06 17:33:45 +01:00
|
|
|
// Background
|
2013-12-24 12:49:53 +01:00
|
|
|
$backgroundQuad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($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);
|
2017-05-07 19:35:53 +02:00
|
|
|
$backgroundQuad->setZ(-1);
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-01-06 17:33:45 +01:00
|
|
|
// Close Quad (X)
|
2013-12-24 12:49:53 +01:00
|
|
|
$closeQuad = new Quad_Icons64x64_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($closeQuad);
|
2017-05-07 19:35:53 +02:00
|
|
|
$closeQuad->setPosition($width / 2 - 3, $height / 2 - 3, 3);
|
2013-12-24 12:49:53 +01:00
|
|
|
$closeQuad->setSize(6, 6);
|
2014-01-06 17:33:45 +01:00
|
|
|
$closeQuad->setSubStyle($closeQuad::SUBSTYLE_QuitRace);
|
2013-12-24 12:49:53 +01:00
|
|
|
$closeQuad->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-01-06 17:33:45 +01:00
|
|
|
// Headline
|
2013-12-24 12:49:53 +01:00
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2013-12-24 12:49:53 +01:00
|
|
|
$label->setY($height / 2 - 5);
|
2014-01-06 17:33:45 +01:00
|
|
|
$label->setStyle($label::STYLE_TextCardMedium);
|
2013-12-24 12:49:53 +01:00
|
|
|
$label->setTextSize(4);
|
|
|
|
$label->setText('Administrative Warning');
|
2014-01-06 17:33:45 +01:00
|
|
|
$label->setTextColor('f00');
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
$posY = $height / 2 - 15;
|
2014-05-02 17:50:30 +02:00
|
|
|
foreach ($message as $line) {
|
2014-01-06 17:33:45 +01:00
|
|
|
// Message lines
|
2013-12-24 12:49:53 +01:00
|
|
|
$label = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-06-14 15:48:27 +02:00
|
|
|
$label->setY($posY);
|
|
|
|
$label->setStyle($label::STYLE_TextCardMedium);
|
2013-12-24 12:49:53 +01:00
|
|
|
$label->setText($line);
|
2014-01-06 17:33:45 +01:00
|
|
|
$label->setTextColor('ff0');
|
2014-01-10 15:58:27 +01:00
|
|
|
$label->setTextSize(1.3);
|
2014-06-14 15:48:27 +02:00
|
|
|
$posY -= 4;
|
2013-12-24 12:49:53 +01:00
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2013-12-31 16:01:22 +01:00
|
|
|
// Display manialink
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $target);
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-01-06 17:33:45 +01:00
|
|
|
// Announce warning
|
2015-06-19 18:30:44 +02:00
|
|
|
if ($calledByAdmin) {
|
2015-06-19 01:37:31 +02:00
|
|
|
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
|
|
|
|
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' warned ' . $target->getEscapedNickname() . '!';
|
|
|
|
} else {
|
2015-06-19 18:30:44 +02:00
|
|
|
$chatMessage = $target->getEscapedNickname() . ' got an administrative warning!';
|
2015-06-19 01:37:31 +02:00
|
|
|
}
|
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
2014-08-05 02:08:41 +02:00
|
|
|
Logger::log($chatMessage, true);
|
2015-06-23 21:20:44 +02:00
|
|
|
|
|
|
|
return true;
|
2013-12-23 20:57:50 +01:00
|
|
|
}
|
|
|
|
|
2015-06-23 21:20:44 +02:00
|
|
|
|
2013-12-23 21:47:39 +01:00
|
|
|
/**
|
2014-01-06 17:33:45 +01:00
|
|
|
* Kick a Player
|
2013-12-31 16:01:22 +01:00
|
|
|
*
|
2017-04-14 19:23:09 +02:00
|
|
|
* @api
|
2015-06-23 21:20:44 +02:00
|
|
|
* @param $adminLogin
|
|
|
|
* @param $targetLogin
|
2013-12-23 21:47:39 +01:00
|
|
|
* @param string $message
|
2015-06-23 21:20:44 +02:00
|
|
|
* @param bool $calledByAdmin
|
|
|
|
* @return bool
|
2013-12-23 21:47:39 +01:00
|
|
|
*/
|
2015-06-23 21:20:44 +02:00
|
|
|
public function kickPlayer($adminLogin, $targetLogin, $message = '', $calledByAdmin = true) {
|
|
|
|
if ($calledByAdmin) {
|
|
|
|
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
2015-07-29 22:07:52 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_KICK_PLAYER)) {
|
2015-06-23 21:20:44 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-06 17:33:45 +01:00
|
|
|
}
|
2015-06-23 21:20:44 +02:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
|
2014-02-27 13:25:11 +01:00
|
|
|
if (!$target) {
|
2015-06-23 21:20:44 +02:00
|
|
|
return false;
|
2014-01-09 19:08:29 +01:00
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2015-06-18 15:52:30 +02:00
|
|
|
if ($target->isFakePlayer()) {
|
|
|
|
try {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getClient()->disconnectFakePlayer($target->login);
|
2015-06-18 15:52:30 +02:00
|
|
|
} catch (PlayerStateException $e) {
|
2015-06-23 21:20:44 +02:00
|
|
|
if ($calledByAdmin) {
|
|
|
|
$this->maniaControl->getChat()->sendException($e, $admin);
|
|
|
|
}
|
|
|
|
return false;
|
2017-02-11 23:26:28 +01:00
|
|
|
} catch (UnknownPlayerException $e) { //TODO check why it's actually needed, but there was a crash at this place
|
|
|
|
if ($calledByAdmin) {
|
|
|
|
$this->maniaControl->getChat()->sendException($e, $admin);
|
|
|
|
}
|
|
|
|
return false;
|
2015-06-18 15:52:30 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getClient()->kick($target->login, $message);
|
2015-06-18 15:52:30 +02:00
|
|
|
} catch (UnknownPlayerException $e) {
|
2015-06-23 21:20:44 +02:00
|
|
|
if ($calledByAdmin) {
|
|
|
|
$this->maniaControl->getChat()->sendException($e, $admin);
|
|
|
|
}
|
|
|
|
return false;
|
2014-01-20 20:51:03 +01:00
|
|
|
}
|
2013-12-23 21:47:39 +01:00
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-01-06 17:33:45 +01:00
|
|
|
// Announce kick
|
2015-06-23 21:20:44 +02:00
|
|
|
if ($calledByAdmin) {
|
|
|
|
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
|
|
|
|
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' kicked ' . $target->getEscapedNickname() . '!';
|
|
|
|
} else {
|
|
|
|
$chatMessage = $target->getEscapedNickname() . ' got kicked!';
|
|
|
|
}
|
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
2014-08-05 02:08:41 +02:00
|
|
|
Logger::logInfo($chatMessage, true);
|
2015-06-23 21:20:44 +02:00
|
|
|
|
|
|
|
return true;
|
2013-12-23 20:57:50 +01:00
|
|
|
}
|
|
|
|
|
2015-06-23 21:20:44 +02:00
|
|
|
|
2013-12-23 21:47:39 +01:00
|
|
|
/**
|
2014-01-06 17:33:45 +01:00
|
|
|
* Ban a Player
|
2013-12-31 16:01:22 +01:00
|
|
|
*
|
2017-04-14 19:23:09 +02:00
|
|
|
* @api
|
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 = '') {
|
2014-08-13 11:05:52 +02:00
|
|
|
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
2015-07-29 22:07:52 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_BAN_PLAYER)) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
|
2014-01-06 17:33:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-07-29 22:07:52 +02:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
|
2014-02-27 13:25:11 +01:00
|
|
|
if (!$target) {
|
2014-01-09 18:32:52 +01:00
|
|
|
return;
|
2014-01-09 19:08:29 +01:00
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2015-07-29 22:07:52 +02:00
|
|
|
//Todo Validate (Problem: Not connected player isFakePlayer)
|
|
|
|
if ($target->isOfficial && $target->isFakePlayer()) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendError('It is not possible to Ban a bot', $admin);
|
2014-01-16 19:49:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-12 13:20:21 +01:00
|
|
|
try {
|
|
|
|
$this->maniaControl->getClient()->ban($target->login, $message);
|
|
|
|
} catch (UnknownPlayerException $e) {
|
|
|
|
$this->maniaControl->getChat()->sendError('Unknown player!', $admin);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-01-06 17:33:45 +01:00
|
|
|
// Announce ban
|
2014-08-13 11:05:52 +02:00
|
|
|
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
|
2014-08-05 02:17:41 +02:00
|
|
|
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' banned ' . $target->getEscapedNickname() . '!';
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
2014-08-05 02:08:41 +02:00
|
|
|
Logger::logInfo($chatMessage, true);
|
2013-12-23 20:57:50 +01:00
|
|
|
}
|
2013-12-26 11:25:10 +01:00
|
|
|
|
2015-01-11 15:53:46 +01:00
|
|
|
/**
|
|
|
|
* Unbans a Player
|
|
|
|
*
|
2017-04-14 19:23:09 +02:00
|
|
|
* @api
|
2015-01-11 15:53:46 +01:00
|
|
|
* @param string $adminLogin
|
|
|
|
* @param string $targetLogin
|
|
|
|
*/
|
|
|
|
public function unBanPlayer($adminLogin, $targetLogin) {
|
|
|
|
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
2015-07-29 22:07:52 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_BAN_PLAYER)) {
|
2015-01-11 15:53:46 +01:00
|
|
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-11 16:00:55 +01:00
|
|
|
try {
|
|
|
|
$this->maniaControl->getClient()->unBan($targetLogin);
|
|
|
|
} catch (NotInListException $e) {
|
|
|
|
$this->maniaControl->getChat()->sendError('This player is not Banned!', $admin);
|
2015-01-11 15:53:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Announce ban
|
|
|
|
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
|
2015-01-11 16:00:55 +01:00
|
|
|
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' unbanned ' . $targetLogin . '!';
|
2015-01-11 15:53:46 +01:00
|
|
|
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
|
|
|
Logger::logInfo($chatMessage, true);
|
|
|
|
}
|
|
|
|
|
2013-12-26 11:25:10 +01:00
|
|
|
/**
|
2013-12-31 16:01:22 +01:00
|
|
|
* Grands the Player an Authorization Level
|
|
|
|
*
|
2017-04-14 19:23:09 +02:00
|
|
|
* @api
|
2013-12-31 16:01:22 +01:00
|
|
|
* @param string $adminLogin
|
|
|
|
* @param string $targetLogin
|
2014-01-09 18:32:52 +01:00
|
|
|
* @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) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
|
|
|
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
|
2014-02-27 13:25:11 +01:00
|
|
|
if (!$admin || !$target) {
|
2014-01-09 18:32:52 +01:00
|
|
|
return;
|
2014-01-09 19:08:29 +01:00
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$authLevelName = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($authLevel);
|
2015-07-29 22:07:52 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkRight($admin, $authLevel + 1)) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendError("You don't have the permission to add a {$authLevelName}!", $admin);
|
2014-01-09 18:32:52 +01:00
|
|
|
return;
|
2014-01-06 17:33:45 +01:00
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2015-07-29 22:07:52 +02:00
|
|
|
if ($this->maniaControl->getAuthenticationManager()->checkRight($target, $authLevel)) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendError("This Player is already {$authLevelName}!", $admin);
|
2013-12-30 22:36:20 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$success = $this->maniaControl->getAuthenticationManager()->grantAuthLevel($target, $authLevel);
|
2014-02-27 13:25:11 +01:00
|
|
|
if (!$success) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendError('Error occurred.', $admin);
|
2013-12-26 11:25:10 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-01-06 17:33:45 +01:00
|
|
|
// Announce granting
|
2014-08-13 11:05:52 +02:00
|
|
|
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
|
2014-08-05 02:17:41 +02:00
|
|
|
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' added ' . $target->getEscapedNickname() . ' as $< ' . $authLevelName . '$>!';
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
2014-08-05 02:08:41 +02:00
|
|
|
Logger::logInfo($chatMessage, true);
|
2013-12-26 11:25:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-31 16:01:22 +01:00
|
|
|
* Revokes all Rights from the Player
|
|
|
|
*
|
2017-04-14 19:23:09 +02:00
|
|
|
* @api
|
2013-12-31 16:01:22 +01:00
|
|
|
* @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) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
|
|
|
|
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
|
2014-02-27 13:25:11 +01:00
|
|
|
if (!$admin || !$target) {
|
2014-01-09 18:32:52 +01:00
|
|
|
return;
|
2014-01-09 19:08:29 +01:00
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2015-07-29 22:07:52 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkRight($admin, $target->authLevel + 1)) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($target->authLevel);
|
|
|
|
$this->maniaControl->getChat()->sendError("You can't revoke the Rights of a {$title}!", $admin);
|
2014-01-06 17:33:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2015-07-29 22:07:52 +02:00
|
|
|
if ($this->maniaControl->getAuthenticationManager()->checkRight($target, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendError("MasterAdmins can't be removed!", $admin);
|
2013-12-26 11:25:10 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$success = $this->maniaControl->getAuthenticationManager()->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_PLAYER);
|
2014-02-27 13:25:11 +01:00
|
|
|
if (!$success) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendError('Error occurred.', $admin);
|
2013-12-26 11:25:10 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-01-09 18:32:52 +01:00
|
|
|
|
2014-01-06 17:33:45 +01:00
|
|
|
// Announce revoke
|
2014-08-13 11:05:52 +02:00
|
|
|
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
|
2014-08-05 02:17:41 +02:00
|
|
|
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' revoked the Rights of ' . $target->getEscapedNickname() . '!';
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
2014-08-05 02:08:41 +02:00
|
|
|
Logger::logInfo($chatMessage, true);
|
2013-12-26 11:25:10 +01:00
|
|
|
}
|
2017-04-14 19:23:09 +02:00
|
|
|
|
2015-06-26 13:06:05 +02:00
|
|
|
}
|