|
|
@ -28,13 +28,14 @@ class MapCommands implements CommandListener {
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
|
|
|
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('nextmap', $this, 'command_NextMap',true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('nextmap', $this, 'command_NextMap', true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('restartmap', $this, 'command_RestartMap',true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('restartmap', $this, 'command_RestartMap', true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('addmap', $this, 'command_AddMap',true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('addmap', $this, 'command_AddMap', true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('removemap', $this, 'command_RemoveMap',true);
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('removemap', $this, 'command_RemoveMap', true);
|
|
|
|
|
|
|
|
|
|
|
|
// Register for player commands
|
|
|
|
// Register for chat commands
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('list', $this, 'command_list');
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('list', $this, 'command_List');
|
|
|
|
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('maps', $this, 'command_List');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -42,27 +43,25 @@ class MapCommands implements CommandListener {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array $chat
|
|
|
|
* @param array $chat
|
|
|
|
* @param \ManiaControl\Players\Player $player
|
|
|
|
* @param \ManiaControl\Players\Player $player
|
|
|
|
* @return bool
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
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_OPERATOR)) {
|
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
|
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return false;
|
|
|
|
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 false;
|
|
|
|
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 false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->maniaControl->chat->sendSuccess('Map removed.', $player->login);
|
|
|
|
$this->maniaControl->chat->sendSuccess('Map removed.', $player->login);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -70,37 +69,36 @@ class MapCommands implements CommandListener {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array $chatCallback
|
|
|
|
* @param array $chatCallback
|
|
|
|
* @param \ManiaControl\Players\Player $player
|
|
|
|
* @param \ManiaControl\Players\Player $player
|
|
|
|
* @return bool
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
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_OPERATOR)) {
|
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
|
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return false;
|
|
|
|
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 false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check if ManiaControl can even write to the maps dir
|
|
|
|
// Check if ManiaControl can even write to the maps dir
|
|
|
|
if (!$this->maniaControl->client->query('GetMapsDirectory')) {
|
|
|
|
if (!$this->maniaControl->client->query('GetMapsDirectory')) {
|
|
|
|
trigger_error("Couldn't get map directory. " . $this->maniaControl->getClientErrorText());
|
|
|
|
trigger_error("Couldn't get map directory. " . $this->maniaControl->getClientErrorText());
|
|
|
|
$this->maniaControl->chat->sendError("ManiaControl couldn't retrieve the maps directory.", $player->login);
|
|
|
|
$this->maniaControl->chat->sendError("ManiaControl couldn't retrieve the maps directory.", $player->login);
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$mapDir = $this->maniaControl->client->getResponse();
|
|
|
|
$mapDir = $this->maniaControl->client->getResponse();
|
|
|
|
if (!is_dir($mapDir)) {
|
|
|
|
if (!is_dir($mapDir)) {
|
|
|
|
trigger_error("ManiaControl doesn't have have access to the maps directory in '{$mapDir}'.");
|
|
|
|
trigger_error("ManiaControl doesn't have have access to the maps directory in '{$mapDir}'.");
|
|
|
|
$this->maniaControl->chat->sendError("ManiaControl doesn't have access to the maps directory.", $player->login);
|
|
|
|
$this->maniaControl->chat->sendError("ManiaControl doesn't have access to the maps directory.", $player->login);
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$downloadDirectory = $this->maniaControl->settingManager->getSetting($this, 'MapDownloadDirectory', 'MX');
|
|
|
|
$downloadDirectory = $this->maniaControl->settingManager->getSetting($this, 'MapDownloadDirectory', 'MX');
|
|
|
|
// Create download directory if necessary
|
|
|
|
// Create download directory if necessary
|
|
|
|
if (!is_dir($mapDir . $downloadDirectory) && !mkdir($mapDir . $downloadDirectory)) {
|
|
|
|
if (!is_dir($mapDir . $downloadDirectory) && !mkdir($mapDir . $downloadDirectory)) {
|
|
|
|
trigger_error("ManiaControl doesn't have to rights to save maps in '{$mapDir}{$downloadDirectory}'.");
|
|
|
|
trigger_error("ManiaControl doesn't have to rights to save maps in '{$mapDir}{$downloadDirectory}'.");
|
|
|
|
$this->maniaControl->chat->sendError("ManiaControl doesn't have the rights to save maps.", $player->login);
|
|
|
|
$this->maniaControl->chat->sendError("ManiaControl doesn't have the rights to save maps.", $player->login);
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$mapDir .= $downloadDirectory . '/';
|
|
|
|
$mapDir .= $downloadDirectory . '/';
|
|
|
|
// Download the map
|
|
|
|
// Download the map
|
|
|
@ -115,7 +113,7 @@ class MapCommands implements CommandListener {
|
|
|
|
if (!$mapInfo || strlen($mapInfo) <= 0) {
|
|
|
|
if (!$mapInfo || strlen($mapInfo) <= 0) {
|
|
|
|
// Invalid id
|
|
|
|
// Invalid id
|
|
|
|
$this->maniaControl->chat->sendError('Invalid MX-Id!', $player->login);
|
|
|
|
$this->maniaControl->chat->sendError('Invalid MX-Id!', $player->login);
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$mapInfo = json_decode($mapInfo, true);
|
|
|
|
$mapInfo = json_decode($mapInfo, true);
|
|
|
|
$url = "http://{$title}.mania-exchange.com/tracks/download/{$mapId}";
|
|
|
|
$url = "http://{$title}.mania-exchange.com/tracks/download/{$mapId}";
|
|
|
@ -123,7 +121,7 @@ class MapCommands implements CommandListener {
|
|
|
|
if (!$file) {
|
|
|
|
if (!$file) {
|
|
|
|
// Download error
|
|
|
|
// Download error
|
|
|
|
$this->maniaControl->chat->sendError('Download failed!', $player->login);
|
|
|
|
$this->maniaControl->chat->sendError('Download failed!', $player->login);
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Save map
|
|
|
|
// Save map
|
|
|
|
$fileName = $mapInfo['TrackID'] . '_' . $mapInfo['Name'] . '.Map.Gbx';
|
|
|
|
$fileName = $mapInfo['TrackID'] . '_' . $mapInfo['Name'] . '.Map.Gbx';
|
|
|
@ -131,31 +129,30 @@ class MapCommands implements CommandListener {
|
|
|
|
if (!file_put_contents($mapDir . $fileName, $file)) {
|
|
|
|
if (!file_put_contents($mapDir . $fileName, $file)) {
|
|
|
|
// Save error
|
|
|
|
// Save error
|
|
|
|
$this->maniaControl->chat->sendError('Saving map failed!', $player->login);
|
|
|
|
$this->maniaControl->chat->sendError('Saving map failed!', $player->login);
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check for valid map
|
|
|
|
// Check for valid map
|
|
|
|
$mapFileName = $downloadDirectory . '/' . $fileName;
|
|
|
|
$mapFileName = $downloadDirectory . '/' . $fileName;
|
|
|
|
if (!$this->maniaControl->client->query('CheckMapForCurrentServerParams', $mapFileName)) {
|
|
|
|
if (!$this->maniaControl->client->query('CheckMapForCurrentServerParams', $mapFileName)) {
|
|
|
|
trigger_error("Couldn't check if map is valid ('{$mapFileName}'). " . $this->maniaControl->getClientErrorText());
|
|
|
|
trigger_error("Couldn't check if map is valid ('{$mapFileName}'). " . $this->maniaControl->getClientErrorText());
|
|
|
|
$this->maniaControl->chat->sendError('Error checking map!', $player->login);
|
|
|
|
$this->maniaControl->chat->sendError('Error checking map!', $player->login);
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$response = $this->maniaControl->client->getResponse();
|
|
|
|
$response = $this->maniaControl->client->getResponse();
|
|
|
|
if (!$response) {
|
|
|
|
if (!$response) {
|
|
|
|
// Invalid map type
|
|
|
|
// Invalid map type
|
|
|
|
$this->maniaControl->chat->sendError("Invalid map type.", $player->login);
|
|
|
|
$this->maniaControl->chat->sendError("Invalid map type.", $player->login);
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Add map to map list
|
|
|
|
// Add map to map list
|
|
|
|
if (!$this->maniaControl->client->query('InsertMap', $mapFileName)) {
|
|
|
|
if (!$this->maniaControl->client->query('InsertMap', $mapFileName)) {
|
|
|
|
$this->maniaControl->chat->sendError("Couldn't add map to match settings!", $player->login);
|
|
|
|
$this->maniaControl->chat->sendError("Couldn't add map to match settings!", $player->login);
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->maniaControl->chat->sendSuccess('Map $<' . $mapInfo['Name'] . '$> added!');
|
|
|
|
$this->maniaControl->chat->sendSuccess('Map $<' . $mapInfo['Name'] . '$> added!');
|
|
|
|
return true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO: add local map by filename
|
|
|
|
// TODO: add local map by filename
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -163,37 +160,38 @@ class MapCommands implements CommandListener {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array $chat
|
|
|
|
* @param array $chat
|
|
|
|
* @param \ManiaControl\Players\Player $player
|
|
|
|
* @param \ManiaControl\Players\Player $player
|
|
|
|
* @return bool
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
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_OPERATOR)) {
|
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
|
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->maniaControl->client->query('NextMap');
|
|
|
|
$this->maniaControl->client->query('NextMap');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Handle retartmap command
|
|
|
|
* Handle restartmap command
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array $chat
|
|
|
|
* @param array $chat
|
|
|
|
* @param \ManiaControl\Players\Player $player
|
|
|
|
* @param \ManiaControl\Players\Player $player
|
|
|
|
* @return bool
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
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_OPERATOR)) {
|
|
|
|
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
|
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->maniaControl->client->query('RestartMap');
|
|
|
|
$this->maniaControl->client->query('RestartMap');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function command_list(array $chatCallback, Player $player){
|
|
|
|
/**
|
|
|
|
// var_dump($chatCallback);
|
|
|
|
* Handle list maps command
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param array $chatCallback
|
|
|
|
|
|
|
|
* @param Player $player
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function command_List(array $chatCallback, Player $player) {
|
|
|
|
|
|
|
|
// var_dump($chatCallback);
|
|
|
|
$mapList = new MapList($this->maniaControl);
|
|
|
|
$mapList = new MapList($this->maniaControl);
|
|
|
|
$mapList->showMapList($player);
|
|
|
|
$mapList->showMapList($player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|