diff --git a/src/TLuaFile.cpp b/src/TLuaFile.cpp index dd1d472..d6b1f33 100644 --- a/src/TLuaFile.cpp +++ b/src/TLuaFile.cpp @@ -74,15 +74,13 @@ std::any FutureWait(TLuaFile* lua, const std::string& R, std::shared_ptr arg, bool Wait) { std::any R; - std::string Type; int Ret = 0; for (auto& Script : Engine().LuaFiles()) { if (Script->IsRegistered(Event)) { if (local) { if (Script->GetPluginName() == Caller->GetPluginName()) { R = FutureWait(Script.get(), Script->GetRegistered(Event), arg, Wait); - Type = R.type().name(); - if (Type.find("int") != std::string::npos) { + if (R.type() == typeid(int)) { if (std::any_cast(R)) Ret++; } else if (Event == "onPlayerAuth") @@ -90,8 +88,7 @@ std::any TriggerLuaEvent(const std::string& Event, bool local, TLuaFile* Caller, } } else { R = FutureWait(Script.get(), Script->GetRegistered(Event), arg, Wait); - Type = R.type().name(); - if (Type.find("int") != std::string::npos) { + if (R.type() == typeid(int)) { if (std::any_cast(R)) Ret++; } else if (Event == "onPlayerAuth") diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 82cf445..474a438 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -327,11 +327,10 @@ void TNetwork::Authentication(SOCKET TCPSock) { auto arg = std::make_unique(TLuaArg { { Client->GetName(), Client->GetRoles(), Client->IsGuest() } }); std::any Res = TriggerLuaEvent("onPlayerAuth", false, nullptr, std::move(arg), true); - std::string Type = Res.type().name(); - if (Type.find("int") != std::string::npos && std::any_cast(Res)) { + if (Res.type() == typeid(int) && std::any_cast(Res)) { ClientKick(*Client, "you are not allowed on the server!"); return; - } else if (Type.find("string") != std::string::npos) { + } else if (Res.type() == typeid(std::string)) { ClientKick(*Client, std::any_cast(Res)); return; } diff --git a/src/TServer.cpp b/src/TServer.cpp index e52fe64..4e90b2d 100644 --- a/src/TServer.cpp +++ b/src/TServer.cpp @@ -164,10 +164,10 @@ void TServer::HandleEvent(TClient& c, const std::string& Data) { a++; } } -bool TServer::IsUnicycle(TClient &c, const std::string &CarJson) { +bool TServer::IsUnicycle(TClient& c, const std::string& CarJson) { rapidjson::Document Car; Car.Parse(CarJson.c_str(), CarJson.size()); - if(Car.HasParseError()){ + if (Car.HasParseError()) { error("Failed to parse vehicle data -> " + CarJson); } else if (Car["jbm"].IsString() && std::string(Car["jbm"].GetString()) == "unicycle") { return true; @@ -176,11 +176,11 @@ bool TServer::IsUnicycle(TClient &c, const std::string &CarJson) { } 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; } - if(IsUnicycle(c,CarJson)){ + if (IsUnicycle(c, CarJson)) { c.SetUnicycleID(ID); return true; } @@ -239,12 +239,12 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ std::make_unique(TLuaArg { { c.GetID(), VID, Packet.substr(3) } }), true); - if ((c.GetUnicycleID() != VID || IsUnicycle(c,Packet.substr(Packet.find('{')))) + if ((c.GetUnicycleID() != VID || IsUnicycle(c, Packet.substr(Packet.find('{')))) && std::any_cast(Res) == 0) { Network.SendToAll(&c, Packet, false, true); Apply(c, VID, Packet); } else { - if(c.GetUnicycleID() == VID){ + if (c.GetUnicycleID() == VID) { c.SetUnicycleID(-1); } std::string Destroy = "Od:" + std::to_string(c.GetID()) + "-" + std::to_string(VID); @@ -266,7 +266,7 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Networ VID = stoi(vid); } if (PID != -1 && VID != -1 && PID == c.GetID()) { - if(c.GetUnicycleID() == VID){ + if (c.GetUnicycleID() == VID) { c.SetUnicycleID(-1); } Network.SendToAll(nullptr, Packet, true, true);