improvments mx communication
This commit is contained in:
parent
161ef44508
commit
fceb0aa9e0
@ -9,28 +9,28 @@ use ManiaControl\ManiaControl;
|
|||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author steeffeen & kremsy
|
||||||
*/
|
*/
|
||||||
class ManiaExchangeInfoSearcher {
|
class ManiaExchangeInfoSearcher { //TODO rename to ManiaExchangeManager
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const SEARCH_ORDER_NONE = -1;
|
const SEARCH_ORDER_NONE = -1;
|
||||||
const SEARCH_ORDER_TRACK_NAME = 0;
|
const SEARCH_ORDER_TRACK_NAME = 0;
|
||||||
const SEARCH_ORDER_AUTHOR = 1;
|
const SEARCH_ORDER_AUTHOR = 1;
|
||||||
const SEARCH_ORDER_UPLOADED_NEWEST = 2;
|
const SEARCH_ORDER_UPLOADED_NEWEST = 2;
|
||||||
const SEARCH_ORDER_UPLOADED_OLDEST = 3;
|
const SEARCH_ORDER_UPLOADED_OLDEST = 3;
|
||||||
const SEARCH_ORDER_UPDATED_NEWEST = 4;
|
const SEARCH_ORDER_UPDATED_NEWEST = 4;
|
||||||
const SEARCH_ORDER_UPDATED_OLDEST = 5;
|
const SEARCH_ORDER_UPDATED_OLDEST = 5;
|
||||||
const SEARCH_ORDER_ACTIVITY_LATEST = 6;
|
const SEARCH_ORDER_ACTIVITY_LATEST = 6;
|
||||||
const SEARCH_ORDER_ACTIVITY_OLDEST = 7;
|
const SEARCH_ORDER_ACTIVITY_OLDEST = 7;
|
||||||
const SEARCH_ORDER_AWARDS_MOST = 8;
|
const SEARCH_ORDER_AWARDS_MOST = 8;
|
||||||
const SEARCH_ORDER_AWARDS_LEAST = 9;
|
const SEARCH_ORDER_AWARDS_LEAST = 9;
|
||||||
const SEARCH_ORDER_COMMENTS_MOST = 10;
|
const SEARCH_ORDER_COMMENTS_MOST = 10;
|
||||||
const SEARCH_ORDER_COMMENTS_LEAST = 11;
|
const SEARCH_ORDER_COMMENTS_LEAST = 11;
|
||||||
const SEARCH_ORDER_DIFFICULTY_EASIEST = 12;
|
const SEARCH_ORDER_DIFFICULTY_EASIEST = 12;
|
||||||
const SEARCH_ORDER_DIFFICULTY_HARDEST = 13;
|
const SEARCH_ORDER_DIFFICULTY_HARDEST = 13;
|
||||||
const SEARCH_ORDER_LENGHT_SHORTEST = 14;
|
const SEARCH_ORDER_LENGHT_SHORTEST = 14;
|
||||||
const SEARCH_ORDER_LENGHT_LONGEST = 15;
|
const SEARCH_ORDER_LENGHT_LONGEST = 15;
|
||||||
|
const MAPS_PER_MX_FETCH = 10;
|
||||||
/**
|
/**
|
||||||
* Private Propertieswc
|
* Private Propertieswc
|
||||||
*/
|
*/
|
||||||
@ -45,68 +45,127 @@ class ManiaExchangeInfoSearcher {
|
|||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateMapObjectWithManiaExchangeIds() {
|
|
||||||
$maps = $this->maniaControl->mapManager->getMaps();
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
|
||||||
$mapIds = array();
|
|
||||||
|
|
||||||
// Fetch mx ids
|
/**
|
||||||
$fetchMapQuery = "SELECT `mxid` FROM `" . MapManager::TABLE_MAPS . "`
|
* Store Map Info from MX and store the mxid in the database and the mx info in the map object
|
||||||
|
*
|
||||||
|
* @param $mxMapInfos
|
||||||
|
*/
|
||||||
|
private function updateMapObjectWithManiaExchangeIds($mxMapInfos) {
|
||||||
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
// Save map data
|
||||||
|
$saveMapQuery = "UPDATE `" . MapManager::TABLE_MAPS . "`
|
||||||
|
SET `mxid` = ?
|
||||||
WHERE `index` = ?;";
|
WHERE `index` = ?;";
|
||||||
$fetchMapStatement = $mysqli->prepare($fetchMapQuery);
|
$saveMapStatement = $mysqli->prepare($saveMapQuery);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$fetchMapStatement->bind_param('i', $mapIndex);
|
foreach($mxMapInfos as $mxMapInfo) {
|
||||||
foreach ($maps as $map) {
|
/** @var MXMapInfo $mxMapInfo */
|
||||||
/**
|
$saveMapStatement->bind_param('is', $mxMapInfo->id, $mxMapInfo->uid);
|
||||||
*
|
$saveMapStatement->execute();
|
||||||
* @var Map $map
|
if($saveMapStatement->error) {
|
||||||
*/
|
trigger_error($saveMapStatement->error);
|
||||||
$mapIndex = $map->index;
|
}
|
||||||
|
$map = $this->maniaControl->mapManager->getMapByUid($mxMapInfo->uid);
|
||||||
|
/** @var Map $map */
|
||||||
|
$map->mx = $mxMapInfo;
|
||||||
|
}
|
||||||
|
$saveMapStatement->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch Map Information from Mania Exchange
|
||||||
|
*/
|
||||||
|
public function fetchManiaExchangeMapInformations() {
|
||||||
|
$maps = $this->maniaControl->mapManager->getMaps();
|
||||||
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
$mapIdString = '';
|
||||||
|
|
||||||
|
// Fetch mx ids
|
||||||
|
$fetchMapQuery = "SELECT `mxid`, `changed` FROM `" . MapManager::TABLE_MAPS . "`
|
||||||
|
WHERE `index` = ?;";
|
||||||
|
$fetchMapStatement = $mysqli->prepare($fetchMapQuery);
|
||||||
|
if($mysqli->error) {
|
||||||
|
trigger_error($mysqli->error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = 0;
|
||||||
|
foreach($maps as $map) {
|
||||||
|
/** @var Map $map */
|
||||||
|
$fetchMapStatement->bind_param('i', $map->index);
|
||||||
$fetchMapStatement->execute();
|
$fetchMapStatement->execute();
|
||||||
if ($fetchMapStatement->error) {
|
if($fetchMapStatement->error) {
|
||||||
trigger_error($fetchMapStatement->error);
|
trigger_error($fetchMapStatement->error);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$fetchMapStatement->store_result();
|
$fetchMapStatement->store_result();
|
||||||
$fetchMapStatement->bind_result($mxId);
|
$fetchMapStatement->bind_result($mxId, $changed);
|
||||||
$fetchMapStatement->fetch();
|
$fetchMapStatement->fetch();
|
||||||
$fetchMapStatement->free_result();
|
$fetchMapStatement->free_result();
|
||||||
|
|
||||||
// FIXME: save ids like that?
|
//Set changed time into the map object
|
||||||
$mapIds[$map->index] = $mxId;
|
$map->lastUpdate = strtotime($changed);
|
||||||
}
|
|
||||||
$fetchMapStatement->close();
|
|
||||||
|
|
||||||
// Fetch mx data
|
//if($mxId != null) { //TODO not working due a fail on mx
|
||||||
// TODO: fetch mx info
|
// $mapIdString .= $mxId . ',';
|
||||||
|
//} else {
|
||||||
|
$mapIdString .= $map->uid . ',';
|
||||||
|
//}
|
||||||
|
|
||||||
// Save map data
|
$id++;
|
||||||
$saveMapQuery = "UPDATE `" . MapManager::TABLE_MAPS . "`
|
|
||||||
SET `mxid` = ?
|
//if($id % self::MAPS_PER_MX_FETCH == 0) {
|
||||||
WHERE `index` = ?;";
|
if($id % 6 == 0) { //TODO 6 is temporary
|
||||||
$saveMapStatement = $mysqli->prepare($saveMapQuery);
|
$maps = $this->getMaplistByMixedUidIdString($mapIdString);
|
||||||
if ($mysqli->error) {
|
$this->updateMapObjectWithManiaExchangeIds($maps);
|
||||||
trigger_error($mysqli->error);
|
$mapIdString = '';
|
||||||
return;
|
|
||||||
}
|
|
||||||
$saveMapStatement->bind_param('ii', $mxId, $mapIndex);
|
|
||||||
foreach ($maps as $map) {
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @var Map $map
|
|
||||||
*/
|
|
||||||
// FIXME: set $mxId
|
|
||||||
$mxId = 1337;
|
|
||||||
$mapIndex = $map->index;
|
|
||||||
$saveMapStatement->execute();
|
|
||||||
if ($saveMapStatement->error) {
|
|
||||||
trigger_error($saveMapStatement->error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$saveMapStatement->close();
|
|
||||||
|
if($mapIdString != '') {
|
||||||
|
$maps = $this->getMaplistByMixedUidIdString($mapIdString);
|
||||||
|
$this->updateMapObjectWithManiaExchangeIds($maps);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fetchMapStatement->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getMaplistByMixedUidIdString($string) {
|
||||||
|
// 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/' . $string;
|
||||||
|
|
||||||
|
// $mapInfo = FileUtil::loadFile($url, "application/json"); //TODO use mc fileutil
|
||||||
|
$mapInfo = $this->get_file($url);
|
||||||
|
|
||||||
|
// TODO errors
|
||||||
|
/*
|
||||||
|
* if ($file === false) { $this->error = 'Connection or response error on ' . $url; return array(); } elseif ($file === -1) { $this->error =
|
||||||
|
* 'Timed out while reading data from ' . $url; return array(); } elseif ($file == '') { if (empty($maps)) { $this->error = 'No data returned
|
||||||
|
* from ' . $url; return array(); } else { break; } }
|
||||||
|
*/
|
||||||
|
|
||||||
|
$mxMapList = json_decode($mapInfo);
|
||||||
|
if($mxMapList === null) {
|
||||||
|
trigger_error('Cannot decode searched JSON data from ' . $url);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$maps = array();
|
||||||
|
foreach($mxMapList as $map) {
|
||||||
|
if(!empty($map)) {
|
||||||
|
array_push($maps, new MXMapInfo($titlePrefix, $map));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $maps;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,13 +174,13 @@ class ManiaExchangeInfoSearcher {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $author
|
* @param string $author
|
||||||
* @param string $env
|
* @param string $env
|
||||||
* @param int $maxMapsReturned
|
* @param int $maxMapsReturned
|
||||||
* @param int $searchOrder
|
* @param int $searchOrder
|
||||||
* @return array null
|
* @return array null
|
||||||
*/
|
*/
|
||||||
public function getMaps($name = '', $author = '', $env = '', $maxMapsReturned = 100, $searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) {
|
public function getMaps($name = '', $author = '', $env = '', $maxMapsReturned = 100, $searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) {
|
||||||
// Get Title Id
|
// Get Title Id
|
||||||
$titleId = $this->maniaControl->server->titleId;
|
$titleId = $this->maniaControl->server->titleId;
|
||||||
$titlePrefix = strtolower(substr($titleId, 0, 2));
|
$titlePrefix = strtolower(substr($titleId, 0, 2));
|
||||||
|
|
||||||
// Get MapTypes
|
// Get MapTypes
|
||||||
@ -133,13 +192,13 @@ class ManiaExchangeInfoSearcher {
|
|||||||
// compile search URL
|
// compile search URL
|
||||||
$url = 'http://' . $titlePrefix . '.mania-exchange.com/tracksearch?api=on';
|
$url = 'http://' . $titlePrefix . '.mania-exchange.com/tracksearch?api=on';
|
||||||
|
|
||||||
if ($env != '') {
|
if($env != '') {
|
||||||
$url .= '&environments=' . $this->getEnvironment($env);
|
$url .= '&environments=' . $this->getEnvironment($env);
|
||||||
}
|
}
|
||||||
if ($name != '') {
|
if($name != '') {
|
||||||
$url .= '&trackname=' . $name;
|
$url .= '&trackname=' . $name;
|
||||||
}
|
}
|
||||||
if ($author != '') {
|
if($author != '') {
|
||||||
$url .= '&author=' . $author;
|
$url .= '&author=' . $author;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,14 +217,14 @@ class ManiaExchangeInfoSearcher {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$mxMapList = json_decode($mapInfo);
|
$mxMapList = json_decode($mapInfo);
|
||||||
if ($mxMapList === null) {
|
if($mxMapList === null) {
|
||||||
trigger_error('Cannot decode searched JSON data from ' . $url);
|
trigger_error('Cannot decode searched JSON data from ' . $url);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$maps = array();
|
$maps = array();
|
||||||
foreach ($mxMapList as $map) {
|
foreach($mxMapList as $map) {
|
||||||
if (!empty($map)) {
|
if(!empty($map)) {
|
||||||
array_push($maps, new MXMapInfo($titlePrefix, $map));
|
array_push($maps, new MXMapInfo($titlePrefix, $map));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,32 +232,29 @@ class ManiaExchangeInfoSearcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function get_file($url) {
|
private function get_file($url) {
|
||||||
$url = parse_url($url);
|
$url = parse_url($url);
|
||||||
$port = isset($url['port']) ? $url['port'] : 80;
|
$port = isset($url['port']) ? $url['port'] : 80;
|
||||||
$query = isset($url['query']) ? "?" . $url['query'] : "";
|
$query = isset($url['query']) ? "?" . $url['query'] : "";
|
||||||
|
|
||||||
$fp = @fsockopen($url['host'], $port, $errno, $errstr, 4);
|
$fp = @fsockopen($url['host'], $port, $errno, $errstr, 4);
|
||||||
if (!$fp) {
|
if(!$fp) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fwrite($fp,
|
fwrite($fp, 'GET ' . $url['path'] . $query . " HTTP/1.0\r\n" . 'Host: ' . $url['host'] . "\r\n" . 'Content-Type: application/json' . "\r\n" . 'User-Agent: ManiaControl v' . ManiaControl::VERSION . "\r\n\r\n");
|
||||||
'GET ' . $url['path'] . $query . " HTTP/1.0\r\n" . 'Host: ' . $url['host'] . "\r\n" . 'Content-Type: application/json' . "\r\n" .
|
|
||||||
'User-Agent: ManiaControl v' . ManiaControl::VERSION . "\r\n\r\n");
|
|
||||||
stream_set_timeout($fp, 2);
|
stream_set_timeout($fp, 2);
|
||||||
$res = '';
|
$res = '';
|
||||||
$info['timed_out'] = false;
|
$info['timed_out'] = false;
|
||||||
while (!feof($fp) && !$info['timed_out']) {
|
while(!feof($fp) && !$info['timed_out']) {
|
||||||
$res .= fread($fp, 512);
|
$res .= fread($fp, 512);
|
||||||
$info = stream_get_meta_data($fp);
|
$info = stream_get_meta_data($fp);
|
||||||
}
|
}
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
|
||||||
if ($info['timed_out']) {
|
if($info['timed_out']) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else {
|
||||||
else {
|
if(substr($res, 9, 3) != '200') {
|
||||||
if (substr($res, 9, 3) != '200') {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$page = explode("\r\n\r\n", $res, 2);
|
$page = explode("\r\n\r\n", $res, 2);
|
||||||
@ -206,7 +262,7 @@ class ManiaExchangeInfoSearcher {
|
|||||||
}
|
}
|
||||||
} // get_file
|
} // get_file
|
||||||
private function getEnvironment($env) {
|
private function getEnvironment($env) {
|
||||||
switch ($env) {
|
switch($env) {
|
||||||
case 'TMCanyon':
|
case 'TMCanyon':
|
||||||
case 'SMStorm':
|
case 'SMStorm':
|
||||||
return 1;
|
return 1;
|
||||||
@ -220,94 +276,95 @@ class ManiaExchangeInfoSearcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO put in own file
|
||||||
class MXMapInfo {
|
class MXMapInfo {
|
||||||
public $prefix, $id, $name, $userid, $author, $uploaded, $updated, $type, $maptype, $titlepack, $style, $envir, $mood, $dispcost, $lightmap, $modname, $exever, $exebld, $routes, $length, $unlimiter, $laps, $diffic, $lbrating, $trkvalue, $replaytyp, $replayid, $replaycnt, $acomment, $awards, $comments, $rating, $ratingex, $ratingcnt, $pageurl, $replayurl, $imageurl, $thumburl, $dloadurl;
|
public $prefix, $id, $uid, $name, $userid, $author, $uploaded, $updated, $type, $maptype;
|
||||||
|
public $titlepack, $style, $envir, $mood, $dispcost, $lightmap, $modname, $exever;
|
||||||
|
public $exebld, $routes, $length, $unlimiter, $laps, $diffic, $lbrating, $trkvalue;
|
||||||
|
public $replaytyp, $replayid, $replaycnt, $acomment, $awards, $comments, $rating;
|
||||||
|
public $ratingex, $ratingcnt, $pageurl, $replayurl, $imageurl, $thumburl, $dloadurl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns map object with all available data from MX map data
|
* Returns map object with all available data from MX map data
|
||||||
*
|
*
|
||||||
* @param String $prefix MX URL prefix
|
* @param String $prefix MX URL prefix
|
||||||
* @param Object $map The MX map data from MXInfoSearcher
|
* @param Object $map The MX map data from MXInfoSearcher
|
||||||
* @return MXMapInfo
|
* @return MXMapInfo
|
||||||
*/
|
*/
|
||||||
public function __construct($prefix, $mx) {
|
public function __construct($prefix, $mx) {
|
||||||
$this->prefix = $prefix;
|
$this->prefix = $prefix;
|
||||||
if ($mx) {
|
if($mx) {
|
||||||
if ($this->prefix == 'tm') {
|
if($this->prefix == 'tm') {
|
||||||
$dir = 'tracks';
|
$dir = 'tracks';
|
||||||
}
|
} else // 'sm' || 'qm'
|
||||||
else // 'sm' || 'qm'
|
|
||||||
{
|
{
|
||||||
$dir = 'maps';
|
$dir = 'maps';
|
||||||
}
|
}
|
||||||
|
|
||||||
// temporary fix
|
if($this->prefix == 'tm' || !property_exists($mx, "MapID")) {
|
||||||
if ($this->prefix == 'tm' || !property_exists($mx, "MapID")) {
|
|
||||||
$this->id = $mx->TrackID;
|
$this->id = $mx->TrackID;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$this->id = $mx->MapID;
|
$this->id = $mx->MapID;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->name = $mx->Name;
|
$this->name = $mx->Name;
|
||||||
|
|
||||||
$this->userid = $mx->UserID;
|
$this->uid = isset($mx->MapUID) ? $mx->MapUID : '';
|
||||||
$this->author = $mx->Username;
|
$this->userid = $mx->UserID;
|
||||||
$this->uploaded = $mx->UploadedAt;
|
$this->author = $mx->Username;
|
||||||
$this->updated = $mx->UpdatedAt;
|
$this->uploaded = $mx->UploadedAt;
|
||||||
$this->type = $mx->TypeName;
|
$this->updated = $mx->UpdatedAt;
|
||||||
$this->maptype = isset($mx->MapType) ? $mx->MapType : '';
|
$this->type = $mx->TypeName;
|
||||||
|
$this->maptype = isset($mx->MapType) ? $mx->MapType : '';
|
||||||
$this->titlepack = isset($mx->TitlePack) ? $mx->TitlePack : '';
|
$this->titlepack = isset($mx->TitlePack) ? $mx->TitlePack : '';
|
||||||
$this->style = isset($mx->StyleName) ? $mx->StyleName : '';
|
$this->style = isset($mx->StyleName) ? $mx->StyleName : '';
|
||||||
$this->envir = $mx->EnvironmentName;
|
$this->envir = $mx->EnvironmentName;
|
||||||
$this->mood = $mx->Mood;
|
$this->mood = $mx->Mood;
|
||||||
$this->dispcost = $mx->DisplayCost;
|
$this->dispcost = $mx->DisplayCost;
|
||||||
$this->lightmap = $mx->Lightmap;
|
$this->lightmap = $mx->Lightmap;
|
||||||
$this->modname = isset($mx->ModName) ? $mx->ModName : '';
|
$this->modname = isset($mx->ModName) ? $mx->ModName : '';
|
||||||
$this->exever = $mx->ExeVersion;
|
$this->exever = $mx->ExeVersion;
|
||||||
$this->exebld = $mx->ExeBuild;
|
$this->exebld = $mx->ExeBuild;
|
||||||
$this->routes = isset($mx->RouteName) ? $mx->RouteName : '';
|
$this->routes = isset($mx->RouteName) ? $mx->RouteName : '';
|
||||||
$this->length = isset($mx->LengthName) ? $mx->LengthName : '';
|
$this->length = isset($mx->LengthName) ? $mx->LengthName : '';
|
||||||
$this->unlimiter = isset($mx->UnlimiterRequired) ? $mx->UnlimiterRequired : false;
|
$this->unlimiter = isset($mx->UnlimiterRequired) ? $mx->UnlimiterRequired : false;
|
||||||
$this->laps = isset($mx->Laps) ? $mx->Laps : 0;
|
$this->laps = isset($mx->Laps) ? $mx->Laps : 0;
|
||||||
$this->diffic = $mx->DifficultyName;
|
$this->diffic = $mx->DifficultyName;
|
||||||
$this->lbrating = isset($mx->LBRating) ? $mx->LBRating : 0;
|
$this->lbrating = isset($mx->LBRating) ? $mx->LBRating : 0;
|
||||||
$this->trkvalue = isset($mx->TrackValue) ? $mx->TrackValue : 0;
|
$this->trkvalue = isset($mx->TrackValue) ? $mx->TrackValue : 0;
|
||||||
$this->replaytyp = isset($mx->ReplayTypeName) ? $mx->ReplayTypeName : '';
|
$this->replaytyp = isset($mx->ReplayTypeName) ? $mx->ReplayTypeName : '';
|
||||||
$this->replayid = isset($mx->ReplayWRID) ? $mx->ReplayWRID : 0;
|
$this->replayid = isset($mx->ReplayWRID) ? $mx->ReplayWRID : 0;
|
||||||
$this->replaycnt = isset($mx->ReplayCount) ? $mx->ReplayCount : 0;
|
$this->replaycnt = isset($mx->ReplayCount) ? $mx->ReplayCount : 0;
|
||||||
$this->acomment = $mx->Comments;
|
$this->acomment = $mx->Comments;
|
||||||
$this->awards = isset($mx->AwardCount) ? $mx->AwardCount : 0;
|
$this->awards = isset($mx->AwardCount) ? $mx->AwardCount : 0;
|
||||||
$this->comments = $mx->CommentCount;
|
$this->comments = $mx->CommentCount;
|
||||||
$this->rating = isset($mx->Rating) ? $mx->Rating : 0.0;
|
$this->rating = isset($mx->Rating) ? $mx->Rating : 0.0;
|
||||||
$this->ratingex = isset($mx->RatingExact) ? $mx->RatingExact : 0.0;
|
$this->ratingex = isset($mx->RatingExact) ? $mx->RatingExact : 0.0;
|
||||||
$this->ratingcnt = isset($mx->RatingCount) ? $mx->RatingCount : 0;
|
$this->ratingcnt = isset($mx->RatingCount) ? $mx->RatingCount : 0;
|
||||||
|
|
||||||
if ($this->trkvalue == 0 && $this->lbrating > 0) {
|
if($this->trkvalue == 0 && $this->lbrating > 0) {
|
||||||
$this->trkvalue = $this->lbrating;
|
$this->trkvalue = $this->lbrating;
|
||||||
}
|
} elseif($this->lbrating == 0 && $this->trkvalue > 0) {
|
||||||
elseif ($this->lbrating == 0 && $this->trkvalue > 0) {
|
|
||||||
$this->lbrating = $this->trkvalue;
|
$this->lbrating = $this->trkvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$search = array(chr(31), '[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[url]', '[/url]');
|
$search = array(chr(31), '[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[url]', '[/url]');
|
||||||
$replace = array('<br/>', '<b>', '</b>', '<i>', '</i>', '<u>', '</u>', '<i>', '</i>');
|
$replace = array('<br/>', '<b>', '</b>', '<i>', '</i>', '<u>', '</u>', '<i>', '</i>');
|
||||||
$this->acomment = str_ireplace($search, $replace, $this->acomment);
|
$this->acomment = str_ireplace($search, $replace, $this->acomment);
|
||||||
$this->acomment = preg_replace('/\[url=.*\]/', '<i>', $this->acomment);
|
$this->acomment = preg_replace('/\[url=.*\]/', '<i>', $this->acomment);
|
||||||
|
|
||||||
$this->pageurl = 'http://' . $this->prefix . '.mania-exchange.com/' . $dir . '/view/' . $this->id;
|
$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->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->thumburl = 'http://' . $this->prefix . '.mania-exchange.com/' . $dir . '/screenshot/small/' . $this->id;
|
||||||
$this->dloadurl = 'http://' . $this->prefix . '.mania-exchange.com/' . $dir . '/download/' . $this->id;
|
$this->dloadurl = 'http://' . $this->prefix . '.mania-exchange.com/' . $dir . '/download/' . $this->id;
|
||||||
|
|
||||||
if ($this->prefix == 'tm' && $this->replayid > 0) {
|
if($this->prefix == 'tm' && $this->replayid > 0) {
|
||||||
$this->replayurl = 'http://' . $this->prefix . '.mania-exchange.com/replays/download/' . $this->replayid;
|
$this->replayurl = 'http://' . $this->prefix . '.mania-exchange.com/replays/download/' . $this->replayid;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$this->replayurl = '';
|
$this->replayurl = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // MXInfo
|
} // MXMapInfo
|
||||||
} // class MXInfo
|
} // class MXMapInfo
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ class Map {
|
|||||||
public $mapType = '';
|
public $mapType = '';
|
||||||
public $mapStyle = '';
|
public $mapStyle = '';
|
||||||
public $nbCheckpoints = -1;
|
public $nbCheckpoints = -1;
|
||||||
|
/** @var MXMapInfo $mx */
|
||||||
public $mx = null;
|
public $mx = null;
|
||||||
public $authorLogin = '';
|
public $authorLogin = '';
|
||||||
public $authorNick = '';
|
public $authorNick = '';
|
||||||
@ -32,6 +33,7 @@ class Map {
|
|||||||
public $comment = '';
|
public $comment = '';
|
||||||
public $titleUid = '';
|
public $titleUid = '';
|
||||||
public $startTime = -1;
|
public $startTime = -1;
|
||||||
|
public $lastUpdate = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private Properties
|
* Private Properties
|
||||||
@ -60,6 +62,7 @@ class Map {
|
|||||||
$this->copperPrice = $rpc_infos['CopperPrice'];
|
$this->copperPrice = $rpc_infos['CopperPrice'];
|
||||||
$this->mapType = $rpc_infos['MapType'];
|
$this->mapType = $rpc_infos['MapType'];
|
||||||
$this->mapStyle = $rpc_infos['MapStyle'];
|
$this->mapStyle = $rpc_infos['MapStyle'];
|
||||||
|
|
||||||
if(isset($rpc_infos['NbCheckpoints'])) {
|
if(isset($rpc_infos['NbCheckpoints'])) {
|
||||||
$this->nbCheckpoints = $rpc_infos['NbCheckpoints'];
|
$this->nbCheckpoints = $rpc_infos['NbCheckpoints'];
|
||||||
}
|
}
|
||||||
@ -79,10 +82,18 @@ class Map {
|
|||||||
trigger_error($e->getMessage());
|
trigger_error($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: define timeout if mx is down,todo fetch all map infos at once (maybe way faster)
|
/**
|
||||||
$serverInfo = $this->maniaControl->server->titleId;
|
* Checks if a map Update is available
|
||||||
$title = strtoupper(substr($serverInfo, 0, 2));
|
*
|
||||||
$this->mx = new \MXInfoFetcher($title, $this->uid, false);
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function updateAvailable() {
|
||||||
|
if($this->lastUpdate < $this->mx->updated || $this->uid != $this->mx->uid) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -213,6 +213,7 @@ class MapManager implements CallbackListener {
|
|||||||
public function handleOnInit(array $callback) {
|
public function handleOnInit(array $callback) {
|
||||||
$this->updateFullMapList();
|
$this->updateFullMapList();
|
||||||
$this->fetchCurrentMap();
|
$this->fetchCurrentMap();
|
||||||
|
$this->mxInfoSearcher->fetchManiaExchangeMapInformations();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user