fix bug in HandlePosition which caused the vehicle position not to be

saved properly
This commit is contained in:
Lion Kortlepel 2024-01-08 12:15:24 +01:00 committed by Lion
parent 9791b8875c
commit 0836fd3af8
2 changed files with 28 additions and 2 deletions

View File

@ -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 {

View File

@ -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);
}
}
}