Add post event(s) (#364)

Adds `post*` events which are triggered after the respective `on*` event
has completed and the results have been sent.

They have the same arguments as the `on*` function, with the exception
that another argument is added in the beginning which contains whether
the `on*` variant was cancelled.
This commit is contained in:
Lion
2024-09-19 01:37:17 +02:00
committed by GitHub
2 changed files with 44 additions and 15 deletions
+19 -6
View File
@@ -423,15 +423,24 @@ 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) {
ClientKick(*Client, "you are not allowed on the server!");
return {};
} else if (NotAllowedWithReason) {
ClientKick(*Client, Reason);
return {};
Allowed = false;
}
if (NotAllowedWithReason) {
Allowed = false;
}
if (mServer.ClientCount() < size_t(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers))) {
if (NotAllowed) {
ClientKick(*Client, "you are not allowed on the server!");
} else if (NotAllowedWithReason) {
ClientKick(*Client, Reason);
}
if (!Allowed) {
return {};
} else if (mServer.ClientCount() < size_t(Application::Settings.getAsInt(Settings::Key::General_MaxPlayers))) {
beammp_info("Identification success");
mServer.InsertClient(Client);
TCPClient(Client);
@@ -439,6 +448,10 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
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;
}