slight performance improve of manialinks

This commit is contained in:
kremsy 2017-05-09 13:15:16 +02:00
parent a15fcefba5
commit fc02be2352
5 changed files with 55 additions and 34 deletions

View File

@ -116,20 +116,30 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
if (!$this->initCompleted) { if (!$this->initCompleted) {
return; return;
} }
$players = $this->maniaControl->getPlayerManager()->getPlayers();
foreach ($players as $player) { //Send Menu to Admins
$manialink = $this->buildMenuIconsManialink($player); $admins = $this->maniaControl->getAuthenticationManager()->getConnectedAdmins(AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getManialinkManager()->sendManialink($manialink, $player->login); if (!empty($admins)) {
$manialink = $this->buildMenuIconsManialink(true);
$this->maniaControl->getManialinkManager()->sendManialink($manialink, $admins);
}
//Send Menu to Players - Players with No Admin Permisssions
$players = $this->maniaControl->getAuthenticationManager()->getConnectedPlayers();
if (!empty($players)) {
$manialink = $this->buildMenuIconsManialink(false);
$this->maniaControl->getManialinkManager()->sendManialink($manialink, $players);
} }
} }
/** /**
* Builds the Manialink * Builds the Manialink
* *
* @param Player $player * @param $admin
* @return ManiaLink * @return ManiaLink
*/ */
private function buildMenuIconsManialink(Player $player) { private function buildMenuIconsManialink($admin = false) {
$posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSX); $posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSX);
$itemSize = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_ITEMSIZE); $itemSize = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_ITEMSIZE);
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle(); $quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
@ -147,7 +157,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
/* /*
* Admin Menu * Admin Menu
*/ */
if ($this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if ($admin) {
// Admin Menu Icon Frame // Admin Menu Icon Frame
$iconFrame = new Frame(); $iconFrame = new Frame();
$frame->addChild($iconFrame); $frame->addChild($iconFrame);
@ -327,7 +337,12 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
* @param Player $player * @param Player $player
*/ */
public function handlePlayerJoined(Player $player) { public function handlePlayerJoined(Player $player) {
$maniaLink = $this->buildMenuIconsManialink($player); if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$maniaLink = $this->buildMenuIconsManialink(true);
} else {
$maniaLink = $this->buildMenuIconsManialink(false);
}
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $player); $this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $player);
} }

View File

@ -287,6 +287,24 @@ class AuthenticationManager implements CallbackListener, EchoListener, Communica
return $admins; return $admins;
} }
/**
* Get all connected Players with less permission than the given Auth Level
*
* @api
* @param int $authLevel
* @return Player[]
*/
public function getConnectedPlayers($authLevel = self::AUTH_LEVEL_MODERATOR) {
$players = $this->maniaControl->getPlayerManager()->getPlayers();
$playerArray = array();
foreach ($players as $player) {
if (!self::checkRight($player, $authLevel)) {
array_push($playerArray, $player);
}
}
return $playerArray;
}
/** /**
* Check whether the Player has enough Rights * Check whether the Player has enough Rights
* *

View File

@ -76,11 +76,7 @@ class CustomUIManager implements CallbackListener, TimerListener, UsageInformati
* @param Player $player * @param Player $player
*/ */
public function updateManialink(Player $player = null) { public function updateManialink(Player $player = null) {
if ($player) {
$this->maniaControl->getManialinkManager()->sendManialink($this->customUI, $player); $this->maniaControl->getManialinkManager()->sendManialink($this->customUI, $player);
return;
}
$this->maniaControl->getManialinkManager()->sendManialink($this->customUI);
} }
/** /**

View File

@ -241,28 +241,25 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener,
return $this->maniaControl->getClient()->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick); return $this->maniaControl->getClient()->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick);
} }
if (is_string($logins)) { if (is_string($logins)) {
$success = $this->maniaControl->getClient()->sendDisplayManialinkPage($logins, $manialinkText, $timeout, $hideOnClick); return $this->maniaControl->getClient()->sendDisplayManialinkPage($logins, $manialinkText, $timeout, $hideOnClick);
return $success;
} }
if ($logins instanceof Player) { if ($logins instanceof Player) {
$success = $this->maniaControl->getClient()->sendDisplayManialinkPage($logins->login, $manialinkText, $timeout, $hideOnClick); return $this->maniaControl->getClient()->sendDisplayManialinkPage($logins->login, $manialinkText, $timeout, $hideOnClick);
return $success;
} }
if (is_array($logins)) { if (is_array($logins)) {
$success = true; $loginList = array();
foreach ($logins as $login) { foreach ($logins as $login) {
$subSuccess = $this->sendManialink($manialinkText, $login, $timeout, $hideOnClick); if($login instanceof Player){
if (!$subSuccess) { $loginList[] = $login->login;
$success = false; }else{
$loginList[] = $login;
} }
} }
return $success; return $this->maniaControl->getClient()->sendDisplayManialinkPage(implode(',', $loginList), $manialinkText, $timeout, $hideOnClick);
} }
} catch (UnknownPlayerException $e) { } catch (UnknownPlayerException $e) {
return false; return false;
} catch (FaultException $e) { } catch (FaultException $e) {
//TODO added 17.01.2015, remove later:
$this->maniaControl->getErrorHandler()->triggerDebugNotice("Fault Exception: ManiaLink Manager, Message: " . $e->getMessage());
return false; return false;
} catch (MessageException $e) { } catch (MessageException $e) {
//TODO verify why this can happen //TODO verify why this can happen

View File

@ -846,17 +846,12 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$karmaLabel->setText('-'); $karmaLabel->setText('-');
} }
// Loop players
foreach ($players as $login => $player) { $this->maniaControl->getManialinkManager()->sendManialink($this->manialink, $players);
// Get player vote
// TODO: show the player his own vote in some way // TODO: show the player his own vote in some way
// $vote = $this->getPlayerVote($player, $map); // $vote = $this->getPlayerVote($player, $map);
// $votesFrame = $this->manialink->votesFrame; // $votesFrame = $this->manialink->votesFrame;
// $votesFrame->removeChildren(); // $votesFrame->removeChildren();
// Send manialink
$this->maniaControl->getManialinkManager()->sendManialink($this->manialink, $login);
}
} }
} }