Merge pull request #9 from jonthekiller/jonthekiller-patch-11

Add first support for Trackmania Exchange
This commit is contained in:
jonthekiller 2020-08-02 18:28:55 +02:00 committed by GitHub
commit ef929ad070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 19 deletions

View File

@ -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 = '';
}

View File

@ -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) {
// For TM2020
if ($this->maniaControl->getServer()->titleId == "Trackmania") {
// Get Title Prefix
$titlePrefix = $this->maniaControl->getMapManager()->getCurrentMap()->getGame();
$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
*/

View File

@ -100,10 +100,15 @@ class ManiaExchangeMapSearch implements UsageInformationAble {
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->titlePrefix = $this->maniaControl->getMapManager()->getCurrentMap()->getGame();
// 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;