asynchronous mapadd
This commit is contained in:
parent
4c8b247896
commit
5ada096e0a
@ -172,6 +172,36 @@ class ManiaExchangeManager {
|
|||||||
$fetchMapStatement->close();
|
$fetchMapStatement->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Map Info Asynchronously
|
||||||
|
*
|
||||||
|
* @param $id
|
||||||
|
* @param $function
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getMapInfo($id, $function) {
|
||||||
|
// Get Title Id
|
||||||
|
$titleId = $this->maniaControl->server->titleId;
|
||||||
|
$titlePrefix = strtolower(substr($titleId, 0, 2));
|
||||||
|
|
||||||
|
// compile search URL
|
||||||
|
$url = 'http://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $id;
|
||||||
|
|
||||||
|
return $this->maniaControl->fileReader->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix, $url) {
|
||||||
|
$mxMapInfo = null;
|
||||||
|
if ($error) {
|
||||||
|
trigger_error($error);
|
||||||
|
} else {
|
||||||
|
$mxMapList = json_decode($mapInfo);
|
||||||
|
if ($mxMapList === null) {
|
||||||
|
trigger_error('Cannot decode searched JSON data from ' . $url);
|
||||||
|
} else {
|
||||||
|
$mxMapInfo = new MXMapInfo($titlePrefix, $mxMapList[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
call_user_func($function, $mxMapInfo);
|
||||||
|
}, "application/json");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a Single Map
|
* Gets a Single Map
|
||||||
|
@ -517,33 +517,31 @@ class MapManager implements CallbackListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download the map
|
|
||||||
if (is_numeric($mapId)) {
|
if (is_numeric($mapId)) {
|
||||||
// Load from MX
|
|
||||||
$serverInfo = $this->maniaControl->server->getSystemInfo();
|
|
||||||
$title = strtolower(substr($serverInfo->titleId, 0, 2));
|
|
||||||
|
|
||||||
// Check if map exists
|
// Check if map exists
|
||||||
$mapInfo = $this->maniaControl->mapManager->mxManager->getMap($mapId);
|
$this->maniaControl->mapManager->mxManager->getMapInfo($mapId, function (MXMapInfo $mapInfo) use ($login) {
|
||||||
|
if (!$mapInfo || !isset($mapInfo->uploaded)) {
|
||||||
if (!$mapInfo || !isset($mapInfo->uploaded)) {
|
// Invalid id
|
||||||
// Invalid id
|
$this->maniaControl->chat->sendError('Invalid MX-Id!', $login);
|
||||||
$this->maniaControl->chat->sendError('Invalid MX-Id!', $login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$url = "http://{$title}.mania-exchange.com/tracks/download/{$mapId}";
|
|
||||||
|
|
||||||
//Download the file
|
|
||||||
$function = function ($file, $error) use (&$login, &$mapInfo, &$mapDir, &$update) {
|
|
||||||
if (!$file) {
|
|
||||||
// Download error
|
|
||||||
$this->maniaControl->chat->sendError('Download failed!', $login);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->processMapFile($file, $mapInfo, $mapDir, $login, $update);
|
|
||||||
};
|
$serverInfo = $this->maniaControl->server->getSystemInfo();
|
||||||
$this->maniaControl->fileReader->loadFile($url, $function);
|
$title = strtolower(substr($serverInfo->titleId, 0, 2));
|
||||||
|
|
||||||
|
$url = "http://{$title}.mania-exchange.com/tracks/download/{$mapInfo->id}";
|
||||||
|
|
||||||
|
//Download the file
|
||||||
|
$function = function ($file, $error) use (&$login, &$mapInfo, &$mapDir, &$update) {
|
||||||
|
if (!$file) {
|
||||||
|
// Download error
|
||||||
|
$this->maniaControl->chat->sendError('Download failed!', $login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->processMapFile($file, $mapInfo, $mapDir, $login, $update);
|
||||||
|
};
|
||||||
|
$this->maniaControl->fileReader->loadFile($url, $function);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -641,5 +639,4 @@ class MapManager implements CallbackListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: add local map by filename
|
// TODO: add local map by filename
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user