From 132fa4cf0199b8aa765eb96642faed1305772510 Mon Sep 17 00:00:00 2001 From: kremsy Date: Wed, 8 Jan 2014 21:03:59 +0100 Subject: [PATCH] started own mxinfosearcher --- application/core/ManiaControl.php | 1 + .../ManiaExchangeInfoSearcher.php | 112 ++++++++++++++++++ application/core/Maps/MapList.php | 2 + application/core/Maps/MapManager.php | 8 +- application/plugins/Donations.php | 1 - 5 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 application/core/ManiaExchange/ManiaExchangeInfoSearcher.php diff --git a/application/core/ManiaControl.php b/application/core/ManiaControl.php index 47167ba4..9c947bae 100644 --- a/application/core/ManiaControl.php +++ b/application/core/ManiaControl.php @@ -32,6 +32,7 @@ require_once __DIR__ . '/Formatter.php'; require_once __DIR__ . '/GbxDataFetcher/gbxdatafetcher.inc.php'; require_once __DIR__ . '/ManiaExchange/mxinfofetcher.inc.php'; require_once __DIR__ . '/ManiaExchange/mxinfosearcher.inc.php'; +require_once __DIR__ . '/ManiaExchange/ManiaExchangeInfoSearcher.php'; require_once __DIR__ . '/Manialinks/ManialinkManager.php'; require_once __DIR__ . '/Statistics/StatisticManager.php'; require_once __DIR__ . '/Maps/MapManager.php'; diff --git a/application/core/ManiaExchange/ManiaExchangeInfoSearcher.php b/application/core/ManiaExchange/ManiaExchangeInfoSearcher.php new file mode 100644 index 00000000..7e09c482 --- /dev/null +++ b/application/core/ManiaExchange/ManiaExchangeInfoSearcher.php @@ -0,0 +1,112 @@ + 6 => "Activity (Latest) [19:16] 7 => "Activity (Oldest) [19:16] 8 => "Awards (Most) [19:16] 9 => "Awards (Least) [19:16] 10 => "Comments (Most) [19:16] 11 => "Comments (Least) [19:16] 12 => "Difficulty (Easiest) [19:16] 13 => "Difficulty (Hardest) [19:16] 14 => "Length (Shortest) [19:16] 15 => "Length (Longest) + */ + + /** + * Private Properties + */ + private $maniaControl = null; + + /** + * Construct map manager + * + * @param \ManiaControl\ManiaControl $maniaControl + */ + public function __construct(ManiaControl $maniaControl) { + $this->maniaControl = $maniaControl; + } + + public function getList($maxMapsReturned = 100, $searchOrder = self::SEARCH_ORDER_UPLOADED_NEWEST, $env = '') { + //Get Title Id + $titleId = $this->maniaControl->server->titleId; + $title = strtoupper(substr($titleId, 0, 2)); + + //Get MapTypes + $this->maniaControl->client->query('GetModeScriptInfo'); + $scriptInfos = $this->maniaControl->client->getResponse(); + + $mapTypes = $scriptInfos["CompatibleMapTypes"]; + $mapTypeArray = explode(",", $mapTypes); + + var_dump($mapTypes); + var_dump($mapTypeArray); + + // compile search URL + $url = 'http://' . $title . '.mania-exchange.com/tracksearch?api=on'; + /* if ($name != '') + $url .= '&trackname=' . $name; + if ($author != '') + $url .= '&author=' . $author;*/ + + if($env != '') { + $url .= '&environments=' . $this->getEnvironment($env); + } + + $url .= '&priord=' . $searchOrder; + $url .= '&limit=' . $maxMapsReturned; + $url .= '&mtype=' . $mapTypeArray[0]; + + var_dump($url); + $mapInfo = FileUtil::loadFile($url, "application/json"); + + //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; + } + }*/ + + $mx = json_decode($mapInfo); + if($mx === null) { + $this->error = 'Cannot decode searched JSON data from ' . $url; + return array(); + } + + var_dump($mx); + + // return list of maps as array of MX objects + //return $maps; + + } + + private function getEnvironment($env) { + switch($env) { + case 'TMCanyon': + case 'SMStorm': + return 1; + case 'TMStadium': + return 2; + case 'TMValley': + return 3; + default: + return -1; + } + } +} \ No newline at end of file diff --git a/application/core/Maps/MapList.php b/application/core/Maps/MapList.php index 74eb2a12..6510be2e 100644 --- a/application/core/Maps/MapList.php +++ b/application/core/Maps/MapList.php @@ -120,6 +120,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { $recent = false; } + $this->maniaControl->mapManager->mxInfoSearcher->getList(''); + // search for matching maps $maps = new MXInfoSearcher($title, $searchString, $author, $environment, $recent); diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index 1d1e2673..ac08e78d 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -31,6 +31,7 @@ class MapManager implements CallbackListener { public $mapQueue = null; public $mapCommands = null; public $mapList = null; + public $mxInfoSearcher = null; /** * Private Properties @@ -50,9 +51,10 @@ class MapManager implements CallbackListener { $this->initTables(); // Create map commands instance - $this->mapList = new MapList($this->maniaControl); - $this->mapCommands = new MapCommands($maniaControl); - $this->mapQueue = new MapQueue($this->maniaControl); + $this->mapList = new MapList($this->maniaControl); + $this->mapCommands = new MapCommands($maniaControl); + $this->mapQueue = new MapQueue($this->maniaControl); + $this->mxInfoSearcher = new ManiaExchangeInfoSearcher($this->maniaControl); // Register for callbacks $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit'); diff --git a/application/plugins/Donations.php b/application/plugins/Donations.php index 6e2eeda1..1e0108c1 100644 --- a/application/plugins/Donations.php +++ b/application/plugins/Donations.php @@ -418,7 +418,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { $login = null; $message = '$<' . $player->nickname . '$> donated ' . $amount . ' Planets! Thanks.'; } else { - $message = 'Donation successful! Thanks.'; }