From ed9fcb842ed381d112f09ef3af1036033d5f22bc Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Sun, 17 Sep 2023 20:07:12 -0400 Subject: [PATCH] antihacks: Patch fast/teleport vulnerability when attached to an entity * backported https://github.com/minetest/minetest/pull/10340/commits * Fixed God Mode * use core::radToDeg and a single v3f to multiply attachment_pos with * Use getLength() for diffvec --- src/content_sao.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 278dd0df6..8fad8ad11 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -1372,12 +1372,34 @@ std::string PlayerSAO::getPropertyPacket() bool PlayerSAO::checkMovementCheat() { - if (isAttached() || m_is_singleplayer || + if (m_is_singleplayer || g_settings->getBool("disable_anticheat")) { m_last_good_position = m_base_position; return false; } + if (UnitSAO *parent = dynamic_cast(getParent())) { + v3f attachment_pos; + { + int parent_id; + std::string bone; + v3f attachment_rot; + getAttachment(&parent_id, &bone, &attachment_pos, &attachment_rot); + } + v3f parent_pos = parent->getBasePosition(); + f32 diff = m_base_position.getDistanceFromSQ(parent_pos) - attachment_pos.getLengthSQ(); + const f32 maxdiff = 4.0f * BS; // fair trade-off value for various latencies + + if (diff > maxdiff * maxdiff) { + setBasePosition(parent_pos); + actionstream << "Server: " << m_player->getName() + << " moved away from parent; diff=" << sqrtf(diff) / BS + << " resetting position." << std::endl; + return true; + } + // Player movement is locked to the entity. Skip further checks + return false; + } bool cheated = false; /* Check player movements