From 1c07cf83b2210e4ee2e3c08f146a49ef05090481 Mon Sep 17 00:00:00 2001 From: Tixx <83774803+WiserTixx@users.noreply.github.com> Date: Sun, 24 Nov 2024 22:28:32 +0100 Subject: [PATCH 1/2] Fix postPlayerAuth and add reason value --- src/TNetwork.cpp | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 6239d81a..52944454 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -430,32 +430,24 @@ std::shared_ptr TNetwork::Authentication(TConnection&& RawConnection) { Reason = "No guests are allowed on this server! To join, sign up at: forum.beammp.com."; } - bool Allowed = true; - if (NotAllowed) { - Allowed = false; - } - if (NotAllowedWithReason) { - Allowed = false; + if (!NotAllowed && !NotAllowedWithReason) { + if (mServer.ClientCount() < size_t(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)) || BypassLimit) { + beammp_info("Identification success"); + mServer.InsertClient(Client); + TCPClient(Client); + } else { + NotAllowedWithReason = true; + Reason = "Server full!"; + } } - if (NotAllowed) { - ClientKick(*Client, "you are not allowed on the server!"); - } else if (NotAllowedWithReason) { + if (NotAllowedWithReason) { ClientKick(*Client, Reason); + } else if (NotAllowed) { + ClientKick(*Client, "you are not allowed on the server!"); } - - if (!Allowed) { - return {}; - } else if (mServer.ClientCount() < size_t(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)) || BypassLimit) { - beammp_info("Identification success"); - mServer.InsertClient(Client); - TCPClient(Client); - } else { - ClientKick(*Client, "Server full!"); - } - - auto PostFutures = LuaAPI::MP::Engine->TriggerEvent("postPlayerAuth", "", Allowed, Client->GetName(), Client->GetRoles(), Client->IsGuest(), Client->GetIdentifiers()); + auto PostFutures = LuaAPI::MP::Engine->TriggerEvent("postPlayerAuth", "", NotAllowed || NotAllowedWithReason, Reason, Client->GetName(), Client->GetRoles(), Client->IsGuest(), Client->GetIdentifiers()); // the post event is not cancellable so we dont wait for it LuaAPI::MP::Engine->ReportErrors(PostFutures); From 99a51808a03a23d37050171c5f472d366709c50a Mon Sep 17 00:00:00 2001 From: Tixx <83774803+WiserTixx@users.noreply.github.com> Date: Mon, 25 Nov 2024 00:33:10 +0100 Subject: [PATCH 2/2] Fix postPlayerAuth not running until after leaving --- src/TNetwork.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 52944454..6aed9f6a 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -430,15 +430,9 @@ std::shared_ptr TNetwork::Authentication(TConnection&& RawConnection) { Reason = "No guests are allowed on this server! To join, sign up at: forum.beammp.com."; } - if (!NotAllowed && !NotAllowedWithReason) { - if (mServer.ClientCount() < size_t(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)) || BypassLimit) { - beammp_info("Identification success"); - mServer.InsertClient(Client); - TCPClient(Client); - } else { + if (!NotAllowed && !NotAllowedWithReason && mServer.ClientCount() >= size_t(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)) && !BypassLimit) { NotAllowedWithReason = true; Reason = "Server full!"; - } } if (NotAllowedWithReason) { @@ -451,6 +445,12 @@ std::shared_ptr TNetwork::Authentication(TConnection&& RawConnection) { // the post event is not cancellable so we dont wait for it LuaAPI::MP::Engine->ReportErrors(PostFutures); + if (!NotAllowed && !NotAllowedWithReason) { + beammp_info("Identification success"); + mServer.InsertClient(Client); + TCPClient(Client); + } + return Client; }