- fixed some map commands
This commit is contained in:
parent
fc66d2d34b
commit
c14c025df3
@ -5,6 +5,7 @@ namespace ManiaControl\Maps;
|
|||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Admin\AuthenticationManager;
|
use ManiaControl\Admin\AuthenticationManager;
|
||||||
use ManiaControl\Commands\CommandListener;
|
use ManiaControl\Commands\CommandListener;
|
||||||
|
use ManiaControl\FileUtil;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,15 +45,14 @@ class MapCommands implements CommandListener {
|
|||||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Get map name
|
// Get map
|
||||||
$map = $this->maniaControl->server->getMap();
|
$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 false;
|
||||||
}
|
}
|
||||||
$mapName = $map['FileName'];
|
|
||||||
// Remove map
|
// Remove map
|
||||||
if (!$this->maniaControl->client->query('RemoveMap', $mapName)) {
|
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 false;
|
||||||
@ -64,17 +64,17 @@ class MapCommands implements CommandListener {
|
|||||||
/**
|
/**
|
||||||
* Handle addmap command
|
* Handle addmap command
|
||||||
*
|
*
|
||||||
* @param array $chat
|
* @param array $chatCallback
|
||||||
* @param \ManiaControl\Players\Player $player
|
* @param \ManiaControl\Players\Player $player
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function command_AddMap(array $chat, 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 false;
|
||||||
}
|
}
|
||||||
// TODO: mx fetcher nutzen?
|
// TODO: mx fetcher nutzen?
|
||||||
$params = explode(' ', $chat[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 false;
|
||||||
@ -91,7 +91,7 @@ class MapCommands implements CommandListener {
|
|||||||
$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 false;
|
||||||
}
|
}
|
||||||
$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}'.");
|
||||||
@ -122,15 +122,17 @@ class MapCommands implements CommandListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Save map
|
// Save map
|
||||||
$fileName = $mapDir . $mapInfo['TrackID'] . '_' . $mapInfo['Name'] . '.Map.Gbx';
|
$fileName = $mapInfo['TrackID'] . '_' . $mapInfo['Name'] . '.Map.Gbx';
|
||||||
if (!file_put_contents($fileName, $file)) {
|
$fileName = FileUtil::getClearedFileName($fileName);
|
||||||
|
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 false;
|
||||||
}
|
}
|
||||||
// Check for valid map
|
// Check for valid map
|
||||||
if (!$this->maniaControl->client->query('CheckMapForCurrentServerParams', $fileName)) {
|
$mapFileName = $downloadDirectory . '/' . $fileName;
|
||||||
trigger_error("Couldn't check if map is valid. " . $this->maniaControl->getClientErrorText());
|
if (!$this->maniaControl->client->query('CheckMapForCurrentServerParams', $mapFileName)) {
|
||||||
|
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 false;
|
||||||
}
|
}
|
||||||
@ -141,7 +143,7 @@ class MapCommands implements CommandListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Add map to map list
|
// Add map to map list
|
||||||
if (!$this->maniaControl->client->query('InsertMap', $fileName)) {
|
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 false;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ namespace ManiaControl;
|
|||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author steeffeen & kremsy
|
||||||
*/
|
*/
|
||||||
class FileUtil {
|
abstract class FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a remote file
|
* Load a remote file
|
||||||
@ -75,6 +75,16 @@ class FileUtil {
|
|||||||
}
|
}
|
||||||
return simplexml_load_file($fileLocation);
|
return simplexml_load_file($fileLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return file name cleared from special characters
|
||||||
|
*
|
||||||
|
* @param string $fileName
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getClearedFileName($fileName) {
|
||||||
|
return str_replace(array('\\', '/', ':', '*', '?', '"', '<', '>', '|'), '_', $fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user