Add server-side enforcement of the 'fast' privilege; also fix client checking 'fly...
authorPerttu Ahola <celeron55@gmail.com>
Sat, 31 Mar 2012 14:08:39 +0000 (17:08 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sat, 31 Mar 2012 14:08:39 +0000 (17:08 +0300)
src/content_sao.cpp
src/content_sao.h
src/localplayer.cpp
src/server.cpp

index 0f3b8829e85821d2dcc93f2889fd6588510b087e..b05ad31d1650a52c1556c1b1336d85d004961dc1 100644 (file)
@@ -747,7 +747,8 @@ 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_):
+PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
+               const std::set<std::string> &privs):
        ServerActiveObject(env_, v3f(0,0,0)),
        m_player(player_),
        m_peer_id(peer_id_),
@@ -759,6 +760,8 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_):
        m_position_not_sent(false),
        m_armor_groups_sent(false),
        m_properties_sent(true),
+       m_privs(privs),
+       // public
        m_teleported(false),
        m_inventory_not_sent(false),
        m_hp_not_sent(false),
@@ -872,10 +875,19 @@ void PlayerSAO::step(float dtime, bool send_recommended)
                explosion.
        */
 
-       //float player_max_speed = BS * 4.0; // Normal speed
-       float player_max_speed = BS * 20; // Fast speed
-       float player_max_speed_up = BS * 20;
-       player_max_speed *= 2.5; // Tolerance
+       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;
index f3b9f8b2f353af6641fddd20fa9dfc998ebfb3c9..55d0637ae4706ffcbaeffc1d4a359b41fd635027 100644 (file)
@@ -105,7 +105,8 @@ private:
 class PlayerSAO : public ServerActiveObject
 {
 public:
-       PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_);
+       PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
+                       const std::set<std::string> &privs);
        ~PlayerSAO();
        u8 getType() const
        { return ACTIVEOBJECT_TYPE_PLAYER; }
@@ -182,6 +183,10 @@ public:
                m_time_from_last_punch = 0.0;
                return r;
        }
+       void updatePrivileges(const std::set<std::string> &privs)
+       {
+               m_privs = privs;
+       }
 
 private:
        std::string getPropertyPacket();
@@ -198,6 +203,8 @@ private:
        bool m_armor_groups_sent;
        bool m_properties_sent;
        struct ObjectProperties m_prop;
+       // Cached privileges for enforcement
+       std::set<std::string> m_privs;
 
 public:
        // Some flags used by Server
index bbe447a6c3f8cc5d096b9141d1585fa333561651..9ee088a9f6ccd62398a01131112bf7be628e8147 100644 (file)
@@ -496,7 +496,7 @@ void LocalPlayer::applyControl(float dtime)
        v3f speed = v3f(0,0,0);
        
        bool fly_allowed = m_gamedef->checkLocalPrivilege("fly");
-       bool fast_allowed = m_gamedef->checkLocalPrivilege("fly");
+       bool fast_allowed = m_gamedef->checkLocalPrivilege("fast");
 
        bool free_move = fly_allowed && g_settings->getBool("free_move");
        bool fast_move = fast_allowed && g_settings->getBool("fast_move");
index d6357e41607f8fb61e2f935398737dfd3034cf72..b015e103e9cd5791f0275cf6d1c0fa6308d388dd 100644 (file)
@@ -4315,13 +4315,16 @@ void Server::reportPrivsModified(const std::string &name)
                                i = m_clients.getIterator();
                                i.atEnd() == false; i++){
                        RemoteClient *client = i.getNode()->getValue();
-                       SendPlayerPrivileges(client->peer_id);
+                       Player *player = m_env->getPlayer(client->peer_id);
+                       reportPrivsModified(player->getName());
                }
        } else {
                Player *player = m_env->getPlayer(name.c_str());
                if(!player)
                        return;
                SendPlayerPrivileges(player->peer_id);
+               player->getPlayerSAO()->updatePrivileges(
+                               getPlayerEffectivePrivs(name));
        }
 }
 
@@ -4520,7 +4523,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);
+       PlayerSAO *playersao = new PlayerSAO(m_env, player, peer_id,
+                       getPlayerEffectivePrivs(player->getName()));
 
        /* Add object to environment */
        m_env->addActiveObject(playersao);