2013-11-12 16:52:23 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Maps;
|
|
|
|
|
2014-01-05 00:43:46 +01:00
|
|
|
use FML\Controls\Quad;
|
2014-01-04 18:18:46 +01:00
|
|
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
2014-01-05 01:29:49 +01:00
|
|
|
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
2013-11-13 01:43:12 +01:00
|
|
|
use ManiaControl\Admin\AuthenticationManager;
|
2014-01-05 00:43:46 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2013-11-12 16:52:23 +01:00
|
|
|
use ManiaControl\Commands\CommandListener;
|
2014-01-04 18:49:33 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
2014-01-05 00:43:46 +01:00
|
|
|
use ManiaControl\Manialinks\IconManager;
|
2014-01-04 18:18:46 +01:00
|
|
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
2013-11-12 16:52:23 +01:00
|
|
|
use ManiaControl\Players\Player;
|
2014-01-05 00:43:46 +01:00
|
|
|
use WidgetPlugin;
|
2013-11-12 16:52:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class offering commands to manage maps
|
|
|
|
*
|
|
|
|
* @author steeffeen & kremsy
|
|
|
|
*/
|
2014-01-05 13:32:59 +01:00
|
|
|
class MapCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener {
|
2014-01-04 18:18:46 +01:00
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
2014-01-04 18:49:33 +01:00
|
|
|
const ACTION_OPEN_MAPLIST = 'MapList.OpenMapList';
|
2014-01-05 13:32:59 +01:00
|
|
|
const ACTION_OPEN_XLIST = 'MapList.OpenMXList';
|
|
|
|
const ACTION_RESTART_MAP = 'MapList.RestartMap';
|
|
|
|
const ACTION_SKIP_MAP = 'MapList.NextMap';
|
|
|
|
|
2013-11-12 16:52:23 +01:00
|
|
|
/**
|
|
|
|
* Private properties
|
|
|
|
*/
|
|
|
|
private $maniaControl = null;
|
2013-12-16 15:08:37 +01:00
|
|
|
private $mapList = null;
|
2013-11-12 16:52:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create MapCommands instance
|
|
|
|
*
|
2014-01-04 18:49:33 +01:00
|
|
|
* @param \ManiaControl\ManiaControl $maniaControl
|
2013-11-12 16:52:23 +01:00
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2014-01-05 13:32:59 +01:00
|
|
|
$this->initActionsMenuButtons();
|
|
|
|
$this->mapList = new MapList($this->maniaControl);
|
|
|
|
|
2013-12-15 11:29:49 +01:00
|
|
|
// 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);
|
2014-01-05 13:32:59 +01:00
|
|
|
|
2013-12-15 11:29:49 +01:00
|
|
|
// 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');
|
2014-01-05 13:32:59 +01:00
|
|
|
|
|
|
|
// Menu Buttons
|
2014-01-04 18:49:33 +01:00
|
|
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_XLIST, $this, 'command_xList');
|
2014-01-05 00:43:46 +01:00
|
|
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_MAPLIST, $this, 'command_List');
|
|
|
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_RESTART_MAP, $this, 'command_RestartMap');
|
|
|
|
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SKIP_MAP, $this, 'command_NextMap');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-01-05 13:32:59 +01:00
|
|
|
* Add all Actions Menu Buttons
|
2014-01-05 00:43:46 +01:00
|
|
|
*/
|
2014-01-05 13:32:59 +01:00
|
|
|
private function initActionsMenuButtons() {
|
|
|
|
// Menu Open xList
|
2014-01-05 00:43:46 +01:00
|
|
|
$itemQuad = new Quad();
|
|
|
|
$itemQuad->setImage($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON));
|
2014-01-05 13:32:59 +01:00
|
|
|
$itemQuad->setImageFocus($this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER));
|
2014-01-04 18:49:33 +01:00
|
|
|
$itemQuad->setAction(self::ACTION_OPEN_XLIST);
|
2014-01-05 13:32:59 +01:00
|
|
|
$this->maniaControl->actionsMenu->addPlayerMenuItem($itemQuad, 5, 'Open MX List');
|
|
|
|
|
|
|
|
// Menu Open List
|
2014-01-04 18:18:46 +01:00
|
|
|
$itemQuad = new Quad_Icons64x64_1();
|
2014-01-05 01:29:49 +01:00
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ToolRoot);
|
2014-01-04 18:18:46 +01:00
|
|
|
$itemQuad->setAction(self::ACTION_OPEN_MAPLIST);
|
2014-01-05 13:32:59 +01:00
|
|
|
$this->maniaControl->actionsMenu->addPlayerMenuItem($itemQuad, 10, 'Open MapList');
|
|
|
|
|
|
|
|
// Menu RestartMap
|
2014-01-05 01:29:49 +01:00
|
|
|
$itemQuad = new Quad_UIConstruction_Buttons();
|
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Reload);
|
2014-01-04 18:49:33 +01:00
|
|
|
$itemQuad->setAction(self::ACTION_RESTART_MAP);
|
2014-01-05 13:32:59 +01:00
|
|
|
$this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad, 0, 'Restart Map');
|
|
|
|
|
|
|
|
// Menu NextMap
|
2014-01-04 18:49:33 +01:00
|
|
|
$itemQuad = new Quad_Icons64x64_1();
|
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ArrowFastNext);
|
|
|
|
$itemQuad->setAction(self::ACTION_SKIP_MAP);
|
2014-01-05 13:32:59 +01:00
|
|
|
$this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad, 1, 'Skip Map');
|
2014-01-05 00:43:46 +01:00
|
|
|
}
|
2014-01-05 13:32:59 +01:00
|
|
|
|
2013-11-12 16:52:23 +01:00
|
|
|
/**
|
|
|
|
* Handle removemap command
|
|
|
|
*
|
2014-01-05 13:32:59 +01:00
|
|
|
* @param array $chat
|
2014-01-04 18:49:33 +01:00
|
|
|
* @param \ManiaControl\Players\Player $player
|
2013-11-12 16:52:23 +01:00
|
|
|
*/
|
|
|
|
public function command_RemoveMap(array $chat, Player $player) {
|
2014-01-05 13:32:59 +01:00
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
2013-11-13 01:43:12 +01:00
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
2013-12-15 09:00:30 +01:00
|
|
|
return;
|
2013-11-12 16:52:23 +01:00
|
|
|
}
|
2013-11-27 02:42:39 +01:00
|
|
|
// Get map
|
|
|
|
$map = $this->maniaControl->mapManager->getCurrentMap();
|
2014-01-05 13:32:59 +01:00
|
|
|
if (!$map) {
|
2013-11-12 16:52:23 +01:00
|
|
|
$this->maniaControl->chat->sendError("Couldn't remove map.", $player->login);
|
2013-12-15 09:00:30 +01:00
|
|
|
return;
|
2013-11-12 16:52:23 +01:00
|
|
|
}
|
|
|
|
// Remove map
|
2014-01-05 13:32:59 +01:00
|
|
|
if (!$this->maniaControl->client->query('RemoveMap', $map->fileName)) {
|
2013-11-12 16:52:23 +01:00
|
|
|
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;
|
2013-11-12 16:52:23 +01:00
|
|
|
}
|
|
|
|
$this->maniaControl->chat->sendSuccess('Map removed.', $player->login);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle addmap command
|
|
|
|
*
|
2014-01-05 13:32:59 +01:00
|
|
|
* @param array $chatCallback
|
2014-01-04 18:49:33 +01:00
|
|
|
* @param \ManiaControl\Players\Player $player
|
2013-11-12 16:52:23 +01:00
|
|
|
*/
|
2013-11-27 02:42:39 +01:00
|
|
|
public function command_AddMap(array $chatCallback, Player $player) {
|
2014-01-05 13:32:59 +01:00
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
2013-11-13 01:43:12 +01:00
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
2013-12-15 09:00:30 +01:00
|
|
|
return;
|
2013-11-12 16:52:23 +01:00
|
|
|
}
|
2013-12-09 13:45:58 +01:00
|
|
|
// TODO: user mx fetcher
|
2013-11-27 02:42:39 +01:00
|
|
|
$params = explode(' ', $chatCallback[1][2], 2);
|
2014-01-05 13:32:59 +01:00
|
|
|
if (count($params) < 2) {
|
2013-11-19 20:29:37 +01:00
|
|
|
$this->maniaControl->chat->sendUsageInfo('Usage example: //addmap 1234', $player->login);
|
2013-12-15 09:00:30 +01:00
|
|
|
return;
|
2013-11-12 16:52:23 +01:00
|
|
|
}
|
2014-01-05 13:32:59 +01:00
|
|
|
|
|
|
|
// add Map from Mania Exchange
|
2014-01-04 18:49:33 +01:00
|
|
|
$this->maniaControl->mapManager->addMapFromMx($params[1], $player->login);
|
2013-11-12 16:52:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle nextmap command
|
|
|
|
*
|
2014-01-05 13:32:59 +01:00
|
|
|
* @param array $chat
|
2014-01-04 18:49:33 +01:00
|
|
|
* @param \ManiaControl\Players\Player $player
|
2013-11-12 16:52:23 +01:00
|
|
|
*/
|
|
|
|
public function command_NextMap(array $chat, Player $player) {
|
2014-01-05 13:32:59 +01:00
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
2013-11-13 01:43:12 +01:00
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
2013-12-15 09:00:30 +01:00
|
|
|
return;
|
2013-11-12 16:52:23 +01:00
|
|
|
}
|
2013-12-15 09:00:30 +01:00
|
|
|
$this->maniaControl->client->query('NextMap');
|
2013-11-12 16:52:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-15 09:00:30 +01:00
|
|
|
* Handle restartmap command
|
2013-11-12 16:52:23 +01:00
|
|
|
*
|
2014-01-05 13:32:59 +01:00
|
|
|
* @param array $chat
|
2014-01-04 18:49:33 +01:00
|
|
|
* @param \ManiaControl\Players\Player $player
|
2013-11-12 16:52:23 +01:00
|
|
|
*/
|
|
|
|
public function command_RestartMap(array $chat, Player $player) {
|
2014-01-05 13:32:59 +01:00
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
2013-11-13 01:43:12 +01:00
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
2013-12-15 09:00:30 +01:00
|
|
|
return;
|
2013-11-12 16:52:23 +01:00
|
|
|
}
|
2013-12-15 09:00:30 +01:00
|
|
|
$this->maniaControl->client->query('RestartMap');
|
2013-11-12 16:52:23 +01:00
|
|
|
}
|
2013-12-14 22:00:59 +01:00
|
|
|
|
2013-12-15 09:00:30 +01:00
|
|
|
/**
|
|
|
|
* Handle list maps command
|
|
|
|
*
|
2014-01-05 13:32:59 +01:00
|
|
|
* @param array $chatCallback
|
2014-01-04 18:49:33 +01:00
|
|
|
* @param Player $player
|
2013-12-15 09:00:30 +01:00
|
|
|
*/
|
|
|
|
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
|
|
|
}
|
2013-12-15 11:29:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle ManiaExchange list command
|
2014-01-04 18:49:33 +01:00
|
|
|
*
|
2014-01-05 13:32:59 +01:00
|
|
|
* @param array $chatCallback
|
2013-12-15 11:29:49 +01:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function command_xList(array $chatCallback, Player $player) {
|
2013-12-16 15:08:37 +01:00
|
|
|
$this->mapList->showManiaExchangeList($chatCallback, $player);
|
2013-12-15 11:29:49 +01:00
|
|
|
}
|
2013-11-12 16:52:23 +01:00
|
|
|
}
|