From fc02be23524ac760d99480fe279465e49c644bac Mon Sep 17 00:00:00 2001 From: kremsy Date: Tue, 9 May 2017 13:15:16 +0200 Subject: [PATCH] slight performance improve of manialinks --- core/Admin/ActionsMenu.php | 31 +++++++++++++++++++++------- core/Admin/AuthenticationManager.php | 18 ++++++++++++++++ core/Manialinks/CustomUIManager.php | 6 +----- core/Manialinks/ManialinkManager.php | 19 +++++++---------- plugins/MCTeam/KarmaPlugin.php | 15 +++++--------- 5 files changed, 55 insertions(+), 34 deletions(-) diff --git a/core/Admin/ActionsMenu.php b/core/Admin/ActionsMenu.php index aff7250b..e640c3b4 100644 --- a/core/Admin/ActionsMenu.php +++ b/core/Admin/ActionsMenu.php @@ -116,20 +116,30 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag if (!$this->initCompleted) { return; } - $players = $this->maniaControl->getPlayerManager()->getPlayers(); - foreach ($players as $player) { - $manialink = $this->buildMenuIconsManialink($player); - $this->maniaControl->getManialinkManager()->sendManialink($manialink, $player->login); + + //Send Menu to Admins + $admins = $this->maniaControl->getAuthenticationManager()->getConnectedAdmins(AuthenticationManager::AUTH_LEVEL_MODERATOR); + 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 * - * @param Player $player + * @param $admin * @return ManiaLink */ - private function buildMenuIconsManialink(Player $player) { + private function buildMenuIconsManialink($admin = false) { $posX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSX); $itemSize = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_ITEMSIZE); $quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle(); @@ -147,7 +157,7 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag /* * Admin Menu */ - if ($this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { + if ($admin) { // Admin Menu Icon Frame $iconFrame = new Frame(); $frame->addChild($iconFrame); @@ -327,7 +337,12 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag * @param 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); } diff --git a/core/Admin/AuthenticationManager.php b/core/Admin/AuthenticationManager.php index abb8d587..4f40acd4 100644 --- a/core/Admin/AuthenticationManager.php +++ b/core/Admin/AuthenticationManager.php @@ -287,6 +287,24 @@ class AuthenticationManager implements CallbackListener, EchoListener, Communica 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 * diff --git a/core/Manialinks/CustomUIManager.php b/core/Manialinks/CustomUIManager.php index f4d4b2ec..24a94be5 100644 --- a/core/Manialinks/CustomUIManager.php +++ b/core/Manialinks/CustomUIManager.php @@ -76,11 +76,7 @@ class CustomUIManager implements CallbackListener, TimerListener, UsageInformati * @param Player $player */ public function updateManialink(Player $player = null) { - if ($player) { - $this->maniaControl->getManialinkManager()->sendManialink($this->customUI, $player); - return; - } - $this->maniaControl->getManialinkManager()->sendManialink($this->customUI); + $this->maniaControl->getManialinkManager()->sendManialink($this->customUI, $player); } /** diff --git a/core/Manialinks/ManialinkManager.php b/core/Manialinks/ManialinkManager.php index cc1eb84f..b2209959 100644 --- a/core/Manialinks/ManialinkManager.php +++ b/core/Manialinks/ManialinkManager.php @@ -241,28 +241,25 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener, return $this->maniaControl->getClient()->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick); } if (is_string($logins)) { - $success = $this->maniaControl->getClient()->sendDisplayManialinkPage($logins, $manialinkText, $timeout, $hideOnClick); - return $success; + return $this->maniaControl->getClient()->sendDisplayManialinkPage($logins, $manialinkText, $timeout, $hideOnClick); } if ($logins instanceof Player) { - $success = $this->maniaControl->getClient()->sendDisplayManialinkPage($logins->login, $manialinkText, $timeout, $hideOnClick); - return $success; + return $this->maniaControl->getClient()->sendDisplayManialinkPage($logins->login, $manialinkText, $timeout, $hideOnClick); } if (is_array($logins)) { - $success = true; + $loginList = array(); foreach ($logins as $login) { - $subSuccess = $this->sendManialink($manialinkText, $login, $timeout, $hideOnClick); - if (!$subSuccess) { - $success = false; + if($login instanceof Player){ + $loginList[] = $login->login; + }else{ + $loginList[] = $login; } } - return $success; + return $this->maniaControl->getClient()->sendDisplayManialinkPage(implode(',', $loginList), $manialinkText, $timeout, $hideOnClick); } } catch (UnknownPlayerException $e) { return false; } catch (FaultException $e) { - //TODO added 17.01.2015, remove later: - $this->maniaControl->getErrorHandler()->triggerDebugNotice("Fault Exception: ManiaLink Manager, Message: " . $e->getMessage()); return false; } catch (MessageException $e) { //TODO verify why this can happen diff --git a/plugins/MCTeam/KarmaPlugin.php b/plugins/MCTeam/KarmaPlugin.php index 8b664d48..1d227733 100644 --- a/plugins/MCTeam/KarmaPlugin.php +++ b/plugins/MCTeam/KarmaPlugin.php @@ -846,17 +846,12 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $karmaLabel->setText('-'); } - // Loop players - foreach ($players as $login => $player) { - // Get player vote - // TODO: show the player his own vote in some way - // $vote = $this->getPlayerVote($player, $map); - // $votesFrame = $this->manialink->votesFrame; - // $votesFrame->removeChildren(); - // Send manialink - $this->maniaControl->getManialinkManager()->sendManialink($this->manialink, $login); - } + $this->maniaControl->getManialinkManager()->sendManialink($this->manialink, $players); + // TODO: show the player his own vote in some way + // $vote = $this->getPlayerVote($player, $map); + // $votesFrame = $this->manialink->votesFrame; + // $votesFrame->removeChildren(); } }