added some buttons to menu

This commit is contained in:
kremsy 2014-01-04 18:49:33 +01:00
parent 97f371fd03
commit 02cae45cbe
4 changed files with 182 additions and 121 deletions

View File

@ -103,10 +103,11 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* *
* @param array $callback * @param array $callback
*/ */
public function handleOnInit(array $callback) { public function handleOnInit(array $callback) { //TODO render only once, but howtodo admin check then?
$manialinkText = $this->buildMenuIconsManialink()->render()->saveXML(); //$manialinkText = $this->buildMenuIconsManialink()->render()->saveXML();
$players = $this->maniaControl->playerManager->getPlayers(); $players = $this->maniaControl->playerManager->getPlayers();
foreach($players as $player) { foreach($players as $player) {
$manialinkText = $this->buildMenuIconsManialink($player)->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
} }
} }
@ -118,7 +119,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
*/ */
public function handlePlayerJoined(array $callback) { public function handlePlayerJoined(array $callback) {
$player = $callback[1]; $player = $callback[1];
$manialinkText = $this->buildMenuIconsManialink()->render()->saveXML(); $manialinkText = $this->buildMenuIconsManialink($player)->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login); $this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
} }
@ -128,9 +129,6 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* @param array $callback * @param array $callback
*/ */
public function openAdminMenu(array $callback, Player $player) { public function openAdminMenu(array $callback, Player $player) {
if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->configurator->toggleMenu($player);
}
} }
/** /**
@ -139,11 +137,15 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* @param array $callback * @param array $callback
*/ */
public function openPlayerMenu(array $callback, Player $player) { public function openPlayerMenu(array $callback, Player $player) {
$this->maniaControl->playerManager->playerCommands->playerList->addPlayerToShownList($player);
$this->maniaControl->playerManager->playerCommands->playerList->showPlayerList($player);
} }
private function buildMenuIconsManialink() { /**
* Builds the Manialink
*
* @param Player $player
* @return ManiaLink
*/
private function buildMenuIconsManialink(Player $player) { //TODO Description Labels, close tooltip on click, adjust size
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX); $posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY); $posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
$itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE); $itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE);
@ -178,37 +180,37 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
$itemQuad->setSize($itemSize, $itemSize); $itemQuad->setSize($itemSize, $itemSize);
$iconFrame->add($itemQuad); $iconFrame->add($itemQuad);
//Admin Menu if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$popoutFrame = new Frame(); //Admin Menu
$manialink->add($popoutFrame); $popoutFrame = new Frame();
$popoutFrame->setPosition($posX - $itemSize * 0.5, $posY); $manialink->add($popoutFrame);
$popoutFrame->setHAlign(Control::RIGHT); $popoutFrame->setPosition($posX - $itemSize * 0.5, $posY);
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY); $popoutFrame->setHAlign(Control::RIGHT);
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$quad = new Quad(); $quad = new Quad();
$popoutFrame->add($quad); $popoutFrame->add($quad);
$quad->setHAlign(Control::RIGHT); $quad->setHAlign(Control::RIGHT);
$quad->setStyles($quadStyle, $quadSubstyle); $quad->setStyles($quadStyle, $quadSubstyle);
$quad->setSize(count($this->adminMenuItems) * $itemSize * $itemMarginFactorX * 1.4, $itemSize * $itemMarginFactorY); $quad->setSize(count($this->adminMenuItems) * $itemSize * $itemMarginFactorX * 1.4, $itemSize * $itemMarginFactorY);
$popoutFrame->add($quad); $popoutFrame->add($quad);
$script->addTooltip($itemQuad, $popoutFrame, Script::OPTION_TOOLTIP_STAYONCLICK); $script->addTooltip($itemQuad, $popoutFrame, Script::OPTION_TOOLTIP_STAYONCLICK);
// Add items // Add items
$x = -1; $x = -1;
foreach($this->adminMenuItems as $menuItems) { foreach(array_reverse($this->adminMenuItems) as $menuItems) {
foreach($menuItems as $menuItem) { foreach($menuItems as $menuItem) {
/** @var Quad $menuItem */ /** @var Quad $menuItem */
$menuItem->setSize($itemSize, $itemSize); $menuItem->setSize($itemSize, $itemSize);
$popoutFrame->add($menuItem); $popoutFrame->add($menuItem);
$menuItem->setX($x); $menuItem->setX($x);
$menuItem->setHAlign(Control::RIGHT); $menuItem->setHAlign(Control::RIGHT);
$x -= $itemSize * 1.05; $x -= $itemSize * 1.05;
}
} }
} }
// Player Menu Icon Frame // Player Menu Icon Frame
$frame = new Frame(); $frame = new Frame();
$manialink->add($frame); $manialink->add($frame);
@ -249,7 +251,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
// Add items // Add items
$x = -1; $x = -1;
foreach($this->playerMenuItems as $menuItems) { foreach(array_reverse($this->playerMenuItems) as $menuItems) {
foreach($menuItems as $menuItem) { foreach($menuItems as $menuItem) {
/** @var Quad $menuItem */ /** @var Quad $menuItem */
$menuItem->setSize($itemSize, $itemSize); $menuItem->setSize($itemSize, $itemSize);

View File

@ -312,6 +312,6 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
$itemQuad = new Quad(); $itemQuad = new Quad();
$itemQuad->setStyles('Icons128x32_1', 'Settings'); $itemQuad->setStyles('Icons128x32_1', 'Settings');
$itemQuad->setAction(self::ACTION_TOGGLEMENU); $itemQuad->setAction(self::ACTION_TOGGLEMENU);
$this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad, 10); $this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad, 20);
} }
} }

