resolved todo

This commit is contained in:
kremsy 2014-01-10 13:28:48 +01:00
parent 7f0c33e45f
commit fd5d2e59e9
2 changed files with 80 additions and 86 deletions

View File

@ -2,9 +2,7 @@
namespace ManiaControl\Players; namespace ManiaControl\Players;
use FML\Controls\Quads\Quad_Icons128x128_1;
use FML\Controls\Quads\Quad_Icons128x32_1; use FML\Controls\Quads\Quad_Icons128x32_1;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Controls\Quads\Quad_UIConstruction_Buttons; use FML\Controls\Quads\Quad_UIConstruction_Buttons;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
@ -22,7 +20,6 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
*/ */
const ACTION_BALANCE_TEAMS = 'PlayerCommands.BalanceTeams'; const ACTION_BALANCE_TEAMS = 'PlayerCommands.BalanceTeams';
const ACTION_OPEN_PLAYERLIST = 'PlayerCommands.OpenPlayerList'; const ACTION_OPEN_PLAYERLIST = 'PlayerCommands.OpenPlayerList';
const ACTION_CANCEL_VOTE = 'PlayerCommands.CancelVote';
/** /**
* Private Properties * Private Properties
@ -53,8 +50,6 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
$this->maniaControl->commandManager->registerCommandListener('removebots', $this, 'command_RemoveFakePlayers', true); $this->maniaControl->commandManager->registerCommandListener('removebots', $this, 'command_RemoveFakePlayers', true);
$this->maniaControl->commandManager->registerCommandListener('mute', $this, 'command_MutePlayer', true); $this->maniaControl->commandManager->registerCommandListener('mute', $this, 'command_MutePlayer', true);
$this->maniaControl->commandManager->registerCommandListener('unmute', $this, 'command_UnmutePlayer', true); $this->maniaControl->commandManager->registerCommandListener('unmute', $this, 'command_UnmutePlayer', true);
// TODO: Move into another class
$this->maniaControl->commandManager->registerCommandListener('cancel', $this, 'command_CancelVote', true);
// Register for player chat commands // Register for player chat commands
$this->maniaControl->commandManager->registerCommandListener('player', $this, 'command_playerList'); $this->maniaControl->commandManager->registerCommandListener('player', $this, 'command_playerList');
@ -67,13 +62,6 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
$itemQuad->setAction(self::ACTION_BALANCE_TEAMS); $itemQuad->setAction(self::ACTION_BALANCE_TEAMS);
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 9, 'Balance Teams'); $this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 9, 'Balance Teams');
// Action cancel Vote
$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);
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 6, 'Cancel Vote');
// Action Open Playerlist // Action Open Playerlist
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYERLIST, $this, 'command_playerList'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYERLIST, $this, 'command_playerList');
$itemQuad = new Quad_UIConstruction_Buttons(); $itemQuad = new Quad_UIConstruction_Buttons();
@ -82,24 +70,6 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 15, 'Open Playerlist'); $this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 15, 'Open Playerlist');
} }
/**
* Handle //cancelvote command
*
* @param array $chatCallback
* @param Player $player
*/
public function command_CancelVote(array $chatCallback, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
$success = $this->maniaControl->client->query('CancelVote');
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return;
}
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> canceled the Vote!');
}
/** /**
* Handle //teambalance command * Handle //teambalance command
@ -108,12 +78,12 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
* @param Player $player * @param Player $player
*/ */
public function command_TeamBalance(array $chatCallback, Player $player) { public function command_TeamBalance(array $chatCallback, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$success = $this->maniaControl->client->query('AutoTeamBalance'); $success = $this->maniaControl->client->query('AutoTeamBalance');
if (!$success) { if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return; return;
} }
@ -127,18 +97,18 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
* @param Player $player * @param Player $player
*/ */
public function command_Kick(array $chat, Player $player) { public function command_Kick(array $chat, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2], 3); $params = explode(' ', $chat[1][2], 3);
if (count($params) <= 1) { if(count($params) <= 1) {
$this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//kick login'", $player->login); $this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//kick login'", $player->login);
return; return;
} }
$targetLogin = $params[1]; $targetLogin = $params[1];
$message = ''; $message = '';
if (isset($params[2])) { if(isset($params[2])) {
$message = $params[2]; $message = $params[2];
} }
$this->maniaControl->playerManager->playerActions->kickPlayer($player->login, $targetLogin, $message); $this->maniaControl->playerManager->playerActions->kickPlayer($player->login, $targetLogin, $message);
@ -152,7 +122,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
*/ */
public function command_Warn(array $chatCallback, Player $player) { public function command_Warn(array $chatCallback, Player $player) {
$params = explode(' ', $chat[1][2], 3); $params = explode(' ', $chat[1][2], 3);
if (count($params) <= 1) { if(count($params) <= 1) {
$this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//kick login'", $player->login); $this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//kick login'", $player->login);
return; return;
} }
@ -167,22 +137,21 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
* @param Player $player * @param Player $player
*/ */
public function command_ForceSpectator(array $chat, Player $player) { public function command_ForceSpectator(array $chat, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if (count($params) <= 1) { if(count($params) <= 1) {
$this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forcespec login'", $player->login); $this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forcespec login'", $player->login);
return; return;
} }
$targetLogin = $params[1]; $targetLogin = $params[1];
if (isset($params[2]) && is_numeric($params[2])) { if(isset($params[2]) && is_numeric($params[2])) {
$type = (int) $params[2]; $type = (int)$params[2];
$this->maniaControl->playerManager->playerActions->forcePlayerToSpectator($player->login, $targetLogin, $type); $this->maniaControl->playerManager->playerActions->forcePlayerToSpectator($player->login, $targetLogin, $type);
} } else {
else {
$this->maniaControl->playerManager->playerActions->forcePlayerToSpectator($player->login, $targetLogin); $this->maniaControl->playerManager->playerActions->forcePlayerToSpectator($player->login, $targetLogin);
} }
} }
@ -194,19 +163,19 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
* @param Player $player * @param Player $player
*/ */
public function command_ForcePlay(array $chat, Player $player) { public function command_ForcePlay(array $chat, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if (!isset($params[1])) { if(!isset($params[1])) {
$this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forceplay login'", $player->login); $this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forceplay login'", $player->login);
return; return;
} }
$targetLogin = $params[1]; $targetLogin = $params[1];
$type = 2; $type = 2;
if (isset($params[2]) && is_numeric($params[2])) { if(isset($params[2]) && is_numeric($params[2])) {
$type = intval($params[2]); $type = intval($params[2]);
} }
$this->maniaControl->playerManager->playerActions->forcePlayerToPlay($player->login, $targetLogin, $type); $this->maniaControl->playerManager->playerActions->forcePlayerToPlay($player->login, $targetLogin, $type);
@ -219,12 +188,12 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
* @param Player $player * @param Player $player
*/ */
public function command_ForceBlue(array $chat, Player $player) { public function command_ForceBlue(array $chat, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if (!isset($params[1])) { if(!isset($params[1])) {
$this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forceblue login'", $player->login); $this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forceblue login'", $player->login);
return; return;
} }
@ -240,12 +209,12 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
* @param Player $player * @param Player $player
*/ */
public function command_ForceRed(array $chat, Player $player) { public function command_ForceRed(array $chat, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$params = explode(' ', $chat[1][2]); $params = explode(' ', $chat[1][2]);
if (!isset($params[1])) { if(!isset($params[1])) {
$this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forcered login'", $player->login); $this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forcered login'", $player->login);
return; return;
} }
@ -261,22 +230,22 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
* @param Player $player * @param Player $player
*/ */
public function command_AddFakePlayers(array $chatCallback, Player $player) { public function command_AddFakePlayers(array $chatCallback, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$amount = 1; $amount = 1;
$messageParts = explode(' ', $chatCallback[1][2]); $messageParts = explode(' ', $chatCallback[1][2]);
if (isset($messageParts[1]) && is_numeric($messageParts[1])) { if(isset($messageParts[1]) && is_numeric($messageParts[1])) {
$amount = intval($messageParts[1]); $amount = intval($messageParts[1]);
} }
$success = true; $success = true;
for ($i = 0; $i < $amount; $i++) { for($i = 0; $i < $amount; $i++) {
if (!$this->maniaControl->client->query('ConnectFakePlayer')) { if(!$this->maniaControl->client->query('ConnectFakePlayer')) {
$success = false; $success = false;
} }
} }
if (!$success) { if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return; return;
} }
@ -290,12 +259,12 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
* @param Player $player * @param Player $player
*/ */
public function command_RemoveFakePlayers(array $chatCallback, Player $player) { public function command_RemoveFakePlayers(array $chatCallback, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) { if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$success = $this->maniaControl->client->query('DisconnectFakePlayer', '*'); $success = $this->maniaControl->client->query('DisconnectFakePlayer', '*');
if (!$success) { if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return; return;
} }
@ -310,7 +279,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
*/ */
public function command_MutePlayer(array $chatCallback, Player $admin) { public function command_MutePlayer(array $chatCallback, Player $admin) {
$commandParts = explode(' ', $chatCallback[1][2]); $commandParts = explode(' ', $chatCallback[1][2]);
if (count($commandParts) <= 1) { if(count($commandParts) <= 1) {
$this->maniaControl->chat->sendUsageInfo("No login specified! Example: '//mute login'"); $this->maniaControl->chat->sendUsageInfo("No login specified! Example: '//mute login'");
return; return;
} }
@ -326,7 +295,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
*/ */
public function command_UnmutePlayer(array $chatCallback, Player $admin) { public function command_UnmutePlayer(array $chatCallback, Player $admin) {
$commandParts = explode(' ', $chatCallback[1][2]); $commandParts = explode(' ', $chatCallback[1][2]);
if (count($commandParts) <= 1) { if(count($commandParts) <= 1) {
$this->maniaControl->chat->sendUsageInfo("No login specified! Example: '//unmute login'"); $this->maniaControl->chat->sendUsageInfo("No login specified! Example: '//unmute login'");
return; return;
} }

View File

@ -3,6 +3,7 @@
namespace ManiaControl\Server; namespace ManiaControl\Server;
use FML\Controls\Quads\Quad_Icons128x32_1; use FML\Controls\Quads\Quad_Icons128x32_1;
use FML\Controls\Quads\Quad_Icons64x64_1;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
@ -21,7 +22,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
* Constants * Constants
*/ */
const ACTION_SET_PAUSE = 'ServerCommands.SetPause'; const ACTION_SET_PAUSE = 'ServerCommands.SetPause';
const ACTION_CANCEL_VOTE = 'ServerCommands.CancelVote';
/** /**
* Private properties * Private properties
*/ */
@ -55,16 +56,40 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$this->maniaControl->commandManager->registerCommandListener('enablehorns', $this, 'command_EnableHorns', true); $this->maniaControl->commandManager->registerCommandListener('enablehorns', $this, 'command_EnableHorns', true);
$this->maniaControl->commandManager->registerCommandListener('disablehorns', $this, 'command_DisableHorns', true); $this->maniaControl->commandManager->registerCommandListener('disablehorns', $this, 'command_DisableHorns', true);
$this->maniaControl->commandManager->registerCommandListener('cancel', $this, 'command_CancelVote', true);
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SET_PAUSE, $this, 'setPause'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SET_PAUSE, $this, 'setPause');
//TODO correct class?
// Set Pause // Set Pause
$itemQuad = new Quad_Icons128x32_1(); //TODO check if mode supports it $itemQuad = new Quad_Icons128x32_1(); //TODO check if mode supports it
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ManiaLinkSwitch); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_ManiaLinkSwitch);
$itemQuad->setAction(self::ACTION_SET_PAUSE); $itemQuad->setAction(self::ACTION_SET_PAUSE);
$this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad, 1, 'Pauses the current game.'); $this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad, 1, 'Pauses the current game.');
// Action cancel Vote
$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);
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 6, 'Cancel Vote');
}
/**
* Handle //cancelvote command
*
* @param array $chatCallback
* @param Player $player
*/
public function command_CancelVote(array $chatCallback, Player $player) {
if(!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
$success = $this->maniaControl->client->query('CancelVote');
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return;
}
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> canceled the Vote!');
} }
/** /**