From bb3c762d682dce9de19a35e6423d9119f3c88396 Mon Sep 17 00:00:00 2001 From: Tixx <83774803+WiserTixx@users.noreply.github.com> Date: Sat, 28 Sep 2024 14:52:04 +0200 Subject: [PATCH] Add player limit bypass to onPlayerAuth --- src/TNetwork.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index b50af560..9e118d71 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -404,10 +404,21 @@ std::shared_ptr TNetwork::Authentication(TConnection&& RawConnection) { auto Futures = LuaAPI::MP::Engine->TriggerEvent("onPlayerAuth", "", Client->GetName(), Client->GetRoles(), Client->IsGuest(), Client->GetIdentifiers()); TLuaEngine::WaitForAll(Futures); - bool NotAllowed = std::any_of(Futures.begin(), Futures.end(), - [](const std::shared_ptr& Result) { - return !Result->Error && Result->Result.is() && bool(Result->Result.as()); - }); + bool NotAllowed = false; + bool BypassLimit = false; + + for (const auto& Result : Futures) { + if (!Result->Error && Result->Result.is()) { + auto Res = Result->Result.as(); + + if (Res == 1) { + NotAllowed = true; + break; + } else if (Res == 2) { + BypassLimit = true; + } + } + } std::string Reason; bool NotAllowedWithReason = std::any_of(Futures.begin(), Futures.end(), [&Reason](const std::shared_ptr& Result) -> bool { @@ -440,7 +451,7 @@ std::shared_ptr TNetwork::Authentication(TConnection&& RawConnection) { if (!Allowed) { return {}; - } else if (mServer.ClientCount() < size_t(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers))) { + } else if (mServer.ClientCount() < size_t(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)) || BypassLimit) { beammp_info("Identification success"); mServer.InsertClient(Client); TCPClient(Client);