mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-06-17 14:12:25 +00:00
Lock when accessing vehicles
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
// FIXME: add debug prints
|
// FIXME: add debug prints
|
||||||
|
|
||||||
void TClient::DeleteCar(int Ident) {
|
void TClient::DeleteCar(int Ident) {
|
||||||
|
std::unique_lock lock(mVehicleDataMutex);
|
||||||
for (auto& v : mVehicleData) {
|
for (auto& v : mVehicleData) {
|
||||||
if (v.ID() == Ident) {
|
if (v.ID() == Ident) {
|
||||||
mVehicleData.erase(v);
|
mVehicleData.erase(v);
|
||||||
@@ -15,6 +16,7 @@ void TClient::DeleteCar(int Ident) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TClient::ClearCars() {
|
void TClient::ClearCars() {
|
||||||
|
std::unique_lock lock(mVehicleDataMutex);
|
||||||
mVehicleData.clear();
|
mVehicleData.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +36,7 @@ int TClient::GetOpenCarID() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TClient::AddNewCar(int Ident, const std::string& Data) {
|
void TClient::AddNewCar(int Ident, const std::string& Data) {
|
||||||
|
std::unique_lock lock(mVehicleDataMutex);
|
||||||
mVehicleData.emplace(Ident, Data);
|
mVehicleData.emplace(Ident, Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,6 +45,7 @@ TClient::TVehicleDataLockPair TClient::GetAllCars() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string TClient::GetCarData(int Ident) {
|
std::string TClient::GetCarData(int Ident) {
|
||||||
|
std::unique_lock lock(mVehicleDataMutex);
|
||||||
for (auto& v : mVehicleData) {
|
for (auto& v : mVehicleData) {
|
||||||
if (v.ID() == Ident) {
|
if (v.ID() == Ident) {
|
||||||
return v.Data();
|
return v.Data();
|
||||||
@@ -52,6 +56,7 @@ std::string TClient::GetCarData(int Ident) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TClient::SetCarData(int Ident, const std::string& Data) {
|
void TClient::SetCarData(int Ident, const std::string& Data) {
|
||||||
|
std::unique_lock lock(mVehicleDataMutex);
|
||||||
for (auto& v : mVehicleData) {
|
for (auto& v : mVehicleData) {
|
||||||
if (v.ID() == Ident) {
|
if (v.ID() == Ident) {
|
||||||
v.SetData(Data);
|
v.SetData(Data);
|
||||||
|
|||||||
+5
-1
@@ -280,7 +280,11 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ
|
|||||||
void TServer::Apply(TClient& c, int VID, const std::string& pckt) {
|
void TServer::Apply(TClient& c, int VID, const std::string& pckt) {
|
||||||
std::string Packet = pckt.substr(pckt.find('{')), VD = c.GetCarData(VID);
|
std::string Packet = pckt.substr(pckt.find('{')), VD = c.GetCarData(VID);
|
||||||
std::string Header = VD.substr(0, VD.find('{'));
|
std::string Header = VD.substr(0, VD.find('{'));
|
||||||
VD = VD.substr(VD.find('{'));
|
if(VD.empty()){
|
||||||
|
error("Applying config for a non existing car?");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
VD = VD.substr(VD.find('{')); //TODO somehow this got hit while VD is empty
|
||||||
rapidjson::Document Veh, Pack;
|
rapidjson::Document Veh, Pack;
|
||||||
Veh.Parse(VD.c_str());
|
Veh.Parse(VD.c_str());
|
||||||
if (Veh.HasParseError()) {
|
if (Veh.HasParseError()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user