From de2e9cae8450ae713175f32cb68a3fbd4643c1c0 Mon Sep 17 00:00:00 2001 From: kremsy Date: Mon, 6 Mar 2017 19:03:09 +0100 Subject: [PATCH] mx update --- core/ManiaExchange/ManiaExchangeManager.php | 16 +++++++++++++--- core/ManiaExchange/ManiaExchangeMapSearch.php | 5 +++++ core/Maps/MapManager.php | 8 +++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/core/ManiaExchange/ManiaExchangeManager.php b/core/ManiaExchange/ManiaExchangeManager.php index 7d07d587..6743289a 100644 --- a/core/ManiaExchange/ManiaExchangeManager.php +++ b/core/ManiaExchange/ManiaExchangeManager.php @@ -6,7 +6,6 @@ use ManiaControl\Files\AsynchronousFileReader; use ManiaControl\ManiaControl; use ManiaControl\Maps\Map; use ManiaControl\Maps\MapManager; -use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException; /** * Mania Exchange Manager Class @@ -44,6 +43,8 @@ class ManiaExchangeManager { const MIN_EXE_BUILD = "2014-04-01_00_00"; + const SETTING_MX_KEY = "Mania exchange Key"; + /* * Private properties */ @@ -58,6 +59,8 @@ class ManiaExchangeManager { */ public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; + + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MX_KEY, ""); } /** @@ -159,6 +162,10 @@ class ManiaExchangeManager { // compile search URL $url = "https://api.mania-exchange.com/{$titlePrefix}/maps/?ids={$string}"; + if ($key = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KEY)) { + $url .= "&key=" . $key; + } + $this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use ($titlePrefix, $url) { if ($error) { trigger_error("Error: '{$error}' for Url '{$url}'"); @@ -252,6 +259,10 @@ class ManiaExchangeManager { // compile search URL $url = 'https://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $mapId; + if ($key = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KEY)) { + $url .= "&key=" . $key; + } + $this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix, $url) { $mxMapInfo = null; if ($error) { @@ -286,7 +297,6 @@ class ManiaExchangeManager { * @param string $env * @param int $maxMapsReturned * @param int $searchOrder - * * @deprecated * @see \ManiaControl\ManiaExchange\ManiaExchangeMapSearch */ @@ -297,7 +307,7 @@ class ManiaExchangeManager { $mapSearch->setMapLimit($maxMapsReturned); $mapSearch->setPrioritySortOrder($sortOrder); - if($env){ + if ($env) { $mapSearch->setEnvironments($env); } diff --git a/core/ManiaExchange/ManiaExchangeMapSearch.php b/core/ManiaExchange/ManiaExchangeMapSearch.php index 3813c9fa..a37f311c 100644 --- a/core/ManiaExchange/ManiaExchangeMapSearch.php +++ b/core/ManiaExchange/ManiaExchangeMapSearch.php @@ -99,6 +99,11 @@ class ManiaExchangeMapSearch { $this->url = 'https://' . $this->titlePrefix . '.mania-exchange.com/tracksearch2/search?api=on'; + if($key = $this->maniaControl->getSettingManager()->getSettingValue($this, ManiaExchangeManager::SETTING_MX_KEY)){ + $this->url .= "&key=" . $key; + } + + //Set some defaults: $this->mapLimit = 100; $this->priorityOrder = self::SEARCH_ORDER_UPDATED_NEWEST; diff --git a/core/Maps/MapManager.php b/core/Maps/MapManager.php index ab579b39..e14cd970 100644 --- a/core/Maps/MapManager.php +++ b/core/Maps/MapManager.php @@ -354,8 +354,14 @@ class MapManager implements CallbackListener, CommunicationListener { return; } + $url = $mapInfo->downloadurl; + + if ($key = $this->maniaControl->getSettingManager()->getSettingValue($this, ManiaExchangeManager::SETTING_MX_KEY)) { + $url .= "&key=" . $key; + } + // Download the file - $this->maniaControl->getFileReader()->loadFile($mapInfo->downloadurl, function ($file, $error) use ( + $this->maniaControl->getFileReader()->loadFile($url, function ($file, $error) use ( &$login, &$mapInfo, &$update ) { if (!$file || $error) {