From 359faee6964c6e9fa22c893b95c6cf5daacd7d33 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 10 Mar 2022 01:27:16 +0100 Subject: [PATCH] Fix Unicycle "infinite spawning" bug --- src/TServer.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/TServer.cpp b/src/TServer.cpp index a4328e2..cee40b3 100644 --- a/src/TServer.cpp +++ b/src/TServer.cpp @@ -174,7 +174,7 @@ bool TServer::IsUnicycle(TClient& c, const std::string& CarJson) { try { auto Car = nlohmann::json::parse(CarJson); const std::string jbm = "jbm"; - if (Car.contains(jbm) && Car["jbm"].is_string() && Car["jbm"] == "unicycle") { + if (Car.contains(jbm) && Car[jbm].is_string() && Car[jbm] == "unicycle") { return true; } } catch (const std::exception& e) { @@ -184,17 +184,12 @@ 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) { - return true; - } - - if (IsUnicycle(c, CarJson)) { + if (IsUnicycle(c, CarJson) && c.GetUnicycleID() < 0) { c.SetUnicycleID(ID); return true; + } else { + return c.GetCarCount() < Application::Settings.MaxCars; } - - return Application::Settings.MaxCars > c.GetCarCount(); } void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Network) {