mp3 mx beta working

This commit is contained in:
kremsy 2014-03-27 18:40:13 +01:00 committed by Steffen Schröder
parent 6a92553e75
commit 46bf05225e
4 changed files with 41 additions and 11 deletions

View File

@ -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);
}

View File

@ -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=.*\]/', '<i>', $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;

View File

@ -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;

View File

@ -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);