]> git.lizzy.rs Git - minetest.git/commitdiff
Patch fast/teleport vulnerability when attached to an entity (#10340)
authorElias Fleckenstein <54945686+EliasFleckenstein03@users.noreply.github.com>
Sat, 26 Sep 2020 16:41:44 +0000 (18:41 +0200)
committerGitHub <noreply@github.com>
Sat, 26 Sep 2020 16:41:44 +0000 (18:41 +0200)
src/server/player_sao.cpp

index 67efed21045ece45aa35f4ad433be7ccf66d673c..e5b239bbaac0ec75915426ae2ffc037cb5062105 100644 (file)
@@ -558,11 +558,34 @@ void PlayerSAO::setMaxSpeedOverride(const v3f &vel)
 
 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<UnitSAO *>(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;
        /*