Skip to content

Commit

Permalink
Add player limit bypass to onPlayerAuth (#372)
Browse files Browse the repository at this point in the history
With this PR, returning 2 in onPlayerAuth will allow the player to join
without checking if the server is full. This makes it easier for plugin
developers to allow for example their staff to join without having to
change the max player count.
  • Loading branch information
lionkor authored Oct 5, 2024
2 parents 0850cde + bb3c762 commit 077bb6b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/TNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,21 @@ std::shared_ptr<TClient> 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<TLuaResult>& Result) {
return !Result->Error && Result->Result.is<int>() && bool(Result->Result.as<int>());
});
bool NotAllowed = false;
bool BypassLimit = false;

for (const auto& Result : Futures) {
if (!Result->Error && Result->Result.is<int>()) {
auto Res = Result->Result.as<int>();

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<TLuaResult>& Result) -> bool {
Expand Down Expand Up @@ -421,7 +432,7 @@ std::shared_ptr<TClient> 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);
Expand Down

0 comments on commit 077bb6b

Please sign in to comment.