map adding
This commit is contained in:
		| @@ -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); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
|   | ||||
| @@ -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 | ||||
| 	 * | ||||
|   | ||||
| @@ -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); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user