View File

@ -2,15 +2,12 @@
namespace ManiaControl\Maps; namespace ManiaControl\Maps;
use FML\Controls\Quads\Quad_Icons128x128_1;
use FML\Controls\Quads\Quad_Icons64x64_1; use FML\Controls\Quads\Quad_Icons64x64_1;
use ManiaControl\ManiaControl;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\FileUtil; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
/** /**
* Class offering commands to manage maps * Class offering commands to manage maps
@ -21,7 +18,10 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Constants * Constants
*/ */
const ACTION_OPEN_MAPLIST = 'MapList.OpenMapList'; const ACTION_OPEN_MAPLIST = 'MapList.OpenMapList';
const ACTION_OPEN_XLIST = 'MapList.OpenMXList';
const ACTION_RESTART_MAP = 'MapList.RestartMap';
const ACTION_SKIP_MAP = 'MapList.NextMap';
/** /**
* Private properties * Private properties
@ -50,33 +50,54 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener {
$this->mapList = new MapList($this->maniaControl); $this->mapList = new MapList($this->maniaControl);
//Action Balance Teams //Menu Open xList
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_XLIST, $this, 'command_xList');
$itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Browser);
$itemQuad->setAction(self::ACTION_OPEN_XLIST);
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 3);
//Menu Open List
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_MAPLIST, $this, 'command_List'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_MAPLIST, $this, 'command_List');
$itemQuad = new Quad_Icons64x64_1(); $itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Browser); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_Browser);
$itemQuad->setAction(self::ACTION_OPEN_MAPLIST); $itemQuad->setAction(self::ACTION_OPEN_MAPLIST);
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 4); $this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 4);
//Menu RestartMap
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_RESTART_MAP, $this, 'command_RestartMap');
$itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowFastPrev);
$itemQuad->setAction(self::ACTION_RESTART_MAP);
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 0);
//Menu NextMap
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SKIP_MAP, $this, 'command_NextMap');
$itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowFastNext);
$itemQuad->setAction(self::ACTION_SKIP_MAP);
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 1);
} }
/** /**
* Handle removemap command * Handle removemap command
* *
* @param array $chat * @param array $chat
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_RemoveMap(array $chat, Player $player) { public function command_RemoveMap(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;
} }
// Get map // Get map
$map = $this->maniaControl->mapManager->getCurrentMap(); $map = $this->maniaControl->mapManager->getCurrentMap();
if (!$map) { if(!$map) {
$this->maniaControl->chat->sendError("Couldn't remove map.", $player->login); $this->maniaControl->chat->sendError("Couldn't remove map.", $player->login);
return; return;
} }
// Remove map // Remove map
if (!$this->maniaControl->client->query('RemoveMap', $map->fileName)) { if(!$this->maniaControl->client->query('RemoveMap', $map->fileName)) {
trigger_error("Couldn't remove current map. " . $this->maniaControl->getClientErrorText()); trigger_error("Couldn't remove current map. " . $this->maniaControl->getClientErrorText());
$this->maniaControl->chat->sendError("Couldn't remove map.", $player->login); $this->maniaControl->chat->sendError("Couldn't remove map.", $player->login);
return; return;
@ -87,33 +108,33 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle addmap command * Handle addmap command
* *
* @param array $chatCallback * @param array $chatCallback
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_AddMap(array $chatCallback, Player $player) { public function command_AddMap(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;
} }
// TODO: user mx fetcher // TODO: user mx fetcher
$params = explode(' ', $chatCallback[1][2], 2); $params = explode(' ', $chatCallback[1][2], 2);
if (count($params) < 2) { if(count($params) < 2) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //addmap 1234', $player->login); $this->maniaControl->chat->sendUsageInfo('Usage example: //addmap 1234', $player->login);
return; return;
} }
//add Map from Mania Exchange //add Map from Mania Exchange
$this->maniaControl->mapManager->addMapFromMx($params[1],$player->login); $this->maniaControl->mapManager->addMapFromMx($params[1], $player->login);
} }
/** /**
* Handle nextmap command * Handle nextmap command
* *
* @param array $chat * @param array $chat
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_NextMap(array $chat, Player $player) { public function command_NextMap(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;
} }
@ -123,11 +144,11 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle restartmap command * Handle restartmap command
* *
* @param array $chat * @param array $chat
* @param \ManiaControl\Players\Player $player * @param \ManiaControl\Players\Player $player
*/ */
public function command_RestartMap(array $chat, Player $player) { public function command_RestartMap(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;
} }
@ -137,7 +158,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle list maps command * Handle list maps command
* *
* @param array $chatCallback * @param array $chatCallback
* @param Player $player * @param Player $player
*/ */
public function command_List(array $chatCallback, Player $player) { public function command_List(array $chatCallback, Player $player) {
@ -146,6 +167,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle ManiaExchange list command * Handle ManiaExchange list command
*
* @param array $chatCallback * @param array $chatCallback
* @param Player $player * @param Player $player
*/ */

View File

@ -2,12 +2,11 @@
namespace ManiaControl\Players; namespace ManiaControl\Players;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Icons128x128_1; use FML\Controls\Quads\Quad_Icons128x128_1;
use FML\Controls\Quads\Quad_Icons64x64_1; use FML\Controls\Quads\Quad_Icons64x64_1;
use ManiaControl\ManiaControl;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
/** /**
@ -19,13 +18,16 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Constants * Constants
*/ */
const ACTION_BALANCE_TEAMS = 'PlayerCommands.BalanceTeams'; const ACTION_BALANCE_TEAMS = 'PlayerCommands.BalanceTeams';
const ACTION_OPEN_PLAYERLIST = 'PlayerCommands.OpenPlayerList';
const ACTION_CANCEL_VOTE = 'PlayerCommands.CancelVote';
/** /**
* Private properties * Private properties
*/ */
private $maniaControl = null; private $maniaControl = null;
public $playerList = null; public $playerList = null;
/** /**
* Create a new server commands instance * Create a new server commands instance
* *
@ -35,18 +37,19 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Register for admin commands // Register for admin commands
$this->maniaControl->commandManager->registerCommandListener('balance', $this, 'command_TeamBalance',true); $this->maniaControl->commandManager->registerCommandListener('balance', $this, 'command_TeamBalance', true);
$this->maniaControl->commandManager->registerCommandListener('teambalance', $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('autoteambalance', $this, 'command_TeamBalance', true);
$this->maniaControl->commandManager->registerCommandListener('kick', $this, 'command_Kick',true); $this->maniaControl->commandManager->registerCommandListener('kick', $this, 'command_Kick', true);
$this->maniaControl->commandManager->registerCommandListener('forcespec', $this, 'command_ForceSpectator',true); $this->maniaControl->commandManager->registerCommandListener('forcespec', $this, 'command_ForceSpectator', true);
$this->maniaControl->commandManager->registerCommandListener('forcespectator', $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('forceplay', $this, 'command_ForcePlayer', true);
$this->maniaControl->commandManager->registerCommandListener('forceplayer', $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('addbot', $this, 'command_AddFakePlayers', true);
$this->maniaControl->commandManager->registerCommandListener('removebot', $this, 'command_RemoveFakePlayers',true); $this->maniaControl->commandManager->registerCommandListener('removebot', $this, 'command_RemoveFakePlayers', true);
$this->maniaControl->commandManager->registerCommandListener('addbots', $this, 'command_AddFakePlayers',true); $this->maniaControl->commandManager->registerCommandListener('addbots', $this, 'command_AddFakePlayers', true);
$this->maniaControl->commandManager->registerCommandListener('removebots', $this, 'command_RemoveFakePlayers',true); $this->maniaControl->commandManager->registerCommandListener('removebots', $this, 'command_RemoveFakePlayers', true);
$this->maniaControl->commandManager->registerCommandListener('cancel', $this, 'command_CancelVote', true); //TODO remove in other class?
// 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');
@ -59,22 +62,55 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
$itemQuad = new Quad_Icons128x128_1(); $itemQuad = new Quad_Icons128x128_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ProfileVehicle); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_ProfileVehicle);
$itemQuad->setAction(self::ACTION_BALANCE_TEAMS); $itemQuad->setAction(self::ACTION_BALANCE_TEAMS);
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 4); $this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 9);
//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);
//Action Balance Teams
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYERLIST, $this, 'command_playerList');
$itemQuad = new Quad_Icons128x128_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Buddies);
$itemQuad->setAction(self::ACTION_OPEN_PLAYERLIST);
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 9);
}
/**
* 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
* *
* @param array $chatCallback * @param array $chatCallback
* @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;
} }
@ -84,27 +120,27 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle //kick command * Handle //kick command
* *
* @param array $chat * @param array $chat
* @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 (!isset($params[1])) { if(!isset($params[1])) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //kick login', $player->login); $this->maniaControl->chat->sendUsageInfo('Usage example: //kick login', $player->login);
return; return;
} }
$target = $params[1]; $target = $params[1];
$target = $this->maniaControl->playerManager->getPlayer($target); $target = $this->maniaControl->playerManager->getPlayer($target);
if (!$target) { if(!$target) {
$this->maniaControl->chat->sendError("Invalid player login.", $player->login); $this->maniaControl->chat->sendError("Invalid player login.", $player->login);
return; return;
} }
$message = ''; $message = '';
if (isset($params[2])) { if(isset($params[2])) {
$message = $params[2]; $message = $params[2];
} }
@ -114,35 +150,35 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle //forcespec command * Handle //forcespec command
* *
* @param array $chat * @param array $chat
* @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 (!isset($params[1])) { if(!isset($params[1])) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //forcespec login', $player->login); $this->maniaControl->chat->sendUsageInfo('Usage example: //forcespec login', $player->login);
return; return;
} }
$target = $params[1]; $target = $params[1];
$target = $this->maniaControl->playerManager->getPlayer($target); $target = $this->maniaControl->playerManager->getPlayer($target);
if (!$target) { if(!$target) {
$this->maniaControl->chat->sendError("Invalid player login.", $player->login); $this->maniaControl->chat->sendError("Invalid player login.", $player->login);
return; return;
} }
$type = 3; $type = 3;
if (isset($params[2]) && is_numeric($params[2])) { if(isset($params[2]) && is_numeric($params[2])) {
$type = intval($params[2]); $type = intval($params[2]);
} }
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, $type); $success = $this->maniaControl->client->query('ForceSpectator', $target->login, $type);
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;
} }
if ($type != 1) { if($type != 1) {
$this->maniaControl->client->query('ForceSpectator', $target->login, 0); $this->maniaControl->client->query('ForceSpectator', $target->login, 0);
} }
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to spectator!'); $this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to spectator!');
@ -151,35 +187,35 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle //forceplay command * Handle //forceplay command
* *
* @param array $chat * @param array $chat
* @param Player $player * @param Player $player
*/ */
public function command_ForcePlayer(array $chat, Player $player) { public function command_ForcePlayer(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('Usage example: //forceplay login', $player->login); $this->maniaControl->chat->sendUsageInfo('Usage example: //forceplay login', $player->login);
return; return;
} }
$target = $params[1]; $target = $params[1];
$target = $this->maniaControl->playerManager->getPlayer($target); $target = $this->maniaControl->playerManager->getPlayer($target);
if (!$target) { if(!$target) {
$this->maniaControl->chat->sendError("Invalid player login.", $player->login); $this->maniaControl->chat->sendError("Invalid player login.", $player->login);
return; return;
} }
$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]);
} }
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, 2); $success = $this->maniaControl->client->query('ForceSpectator', $target->login, 2);
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;
} }
if ($type != 1) { if($type != 1) {
$this->maniaControl->client->query('ForceSpectator', $target->login, 0); $this->maniaControl->client->query('ForceSpectator', $target->login, 0);
} }
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to player!'); $this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to player!');
@ -188,26 +224,26 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle //addfakeplayers command * Handle //addfakeplayers command
* *
* @param array $chatCallback * @param array $chatCallback
* @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;
} }
@ -217,16 +253,16 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle //removefakeplayers command * Handle //removefakeplayers command
* *
* @param array $chatCallback * @param array $chatCallback
* @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;
} }
@ -235,11 +271,12 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
/** /**
* Handle Player list command * Handle Player list command
*
* @param array $chatCallback * @param array $chatCallback
* @param Player $player * @param Player $player
*/ */
public function command_playerList(array $chatCallback, Player $player) { public function command_playerList(array $chatCallback, Player $player) {
$this->playerList->addPlayerToShownList($player, PlayerList::SHOWN_MAIN_WINDOW); $this->playerList->addPlayerToShownList($player, PlayerList::SHOWN_MAIN_WINDOW);
$this->playerList->showPlayerList($player); $this->playerList->showPlayerList($player);
} }
} }