mirror of
https://github.com/SantaSpeen/BeamMP-Server.git
synced 2025-08-18 12:45:36 +00:00
Lock when accessing vehicles
This commit is contained in:
parent
3c68dfaeaf
commit
7231c69e10
@ -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);
|
||||
|
@ -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()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user