From dfb9debdd272c37561bc96c144217f1e2a106389 Mon Sep 17 00:00:00 2001 From: kremsy Date: Fri, 7 Feb 2014 14:05:10 +0100 Subject: [PATCH] some fixes --- .../core/Files/AsynchronousFileReader.php | 2 +- .../core/ManiaExchange/ManiaExchangeList.php | 46 ++++++++++--------- .../ManiaExchange/ManiaExchangeManager.php | 4 +- application/core/Maps/MapCommands.php | 2 +- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/application/core/Files/AsynchronousFileReader.php b/application/core/Files/AsynchronousFileReader.php index a72e7f75..6168c632 100644 --- a/application/core/Files/AsynchronousFileReader.php +++ b/application/core/Files/AsynchronousFileReader.php @@ -28,7 +28,7 @@ class AsynchronousFileReader implements TimerListener { public function appendData() { foreach($this->sockets as $key => &$socket) { /** @var SocketStructure $socket */ - $socket->streamBuffer .= fread($socket->socket, 512); + $socket->streamBuffer .= fread($socket->socket, 1024); $info = stream_get_meta_data($socket->socket); if (feof($socket->socket) || $info['timed_out']) { diff --git a/application/core/ManiaExchange/ManiaExchangeList.php b/application/core/ManiaExchange/ManiaExchangeList.php index bed09cb0..bcd9d0f8 100644 --- a/application/core/ManiaExchange/ManiaExchangeList.php +++ b/application/core/ManiaExchange/ManiaExchangeList.php @@ -58,29 +58,23 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener $this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); - $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SEARCH_MAPNAME, $this, 'showManiaExchangeList'); - $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SEARCH_AUTHOR, $this, 'showManiaExchangeList'); + $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SEARCH_MAPNAME, $this, 'showList'); + $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SEARCH_AUTHOR, $this, 'showList'); } - public function showList(array $chatCallback, Player $player) { - $this->showManiaExchangeList($chatCallback, $player); - } - /** - * Display the Mania Exchange List + * Shows the List * * @param array $chatCallback * @param Player $player */ - public function showManiaExchangeList(array $chatCallback, Player $player) { + public function showList(array $chatCallback, Player $player) { $this->mapListShown[$player->login] = true; - - $params = explode(' ', $chatCallback[1][2]); - - $searchString = ''; - $author = ''; - $environment = ''; + $params = explode(' ', $chatCallback[1][2]); + $searchString = ''; + $author = ''; + $environment = ''; if (count($params) >= 1) { foreach($params as $param) { if ($param == '/xlist' || $param == MapCommands::ACTION_OPEN_XLIST) { @@ -105,14 +99,22 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener } // search for matching maps - $maps = $this->maniaControl->mapManager->mxManager->getMaps($searchString, $author, $environment); - - // check if there are any results - if ($maps == null) { - $this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login); - return; - } + $this->maniaControl->mapManager->mxManager->getMapsAssync(function ($maps) use (&$player) { + if ($maps == null) { + $this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login); + return; + } + $this->showManiaExchangeList($maps, $player); + }, $searchString, $author, $environment); + } + /** + * Display the Mania Exchange List + * + * @param array $chatCallback + * @param Player $player + */ + private function showManiaExchangeList($maps, Player $player) { // Start offsets $width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth(); $height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight(); @@ -293,7 +295,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener switch($action) { case self::ACTION_GET_MAPS_FROM_AUTHOR: $callback[1][2] = 'auth:' . $actionArray[2]; - $this->showManiaExchangeList($callback, $player); + $this->showList($callback, $player); break; case self::ACTION_ADD_MAP: $this->maniaControl->mapManager->addMapFromMx($mapId, $player->login); diff --git a/application/core/ManiaExchange/ManiaExchangeManager.php b/application/core/ManiaExchange/ManiaExchangeManager.php index af4ce216..cba60f3d 100644 --- a/application/core/ManiaExchange/ManiaExchangeManager.php +++ b/application/core/ManiaExchange/ManiaExchangeManager.php @@ -251,7 +251,7 @@ class ManiaExchangeManager { return $success; } - /*public function getMapsAssync($function, $name = '', $author = '', $env = '', $maxMapsReturned = 100, $searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) { + public function getMapsAssync($function, $name = '', $author = '', $env = '', $maxMapsReturned = 100, $searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) { if (!is_callable($function)) { $this->maniaControl->log("Function is not callable"); return false; @@ -312,7 +312,7 @@ class ManiaExchangeManager { } return $success; - }*/ + } /** diff --git a/application/core/Maps/MapCommands.php b/application/core/Maps/MapCommands.php index 04635048..12eafeeb 100644 --- a/application/core/Maps/MapCommands.php +++ b/application/core/Maps/MapCommands.php @@ -238,6 +238,6 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb * @param Player $player */ public function command_xList(array $chatCallback, Player $player) { - $this->maniaControl->mapManager->mxList->showManiaExchangeList($chatCallback, $player); + $this->maniaControl->mapManager->mxList->showList($chatCallback, $player); } }