improved mxinfosearcher

This commit is contained in:
kremsy 2014-01-08 22:49:09 +01:00
parent 0d7f02a89a
commit 160d10b766
3 changed files with 44 additions and 50 deletions

View File

@ -26,7 +26,7 @@ abstract class FileUtil {
$fsock = fsockopen($urlData['host'], $port); $fsock = fsockopen($urlData['host'], $port);
stream_set_timeout($fsock, 3); 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 .= 'Host: ' . $urlData['host'] . PHP_EOL;
$query .= 'Content-Type: ' . $contentType . PHP_EOL; $query .= 'Content-Type: ' . $contentType . PHP_EOL;
$query .= 'User-Agent: ManiaControl v' . ManiaControl::VERSION . PHP_EOL; $query .= 'User-Agent: ManiaControl v' . ManiaControl::VERSION . PHP_EOL;

View File

@ -3,24 +3,35 @@ namespace ManiaControl\Maps;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
/**
* Mania Exchange Info Searcher Class
*
* @author steeffeen & kremsy
*/
class ManiaExchangeInfoSearcher { class ManiaExchangeInfoSearcher {
/** /**
* 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;
//TODO finish that list const SEARCH_ORDER_ACTIVITY_LATEST = 6;
/* const SEARCH_ORDER_ACTIVITY_OLDEST = 7;
* [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_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; private $maniaControl = null;
@ -33,7 +44,17 @@ class ManiaExchangeInfoSearcher {
$this->maniaControl = $maniaControl; $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 //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));
@ -47,22 +68,23 @@ 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 ($name != '')
$url .= '&trackname=' . $name;
if ($author != '')
$url .= '&author=' . $author;*/
if($env != '') { if($env != '') {
$url .= '&environments=' . $this->getEnvironment($env); $url .= '&environments=' . $this->getEnvironment($env);
} }
if($name != '') {
$url .= '&trackname=' . $name;
}
if($author != '') {
$url .= '&author=' . $author;
}
$url .= '&priord=' . $searchOrder; $url .= '&priord=' . $searchOrder;
$url .= '&limit=' . $maxMapsReturned; //TODO $url .= '&limit=' . $maxMapsReturned;
$url .= '&mtype=' . $mapTypeArray[0]; $url .= '&mtype=' . $mapTypeArray[0];
// $mapInfo = FileUtil::loadFile($url, "application/json"); //TODO use mp fileutil // $mapInfo = FileUtil::loadFile($url, "application/json"); //TODO use mp fileutil
$mapInfo = $this->get_file($url); $mapInfo = $this->get_file($url);
var_dump($url);
//TODO errors //TODO errors
/*if ($file === false) { /*if ($file === false) {
@ -173,7 +195,6 @@ class MXMapInfo {
} else { } else {
$this->id = $mx->MapID; $this->id = $mx->MapID;
} }
// $this->id = ($this->prefix == 'tm') ? $mx->TrackID : $mx->MapID;
$this->name = $mx->Name; $this->name = $mx->Name;
@ -230,8 +251,6 @@ class MXMapInfo {
} else { } else {
$this->replayurl = ''; $this->replayurl = '';
} }
//var_dump($this->pageurl);
} }
} // MXInfo } // MXInfo
} // class MXInfo } // class MXInfo

View File

@ -23,7 +23,6 @@ use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use MXInfoSearcher;
/** /**
* MapList Widget Class * MapList Widget Class
@ -78,29 +77,12 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$params = explode(' ', $chatCallback[1][2]); $params = explode(' ', $chatCallback[1][2]);
$titleId = $this->maniaControl->server->titleId;
$title = strtoupper(substr($titleId, 0, 2));
$searchString = ''; $searchString = '';
$author = ''; $author = '';
$environment = ''; $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) { if(count($params) >= 1) {
foreach($params as $param) { foreach($params as $param) {
if($param == '/xlist' || $param == MapCommands::ACTION_OPEN_XLIST) { 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; continue;
} }
if(strtolower(substr($param, 0, 5)) == 'auth:') { if(strtolower(substr($param, 0, 5)) == 'auth:') {
@ -113,23 +95,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
} else { // concatenate words in name } else { // concatenate words in name
$searchString .= '%20' . $param; $searchString .= '%20' . $param;
} }
var_dump("test");
} }
} }
$recent = false;
} }
// search for matching maps // search for matching maps
//$maps = new MXInfoSearcher($title, $searchString, $author, $environment, $recent); $maps = $this->maniaControl->mapManager->mxInfoSearcher->getMaps($searchString, $author, $environment, 15);
$maps = $this->maniaControl->mapManager->mxInfoSearcher->getMaps(15);
// check if there are any results // check if there are any results
if($maps == null) { if($maps == null) {
$this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login); $this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login);
if($maps->error != '') {
trigger_error($maps->error, E_USER_WARNING);
}
return; return;
} }
@ -156,7 +131,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$i = 0; $i = 0;
$y -= 10; $y -= 10;
foreach($maps as $map) { foreach($maps as $map) { //TODO pagers, search entry, click on nickname...
$mapFrame = new Frame(); $mapFrame = new Frame();
$frame->add($mapFrame); $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); $array = array($map->id => $x + 5, $map->name => $x + 17, $map->author => $x + 65, $map->mood => $x + 100, $map->maptype => $x + 115);