From e5c7fdbf6b2189e8cf66c2bfb9cd1ca8273d5d8e Mon Sep 17 00:00:00 2001 From: kremsy Date: Sun, 14 May 2017 09:25:52 +0200 Subject: [PATCH] drastic speedup through multicalls --- core/Callbacks/CallbackManager.php | 9 +++++++++ core/Chat.php | 12 +++++------- core/Manialinks/ManialinkManager.php | 8 ++++---- core/Maps/MapQueue.php | 2 +- core/Script/ModeScriptEventManager.php | 14 +++++++------- plugins/MCTeam/CustomVotesPlugin.php | 2 +- plugins/MCTeam/ServerRankingPlugin.php | 17 ++++++----------- 7 files changed, 33 insertions(+), 31 deletions(-) diff --git a/core/Callbacks/CallbackManager.php b/core/Callbacks/CallbackManager.php index 5ac2de44..812ba807 100644 --- a/core/Callbacks/CallbackManager.php +++ b/core/Callbacks/CallbackManager.php @@ -252,10 +252,19 @@ class CallbackManager implements UsageInformationAble { $timings[$key] = array($callback[0], microtime(true) - $time1); } + //Execute Multicalls + $this->maniaControl->getClient()->executeMulticall(); + $fullTime = microtime(true) - $startTime; + if ($fullTime > ErrorHandler::LONG_LOOP_REPORT_TIME) { $this->maniaControl->getErrorHandler()->triggerDebugNotice(json_encode(array("Long Loop Detected: " . $fullTime, $timings))); } + + + + + } /** diff --git a/core/Chat.php b/core/Chat.php index f98b155e..4cc808d5 100644 --- a/core/Chat.php +++ b/core/Chat.php @@ -72,12 +72,11 @@ class Chat implements CallbackListener, CommunicationListener, UsageInformationA * @param string $message * @param string $login * @param string|bool $prefix - * @param bool $multiCall * @return bool */ - public function sendInformation($message, $login = null, $prefix = true, $multiCall = false) { + public function sendInformation($message, $login = null, $prefix = true) { $format = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_FORMAT_INFORMATION); - return $this->sendChat($format . $message, $login, $prefix, $multiCall); + return $this->sendChat($format . $message, $login, $prefix); } /** @@ -86,10 +85,9 @@ class Chat implements CallbackListener, CommunicationListener, UsageInformationA * @param string $message * @param string $login * @param string|bool $prefix - * @param bool $multiCall * @return bool */ - public function sendChat($message, $login = null, $prefix = true, $multiCall = false) { + public function sendChat($message, $login = null, $prefix = true) { if (!$this->maniaControl->getClient()) { return false; } @@ -102,13 +100,13 @@ class Chat implements CallbackListener, CommunicationListener, UsageInformationA $login = Player::parseLogin($login); } try { - return $this->maniaControl->getClient()->chatSendServerMessage($chatMessage, $login, $multiCall); + return $this->maniaControl->getClient()->chatSendServerMessage($chatMessage, $login, true); } catch (UnknownPlayerException $e) { return false; } } - return $this->maniaControl->getClient()->chatSendServerMessage($chatMessage, null, $multiCall); + return $this->maniaControl->getClient()->chatSendServerMessage($chatMessage, null, true); } /** diff --git a/core/Manialinks/ManialinkManager.php b/core/Manialinks/ManialinkManager.php index f73e3316..8deae608 100644 --- a/core/Manialinks/ManialinkManager.php +++ b/core/Manialinks/ManialinkManager.php @@ -241,13 +241,13 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener, try { if (!$logins) { - return $this->maniaControl->getClient()->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick); + return $this->maniaControl->getClient()->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick, true); } if (is_string($logins)) { - return $this->maniaControl->getClient()->sendDisplayManialinkPage($logins, $manialinkText, $timeout, $hideOnClick); + return $this->maniaControl->getClient()->sendDisplayManialinkPage($logins, $manialinkText, $timeout, $hideOnClick, true); } if ($logins instanceof Player) { - return $this->maniaControl->getClient()->sendDisplayManialinkPage($logins->login, $manialinkText, $timeout, $hideOnClick); + return $this->maniaControl->getClient()->sendDisplayManialinkPage($logins->login, $manialinkText, $timeout, $hideOnClick, true); } if (is_array($logins)) { $loginList = array(); @@ -258,7 +258,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener, $loginList[] = $login; } } - return $this->maniaControl->getClient()->sendDisplayManialinkPage(implode(',', $loginList), $manialinkText, $timeout, $hideOnClick); + return $this->maniaControl->getClient()->sendDisplayManialinkPage(implode(',', $loginList), $manialinkText, $timeout, $hideOnClick, true); } } catch (UnknownPlayerException $e) { return false; diff --git a/core/Maps/MapQueue.php b/core/Maps/MapQueue.php index c1c7ccb2..db00417b 100644 --- a/core/Maps/MapQueue.php +++ b/core/Maps/MapQueue.php @@ -410,7 +410,7 @@ class MapQueue implements CallbackListener, CommandListener, UsageInformationAbl } try { - $this->maniaControl->getClient()->setNextMapIdent($map->uid); + $this->maniaControl->getClient()->setNextMapIdent($map->uid, true); } catch (NextMapException $e) { } catch (NotInListException $e) { } diff --git a/core/Script/ModeScriptEventManager.php b/core/Script/ModeScriptEventManager.php index b7cb7739..59557bd3 100644 --- a/core/Script/ModeScriptEventManager.php +++ b/core/Script/ModeScriptEventManager.php @@ -533,14 +533,14 @@ class ModeScriptEventManager implements UsageInformationAble { * @param string $data */ public function triggerModeScriptEvent($eventName, $data = '') { - try { - $this->maniaControl->getClient()->triggerModeScriptEvent($eventName, $data); - } catch (GameModeException $e) { - if ($e->getMessage() != 'Not in script mode.') { - throw $e; + $this->maniaControl->getClient()->triggerModeScriptEvent($eventName, $data, function ($exception) use ($eventName) { + if ($exception instanceof GameModeException) { + if ($exception->getMessage() != 'Not in script mode.') { + throw $exception; + } + Logger::logWarning($eventName . " can't be triggered because you are not in Scriptmode, start your server in Scriptmode!"); } - Logger::logWarning($eventName . " can't be triggered because you are not in Scriptmode, start your server in Scriptmode!"); - } + }); } /** diff --git a/plugins/MCTeam/CustomVotesPlugin.php b/plugins/MCTeam/CustomVotesPlugin.php index 988d6777..219b50c3 100644 --- a/plugins/MCTeam/CustomVotesPlugin.php +++ b/plugins/MCTeam/CustomVotesPlugin.php @@ -185,7 +185,7 @@ class CustomVotesPlugin implements SidebarMenuEntryRenderable, CommandListener, $ratioArray[] = new VoteRatio(VoteRatio::COMMAND_TEAM_BALANCE, -1.); $ratioArray[] = new VoteRatio(VoteRatio::COMMAND_NEXT_MAP, -1.); - $this->maniaControl->getClient()->setCallVoteRatios($ratioArray, false); + $this->maniaControl->getClient()->setCallVoteRatios($ratioArray, false, true); $this->constructMenu(); return true; diff --git a/plugins/MCTeam/ServerRankingPlugin.php b/plugins/MCTeam/ServerRankingPlugin.php index 871677ac..acc3caed 100644 --- a/plugins/MCTeam/ServerRankingPlugin.php +++ b/plugins/MCTeam/ServerRankingPlugin.php @@ -290,9 +290,8 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener { * Shows the serverRank to a certain Player * * @param Player $player - * @param $multiCall */ - public function showRank(Player $player, $multiCall = false) { + public function showRank(Player $player) { $rankObj = $this->getRank($player); $type = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_RANKING_TYPE); @@ -326,7 +325,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener { $message = '$0f3 You need $<$fff' . $minRecords . '$> Records on this server before receiving a rank...'; } } - $this->maniaControl->getChat()->sendChat($message, $player, $multiCall); + $this->maniaControl->getChat()->sendChat($message, $player); } /** @@ -360,10 +359,9 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener { * Show which Player is next ranked to you * * @param Player $player - * @param bool $multiCall * @return bool */ - public function showNextRank(Player $player, $multiCall = false) { + public function showNextRank(Player $player) { $rankObject = $this->getRank($player); if (!$rankObject) { return false; @@ -382,7 +380,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener { } else { $message = '$0f3No better ranked player.'; } - $this->maniaControl->getChat()->sendChat($message, $player, $multiCall); + $this->maniaControl->getChat()->sendChat($message, $player); return true; } @@ -429,13 +427,10 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener { continue; } //TODO combine the following to message to one (saves half of calls) - $this->showRank($player, true); - $this->showNextRank($player, true); + $this->showRank($player); + $this->showNextRank($player); } - //Execute as a MultiCall - $this->maniaControl->getClient()->executeMulticall(); - // Trigger callback $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_RANK_BUILT); }