improved mxinfosearcher
This commit is contained in:
parent
0d7f02a89a
commit
160d10b766
@ -26,7 +26,7 @@ abstract class FileUtil {
|
||||
$fsock = fsockopen($urlData['host'], $port);
|
||||
stream_set_timeout($fsock, 3);
|
||||
|
||||
$query = 'GET ' . $urlData['path'] . ' HTTP/1.1' . PHP_EOL;
|
||||
$query = 'GET ' . $urlData['path'] . ' HTTP/1.0' . PHP_EOL;
|
||||
$query .= 'Host: ' . $urlData['host'] . PHP_EOL;
|
||||
$query .= 'Content-Type: ' . $contentType . PHP_EOL;
|
||||
$query .= 'User-Agent: ManiaControl v' . ManiaControl::VERSION . PHP_EOL;
|
||||
|
@ -3,6 +3,11 @@ namespace ManiaControl\Maps;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Mania Exchange Info Searcher Class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class ManiaExchangeInfoSearcher {
|
||||
/**
|
||||
* Constants
|
||||
@ -14,13 +19,19 @@ class ManiaExchangeInfoSearcher {
|
||||
const SEARCH_ORDER_UPLOADED_OLDEST = 3;
|
||||
const SEARCH_ORDER_UPDATED_NEWEST = 4;
|
||||
const SEARCH_ORDER_UPDATED_OLDEST = 5;
|
||||
//TODO finish that list
|
||||
/*
|
||||
* [19:16] <TGYoshi> 6 => "Activity (Latest) [19:16] <TGYoshi> 7 => "Activity (Oldest) [19:16] <TGYoshi> 8 => "Awards (Most) [19:16] <TGYoshi> 9 => "Awards (Least) [19:16] <TGYoshi> 10 => "Comments (Most) [19:16] <TGYoshi> 11 => "Comments (Least) [19:16] <TGYoshi> 12 => "Difficulty (Easiest) [19:16] <TGYoshi> 13 => "Difficulty (Hardest) [19:16] <TGYoshi> 14 => "Length (Shortest) [19:16] <TGYoshi> 15 => "Length (Longest)
|
||||
*/
|
||||
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;
|
||||
const SEARCH_ORDER_DIFFICULTY_EASIEST = 12;
|
||||
const SEARCH_ORDER_DIFFICULTY_HARDEST = 13;
|
||||
const SEARCH_ORDER_LENGHT_SHORTEST = 14;
|
||||
const SEARCH_ORDER_LENGHT_LONGEST = 15;
|
||||
|
||||
/**
|
||||
* Private Properties
|
||||
* Private Propertieswc
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
@ -33,7 +44,17 @@ class ManiaExchangeInfoSearcher {
|
||||
$this->maniaControl = $maniaControl;
|
||||
}
|
||||
|
||||
public function getMaps($maxMapsReturned = 100, $searchOrder = self::SEARCH_ORDER_UPLOADED_NEWEST, $env = '') {
|
||||
/**
|
||||
* Gets a Maplist from Mania Exchange
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $author
|
||||
* @param string $env
|
||||
* @param int $maxMapsReturned
|
||||
* @param int $searchOrder
|
||||
* @return array|null
|
||||
*/
|
||||
public function getMaps($name = '', $author = '', $env = '', $maxMapsReturned = 100, $searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) {
|
||||
//Get Title Id
|
||||
$titleId = $this->maniaControl->server->titleId;
|
||||
$titlePrefix = strtolower(substr($titleId, 0, 2));
|
||||
@ -47,22 +68,23 @@ class ManiaExchangeInfoSearcher {
|
||||
|
||||
// compile search URL
|
||||
$url = 'http://' . $titlePrefix . '.mania-exchange.com/tracksearch?api=on';
|
||||
/* if ($name != '')
|
||||
$url .= '&trackname=' . $name;
|
||||
if ($author != '')
|
||||
$url .= '&author=' . $author;*/
|
||||
|
||||
if($env != '') {
|
||||
$url .= '&environments=' . $this->getEnvironment($env);
|
||||
}
|
||||
if($name != '') {
|
||||
$url .= '&trackname=' . $name;
|
||||
}
|
||||
if($author != '') {
|
||||
$url .= '&author=' . $author;
|
||||
}
|
||||
|
||||
$url .= '&priord=' . $searchOrder;
|
||||
$url .= '&limit=' . $maxMapsReturned; //TODO
|
||||
$url .= '&limit=' . $maxMapsReturned;
|
||||
$url .= '&mtype=' . $mapTypeArray[0];
|
||||
|
||||
// $mapInfo = FileUtil::loadFile($url, "application/json"); //TODO use mp fileutil
|
||||
$mapInfo = $this->get_file($url);
|
||||
var_dump($url);
|
||||
|
||||
//TODO errors
|
||||
/*if ($file === false) {
|
||||
@ -173,7 +195,6 @@ class MXMapInfo {
|
||||
} else {
|
||||
$this->id = $mx->MapID;
|
||||
}
|
||||
// $this->id = ($this->prefix == 'tm') ? $mx->TrackID : $mx->MapID;
|
||||
|
||||
$this->name = $mx->Name;
|
||||
|
||||
@ -230,8 +251,6 @@ class MXMapInfo {
|
||||
} else {
|
||||
$this->replayurl = '';
|
||||
}
|
||||
|
||||
//var_dump($this->pageurl);
|
||||
}
|
||||
} // MXInfo
|
||||
} // class MXInfo
|
||||
|
@ -23,7 +23,6 @@ use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Players\Player;
|
||||
use MXInfoSearcher;
|
||||
|
||||
/**
|
||||
* MapList Widget Class
|
||||
@ -78,29 +77,12 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
|
||||
$params = explode(' ', $chatCallback[1][2]);
|
||||
|
||||
$titleId = $this->maniaControl->server->titleId;
|
||||
$title = strtoupper(substr($titleId, 0, 2));
|
||||
|
||||
$searchString = '';
|
||||
$author = '';
|
||||
$environment = '';
|
||||
// TODO also get actual environment
|
||||
$recent = false;
|
||||
|
||||
$this->maniaControl->client->query('GetModeScriptInfo');
|
||||
$scriptInfos = $this->maniaControl->client->getResponse();
|
||||
|
||||
//var_dump($scriptInfos);
|
||||
if(count($params) >= 1) {
|
||||
foreach($params as $param) {
|
||||
if($param == '/xlist' || $param == MapCommands::ACTION_OPEN_XLIST) {
|
||||
/* $mapTypes = str_replace($scriptInfos["CompatibleMapTypes"][0]);
|
||||
$mapTypeArray = explode($mapTypes, ",");
|
||||
$searchString = $mapTypeArray[0];
|
||||
var_dump($mapTypes);
|
||||
var_dump($mapTypeArray);
|
||||
//$searchString = str_replace($mapTypeArray[0], '',)
|
||||
var_dump($searchString);*/
|
||||
continue;
|
||||
}
|
||||
if(strtolower(substr($param, 0, 5)) == 'auth:') {
|
||||
@ -113,23 +95,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
} else { // concatenate words in name
|
||||
$searchString .= '%20' . $param;
|
||||
}
|
||||
var_dump("test");
|
||||
}
|
||||
}
|
||||
|
||||
$recent = false;
|
||||
}
|
||||
|
||||
// search for matching maps
|
||||
//$maps = new MXInfoSearcher($title, $searchString, $author, $environment, $recent);
|
||||
$maps = $this->maniaControl->mapManager->mxInfoSearcher->getMaps(15);
|
||||
$maps = $this->maniaControl->mapManager->mxInfoSearcher->getMaps($searchString, $author, $environment, 15);
|
||||
|
||||
// check if there are any results
|
||||
if($maps == null) {
|
||||
$this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login);
|
||||
if($maps->error != '') {
|
||||
trigger_error($maps->error, E_USER_WARNING);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -156,7 +131,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
|
||||
$i = 0;
|
||||
$y -= 10;
|
||||
foreach($maps as $map) {
|
||||
foreach($maps as $map) { //TODO pagers, search entry, click on nickname...
|
||||
$mapFrame = new Frame();
|
||||
$frame->add($mapFrame);
|
||||
$array = array($map->id => $x + 5, $map->name => $x + 17, $map->author => $x + 65, $map->mood => $x + 100, $map->maptype => $x + 115);
|
||||
|
Loading…
Reference in New Issue
Block a user