aboutsummaryrefslogtreecommitdiff
path: root/src/server/player_sao.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2022-06-07 21:27:05 +0200
committerGitHub <noreply@github.com>2022-06-07 21:27:05 +0200
commit3ac5a24b12950a2d92860d000b9477a11c1ad68b (patch)
treea4f6730c1bf7c93841b9a2bea63df3331c9ffe99 /src/server/player_sao.cpp
parent3107c9859114336989855a2c9ee2cbde0e88e3d3 (diff)
downloadminetest-3ac5a24b12950a2d92860d000b9477a11c1ad68b.tar.gz
minetest-3ac5a24b12950a2d92860d000b9477a11c1ad68b.tar.bz2
minetest-3ac5a24b12950a2d92860d000b9477a11c1ad68b.zip
Sanitize player position and speed server-side (#12396)
Diffstat (limited to 'src/server/player_sao.cpp')
-rw-r--r--src/server/player_sao.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp
index d076d5783..27759ba9d 100644
--- a/src/server/player_sao.cpp
+++ b/src/server/player_sao.cpp
@@ -319,8 +319,14 @@ std::string PlayerSAO::generateUpdatePhysicsOverrideCommand() const
return os.str();
}
-void PlayerSAO::setBasePosition(const v3f &position)
+void PlayerSAO::setBasePosition(v3f position)
{
+ // It's not entirely clear which parts of the network protocol still use
+ // v3f1000, but the script API enforces its bound on all float vectors
+ // (maybe it shouldn't?). For that reason we need to make sure the position
+ // isn't ever set to values that fail this restriction.
+ clampToF1000(position);
+
if (m_player && position != m_base_position)
m_player->setDirty(true);
@@ -344,7 +350,7 @@ void PlayerSAO::setPos(const v3f &pos)
setBasePosition(pos);
// Movement caused by this command is always valid
- m_last_good_position = pos;
+ m_last_good_position = getBasePosition();
m_move_pool.empty();
m_time_from_last_teleport = 0.0;
m_env->getGameDef()->SendMovePlayer(m_peer_id);
@@ -357,7 +363,7 @@ void PlayerSAO::moveTo(v3f pos, bool continuous)
setBasePosition(pos);
// Movement caused by this command is always valid
- m_last_good_position = pos;
+ m_last_good_position = getBasePosition();
m_move_pool.empty();
m_time_from_last_teleport = 0.0;
m_env->getGameDef()->SendMovePlayer(m_peer_id);