Don't apply player movement cheat detection in singleplayer
authorPerttu Ahola <celeron55@gmail.com>
Sun, 1 Apr 2012 10:19:50 +0000 (13:19 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 1 Apr 2012 10:19:50 +0000 (13:19 +0300)
src/content_sao.cpp
src/content_sao.h
src/server.cpp

index b05ad31d1650a52c1556c1b1336d85d004961dc1..810bd5a7c7e7ba83b9a8127a962c0f1c843e96c9 100644 (file)
@@ -748,7 +748,7 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
 // No prototype, PlayerSAO does not need to be deserialized
 
 PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
-               const std::set<std::string> &privs):
+               const std::set<std::string> &privs, bool is_singleplayer):
        ServerActiveObject(env_, v3f(0,0,0)),
        m_player(player_),
        m_peer_id(peer_id_),
@@ -761,6 +761,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
        m_armor_groups_sent(false),
        m_properties_sent(true),
        m_privs(privs),
+       m_is_singleplayer(is_singleplayer),
        // public
        m_teleported(false),
        m_inventory_not_sent(false),
@@ -865,51 +866,54 @@ void PlayerSAO::step(float dtime, bool send_recommended)
        }
 
        m_time_from_last_punch += dtime;
-
-       /*
-               Check player movements
-
-               NOTE: Actually the server should handle player physics like the
-               client does and compare player's position to what is calculated
-               on our side. This is required when eg. players fly due to an
-               explosion.
-       */
-
-       float player_max_speed = 0;
-       float player_max_speed_up = 0;
-       if(m_privs.count("fast") != 0){
-               // Fast speed
-               player_max_speed = BS * 20;
-               player_max_speed_up = BS * 20;
-       } else {
-               // Normal speed
-               player_max_speed = BS * 4.0;
-               player_max_speed_up = BS * 4.0;
-       }
-       // Tolerance
-       player_max_speed *= 2.5;
-       player_max_speed_up *= 2.5;
-
-       m_last_good_position_age += dtime;
-       if(m_last_good_position_age >= 1.0){
-               float age = m_last_good_position_age;
-               v3f diff = (m_player->getPosition() - m_last_good_position);
-               float d_vert = diff.Y;
-               diff.Y = 0;
-               float d_horiz = diff.getLength();
-               /*infostream<<m_player->getName()<<"'s horizontal speed is "
-                               <<(d_horiz/age)<<std::endl;*/
-               if(d_horiz <= age * player_max_speed &&
-                               (d_vert < 0 || d_vert < age * player_max_speed_up)){
-                       m_last_good_position = m_player->getPosition();
+       
+       if(!m_is_singleplayer)
+       {
+               /*
+                       Check player movements
+
+                       NOTE: Actually the server should handle player physics like the
+                       client does and compare player's position to what is calculated
+                       on our side. This is required when eg. players fly due to an
+                       explosion.
+               */
+
+               float player_max_speed = 0;
+               float player_max_speed_up = 0;
+               if(m_privs.count("fast") != 0){
+                       // Fast speed
+                       player_max_speed = BS * 20;
+                       player_max_speed_up = BS * 20;
                } else {
-                       actionstream<<"Player "<<m_player->getName()
-                                       <<" moved too fast; resetting position"
-                                       <<std::endl;
-                       m_player->setPosition(m_last_good_position);
-                       m_teleported = true;
+                       // Normal speed
+                       player_max_speed = BS * 4.0;
+                       player_max_speed_up = BS * 4.0;
+               }
+               // Tolerance
+               player_max_speed *= 2.5;
+               player_max_speed_up *= 2.5;
+
+               m_last_good_position_age += dtime;
+               if(m_last_good_position_age >= 1.0){
+                       float age = m_last_good_position_age;
+                       v3f diff = (m_player->getPosition() - m_last_good_position);
+                       float d_vert = diff.Y;
+                       diff.Y = 0;
+                       float d_horiz = diff.getLength();
+                       /*infostream<<m_player->getName()<<"'s horizontal speed is "
+                                       <<(d_horiz/age)<<std::endl;*/
+                       if(d_horiz <= age * player_max_speed &&
+                                       (d_vert < 0 || d_vert < age * player_max_speed_up)){
+                               m_last_good_position = m_player->getPosition();
+                       } else {
+                               actionstream<<"Player "<<m_player->getName()
+                                               <<" moved too fast; resetting position"
+                                               <<std::endl;
+                               m_player->setPosition(m_last_good_position);
+                               m_teleported = true;
+                       }
+                       m_last_good_position_age = 0;
                }
-               m_last_good_position_age = 0;
        }
 
        if(send_recommended == false)
index 55d0637ae4706ffcbaeffc1d4a359b41fd635027..d336c5eea90b900efbc97d78ace1f02a2a1a5eb1 100644 (file)
@@ -106,7 +106,7 @@ class PlayerSAO : public ServerActiveObject
 {
 public:
        PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
-                       const std::set<std::string> &privs);
+                       const std::set<std::string> &privs, bool is_singleplayer);
        ~PlayerSAO();
        u8 getType() const
        { return ACTIVEOBJECT_TYPE_PLAYER; }
@@ -183,9 +183,11 @@ public:
                m_time_from_last_punch = 0.0;
                return r;
        }
-       void updatePrivileges(const std::set<std::string> &privs)
+       void updatePrivileges(const std::set<std::string> &privs,
+                       bool is_singleplayer)
        {
                m_privs = privs;
+               m_is_singleplayer = is_singleplayer;
        }
 
 private:
@@ -205,6 +207,7 @@ private:
        struct ObjectProperties m_prop;
        // Cached privileges for enforcement
        std::set<std::string> m_privs;
+       bool m_is_singleplayer;
 
 public:
        // Some flags used by Server
index c06fcb0fd98777869fda7c35ce3defeecf96f92b..b33e2477e78f5d692b6a1eaf15148889a04acc86 100644 (file)
@@ -4323,7 +4323,8 @@ void Server::reportPrivsModified(const std::string &name)
                        return;
                SendPlayerPrivileges(player->peer_id);
                player->getPlayerSAO()->updatePrivileges(
-                               getPlayerEffectivePrivs(name));
+                               getPlayerEffectivePrivs(name),
+                               isSingleplayer());
        }
 }
 
@@ -4527,7 +4528,8 @@ PlayerSAO* Server::emergePlayer(const char *name, u16 peer_id)
                Create a new player active object
        */
        PlayerSAO *playersao = new PlayerSAO(m_env, player, peer_id,
-                       getPlayerEffectivePrivs(player->getName()));
+                       getPlayerEffectivePrivs(player->getName()),
+                       isSingleplayer());
 
        /* Add object to environment */
        m_env->addActiveObject(playersao);