TrackManiaControl/application/core/Maps/MapCommands.php

156 lines
5.1 KiB
PHP
Raw Normal View History

<?php
namespace ManiaControl\Maps;
2014-01-04 18:18:46 +01:00
use FML\Controls\Quads\Quad_Icons128x128_1;
use FML\Controls\Quads\Quad_Icons64x64_1;
use ManiaControl\ManiaControl;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Commands\CommandListener;
2013-11-27 02:42:39 +01:00
use ManiaControl\FileUtil;
2014-01-04 18:18:46 +01:00
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
2013-12-14 22:00:59 +01:00
use ManiaControl\Players\PlayerManager;
/**
* Class offering commands to manage maps
*
* @author steeffeen & kremsy
*/
2014-01-04 18:18:46 +01:00
class MapCommands implements CommandListener, ManialinkPageAnswerListener {
/**
* Constants
*/
const ACTION_OPEN_MAPLIST = 'MapList.OpenMapList';
/**
* Private properties
*/
private $maniaControl = null;
2013-12-16 15:08:37 +01:00
private $mapList = null;
/**
* Create MapCommands instance
*
* @param \ManiaControl\ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
// Register for admin chat commands
2013-12-15 09:00:30 +01:00
$this->maniaControl->commandManager->registerCommandListener('nextmap', $this, 'command_NextMap', true);
$this->maniaControl->commandManager->registerCommandListener('restartmap', $this, 'command_RestartMap', true);
$this->maniaControl->commandManager->registerCommandListener('addmap', $this, 'command_AddMap', true);
$this->maniaControl->commandManager->registerCommandListener('removemap', $this, 'command_RemoveMap', true);
// Register for player chat commands
$this->maniaControl->commandManager->registerCommandListener('xlist', $this, 'command_xList');
2013-12-15 09:00:30 +01:00
$this->maniaControl->commandManager->registerCommandListener('list', $this, 'command_List');
$this->maniaControl->commandManager->registerCommandListener('maps', $this, 'command_List');
2013-12-16 15:08:37 +01:00
$this->mapList = new MapList($this->maniaControl);
2014-01-04 18:18:46 +01:00
//Action Balance Teams
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_MAPLIST, $this, 'command_List');
$itemQuad = new Quad_Icons64x64_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Browser);
$itemQuad->setAction(self::ACTION_OPEN_MAPLIST);
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 4);
}
/**
* Handle removemap command
*
* @param array $chat
* @param \ManiaControl\Players\Player $player
*/
public function command_RemoveMap(array $chat, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
2013-12-15 09:00:30 +01:00
return;
}
2013-11-27 02:42:39 +01:00
// Get map
$map = $this->maniaControl->mapManager->getCurrentMap();
if (!$map) {
$this->maniaControl->chat->sendError("Couldn't remove map.", $player->login);
2013-12-15 09:00:30 +01:00
return;
}
// Remove map
2013-11-27 02:42:39 +01:00
if (!$this->maniaControl->client->query('RemoveMap', $map->fileName)) {
trigger_error("Couldn't remove current map. " . $this->maniaControl->getClientErrorText());
$this->maniaControl->chat->sendError("Couldn't remove map.", $player->login);
2013-12-15 09:00:30 +01:00
return;
}
$this->maniaControl->chat->sendSuccess('Map removed.', $player->login);
}
/**
* Handle addmap command
*
2013-11-27 02:42:39 +01:00
* @param array $chatCallback
* @param \ManiaControl\Players\Player $player
*/
2013-11-27 02:42:39 +01:00
public function command_AddMap(array $chatCallback, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
2013-12-15 09:00:30 +01:00
return;
}
// TODO: user mx fetcher
2013-11-27 02:42:39 +01:00
$params = explode(' ', $chatCallback[1][2], 2);
if (count($params) < 2) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //addmap 1234', $player->login);
2013-12-15 09:00:30 +01:00
return;
}
2013-12-15 15:13:56 +01:00
//add Map from Mania Exchange
$this->maniaControl->mapManager->addMapFromMx($params[1],$player->login);
}
/**
* Handle nextmap command
*
* @param array $chat
* @param \ManiaControl\Players\Player $player
*/
public function command_NextMap(array $chat, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
2013-12-15 09:00:30 +01:00
return;
}
2013-12-15 09:00:30 +01:00
$this->maniaControl->client->query('NextMap');
}
/**
2013-12-15 09:00:30 +01:00
* Handle restartmap command
*
* @param array $chat
* @param \ManiaControl\Players\Player $player
*/
public function command_RestartMap(array $chat, Player $player) {
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
2013-12-15 09:00:30 +01:00
return;
}
2013-12-15 09:00:30 +01:00
$this->maniaControl->client->query('RestartMap');
}
2013-12-14 22:00:59 +01:00
2013-12-15 09:00:30 +01:00
/**
* Handle list maps command
*
* @param array $chatCallback
* @param Player $player
*/
public function command_List(array $chatCallback, Player $player) {
2013-12-16 15:08:37 +01:00
$this->mapList->showMapList($player);
2013-12-14 22:00:59 +01:00
}
/**
* Handle ManiaExchange list command
* @param array $chatCallback
* @param Player $player
*/
public function command_xList(array $chatCallback, Player $player) {
2013-12-16 15:08:37 +01:00
$this->mapList->showManiaExchangeList($chatCallback, $player);
}
}