some fixes

This commit is contained in:
kremsy 2014-02-07 14:05:10 +01:00 committed by Steffen Schröder
parent f40b60e065
commit dfb9debdd2
4 changed files with 28 additions and 26 deletions

View File

@ -28,7 +28,7 @@ class AsynchronousFileReader implements TimerListener {
public function appendData() { public function appendData() {
foreach($this->sockets as $key => &$socket) { foreach($this->sockets as $key => &$socket) {
/** @var SocketStructure $socket */ /** @var SocketStructure $socket */
$socket->streamBuffer .= fread($socket->socket, 512); $socket->streamBuffer .= fread($socket->socket, 1024);
$info = stream_get_meta_data($socket->socket); $info = stream_get_meta_data($socket->socket);
if (feof($socket->socket) || $info['timed_out']) { if (feof($socket->socket) || $info['timed_out']) {

View File

@ -58,29 +58,23 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened'); $this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $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_MAPNAME, $this, 'showList');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SEARCH_AUTHOR, $this, 'showManiaExchangeList'); $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 array $chatCallback
* @param Player $player * @param Player $player
*/ */
public function showManiaExchangeList(array $chatCallback, Player $player) { public function showList(array $chatCallback, Player $player) {
$this->mapListShown[$player->login] = true; $this->mapListShown[$player->login] = true;
$params = explode(' ', $chatCallback[1][2]);
$params = explode(' ', $chatCallback[1][2]); $searchString = '';
$author = '';
$searchString = ''; $environment = '';
$author = '';
$environment = '';
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) {
@ -105,14 +99,22 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
} }
// search for matching maps // search for matching maps
$maps = $this->maniaControl->mapManager->mxManager->getMaps($searchString, $author, $environment); $this->maniaControl->mapManager->mxManager->getMapsAssync(function ($maps) use (&$player) {
if ($maps == null) {
// check if there are any results $this->maniaControl->chat->sendError('No maps found, or MX is down!', $player->login);
if ($maps == null) { return;
$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 // Start offsets
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth(); $width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight(); $height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
@ -293,7 +295,7 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
switch($action) { switch($action) {
case self::ACTION_GET_MAPS_FROM_AUTHOR: case self::ACTION_GET_MAPS_FROM_AUTHOR:
$callback[1][2] = 'auth:' . $actionArray[2]; $callback[1][2] = 'auth:' . $actionArray[2];
$this->showManiaExchangeList($callback, $player); $this->showList($callback, $player);
break; break;
case self::ACTION_ADD_MAP: case self::ACTION_ADD_MAP:
$this->maniaControl->mapManager->addMapFromMx($mapId, $player->login); $this->maniaControl->mapManager->addMapFromMx($mapId, $player->login);

View File

@ -251,7 +251,7 @@ class ManiaExchangeManager {
return $success; 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)) { if (!is_callable($function)) {
$this->maniaControl->log("Function is not callable"); $this->maniaControl->log("Function is not callable");
return false; return false;
@ -312,7 +312,7 @@ class ManiaExchangeManager {
} }
return $success; return $success;
}*/ }
/** /**

View File

@ -238,6 +238,6 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
* @param Player $player * @param Player $player
*/ */
public function command_xList(array $chatCallback, Player $player) { public function command_xList(array $chatCallback, Player $player) {
$this->maniaControl->mapManager->mxList->showManiaExchangeList($chatCallback, $player); $this->maniaControl->mapManager->mxList->showList($chatCallback, $player);
} }
} }