Skip to content

Commit

Permalink
Fix disconnect not calling onVehicleDeleted (#336)
Browse files Browse the repository at this point in the history
OnDisconnect sent a packet to the client, which was already
disconnected.
  • Loading branch information
lionkor authored Sep 18, 2024
2 parents 5f7207b + 3068a0e commit a7a19d9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/LuaAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ std::pair<bool, std::string> LuaAPI::MP::RemoveVehicle(int PID, int VID) {
auto c = MaybeClient.value().lock();
if (!c->GetCarData(VID).empty()) {
std::string Destroy = "Od:" + std::to_string(PID) + "-" + std::to_string(VID);
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onVehicleDeleted", "", PID, VID));
Engine->Network().SendToAll(nullptr, StringToVector(Destroy), true, true);
c->DeleteCar(VID);
Result.first = true;
Expand Down
1 change: 1 addition & 0 deletions src/TNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ void TNetwork::OnDisconnect(const std::weak_ptr<TClient>& ClientPtr) {
VehicleData = *LockedData.VehicleData;
} // End Vehicle Data Lock Scope
for (auto& v : VehicleData) {
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onVehicleDeleted", "", c.GetID(), v.ID()));
Packet = "Od:" + std::to_string(c.GetID()) + "-" + std::to_string(v.ID());
SendToAll(&c, StringToVector(Packet), false, true);
}
Expand Down
3 changes: 2 additions & 1 deletion src/TServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ void TServer::RemoveClient(const std::weak_ptr<TClient>& WeakClientPtr) {
beammp_assert(LockedClientPtr != nullptr);
TClient& Client = *LockedClientPtr;
beammp_debug("removing client " + Client.GetName() + " (" + std::to_string(ClientCount()) + ")");
// TODO: Send delete packets for all cars
Client.ClearCars();
WriteLock Lock(mClientsMutex);
mClients.erase(WeakClientPtr.lock());
Expand Down Expand Up @@ -322,6 +321,7 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ
// TODO: handle
}
std::string Destroy = "Od:" + std::to_string(c.GetID()) + "-" + std::to_string(CarID);
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onVehicleDeleted", "", c.GetID(), CarID));
if (!Network.Respond(c, StringToVector(Destroy), true)) {
// TODO: handle
}
Expand Down Expand Up @@ -355,6 +355,7 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ
}
std::string Destroy = "Od:" + std::to_string(c.GetID()) + "-" + std::to_string(VID);
Network.SendToAll(nullptr, StringToVector(Destroy), true, true);
LuaAPI::MP::Engine->ReportErrors(LuaAPI::MP::Engine->TriggerEvent("onVehicleDeleted", "", c.GetID(), VID));
c.DeleteCar(VID);
}
}
Expand Down

0 comments on commit a7a19d9

Please sign in to comment.