mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-08-16 00:06:33 +00:00
Fix postPlayerAuth and add reason value (#395)
Closes #393 and #394 This PR cleans up and fixes the code in TNetwork::Authentication and sends the kick reason to lua. The event is now `function postPlayerAuth(Kicked: bool, Reason: string, Name: string, Role: string, Guest: bool, Identifiers: table)` --- By creating this pull request, I understand that code that is AI generated or otherwise automatically generated may be rejected without further discussion. I declare that I fully understand all code I pushed into this PR, and wrote all this code myself and own the rights to this code.
This commit is contained in:
commit
fc208770dd
@ -430,35 +430,27 @@ std::shared_ptr<TClient> 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 (!NotAllowed && !NotAllowedWithReason && mServer.ClientCount() >= size_t(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)) && !BypassLimit) {
|
||||
NotAllowedWithReason = true;
|
||||
Reason = "Server full!";
|
||||
}
|
||||
|
||||
if (NotAllowedWithReason) {
|
||||
Allowed = false;
|
||||
}
|
||||
|
||||
if (NotAllowed) {
|
||||
ClientKick(*Client, "you are not allowed on the server!");
|
||||
} else if (NotAllowedWithReason) {
|
||||
ClientKick(*Client, Reason);
|
||||
} else if (NotAllowed) {
|
||||
ClientKick(*Client, "you are not allowed on the server!");
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (!Allowed) {
|
||||
return {};
|
||||
} else if (mServer.ClientCount() < size_t(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)) || BypassLimit) {
|
||||
if (!NotAllowed && !NotAllowedWithReason) {
|
||||
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());
|
||||
// the post event is not cancellable so we dont wait for it
|
||||
LuaAPI::MP::Engine->ReportErrors(PostFutures);
|
||||
|
||||
return Client;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user