Report more errors, better

This commit is contained in:
Lion Kortlepel 2021-10-01 03:52:12 +02:00
parent ae7a63669f
commit 9eabd19e17
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B
4 changed files with 11 additions and 9 deletions

View File

@ -83,7 +83,7 @@ public:
void SetServer(TServer* Server) { mServer = Server; }
static void WaitForAll(std::vector<std::shared_ptr<TLuaResult>>& Results);
void IgnoreIfNotError(const std::vector<std::shared_ptr<TLuaResult> >& Results);
void ReportErrors(const std::vector<std::shared_ptr<TLuaResult> >& Results);
[[nodiscard]] std::shared_ptr<TLuaResult> EnqueueScript(TLuaStateId StateID, const TLuaChunk& Script);
[[nodiscard]] std::shared_ptr<TLuaResult> EnqueueFunctionCall(TLuaStateId StateID, const std::string& FunctionName, const std::vector<TLuaArgTypes>& Args);
void EnsureStateExists(TLuaStateId StateId, const std::string& Name, bool DontCallOnInit = false);

View File

@ -143,7 +143,7 @@ void TLuaEngine::WaitForAll(std::vector<std::shared_ptr<TLuaResult>>& Results) {
}
// run this on the error checking thread
void TLuaEngine::IgnoreIfNotError(const std::vector<std::shared_ptr<TLuaResult>>& Results) {
void TLuaEngine::ReportErrors(const std::vector<std::shared_ptr<TLuaResult>>& Results) {
std::unique_lock Lock2(mResultsToCheckMutex);
for (const auto& Result : Results) {
mResultsToCheck.push(Result);

View File

@ -331,6 +331,8 @@ void TNetwork::Authentication(const TConnection& ClientConnection) {
return;
}
LuaAPI::MP::Engine->ReportErrors(Futures);
if (mServer.ClientCount() < size_t(Application::Settings.MaxPlayers)) {
beammp_info("Identification success");
mServer.InsertClient(Client);
@ -571,7 +573,7 @@ void TNetwork::OnDisconnect(const std::weak_ptr<TClient>& ClientPtr, bool kicked
SendToAll(&c, Packet, false, true);
Packet.clear();
auto Futures = LuaAPI::MP::Engine->TriggerEvent("onPlayerDisconnect", "", c.GetID());
LuaAPI::MP::Engine->IgnoreIfNotError(Futures);
LuaAPI::MP::Engine->ReportErrors(Futures);
if (c.GetTCPSock())
CloseSocketProper(c.GetTCPSock());
if (c.GetDownSock())
@ -605,13 +607,13 @@ void TNetwork::OnConnect(const std::weak_ptr<TClient>& c) {
auto LockedClient = c.lock();
LockedClient->SetID(OpenID());
beammp_info("Assigned ID " + std::to_string(LockedClient->GetID()) + " to " + LockedClient->GetName());
LuaAPI::MP::Engine->IgnoreIfNotError(LuaAPI::MP::Engine->TriggerEvent("onPlayerConnecting", "", LockedClient->GetID()));
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onPlayerConnecting", "", LockedClient->GetID()));
SyncResources(*LockedClient);
if (LockedClient->GetStatus() < 0)
return;
(void)Respond(*LockedClient, "M" + Application::Settings.MapName, true); //Send the Map on connect
beammp_info(LockedClient->GetName() + " : Connected");
LuaAPI::MP::Engine->IgnoreIfNotError(LuaAPI::MP::Engine->TriggerEvent("onPlayerJoining", "", LockedClient->GetID()));
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onPlayerJoining", "", LockedClient->GetID()));
}
void TNetwork::SyncResources(TClient& c) {
@ -810,7 +812,7 @@ bool TNetwork::SyncClient(const std::weak_ptr<TClient>& c) {
// ignore error
(void)SendToAll(LockedClient.get(), ("JWelcome ") + LockedClient->GetName() + "!", false, true);
LuaAPI::MP::Engine->IgnoreIfNotError(LuaAPI::MP::Engine->TriggerEvent("onPlayerJoin", "", LockedClient->GetID()));
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onPlayerJoin", "", LockedClient->GetID()));
LockedClient->SetIsSyncing(true);
bool Return = false;
bool res = true;

View File

@ -162,7 +162,7 @@ void TServer::HandleEvent(TClient& c, const std::string& Data) {
Name = t;
break;
case 2:
LuaAPI::MP::Engine->IgnoreIfNotError(LuaAPI::MP::Engine->TriggerEvent(Name, "", c.GetID(), t));
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent(Name, "", c.GetID(), t));
break;
default:
break;
@ -282,7 +282,7 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ
c.SetUnicycleID(-1);
}
Network.SendToAll(nullptr, Packet, true, true);
LuaAPI::MP::Engine->IgnoreIfNotError(LuaAPI::MP::Engine->TriggerEvent("onVehicleDeleted", "", c.GetID(), VID));
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onVehicleDeleted", "", c.GetID(), VID));
c.DeleteCar(VID);
beammp_debug(c.GetName() + (" deleted car with ID ") + std::to_string(VID));
}
@ -300,7 +300,7 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ
if (PID != -1 && VID != -1 && PID == c.GetID()) {
Data = Data.substr(Data.find('{'));
LuaAPI::MP::Engine->IgnoreIfNotError(LuaAPI::MP::Engine->TriggerEvent("onVehicleReset", "", c.GetID(), VID, Data));
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onVehicleReset", "", c.GetID(), VID, Data));
Network.SendToAll(&c, Packet, false, true);
}
return;