diff --git a/include/TServer.h b/include/TServer.h index 0967381..01ea940 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); + void HandlePosition(TClient& c, const std::string& Packet); }; struct BufferView { diff --git a/src/TServer.cpp b/src/TServer.cpp index 9a64189..ac06aa5 100644 --- a/src/TServer.cpp +++ b/src/TServer.cpp @@ -51,6 +51,30 @@ TEST_CASE("GetPidVid") { CHECK_EQ(pid, 10); CHECK_EQ(vid, 12); } + SUBCASE("Valid doubledigit 2") { + const auto MaybePidVid = GetPidVid("10-2"); + CHECK(MaybePidVid); + auto [pid, vid] = MaybePidVid.value(); + + CHECK_EQ(pid, 10); + CHECK_EQ(vid, 2); + } + SUBCASE("Valid doubledigit 3") { + const auto MaybePidVid = GetPidVid("33-23"); + CHECK(MaybePidVid); + auto [pid, vid] = MaybePidVid.value(); + + CHECK_EQ(pid, 33); + CHECK_EQ(vid, 23); + } + SUBCASE("Valid doubledigit 4") { + const auto MaybePidVid = GetPidVid("3-23"); + CHECK(MaybePidVid); + auto [pid, vid] = MaybePidVid.value(); + + CHECK_EQ(pid, 3); + CHECK_EQ(vid, 23); + } SUBCASE("Empty string") { const auto MaybePidVid = GetPidVid(""); CHECK(!MaybePidVid); @@ -451,6 +475,8 @@ void TServer::HandlePosition(TClient& c, const std::string& Packet) { // 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 (auto ClientPtr = GetClient(*this, PID); ClientPtr.has_value()) { + ClientPtr->lock()->SetCarPosition(VID, Data); + } } }