From 46bf05225e61fa6be3474dbfd1920be96379ce41 Mon Sep 17 00:00:00 2001 From: kremsy Date: Thu, 27 Mar 2014 18:40:13 +0100 Subject: [PATCH] mp3 mx beta working --- application/core/ManiaControl.php | 2 +- application/core/ManiaExchange/MXMapInfo.php | 14 +++++----- .../ManiaExchange/ManiaExchangeManager.php | 27 +++++++++++++++++-- application/core/Maps/MapManager.php | 9 ++++++- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/application/core/ManiaControl.php b/application/core/ManiaControl.php index 316a046c..f573b437 100644 --- a/application/core/ManiaControl.php +++ b/application/core/ManiaControl.php @@ -341,7 +341,7 @@ class ManiaControl implements CommandListener, TimerListener { // Yield for next tick $loopEnd = microtime(true); - $sleepTime = (int) (5000 - ($loopEnd - $loopStart) * 1000000); + $sleepTime = (int) (2000 - ($loopEnd - $loopStart) * 1000000); if ($sleepTime > 0) { usleep($sleepTime); } diff --git a/application/core/ManiaExchange/MXMapInfo.php b/application/core/ManiaExchange/MXMapInfo.php index 1b5936c3..938388d7 100644 --- a/application/core/ManiaExchange/MXMapInfo.php +++ b/application/core/ManiaExchange/MXMapInfo.php @@ -15,7 +15,7 @@ class MXMapInfo { public $titlepack, $style, $envir, $mood, $dispcost, $lightmap, $modname, $exever; public $exebld, $routes, $length, $unlimiter, $laps, $difficulty, $lbrating, $trkvalue; public $replaytyp, $replayid, $replaycnt, $acomment, $awards, $comments, $rating; - public $ratingex, $ratingcnt, $pageurl, $replayurl, $imageurl, $thumburl, $downloadurl; + public $ratingex, $ratingcnt, $pageurl, $replayurl, $imageurl, $thumburl, $downloadurl, $dir; /** * Returns map object with all available data from MX map data @@ -30,11 +30,11 @@ class MXMapInfo { if ($mx) { if ($this->prefix == 'tm') { - $dir = 'tracks'; + $this->dir = 'tracks'; $this->id = $mx->TrackID; $this->uid = isset($mx->TrackUID) ? $mx->TrackUID : ''; } else { - $dir = 'maps'; + $this->dir = 'maps'; $this->id = $mx->MapID; $this->uid = isset($mx->MapUID) ? $mx->MapUID : ''; } @@ -88,10 +88,10 @@ class MXMapInfo { $this->acomment = str_ireplace($search, $replace, $this->acomment); $this->acomment = preg_replace('/\[url=.*\]/', '', $this->acomment); - $this->pageurl = 'http://' . $this->prefix . '.mania-exchange.com/' . $dir . '/view/' . $this->id; - $this->imageurl = 'http://' . $this->prefix . '.mania-exchange.com/' . $dir . '/screenshot/normal/' . $this->id; - $this->thumburl = 'http://' . $this->prefix . '.mania-exchange.com/' . $dir . '/screenshot/small/' . $this->id; - $this->downloadurl = 'http://' . $this->prefix . '.mania-exchange.com/' . $dir . '/download/' . $this->id; + $this->pageurl = 'http://' . $this->prefix . '.mania-exchange.com/' . $this->dir . '/view/' . $this->id; + $this->imageurl = 'http://' . $this->prefix . '.mania-exchange.com/' . $this->dir . '/screenshot/normal/' . $this->id; + $this->thumburl = 'http://' . $this->prefix . '.mania-exchange.com/' . $this->dir . '/screenshot/small/' . $this->id; + $this->downloadurl = 'http://' . $this->prefix . '.mania-exchange.com/' . $this->dir . '/download/' . $this->id; if ($this->prefix == 'tm' && $this->replayid > 0) { $this->replayurl = 'http://' . $this->prefix . '.mania-exchange.com/replays/download/' . $this->replayid; diff --git a/application/core/ManiaExchange/ManiaExchangeManager.php b/application/core/ManiaExchange/ManiaExchangeManager.php index dce366a3..46d3f835 100644 --- a/application/core/ManiaExchange/ManiaExchangeManager.php +++ b/application/core/ManiaExchange/ManiaExchangeManager.php @@ -12,7 +12,7 @@ use Maniaplanet\DedicatedServer\Xmlrpc\Exception; * * @author steeffeen & kremsy */ -class ManiaExchangeManager { +class ManiaExchangeManager{ /** * Constants */ @@ -38,6 +38,9 @@ class ManiaExchangeManager { //Maximum Maps per request const MAPS_PER_MX_FETCH = 50; + //Beta Testing Activated + const SETTING_MP3_BETA_TESTING = 'Activate MP3 Beta Testing'; + /** * Private Propertieswc */ @@ -51,6 +54,8 @@ class ManiaExchangeManager { */ public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; + + $this->maniaControl->settingManager->initSetting($this, self::SETTING_MP3_BETA_TESTING, false); } @@ -187,6 +192,9 @@ class ManiaExchangeManager { // compile search URL $url = 'http://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $id; + if($this->maniaControl->settingManager->getSetting($this, self::SETTING_MP3_BETA_TESTING)){ + $url .= '&key=t42kEMjzH7xpAjBFHAvEkC7rqAlw'; + } return $this->maniaControl->fileReader->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix, $url) { $mxMapInfo = null; @@ -217,6 +225,9 @@ class ManiaExchangeManager { // compile search URL $url = 'http://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $string; + if($this->maniaControl->settingManager->getSetting($this, self::SETTING_MP3_BETA_TESTING)){ + $url .= '&key=t42kEMjzH7xpAjBFHAvEkC7rqAlw'; + } $thisRef = $this; $success = $this->maniaControl->fileReader->loadFile($url, function ($mapInfo, $error) use ($thisRef, $titlePrefix, $url) { @@ -274,7 +285,7 @@ class ManiaExchangeManager { $titlePrefix = $this->maniaControl->mapManager->getCurrentMap()->getGame(); // compile search URL - $url = 'http://' . $titlePrefix . '.mania-exchange.com/tracksearch?api=on'; + $url = 'http://' . $titlePrefix . '.mania-exchange.com/tracksearch2/search?api=on'; $game = explode('@', $titleId); $envNumber = $this->getEnvironment($game[0]); @@ -291,6 +302,10 @@ class ManiaExchangeManager { $url .= '&priord=' . $searchOrder; $url .= '&limit=' . $maxMapsReturned; + if($this->maniaControl->settingManager->getSetting($this, self::SETTING_MP3_BETA_TESTING)){ + $url .= '&key=t42kEMjzH7xpAjBFHAvEkC7rqAlw'; + $url .= '&mapgroup=1'; + } // Get MapTypes try { @@ -311,6 +326,14 @@ class ManiaExchangeManager { } $mxMapList = json_decode($mapInfo); + + if (!isset($mxMapList->results)) { + trigger_error('Cannot decode searched JSON data'); + return null; + } + + $mxMapList = $mxMapList->results; + if ($mxMapList === null) { trigger_error('Cannot decode searched JSON data'); return null; diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index 13292b5b..14a40077 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -569,8 +569,15 @@ class MapManager implements CallbackListener { $this->maniaControl->chat->sendError('Invalid MX-Id!', $login); return; } + + //TODO hardcoded whiel beta, later take just $mapInfo->url again + $url = 'http://' . $mapInfo->prefix . '.mania-exchange.com/' . $mapInfo->dir . '/download/' . $mapInfo->id; + if($this->maniaControl->settingManager->getSetting($this->mxManager, ManiaExchangeManager::SETTING_MP3_BETA_TESTING)){ + $url .= '?key=t42kEMjzH7xpAjBFHAvEkC7rqAlw'; + } + //Download the file - $this->maniaControl->fileReader->loadFile($mapInfo->downloadurl, function ($file, $error) use (&$login, &$mapInfo, &$update) { + $this->maniaControl->fileReader->loadFile($url, function ($file, $error) use (&$login, &$mapInfo, &$update) { if (!$file) { // Download error $this->maniaControl->chat->sendError('Download failed!', $login);