2013-12-05 00:30:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Players;
|
|
|
|
|
2013-12-14 22:00:59 +01:00
|
|
|
use FML\Controls\Quad;
|
2013-12-05 00:30:10 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use ManiaControl\Admin\AuthenticationManager;
|
|
|
|
use ManiaControl\Commands\CommandListener;
|
|
|
|
|
|
|
|
/**
|
2013-12-08 22:38:20 +01:00
|
|
|
* Class offering various admin commands related to players
|
2013-12-05 00:30:10 +01:00
|
|
|
*
|
|
|
|
* @author steeffeen & kremsy
|
|
|
|
*/
|
|
|
|
class PlayerCommands implements CommandListener {
|
|
|
|
/**
|
|
|
|
* Private properties
|
|
|
|
*/
|
|
|
|
private $maniaControl = null;
|
2013-12-18 15:48:33 +01:00
|
|
|
private $playerList = null;
|
2013-12-05 00:30:10 +01:00
|
|
|
/**
|
|
|
|
* Create a new server commands instance
|
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
2013-12-14 22:00:59 +01:00
|
|
|
// Register for admin commands
|
2013-12-09 22:12:57 +01:00
|
|
|
$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);
|
2013-12-18 15:48:33 +01:00
|
|
|
$this->maniaControl->commandManager->registerCommandListener('addbot', $this, 'command_AddFakePlayers',true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('removebot', $this, 'command_RemoveFakePlayers',true);
|
2013-12-09 22:12:57 +01:00
|
|
|
$this->maniaControl->commandManager->registerCommandListener('addbots', $this, 'command_AddFakePlayers',true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('removebots', $this, 'command_RemoveFakePlayers',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');
|
|
|
|
|
|
|
|
$this->playerList = new PlayerList($this->maniaControl);
|
|
|
|
|
2013-12-05 00:30:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle //teambalance command
|
|
|
|
*
|
|
|
|
* @param array $chatCallback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function command_TeamBalance(array $chatCallback, Player $player) {
|
2013-12-31 17:17:11 +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');
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @param array $chat
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function command_Kick(array $chat, Player $player) {
|
2013-12-31 17:17:11 +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);
|
|
|
|
if (!isset($params[1])) {
|
|
|
|
$this->maniaControl->chat->sendUsageInfo('Usage example: //kick login', $player->login);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$target = $params[1];
|
|
|
|
$target = $this->maniaControl->playerManager->getPlayer($target);
|
|
|
|
if (!$target) {
|
|
|
|
$this->maniaControl->chat->sendError("Invalid player login.", $player->login);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$message = '';
|
|
|
|
if (isset($params[2])) {
|
|
|
|
$message = $params[2];
|
|
|
|
}
|
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
|
|
|
|
*
|
|
|
|
* @param array $chat
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function command_ForceSpectator(array $chat, Player $player) {
|
2013-12-31 17:17:11 +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]);
|
|
|
|
if (!isset($params[1])) {
|
|
|
|
$this->maniaControl->chat->sendUsageInfo('Usage example: //forcespec login', $player->login);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$target = $params[1];
|
|
|
|
$target = $this->maniaControl->playerManager->getPlayer($target);
|
|
|
|
if (!$target) {
|
|
|
|
$this->maniaControl->chat->sendError("Invalid player login.", $player->login);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$type = 3;
|
|
|
|
if (isset($params[2]) && is_numeric($params[2])) {
|
|
|
|
$type = intval($params[2]);
|
|
|
|
}
|
|
|
|
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, $type);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if ($type != 1) {
|
|
|
|
$this->maniaControl->client->query('ForceSpectator', $target->login, 0);
|
|
|
|
}
|
|
|
|
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to spectator!');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle //forceplay command
|
|
|
|
*
|
|
|
|
* @param array $chat
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function command_ForcePlayer(array $chat, Player $player) {
|
2013-12-31 17:17:11 +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]);
|
|
|
|
if (!isset($params[1])) {
|
|
|
|
$this->maniaControl->chat->sendUsageInfo('Usage example: //forceplay login', $player->login);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$target = $params[1];
|
|
|
|
$target = $this->maniaControl->playerManager->getPlayer($target);
|
|
|
|
if (!$target) {
|
|
|
|
$this->maniaControl->chat->sendError("Invalid player login.", $player->login);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$type = 2;
|
|
|
|
if (isset($params[2]) && is_numeric($params[2])) {
|
|
|
|
$type = intval($params[2]);
|
|
|
|
}
|
|
|
|
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, 2);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if ($type != 1) {
|
|
|
|
$this->maniaControl->client->query('ForceSpectator', $target->login, 0);
|
|
|
|
}
|
|
|
|
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to player!');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle //addfakeplayers command
|
|
|
|
*
|
|
|
|
* @param array $chatCallback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function command_AddFakePlayers(array $chatCallback, Player $player) {
|
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$amount = 1;
|
|
|
|
$messageParts = explode(' ', $chatCallback[1][2]);
|
|
|
|
if (isset($messageParts[1]) && is_numeric($messageParts[1])) {
|
|
|
|
$amount = intval($messageParts[1]);
|
|
|
|
}
|
|
|
|
$success = true;
|
|
|
|
for ($i = 0; $i < $amount; $i++) {
|
|
|
|
if (!$this->maniaControl->client->query('ConnectFakePlayer')) {
|
|
|
|
$success = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @param array $chatCallback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function command_RemoveFakePlayers(array $chatCallback, Player $player) {
|
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
|
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$success = $this->maniaControl->client->query('DisconnectFakePlayer', '*');
|
|
|
|
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
|
|
|
|
* @param array $chatCallback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function command_playerList(array $chatCallback, Player $player) {
|
2013-12-26 17:27:21 +01:00
|
|
|
$this->playerList->addPlayerToShownList($player, PlayerList::SHOWN_MAIN_WINDOW);
|
|
|
|
$this->playerList->showPlayerList($player);
|
2013-12-18 15:48:33 +01:00
|
|
|
}
|
2013-12-05 00:30:10 +01:00
|
|
|
}
|