diff --git a/include/TServer.h b/include/TServer.h index 0967381..547073a 100644 --- a/include/TServer.h +++ b/include/TServer.h @@ -43,7 +43,7 @@ private: 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 HandlePosition(TClient& c, const std::string& Packet); + static bool HandlePosition(TClient& c, const std::string& Packet); }; struct BufferView { diff --git a/src/TServer.cpp b/src/TServer.cpp index 655eeb8..660fb2d 100644 --- a/src/TServer.cpp +++ b/src/TServer.cpp @@ -212,9 +212,11 @@ void TServer::GlobalParser(const std::weak_ptr& Client, std::vectorGetName(), LockedClient->GetID()); + } default: return; } @@ -433,10 +435,10 @@ void TServer::InsertClient(const std::shared_ptr& NewClient) { (void)mClients.insert(NewClient); } -void TServer::HandlePosition(TClient& c, const std::string& Packet) { +bool TServer::HandlePosition(TClient& c, const std::string& Packet) { if (Packet.size() < 3) { // invalid packet - return; + return false; } // Zp:serverVehicleID:data // Zp:0:data @@ -444,13 +446,13 @@ void TServer::HandlePosition(TClient& c, const std::string& Packet) { auto NameDataSep = withoutCode.find(':', 2); if (NameDataSep == std::string::npos || NameDataSep < 2) { // invalid packet - return; + return false; } // FIXME: ensure that -2 does what it should... it seems weird. std::string ServerVehicleID = withoutCode.substr(2, NameDataSep - 2); if (NameDataSep + 1 > withoutCode.size()) { // invalid packet - return; + return false; } std::string Data = withoutCode.substr(NameDataSep + 1); @@ -459,9 +461,11 @@ void TServer::HandlePosition(TClient& c, const std::string& Packet) { if (MaybePidVid) { int PID = -1; int VID = -1; - // FIXME: check that the VID and PID are valid, so that we don't waste memory std::tie(PID, VID) = MaybePidVid.value(); - - c.SetCarPosition(VID, Data); + if (PID == c.GetID()) { + c.SetCarPosition(VID, Data); + return true; + } } + return false; }