2013-12-05 00:30:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Players;
|
|
|
|
|
2014-01-04 18:18:46 +01:00
|
|
|
use FML\Controls\Quads\Quad_Icons128x128_1;
|
2014-01-05 00:02:13 +01:00
|
|
|
use FML\Controls\Quads\Quad_Icons128x32_1;
|
2014-01-04 18:18:46 +01:00
|
|
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
2014-01-05 00:43:46 +01:00
|
|
|
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
2013-12-05 00:30:10 +01:00
|
|
|
use ManiaControl\Admin\AuthenticationManager;
|
|
|
|
use ManiaControl\Commands\CommandListener;
|
2014-01-04 18:49:33 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
2014-01-04 18:18:46 +01:00
|
|
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
2013-12-05 00:30:10 +01:00
|
|
|
|
|
|
|
/**
|
2014-01-06 16:14:49 +01:00
|
|
|
* Class offering various Admin Commands related to Players
|
2013-12-05 00:30:10 +01:00
|
|
|
*
|
|
|
|
* @author steeffeen & kremsy
|
|
|
|
*/
|
2014-01-04 18:18:46 +01:00
|
|
|
class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
|
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
2014-01-06 16:14:49 +01:00
|
|
|
const ACTION_BALANCE_TEAMS = 'PlayerCommands.BalanceTeams';
|
2014-01-04 18:49:33 +01:00
|
|
|
const ACTION_OPEN_PLAYERLIST = 'PlayerCommands.OpenPlayerList';
|
2014-01-06 16:14:49 +01:00
|
|
|
const ACTION_CANCEL_VOTE = 'PlayerCommands.CancelVote';
|
|
|
|
|
2013-12-05 00:30:10 +01:00
|
|
|
/**
|
2014-01-06 16:14:49 +01:00
|
|
|
* Private Properties
|
2013-12-05 00:30:10 +01:00
|
|
|
*/
|
|
|
|
private $maniaControl = null;
|
2014-01-04 18:49:33 +01:00
|
|
|
|
2013-12-05 00:30:10 +01:00
|
|
|
/**
|
2014-01-06 16:14:49 +01:00
|
|
|
* Create a new Player Commands Instance
|
2013-12-05 00:30:10 +01:00
|
|
|
*
|
2014-01-04 18:49:33 +01:00
|
|
|
* @param ManiaControl $maniaControl
|
2013-12-05 00:30:10 +01:00
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2014-01-06 16:14:49 +01:00
|
|
|
|
2013-12-14 22:00:59 +01:00
|
|
|
// Register for admin commands
|
2014-01-04 18:49:33 +01:00
|
|
|
$this->maniaControl->commandManager->registerCommandListener('balance', $this, 'command_TeamBalance', true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('teambalance', $this, 'command_TeamBalance', true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('autoteambalance', $this, 'command_TeamBalance', true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('kick', $this, 'command_Kick', true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('forcespec', $this, 'command_ForceSpectator', true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('forcespectator', $this, 'command_ForceSpectator', true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('forceplay', $this, 'command_ForcePlayer', true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('forceplayer', $this, 'command_ForcePlayer', true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('addbot', $this, 'command_AddFakePlayers', true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('removebot', $this, 'command_RemoveFakePlayers', true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('addbots', $this, 'command_AddFakePlayers', true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('removebots', $this, 'command_RemoveFakePlayers', true);
|
2014-01-06 16:14:49 +01:00
|
|
|
// TODO: Move into another class
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('cancel', $this, 'command_CancelVote', true);
|
|
|
|
|
2013-12-18 15:48:33 +01:00
|
|
|
// Register for player chat commands
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('player', $this, 'command_playerList');
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('players', $this, 'command_playerList');
|
2014-01-06 16:14:49 +01:00
|
|
|
|
|
|
|
// Action Balance Teams
|
2014-01-04 18:18:46 +01:00
|
|
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_BALANCE_TEAMS, $this, 'command_TeamBalance');
|
2014-01-05 00:02:13 +01:00
|
|
|
$itemQuad = new Quad_Icons128x32_1();
|
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team);
|
2014-01-04 18:18:46 +01:00
|
|
|
$itemQuad->setAction(self::ACTION_BALANCE_TEAMS);
|
2014-01-05 01:29:49 +01:00
|
|
|
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 9, 'Balance Teams');
|
2014-01-06 16:14:49 +01:00
|
|
|
|
|
|
|
// Action cancel Vote
|
2014-01-04 18:49:33 +01:00
|
|
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CANCEL_VOTE, $this, 'command_cancelVote');
|
|
|
|
$itemQuad = new Quad_Icons64x64_1();
|
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowRed);
|
|
|
|
$itemQuad->setAction(self::ACTION_CANCEL_VOTE);
|
2014-01-05 01:29:49 +01:00
|
|
|
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 6, 'Cancel Vote');
|
2014-01-06 16:14:49 +01:00
|
|
|
|
|
|
|
// Action Open Playerlist
|
2014-01-04 18:49:33 +01:00
|
|
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYERLIST, $this, 'command_playerList');
|
2014-01-05 00:43:46 +01:00
|
|
|
$itemQuad = new Quad_UIConstruction_Buttons();
|
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Author);
|
2014-01-04 18:49:33 +01:00
|
|
|
$itemQuad->setAction(self::ACTION_OPEN_PLAYERLIST);
|
2014-01-05 01:29:49 +01:00
|
|
|
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 15, 'Open Playerlist');
|
2014-01-04 18:49:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle //cancelvote command
|
|
|
|
*
|
2014-01-06 16:14:49 +01:00
|
|
|
* @param array $chatCallback
|
2014-01-04 18:49:33 +01:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function command_CancelVote(array $chatCallback, Player $player) {
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
2014-01-04 18:49:33 +01:00
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$success = $this->maniaControl->client->query('CancelVote');
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$success) {
|
2014-01-04 18:49:33 +01:00
|
|
|
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> canceled the Vote!');
|
2013-12-05 00:30:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle //teambalance command
|
|
|
|
*
|
2014-01-06 16:14:49 +01:00
|
|
|
* @param array $chatCallback
|
2014-01-04 18:49:33 +01:00
|
|
|
* @param Player $player
|
2013-12-05 00:30:10 +01:00
|
|
|
*/
|
|
|
|
public function command_TeamBalance(array $chatCallback, Player $player) {
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$success = $this->maniaControl->client->query('AutoTeamBalance');
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$success) {
|
2013-12-09 13:45:58 +01:00
|
|
|
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
2013-12-05 00:30:10 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> balanced Teams!');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle //kick command
|
|
|
|
*
|
2014-01-06 16:14:49 +01:00
|
|
|
* @param array $chat
|
2014-01-04 18:49:33 +01:00
|
|
|
* @param Player $player
|
2013-12-05 00:30:10 +01:00
|
|
|
*/
|
|
|
|
public function command_Kick(array $chat, Player $player) {
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$params = explode(' ', $chat[1][2], 3);
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!isset($params[1])) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$this->maniaControl->chat->sendUsageInfo('Usage example: //kick login', $player->login);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$target = $params[1];
|
|
|
|
$target = $this->maniaControl->playerManager->getPlayer($target);
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$target) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$this->maniaControl->chat->sendError("Invalid player login.", $player->login);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$message = '';
|
2014-01-06 16:14:49 +01:00
|
|
|
if (isset($params[2])) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$message = $params[2];
|
|
|
|
}
|
2014-01-06 16:14:49 +01:00
|
|
|
|
2013-12-23 21:47:39 +01:00
|
|
|
$this->maniaControl->playerManager->playerActions->kickPlayer($player->login, $target, $message);
|
2013-12-05 00:30:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle //forcespec command
|
|
|
|
*
|
2014-01-06 16:14:49 +01:00
|
|
|
* @param array $chat
|
2014-01-04 18:49:33 +01:00
|
|
|
* @param Player $player
|
2013-12-05 00:30:10 +01:00
|
|
|
*/
|
|
|
|
public function command_ForceSpectator(array $chat, Player $player) {
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$params = explode(' ', $chat[1][2]);
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!isset($params[1])) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$this->maniaControl->chat->sendUsageInfo('Usage example: //forcespec login', $player->login);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$target = $params[1];
|
|
|
|
$target = $this->maniaControl->playerManager->getPlayer($target);
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$target) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$this->maniaControl->chat->sendError("Invalid player login.", $player->login);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$type = 3;
|
2014-01-06 16:14:49 +01:00
|
|
|
if (isset($params[2]) && is_numeric($params[2])) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$type = intval($params[2]);
|
|
|
|
}
|
|
|
|
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, $type);
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$success) {
|
2013-12-09 13:45:58 +01:00
|
|
|
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
2013-12-05 00:30:10 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-01-06 16:14:49 +01:00
|
|
|
if ($type != 1) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$this->maniaControl->client->query('ForceSpectator', $target->login, 0);
|
|
|
|
}
|
|
|
|
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to spectator!');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle //forceplay command
|
|
|
|
*
|
2014-01-06 16:14:49 +01:00
|
|
|
* @param array $chat
|
2014-01-04 18:49:33 +01:00
|
|
|
* @param Player $player
|
2013-12-05 00:30:10 +01:00
|
|
|
*/
|
|
|
|
public function command_ForcePlayer(array $chat, Player $player) {
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$params = explode(' ', $chat[1][2]);
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!isset($params[1])) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$this->maniaControl->chat->sendUsageInfo('Usage example: //forceplay login', $player->login);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$target = $params[1];
|
|
|
|
$target = $this->maniaControl->playerManager->getPlayer($target);
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$target) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$this->maniaControl->chat->sendError("Invalid player login.", $player->login);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$type = 2;
|
2014-01-06 16:14:49 +01:00
|
|
|
if (isset($params[2]) && is_numeric($params[2])) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$type = intval($params[2]);
|
|
|
|
}
|
|
|
|
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, 2);
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$success) {
|
2013-12-09 13:45:58 +01:00
|
|
|
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
2013-12-05 00:30:10 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-01-06 16:14:49 +01:00
|
|
|
if ($type != 1) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$this->maniaControl->client->query('ForceSpectator', $target->login, 0);
|
|
|
|
}
|
|
|
|
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to player!');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle //addfakeplayers command
|
|
|
|
*
|
2014-01-06 16:14:49 +01:00
|
|
|
* @param array $chatCallback
|
2014-01-04 18:49:33 +01:00
|
|
|
* @param Player $player
|
2013-12-05 00:30:10 +01:00
|
|
|
*/
|
|
|
|
public function command_AddFakePlayers(array $chatCallback, Player $player) {
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
2014-01-06 16:14:49 +01:00
|
|
|
$amount = 1;
|
2013-12-05 00:30:10 +01:00
|
|
|
$messageParts = explode(' ', $chatCallback[1][2]);
|
2014-01-06 16:14:49 +01:00
|
|
|
if (isset($messageParts[1]) && is_numeric($messageParts[1])) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$amount = intval($messageParts[1]);
|
|
|
|
}
|
|
|
|
$success = true;
|
2014-01-06 16:14:49 +01:00
|
|
|
for ($i = 0; $i < $amount; $i++) {
|
|
|
|
if (!$this->maniaControl->client->query('ConnectFakePlayer')) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$success = false;
|
|
|
|
}
|
|
|
|
}
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$success) {
|
2013-12-09 13:45:58 +01:00
|
|
|
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
2013-12-05 00:30:10 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->maniaControl->chat->sendSuccess('Fake players connected!', $player->login);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle //removefakeplayers command
|
|
|
|
*
|
2014-01-06 16:14:49 +01:00
|
|
|
* @param array $chatCallback
|
2014-01-04 18:49:33 +01:00
|
|
|
* @param Player $player
|
2013-12-05 00:30:10 +01:00
|
|
|
*/
|
|
|
|
public function command_RemoveFakePlayers(array $chatCallback, Player $player) {
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
2013-12-05 00:30:10 +01:00
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$success = $this->maniaControl->client->query('DisconnectFakePlayer', '*');
|
2014-01-06 16:14:49 +01:00
|
|
|
if (!$success) {
|
2013-12-09 13:45:58 +01:00
|
|
|
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
2013-12-05 00:30:10 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->maniaControl->chat->sendSuccess('Fake players disconnected!', $player->login);
|
|
|
|
}
|
2013-12-18 15:48:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Player list command
|
2014-01-04 18:49:33 +01:00
|
|
|
*
|
2014-01-06 16:14:49 +01:00
|
|
|
* @param array $chatCallback
|
2013-12-18 15:48:33 +01:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function command_playerList(array $chatCallback, Player $player) {
|
2014-01-06 16:14:49 +01:00
|
|
|
$this->maniaControl->playerManager->playerList->addPlayerToShownList($player, PlayerList::SHOWN_MAIN_WINDOW);
|
|
|
|
$this->maniaControl->playerManager->playerList->showPlayerList($player);
|
2013-12-18 15:48:33 +01:00
|
|
|
}
|
2013-12-05 00:30:10 +01:00
|
|
|
}
|