]> git.lizzy.rs Git - minetest.git/commitdiff
Move f1000 sanitizing to the places that still use this type
authorsfan5 <sfan5@live.de>
Wed, 8 Jun 2022 17:33:46 +0000 (19:33 +0200)
committersfan5 <sfan5@live.de>
Thu, 14 Jul 2022 18:55:45 +0000 (20:55 +0200)
src/player.h
src/server/luaentity_sao.cpp
src/server/player_sao.cpp
src/staticobject.cpp
src/staticobject.h
src/util/serialize.h

index cc13570103873feb176673551b3f3f322cdcfd2f..beca82f66953025ac8a9123bfebf9b9ff24d1cd6 100644 (file)
@@ -141,7 +141,6 @@ class Player
 
        void setSpeed(v3f speed)
        {
-               clampToF1000(speed);
                m_speed = speed;
        }
 
index a0a8aede08fc043e42d20a0e8a0b8bcaa269667b..ab4a9e3f2bdf0c52ec92887f44435781fba27526 100644 (file)
@@ -290,7 +290,7 @@ void LuaEntitySAO::getStaticData(std::string *result) const
                os<<serializeString32(m_init_state);
        }
        writeU16(os, m_hp);
-       writeV3F1000(os, m_velocity);
+       writeV3F1000(os, clampToF1000(m_velocity));
        // yaw
        writeF1000(os, m_rotation.Y);
 
index c5f6d0a247108a608e0b193207ad0928dd72b614..a58a0397f0bb70b24c5fd9db99ace3127efb5523 100644 (file)
@@ -321,12 +321,6 @@ std::string PlayerSAO::generateUpdatePhysicsOverrideCommand() const
 
 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);
 
index 1160ec68f1c01dee8aa3c6791eec6ecf65ae09fc..f92995d0ba1cf28191c463da0aa060447e92d374 100644 (file)
@@ -28,12 +28,12 @@ StaticObject::StaticObject(const ServerActiveObject *s_obj, const v3f &pos_):
        s_obj->getStaticData(&data);
 }
 
-void StaticObject::serialize(std::ostream &os)
+void StaticObject::serialize(std::ostream &os) const
 {
        // type
        writeU8(os, type);
        // pos
-       writeV3F1000(os, pos);
+       writeV3F1000(os, clampToF1000(pos));
        // data
        os<<serializeString16(data);
 }
index 6fb486193c9790fc2727c7283d959e808fe0107b..03cd23cc8ebcacfa479e92ff16d2d231d6d04366 100644 (file)
@@ -37,7 +37,7 @@ struct StaticObject
        StaticObject() = default;
        StaticObject(const ServerActiveObject *s_obj, const v3f &pos_);
 
-       void serialize(std::ostream &os);
+       void serialize(std::ostream &os) const;
        void deSerialize(std::istream &is, u8 version);
 };
 
index 2203fff0ceb3e22abbaec76cdbf7fa3041c62ea2..4dc1a54c6100ae1d6369522144829ed6586b2b60 100644 (file)
@@ -439,16 +439,14 @@ MAKE_STREAM_WRITE_FXN(video::SColor, ARGB8, 4);
 //// More serialization stuff
 ////
 
-inline void clampToF1000(float &v)
+inline float clampToF1000(float v)
 {
-       v = core::clamp(v, F1000_MIN, F1000_MAX);
+       return core::clamp(v, F1000_MIN, F1000_MAX);
 }
 
-inline void clampToF1000(v3f &v)
+inline v3f clampToF1000(v3f v)
 {
-       clampToF1000(v.X);
-       clampToF1000(v.Y);
-       clampToF1000(v.Z);
+       return {clampToF1000(v.X), clampToF1000(v.Y), clampToF1000(v.Z)};
 }
 
 // Creates a string with the length as the first two bytes