2014-01-08 21:03:59 +01:00
|
|
|
<?php
|
2014-01-09 22:08:34 +01:00
|
|
|
|
2014-01-28 15:56:50 +01:00
|
|
|
namespace ManiaControl\ManiaExchange;
|
2014-01-08 21:03:59 +01:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
use ManiaControl\Files\AsynchronousFileReader;
|
2014-01-08 21:03:59 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
2014-01-28 15:56:50 +01:00
|
|
|
use ManiaControl\Maps\Map;
|
|
|
|
use ManiaControl\Maps\MapManager;
|
2014-05-13 17:59:37 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
2014-01-08 21:03:59 +01:00
|
|
|
|
2014-01-08 22:49:09 +01:00
|
|
|
/**
|
|
|
|
* Mania Exchange Info Searcher Class
|
|
|
|
*
|
2014-05-02 17:50:30 +02:00
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
|
|
|
* @copyright 2014 ManiaControl Team
|
2014-04-29 21:06:38 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-01-08 22:49:09 +01:00
|
|
|
*/
|
2014-04-29 21:06:38 +02:00
|
|
|
class ManiaExchangeManager {
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-01-08 21:03:59 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
2014-01-14 15:15:13 +01:00
|
|
|
//Search others
|
2014-01-09 23:21:44 +01:00
|
|
|
const SEARCH_ORDER_NONE = -1;
|
|
|
|
const SEARCH_ORDER_TRACK_NAME = 0;
|
|
|
|
const SEARCH_ORDER_AUTHOR = 1;
|
|
|
|
const SEARCH_ORDER_UPLOADED_NEWEST = 2;
|
|
|
|
const SEARCH_ORDER_UPLOADED_OLDEST = 3;
|
|
|
|
const SEARCH_ORDER_UPDATED_NEWEST = 4;
|
|
|
|
const SEARCH_ORDER_UPDATED_OLDEST = 5;
|
|
|
|
const SEARCH_ORDER_ACTIVITY_LATEST = 6;
|
|
|
|
const SEARCH_ORDER_ACTIVITY_OLDEST = 7;
|
|
|
|
const SEARCH_ORDER_AWARDS_MOST = 8;
|
|
|
|
const SEARCH_ORDER_AWARDS_LEAST = 9;
|
|
|
|
const SEARCH_ORDER_COMMENTS_MOST = 10;
|
|
|
|
const SEARCH_ORDER_COMMENTS_LEAST = 11;
|
2014-01-08 22:49:09 +01:00
|
|
|
const SEARCH_ORDER_DIFFICULTY_EASIEST = 12;
|
|
|
|
const SEARCH_ORDER_DIFFICULTY_HARDEST = 13;
|
2014-05-18 16:26:52 +02:00
|
|
|
const SEARCH_ORDER_LENGTH_SHORTEST = 14;
|
|
|
|
const SEARCH_ORDER_LENGTH_LONGEST = 15;
|
2014-01-14 15:15:13 +01:00
|
|
|
|
|
|
|
//Maximum Maps per request
|
|
|
|
const MAPS_PER_MX_FETCH = 50;
|
2014-01-12 19:08:56 +01:00
|
|
|
|
2014-04-29 21:06:38 +02:00
|
|
|
const MIN_EXE_BUILD = "2014-04-01_00_00";
|
2014-03-27 18:40:13 +01:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-08-02 22:31:46 +02:00
|
|
|
* Private properties
|
2014-01-08 21:03:59 +01:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2014-01-08 21:03:59 +01:00
|
|
|
private $maniaControl = null;
|
2014-01-11 22:06:52 +01:00
|
|
|
private $mxIdUidVector = array();
|
2014-01-08 21:03:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct map manager
|
|
|
|
*
|
|
|
|
* @param \ManiaControl\ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
}
|
|
|
|
|
2014-01-15 20:40:14 +01:00
|
|
|
/**
|
|
|
|
* Unset Map by Mx Id
|
|
|
|
*
|
2014-05-13 16:40:05 +02:00
|
|
|
* @param int $mxId
|
2014-01-15 20:40:14 +01:00
|
|
|
*/
|
|
|
|
public function unsetMap($mxId) {
|
2014-03-13 18:25:29 +01:00
|
|
|
if (isset($this->mxIdUidVector[$mxId])) {
|
|
|
|
unset($this->mxIdUidVector[$mxId]);
|
|
|
|
}
|
2014-01-15 20:40:14 +01:00
|
|
|
}
|
2014-01-15 18:31:06 +01:00
|
|
|
|
2014-01-09 23:21:44 +01:00
|
|
|
/**
|
|
|
|
* Fetch Map Information from Mania Exchange
|
2014-01-15 20:40:14 +01:00
|
|
|
*
|
2014-05-27 22:32:54 +02:00
|
|
|
* @param mixed $maps
|
2014-01-09 23:21:44 +01:00
|
|
|
*/
|
2014-05-27 22:32:54 +02:00
|
|
|
public function fetchManiaExchangeMapInformation($maps = null) {
|
2014-06-14 19:45:32 +02:00
|
|
|
if ($maps) {
|
|
|
|
// Fetch Information for a single map
|
|
|
|
$maps = array($maps);
|
2014-01-15 20:40:14 +01:00
|
|
|
} else {
|
2014-06-14 19:45:32 +02:00
|
|
|
// Fetch Information for whole MapList
|
2014-08-03 01:34:18 +02:00
|
|
|
$maps = $this->maniaControl->getMapManager()->getMaps();
|
2014-01-15 18:31:06 +01:00
|
|
|
}
|
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
2014-01-09 23:21:44 +01:00
|
|
|
$mapIdString = '';
|
|
|
|
|
2014-01-09 22:08:34 +01:00
|
|
|
// Fetch mx ids
|
2014-01-09 23:21:44 +01:00
|
|
|
$fetchMapQuery = "SELECT `mxid`, `changed` FROM `" . MapManager::TABLE_MAPS . "`
|
2014-01-09 22:08:34 +01:00
|
|
|
WHERE `index` = ?;";
|
|
|
|
$fetchMapStatement = $mysqli->prepare($fetchMapQuery);
|
2014-01-28 15:56:50 +01:00
|
|
|
if ($mysqli->error) {
|
2014-01-09 22:08:34 +01:00
|
|
|
trigger_error($mysqli->error);
|
|
|
|
return;
|
2014-01-09 21:37:01 +01:00
|
|
|
}
|
2014-01-09 23:21:44 +01:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
$index = 0;
|
2014-05-02 17:50:30 +02:00
|
|
|
foreach ($maps as $map) {
|
2014-06-14 15:58:24 +02:00
|
|
|
if (!$map) {
|
|
|
|
// TODO: remove after resolving of error report about "non-object"
|
2014-08-03 01:34:18 +02:00
|
|
|
$this->maniaControl->getErrorHandler()->triggerDebugNotice('Non-Object-Map', $map, $maps);
|
2014-06-14 15:58:24 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-01-09 23:21:44 +01:00
|
|
|
/** @var Map $map */
|
|
|
|
$fetchMapStatement->bind_param('i', $map->index);
|
2014-01-09 22:08:34 +01:00
|
|
|
$fetchMapStatement->execute();
|
2014-01-28 15:56:50 +01:00
|
|
|
if ($fetchMapStatement->error) {
|
2014-01-09 22:08:34 +01:00
|
|
|
trigger_error($fetchMapStatement->error);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$fetchMapStatement->store_result();
|
2014-01-09 23:21:44 +01:00
|
|
|
$fetchMapStatement->bind_result($mxId, $changed);
|
2014-01-09 22:08:34 +01:00
|
|
|
$fetchMapStatement->fetch();
|
|
|
|
$fetchMapStatement->free_result();
|
2014-01-09 23:21:44 +01:00
|
|
|
|
|
|
|
//Set changed time into the map object
|
|
|
|
$map->lastUpdate = strtotime($changed);
|
|
|
|
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($mxId) {
|
2014-01-12 19:08:56 +01:00
|
|
|
$appendString = $mxId . ',';
|
2014-01-11 22:06:52 +01:00
|
|
|
//Set the mx id to the mxidmapvektor
|
|
|
|
$this->mxIdUidVector[$mxId] = $map->uid;
|
|
|
|
} else {
|
2014-01-12 19:08:56 +01:00
|
|
|
$appendString = $map->uid . ',';
|
2014-01-11 22:06:52 +01:00
|
|
|
}
|
2014-01-09 23:21:44 +01:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
$index++;
|
2014-01-09 23:21:44 +01:00
|
|
|
|
2014-01-12 19:08:56 +01:00
|
|
|
//If Max Maplimit is reached, or string gets too long send the request
|
2014-06-14 15:48:27 +02:00
|
|
|
if ($index % self::MAPS_PER_MX_FETCH === 0) {
|
2014-01-12 22:31:50 +01:00
|
|
|
$mapIdString = substr($mapIdString, 0, -1);
|
2014-06-17 23:56:31 +02:00
|
|
|
$this->fetchMaplistByMixedUidIdString($mapIdString);
|
2014-01-09 23:21:44 +01:00
|
|
|
$mapIdString = '';
|
|
|
|
}
|
2014-01-12 19:08:56 +01:00
|
|
|
|
|
|
|
$mapIdString .= $appendString;
|
2014-01-09 21:32:17 +01:00
|
|
|
}
|
2014-01-09 23:21:44 +01:00
|
|
|
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($mapIdString) {
|
2014-01-12 22:31:50 +01:00
|
|
|
$mapIdString = substr($mapIdString, 0, -1);
|
2014-06-17 23:56:31 +02:00
|
|
|
$this->fetchMaplistByMixedUidIdString($mapIdString);
|
2014-01-09 23:21:44 +01:00
|
|
|
}
|
|
|
|
|
2014-01-09 22:08:34 +01:00
|
|
|
$fetchMapStatement->close();
|
2014-01-09 23:21:44 +01:00
|
|
|
}
|
|
|
|
|
2014-01-14 15:15:13 +01:00
|
|
|
/**
|
2014-06-17 23:56:31 +02:00
|
|
|
* Fetch the whole Map List from MX via mixed Uid and Id Strings
|
2014-01-14 15:15:13 +01:00
|
|
|
*
|
2014-05-13 16:40:05 +02:00
|
|
|
* @param string $string
|
2014-01-14 15:15:13 +01:00
|
|
|
*/
|
2014-06-17 23:56:31 +02:00
|
|
|
public function fetchMaplistByMixedUidIdString($string) {
|
2014-03-12 13:07:02 +01:00
|
|
|
// Get Title Prefix
|
2014-08-03 01:34:18 +02:00
|
|
|
$titlePrefix = $this->maniaControl->getMapManager()->getCurrentMap()
|
2014-06-27 01:18:39 +02:00
|
|
|
->getGame();
|
2014-01-09 23:21:44 +01:00
|
|
|
|
|
|
|
// compile search URL
|
2014-06-17 23:56:31 +02:00
|
|
|
$url = "http://api.mania-exchange.com/{$titlePrefix}/maps/?ids={$string}";
|
2014-01-09 23:21:44 +01:00
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
$this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use ($titlePrefix, $url) {
|
2014-02-07 17:27:09 +01:00
|
|
|
if ($error) {
|
2014-05-27 22:19:47 +02:00
|
|
|
trigger_error("Error: '{$error}' for Url '{$url}'");
|
|
|
|
return;
|
2014-02-07 17:27:09 +01:00
|
|
|
}
|
2014-03-19 10:54:21 +01:00
|
|
|
if (!$mapInfo) {
|
2014-05-27 22:19:47 +02:00
|
|
|
return;
|
2014-02-15 16:33:48 +01:00
|
|
|
}
|
2014-04-29 21:06:38 +02:00
|
|
|
|
2014-02-07 17:27:09 +01:00
|
|
|
$mxMapList = json_decode($mapInfo);
|
|
|
|
if ($mxMapList === null) {
|
2014-05-27 22:19:47 +02:00
|
|
|
trigger_error("Can't decode searched JSON Data from Url '{$url}'");
|
|
|
|
return;
|
2014-02-07 17:27:09 +01:00
|
|
|
}
|
2014-01-09 23:21:44 +01:00
|
|
|
|
2014-02-07 17:27:09 +01:00
|
|
|
$maps = array();
|
2014-05-02 17:50:30 +02:00
|
|
|
foreach ($mxMapList as $map) {
|
2014-03-31 21:41:05 +02:00
|
|
|
if ($map) {
|
2014-02-13 21:14:56 +01:00
|
|
|
$mxMapObject = new MXMapInfo($titlePrefix, $map);
|
2014-03-31 21:41:05 +02:00
|
|
|
if ($mxMapObject) {
|
2014-02-13 21:14:56 +01:00
|
|
|
array_push($maps, $mxMapObject);
|
|
|
|
}
|
2014-02-07 12:30:53 +01:00
|
|
|
}
|
2014-02-07 17:27:09 +01:00
|
|
|
}
|
2014-02-07 12:30:53 +01:00
|
|
|
|
2014-06-17 23:56:31 +02:00
|
|
|
$this->updateMapObjectsWithManiaExchangeIds($maps);
|
2014-06-14 15:48:27 +02:00
|
|
|
}, AsynchronousFileReader::CONTENT_TYPE_JSON);
|
2014-02-07 14:05:10 +01:00
|
|
|
}
|
2014-02-07 13:12:53 +01:00
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
/**
|
2014-05-13 16:40:05 +02:00
|
|
|
* Store MX Map Info in the Database and the MX Info in the Map Object
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2014-05-13 16:40:05 +02:00
|
|
|
* @param array $mxMapInfos
|
2014-05-02 17:50:30 +02:00
|
|
|
*/
|
2014-05-13 16:40:05 +02:00
|
|
|
public function updateMapObjectsWithManiaExchangeIds(array $mxMapInfos) {
|
2014-08-03 01:34:18 +02:00
|
|
|
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
2014-05-02 17:50:30 +02:00
|
|
|
// Save map data
|
|
|
|
$saveMapQuery = "UPDATE `" . MapManager::TABLE_MAPS . "`
|
|
|
|
SET `mxid` = ?
|
|
|
|
WHERE `uid` = ?;";
|
|
|
|
$saveMapStatement = $mysqli->prepare($saveMapQuery);
|
|
|
|
if ($mysqli->error) {
|
|
|
|
trigger_error($mysqli->error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$saveMapStatement->bind_param('is', $mapMxId, $mapUId);
|
|
|
|
foreach ($mxMapInfos as $mxMapInfo) {
|
|
|
|
/** @var MXMapInfo $mxMapInfo */
|
|
|
|
$mapMxId = $mxMapInfo->id;
|
|
|
|
$mapUId = $mxMapInfo->uid;
|
|
|
|
$saveMapStatement->execute();
|
|
|
|
if ($saveMapStatement->error) {
|
|
|
|
trigger_error($saveMapStatement->error);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Take the uid out of the vector
|
|
|
|
if (isset($this->mxIdUidVector[$mxMapInfo->id])) {
|
|
|
|
$uid = $this->mxIdUidVector[$mxMapInfo->id];
|
|
|
|
} else {
|
|
|
|
$uid = $mxMapInfo->uid;
|
|
|
|
}
|
2014-08-03 01:34:18 +02:00
|
|
|
$map = $this->maniaControl->getMapManager()->getMapByUid($uid);
|
2014-05-02 17:50:30 +02:00
|
|
|
if ($map) {
|
|
|
|
// TODO: how does it come that $map can be empty here? we got an error report for that
|
|
|
|
/** @var Map $map */
|
|
|
|
$map->mx = $mxMapInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$saveMapStatement->close();
|
|
|
|
}
|
|
|
|
|
2014-06-17 23:56:31 +02:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* @see \ManiaControl\ManiaExchange\ManiaExchangeManager::fetchMaplistByMixedUidIdString()
|
|
|
|
*/
|
|
|
|
public function getMaplistByMixedUidIdString($string) {
|
|
|
|
$this->fetchMaplistByMixedUidIdString($string);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
/**
|
2014-06-14 19:08:07 +02:00
|
|
|
* Fetch Map Info asynchronously
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2014-06-14 15:48:27 +02:00
|
|
|
* @param int $mapId
|
2014-05-13 16:40:05 +02:00
|
|
|
* @param callable $function
|
2014-05-02 17:50:30 +02:00
|
|
|
*/
|
2014-06-14 19:08:07 +02:00
|
|
|
public function fetchMapInfo($mapId, callable $function) {
|
2014-05-02 17:50:30 +02:00
|
|
|
// Get Title Prefix
|
2014-08-03 01:34:18 +02:00
|
|
|
$titlePrefix = $this->maniaControl->getMapManager()->getCurrentMap()
|
2014-06-27 01:18:39 +02:00
|
|
|
->getGame();
|
2014-05-02 17:50:30 +02:00
|
|
|
|
|
|
|
// compile search URL
|
2014-06-14 15:48:27 +02:00
|
|
|
$url = 'http://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $mapId;
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
$this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix, $url) {
|
2014-05-02 17:50:30 +02:00
|
|
|
$mxMapInfo = null;
|
|
|
|
if ($error) {
|
|
|
|
trigger_error($error);
|
|
|
|
} else {
|
|
|
|
$mxMapList = json_decode($mapInfo);
|
2014-05-22 16:21:32 +02:00
|
|
|
if (!is_array($mxMapList)) {
|
2014-05-02 17:50:30 +02:00
|
|
|
trigger_error('Cannot decode searched JSON data from ' . $url);
|
2014-06-14 15:48:27 +02:00
|
|
|
} else if (!empty($mxMapList)) {
|
2014-05-02 17:50:30 +02:00
|
|
|
$mxMapInfo = new MXMapInfo($titlePrefix, $mxMapList[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
call_user_func($function, $mxMapInfo);
|
2014-06-14 15:48:27 +02:00
|
|
|
}, AsynchronousFileReader::CONTENT_TYPE_JSON);
|
2014-05-02 17:50:30 +02:00
|
|
|
}
|
|
|
|
|
2014-06-17 23:56:31 +02:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* @see \ManiaControl\ManiaExchange\ManiaExchangeManager::fetchMapsAsync()
|
|
|
|
*/
|
2014-06-27 01:18:39 +02:00
|
|
|
public function getMapsAsync(callable $function, $name = '', $author = '', $env = '', $maxMapsReturned = 100,
|
|
|
|
$searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) {
|
2014-06-17 23:56:31 +02:00
|
|
|
$this->fetchMapsAsync($function, $name, $author, $env, $maxMapsReturned, $searchOrder);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-08 22:49:09 +01:00
|
|
|
/**
|
2014-02-07 17:27:09 +01:00
|
|
|
* Fetch a MapList Asynchronously
|
2014-01-08 22:49:09 +01:00
|
|
|
*
|
2014-06-14 15:48:27 +02:00
|
|
|
* @param callable $function
|
|
|
|
* @param string $name
|
|
|
|
* @param string $author
|
|
|
|
* @param string $env
|
|
|
|
* @param int $maxMapsReturned
|
|
|
|
* @param int $searchOrder
|
2014-01-08 22:49:09 +01:00
|
|
|
*/
|
2014-06-27 01:18:39 +02:00
|
|
|
public function fetchMapsAsync(callable $function, $name = '', $author = '', $env = '', $maxMapsReturned = 100,
|
|
|
|
$searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) {
|
2014-06-14 14:32:29 +02:00
|
|
|
// TODO: remove $env because it's not really used?
|
|
|
|
|
2014-01-09 22:08:34 +01:00
|
|
|
// Get Title Id
|
2014-08-03 01:34:18 +02:00
|
|
|
$titleId = $this->maniaControl->getServer()->titleId;
|
|
|
|
$titlePrefix = $this->maniaControl->getMapManager()->getCurrentMap()
|
2014-06-27 01:18:39 +02:00
|
|
|
->getGame();
|
2014-01-09 23:21:44 +01:00
|
|
|
|
2014-01-08 21:03:59 +01:00
|
|
|
// compile search URL
|
2014-03-27 18:40:13 +01:00
|
|
|
$url = 'http://' . $titlePrefix . '.mania-exchange.com/tracksearch2/search?api=on';
|
2014-01-09 23:21:44 +01:00
|
|
|
|
2014-03-13 18:25:29 +01:00
|
|
|
$game = explode('@', $titleId);
|
2014-03-01 12:58:08 +01:00
|
|
|
$envNumber = $this->getEnvironment($game[0]);
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($env || $envNumber > -1) {
|
2014-03-01 12:58:08 +01:00
|
|
|
$url .= '&environments=' . $envNumber;
|
2014-01-08 21:03:59 +01:00
|
|
|
}
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($name) {
|
2014-01-09 23:58:47 +01:00
|
|
|
$url .= '&trackname=' . str_replace(" ", "%20", $name);
|
2014-01-08 22:49:09 +01:00
|
|
|
}
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($author) {
|
2014-01-08 22:49:09 +01:00
|
|
|
$url .= '&author=' . $author;
|
|
|
|
}
|
2014-01-09 23:21:44 +01:00
|
|
|
|
2014-01-08 21:03:59 +01:00
|
|
|
$url .= '&priord=' . $searchOrder;
|
2014-01-08 22:49:09 +01:00
|
|
|
$url .= '&limit=' . $maxMapsReturned;
|
2014-01-09 23:21:44 +01:00
|
|
|
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($titlePrefix !== "tm") {
|
2014-04-30 15:29:12 +02:00
|
|
|
$url .= '&minexebuild=' . self::MIN_EXE_BUILD;
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-02-13 00:26:18 +01:00
|
|
|
// Get MapTypes
|
|
|
|
try {
|
2014-08-03 01:34:18 +02:00
|
|
|
$scriptInfos = $this->maniaControl->getClient()->getModeScriptInfo();
|
2014-02-13 00:26:18 +01:00
|
|
|
$mapTypes = $scriptInfos->compatibleMapTypes;
|
|
|
|
$url .= '&mtype=' . $mapTypes;
|
2014-05-13 17:59:37 +02:00
|
|
|
} catch (GameModeException $e) {
|
2014-02-13 00:26:18 +01:00
|
|
|
}
|
2014-01-09 23:21:44 +01:00
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
$this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix) {
|
2014-02-07 17:27:09 +01:00
|
|
|
if ($error) {
|
|
|
|
trigger_error($error);
|
2014-05-27 22:25:55 +02:00
|
|
|
return;
|
2014-01-14 13:57:10 +01:00
|
|
|
}
|
2014-01-09 23:21:44 +01:00
|
|
|
|
2014-02-07 17:27:09 +01:00
|
|
|
$mxMapList = json_decode($mapInfo);
|
2014-03-27 18:40:13 +01:00
|
|
|
|
|
|
|
if (!isset($mxMapList->results)) {
|
|
|
|
trigger_error('Cannot decode searched JSON data');
|
2014-05-27 22:25:55 +02:00
|
|
|
return;
|
2014-03-27 18:40:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$mxMapList = $mxMapList->results;
|
|
|
|
|
2014-02-07 17:27:09 +01:00
|
|
|
if ($mxMapList === null) {
|
|
|
|
trigger_error('Cannot decode searched JSON data');
|
2014-05-27 22:25:55 +02:00
|
|
|
return;
|
2014-02-07 17:27:09 +01:00
|
|
|
}
|
2014-01-09 23:21:44 +01:00
|
|
|
|
2014-02-07 17:27:09 +01:00
|
|
|
$maps = array();
|
2014-05-02 17:50:30 +02:00
|
|
|
foreach ($mxMapList as $map) {
|
2014-02-07 17:27:09 +01:00
|
|
|
if (!empty($map)) {
|
|
|
|
array_push($maps, new MXMapInfo($titlePrefix, $map));
|
|
|
|
}
|
2014-01-08 21:52:42 +01:00
|
|
|
}
|
2014-02-07 17:27:09 +01:00
|
|
|
|
|
|
|
call_user_func($function, $maps);
|
2014-06-14 15:48:27 +02:00
|
|
|
}, AsynchronousFileReader::CONTENT_TYPE_JSON);
|
2014-01-08 21:03:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-14 15:15:13 +01:00
|
|
|
/**
|
2014-05-13 16:40:05 +02:00
|
|
|
* Get the Current Environment by String
|
2014-01-14 15:15:13 +01:00
|
|
|
*
|
2014-05-13 16:40:05 +02:00
|
|
|
* @param string $env
|
2014-01-14 15:15:13 +01:00
|
|
|
* @return int
|
|
|
|
*/
|
2014-01-08 21:03:59 +01:00
|
|
|
private function getEnvironment($env) {
|
2014-05-02 17:50:30 +02:00
|
|
|
switch ($env) {
|
2014-01-08 21:03:59 +01:00
|
|
|
case 'TMCanyon':
|
|
|
|
return 1;
|
|
|
|
case 'TMStadium':
|
|
|
|
return 2;
|
|
|
|
case 'TMValley':
|
|
|
|
return 3;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2014-06-14 15:58:24 +02:00
|
|
|
}
|