diff --git a/src/Client.cpp b/src/Client.cpp index ae0f325..d6da252 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -6,6 +6,7 @@ // FIXME: add debug prints void TClient::DeleteCar(int Ident) { + std::unique_lock lock(mVehicleDataMutex); for (auto& v : mVehicleData) { if (v.ID() == Ident) { mVehicleData.erase(v); @@ -15,6 +16,7 @@ void TClient::DeleteCar(int Ident) { } void TClient::ClearCars() { + std::unique_lock lock(mVehicleDataMutex); mVehicleData.clear(); } @@ -34,6 +36,7 @@ int TClient::GetOpenCarID() const { } void TClient::AddNewCar(int Ident, const std::string& Data) { + std::unique_lock lock(mVehicleDataMutex); mVehicleData.emplace(Ident, Data); } @@ -42,6 +45,7 @@ TClient::TVehicleDataLockPair TClient::GetAllCars() { } std::string TClient::GetCarData(int Ident) { + std::unique_lock lock(mVehicleDataMutex); for (auto& v : mVehicleData) { if (v.ID() == Ident) { return v.Data(); @@ -52,6 +56,7 @@ std::string TClient::GetCarData(int Ident) { } void TClient::SetCarData(int Ident, const std::string& Data) { + std::unique_lock lock(mVehicleDataMutex); for (auto& v : mVehicleData) { if (v.ID() == Ident) { v.SetData(Data); diff --git a/src/TServer.cpp b/src/TServer.cpp index b03e266..a25ccf5 100644 --- a/src/TServer.cpp +++ b/src/TServer.cpp @@ -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) { std::string Packet = pckt.substr(pckt.find('{')), VD = c.GetCarData(VID); 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; Veh.Parse(VD.c_str()); if (Veh.HasParseError()) {