map adding

This commit is contained in:
steeffeen 2014-07-05 13:58:35 +02:00
parent 698cb7d146
commit 9fde082a71
3 changed files with 59 additions and 14 deletions

View File

@ -15,6 +15,9 @@ use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\AlreadyInListException;
use Maniaplanet\DedicatedServer\Xmlrpc\FileException;
use Maniaplanet\DedicatedServer\Xmlrpc\InvalidMapException;
/**
* Maps Directory Browser
@ -362,8 +365,45 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
public function handleAddFile(array $actionCallback, Player $player) {
$actionName = $actionCallback[1][2];
$fileName = substr($actionName, strlen(self::ACTION_ADD_FILE));
// TODO: add map
var_dump($fileName);
$folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
$filePath = $folderPath . $fileName;
$mapsFolder = $this->maniaControl->server->directory->getMapsFolder();
$relativeFilePath = substr($filePath, strlen($mapsFolder));
// Check for valid map
try {
$this->maniaControl->client->checkMapForCurrentServerParams($relativeFilePath);
} catch (InvalidMapException $exception) {
$this->maniaControl->chat->sendException($exception, $player);
return;
} catch (FileException $exception) {
$this->maniaControl->chat->sendException($exception, $player);
return;
}
// Add map to map list
try {
$this->maniaControl->client->insertMap($relativeFilePath);
} catch (AlreadyInListException $exception) {
$this->maniaControl->chat->sendException($exception, $player);
return;
}
$map = $this->maniaControl->mapManager->fetchMapByFileName($relativeFilePath);
if (!$map) {
$this->maniaControl->chat->sendError('Error occurred.', $player);
return;
}
// Message
$message = $player->getEscapedNickname() . ' added ' . $map->getEscapedName() . '!';
$this->maniaControl->chat->sendSuccess($message);
$this->maniaControl->log($message, true);
// Queue requested Map
$this->maniaControl->mapManager->mapQueue->addMapToMapQueue($player, $map);
$this->showManiaLink($player);
}
/**

View File

@ -447,16 +447,6 @@ class MapManager implements CallbackListener {
public function initializeMap($rpcMap) {
$map = new Map($rpcMap);
$this->saveMap($map);
/*$mapsDirectory = $this->maniaControl->server->getMapsDirectory();
if (is_readable($mapsDirectory . $map->fileName)) {
$mapFetcher = new \GBXChallMapFetcher(true);
$mapFetcher->processFile($mapsDirectory . $map->fileName);
$map->authorNick = FORMATTER::stripDirtyCodes($mapFetcher->authorNick);
$map->authorEInfo = $mapFetcher->authorEInfo;
$map->authorZone = $mapFetcher->authorZone;
$map->comment = $mapFetcher->comment;
}*/
return $map;
}
@ -723,6 +713,14 @@ class MapManager implements CallbackListener {
$this->maniaControl->callbackManager->triggerCallback(Callbacks::ENDMAP, $this->currentMap);
}
public function fetchMapByFileName($relativeFileName) {
$mapInfo = $this->maniaControl->client->getMapInfo($relativeFileName);
if (!$mapInfo) {
return false;
}
return $this->initializeMap($mapInfo);
}
/**
* Handle BeginMap callback
*

View File

@ -257,6 +257,11 @@ class MapQueue implements CallbackListener, CommandListener {
}
// Check if the map is already juked
$map = null;
if ($uid instanceof Map) {
$map = $uid;
$uid = $map->uid;
}
if (array_key_exists($uid, $this->queuedMaps)) {
$this->maniaControl->chat->sendError('That map is already in the Map-Queue!', $login);
return;
@ -271,7 +276,9 @@ class MapQueue implements CallbackListener, CommandListener {
}
}
if (!$map) {
$map = $this->maniaControl->mapManager->getMapByUid($uid);
}
$this->queuedMaps[$uid] = array($player, $map);