mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 23:35:41 +00:00
Unicycle edit check
This commit is contained in:
parent
86b5d91579
commit
15f7a6ba85
@ -32,5 +32,6 @@ private:
|
|||||||
mutable RWMutex mClientsMutex;
|
mutable RWMutex mClientsMutex;
|
||||||
static void ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Network);
|
static void ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Network);
|
||||||
static bool ShouldSpawn(TClient& c, const std::string& CarJson, int ID);
|
static bool ShouldSpawn(TClient& c, const std::string& CarJson, int ID);
|
||||||
|
static bool IsUnicycle(TClient& c, const std::string& CarJson);
|
||||||
static void Apply(TClient& c, int VID, const std::string& pckt);
|
static void Apply(TClient& c, int VID, const std::string& pckt);
|
||||||
};
|
};
|
||||||
|
@ -164,18 +164,23 @@ void TServer::HandleEvent(TClient& c, const std::string& Data) {
|
|||||||
a++;
|
a++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bool TServer::IsUnicycle(TClient &c, const std::string &CarJson) {
|
||||||
|
rapidjson::Document Car;
|
||||||
|
Car.Parse(CarJson.c_str(), CarJson.size());
|
||||||
|
if(Car.HasParseError()){
|
||||||
|
error("Failed to parse vehicle data -> " + CarJson);
|
||||||
|
} else if (Car["jbm"].IsString() && std::string(Car["jbm"].GetString()) == "unicycle") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
bool TServer::ShouldSpawn(TClient& c, const std::string& CarJson, int ID) {
|
bool TServer::ShouldSpawn(TClient& c, const std::string& CarJson, int ID) {
|
||||||
|
|
||||||
if(c.GetUnicycleID() > -1 && (c.GetCarCount() - 1) < Application::Settings.MaxCars){
|
if(c.GetUnicycleID() > -1 && (c.GetCarCount() - 1) < Application::Settings.MaxCars){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
rapidjson::Document Car;
|
if(IsUnicycle(c,CarJson)){
|
||||||
Car.Parse(CarJson.c_str(), CarJson.size());
|
|
||||||
if(Car.HasParseError()){
|
|
||||||
error("Failed to parse vehicle data -> " + CarJson);
|
|
||||||
} else if (Car["jbm"].IsString() && std::string(Car["jbm"].GetString()) == "unicycle") {
|
|
||||||
c.SetUnicycleID(ID);
|
c.SetUnicycleID(ID);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -230,13 +235,12 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ
|
|||||||
VID = stoi(vid);
|
VID = stoi(vid);
|
||||||
}
|
}
|
||||||
if (PID != -1 && VID != -1 && PID == c.GetID()) {
|
if (PID != -1 && VID != -1 && PID == c.GetID()) {
|
||||||
if(c.GetUnicycleID() == VID){
|
|
||||||
c.SetUnicycleID(-1);
|
|
||||||
}
|
|
||||||
auto Res = TriggerLuaEvent(("onVehicleEdited"), false, nullptr,
|
auto Res = TriggerLuaEvent(("onVehicleEdited"), false, nullptr,
|
||||||
std::make_unique<TLuaArg>(TLuaArg { { c.GetID(), VID, Packet.substr(3) } }),
|
std::make_unique<TLuaArg>(TLuaArg { { c.GetID(), VID, Packet.substr(3) } }),
|
||||||
true);
|
true);
|
||||||
if (!std::any_cast<int>(Res)) {
|
|
||||||
|
if ((c.GetUnicycleID() != VID || IsUnicycle(c,Packet.substr(Packet.find('{'))))
|
||||||
|
&& std::any_cast<int>(Res) == 0) {
|
||||||
Network.SendToAll(&c, Packet, false, true);
|
Network.SendToAll(&c, Packet, false, true);
|
||||||
Apply(c, VID, Packet);
|
Apply(c, VID, Packet);
|
||||||
} else {
|
} else {
|
||||||
@ -259,6 +263,9 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ
|
|||||||
VID = stoi(vid);
|
VID = stoi(vid);
|
||||||
}
|
}
|
||||||
if (PID != -1 && VID != -1 && PID == c.GetID()) {
|
if (PID != -1 && VID != -1 && PID == c.GetID()) {
|
||||||
|
if(c.GetUnicycleID() == VID){
|
||||||
|
c.SetUnicycleID(-1);
|
||||||
|
}
|
||||||
Network.SendToAll(nullptr, Packet, true, true);
|
Network.SendToAll(nullptr, Packet, true, true);
|
||||||
TriggerLuaEvent(("onVehicleDeleted"), false, nullptr,
|
TriggerLuaEvent(("onVehicleDeleted"), false, nullptr,
|
||||||
std::make_unique<TLuaArg>(TLuaArg { { c.GetID(), VID } }), false);
|
std::make_unique<TLuaArg>(TLuaArg { { c.GetID(), VID } }), false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user