From 2d2f5642a3ffca8b59fd45db2951a269509cd4f1 Mon Sep 17 00:00:00 2001 From: jonthekiller Date: Sun, 2 Aug 2020 12:14:05 +0200 Subject: [PATCH] Add first support for Trackmania Exchange Move to the new API of MX and add TM2020 compatibility --- core/ManiaExchange/MXMapInfo.php | 12 +++--- core/ManiaExchange/ManiaExchangeManager.php | 38 +++++++++++++++---- core/ManiaExchange/ManiaExchangeMapSearch.php | 15 +++++--- 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/core/ManiaExchange/MXMapInfo.php b/core/ManiaExchange/MXMapInfo.php index 2ede42f9..a3551d69 100644 --- a/core/ManiaExchange/MXMapInfo.php +++ b/core/ManiaExchange/MXMapInfo.php @@ -37,7 +37,7 @@ class MXMapInfo { return; } - if ($this->prefix === 'tm') { + if ($this->prefix === 'tm.mania-exchange.com' OR $this->prefix === 'trackmania.exchange') { $this->dir = 'tracks'; $this->id = $mx->TrackID; $this->uid = isset($mx->TrackUID) ? $mx->TrackUID : ''; @@ -93,23 +93,23 @@ class MXMapInfo { $this->lbrating = $this->trkvalue; } - $this->pageurl = 'https://' . $this->prefix . '.mania-exchange.com/' . $this->dir . '/view/' . $this->id; - $this->downloadurl = 'https://' . $this->prefix . '.mania-exchange.com/' . $this->dir . '/download/' . $this->id; + $this->pageurl = 'https://' . $this->prefix . '/' . $this->dir . '/view/' . $this->id; + $this->downloadurl = 'https://' . $this->prefix . '/' . $this->dir . '/download/' . $this->id; if ($mx->HasScreenshot) { - $this->imageurl = 'https://' . $this->prefix . '.mania-exchange.com/' . $this->dir . '/screenshot/normal/' . $this->id; + $this->imageurl = 'https://' . $this->prefix . '/' . $this->dir . '/screenshot/normal/' . $this->id; } else { $this->imageurl = ''; } if ($mx->HasThumbnail) { - $this->thumburl = 'https://' . $this->prefix . '.mania-exchange.com/' . $this->dir . '/thumbnail/' . $this->id; + $this->thumburl = 'https://' . $this->prefix . '/' . $this->dir . '/thumbnail/' . $this->id; } else { $this->thumburl = ''; } if ($this->prefix === 'tm' && $this->replayid > 0) { - $this->replayurl = 'https://' . $this->prefix . '.mania-exchange.com/replays/download/' . $this->replayid; + $this->replayurl = 'https://' . $this->prefix . '/replays/download/' . $this->replayid; } else { $this->replayurl = ''; } diff --git a/core/ManiaExchange/ManiaExchangeManager.php b/core/ManiaExchange/ManiaExchangeManager.php index 06988e97..94949078 100644 --- a/core/ManiaExchange/ManiaExchangeManager.php +++ b/core/ManiaExchange/ManiaExchangeManager.php @@ -160,11 +160,19 @@ class ManiaExchangeManager implements UsageInformationAble { * @param string $string */ public function fetchMaplistByMixedUidIdString($string) { - // Get Title Prefix - $titlePrefix = $this->maniaControl->getMapManager()->getCurrentMap()->getGame(); + // For TM2020 + if ($this->maniaControl->getServer()->titleId == "Trackmania") { + // Get Title Prefix + $titlePrefix = "trackmania.exchange"; + + } else { + // Get Title Prefix + $titlePrefix = $this->maniaControl->getMapManager()->getCurrentMap()->getGame() . ".mania-exchange.com"; + + } // compile search URL - $url = "https://api.mania-exchange.com/{$titlePrefix}/maps/?ids={$string}"; + $url = "https://{$titlePrefix}/api/maps/get_map_info/multi/{$string}"; /*if ($key = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KEY)) { $url .= "&key=" . $key; @@ -261,11 +269,18 @@ class ManiaExchangeManager implements UsageInformationAble { * @param callable $function */ public function fetchMapInfo($mapId, callable $function) { - // Get Title Prefix - $titlePrefix = $this->maniaControl->getMapManager()->getCurrentMap()->getGame(); + // For TM2020 + if ($this->maniaControl->getServer()->titleId == "Trackmania") { + // Get Title Prefix + $titlePrefix = "trackmania.exchange"; + } else { + // Get Title Prefix + $titlePrefix = $this->maniaControl->getMapManager()->getCurrentMap()->getGame() . ".mania-exchange.com"; + + } // compile search URL - $url = 'https://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $mapId; + $url = "https://{$titlePrefix}/api/maps/get_map_info/multi/{$mapId}"; /*if ($key = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KEY)) { $url .= "&key=" . $key; @@ -292,8 +307,15 @@ class ManiaExchangeManager implements UsageInformationAble { } /** - * @deprecated + * @param callable $function + * @param string $name + * @param string $author + * @param string $env + * @param int $maxMapsReturned + * @param int $searchOrder + * @return bool * @see \ManiaControl\ManiaExchange\ManiaExchangeMapSearch + * @deprecated */ public function getMapsAsync(callable $function, $name = '', $author = '', $env = '', $maxMapsReturned = 100, $searchOrder = ManiaExchangeMapSearch::SEARCH_ORDER_UPDATED_NEWEST) { $this->fetchMapsAsync($function, $name, $author, $env, $maxMapsReturned, $searchOrder); @@ -308,7 +330,7 @@ class ManiaExchangeManager implements UsageInformationAble { * @param string $author * @param string $env * @param int $maxMapsReturned - * @param int $searchOrder + * @param int $sortOrder * @deprecated * @see \ManiaControl\ManiaExchange\ManiaExchangeMapSearch */ diff --git a/core/ManiaExchange/ManiaExchangeMapSearch.php b/core/ManiaExchange/ManiaExchangeMapSearch.php index 5dc61c50..451b1442 100644 --- a/core/ManiaExchange/ManiaExchangeMapSearch.php +++ b/core/ManiaExchange/ManiaExchangeMapSearch.php @@ -100,10 +100,15 @@ class ManiaExchangeMapSearch implements UsageInformationAble { public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; - $this->titlePrefix = $this->maniaControl->getMapManager()->getCurrentMap()->getGame(); - - $this->url = 'https://' . $this->titlePrefix . '.mania-exchange.com/tracksearch2/search?api=on'; - + // For TM2020 + if ($this->maniaControl->getServer()->titleId == "Trackmania") + { + $this->titlePrefix = "trackmania.exchange"; + $this->url = 'https://trackmania.exchange/tracksearch2/search?api=on'; + }else { + $this->titlePrefix = $this->maniaControl->getMapManager()->getCurrentMap()->getGame() . '.mania-exchange.com'; + $this->url = 'https://' . $this->titlePrefix . '.mania-exchange.com/tracksearch2/search?api=on'; + } /*if ($key = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getMapManager()->getMXManager(), ManiaExchangeManager::SETTING_MX_KEY)) { $this->url .= "&key=" . $key; }*/ @@ -160,7 +165,7 @@ class ManiaExchangeMapSearch implements UsageInformationAble { $parameters .= "&tpack=" . urlencode($this->titlePack); } if ($this->replayType) { - $parameters .= "&rytpe=" . $this->replayType; + $parameters .= "&rtype=" . $this->replayType; } if ($this->style) { $parameters .= "&style=" . $this->style;