1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-11-04 16:35:03 -05:00

Add server-side enforcement of the 'fast' privilege; also fix client checking 'fly' instead of 'fast'

This commit is contained in:
Perttu Ahola 2012-03-31 17:08:39 +03:00
parent 0fbef74f31
commit 13159c1a48
4 changed files with 32 additions and 9 deletions

View File

@ -747,7 +747,8 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
// No prototype, PlayerSAO does not need to be deserialized // 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)), ServerActiveObject(env_, v3f(0,0,0)),
m_player(player_), m_player(player_),
m_peer_id(peer_id_), m_peer_id(peer_id_),
@ -759,6 +760,8 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_):
m_position_not_sent(false), m_position_not_sent(false),
m_armor_groups_sent(false), m_armor_groups_sent(false),
m_properties_sent(true), m_properties_sent(true),
m_privs(privs),
// public
m_teleported(false), m_teleported(false),
m_inventory_not_sent(false), m_inventory_not_sent(false),
m_hp_not_sent(false), m_hp_not_sent(false),
@ -872,10 +875,19 @@ void PlayerSAO::step(float dtime, bool send_recommended)
explosion. explosion.
*/ */
//float player_max_speed = BS * 4.0; // Normal speed float player_max_speed = 0;
float player_max_speed = BS * 20; // Fast speed float player_max_speed_up = 0;
float player_max_speed_up = BS * 20; if(m_privs.count("fast") != 0){
player_max_speed *= 2.5; // Tolerance // 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; player_max_speed_up *= 2.5;
m_last_good_position_age += dtime; m_last_good_position_age += dtime;

View File

@ -105,7 +105,8 @@ private:
class PlayerSAO : public ServerActiveObject class PlayerSAO : public ServerActiveObject
{ {
public: public:
PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_); PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
const std::set<std::string> &privs);
~PlayerSAO(); ~PlayerSAO();
u8 getType() const u8 getType() const
{ return ACTIVEOBJECT_TYPE_PLAYER; } { return ACTIVEOBJECT_TYPE_PLAYER; }
@ -182,6 +183,10 @@ public:
m_time_from_last_punch = 0.0; m_time_from_last_punch = 0.0;
return r; return r;
} }
void updatePrivileges(const std::set<std::string> &privs)
{
m_privs = privs;
}
private: private:
std::string getPropertyPacket(); std::string getPropertyPacket();
@ -198,6 +203,8 @@ private:
bool m_armor_groups_sent; bool m_armor_groups_sent;
bool m_properties_sent; bool m_properties_sent;
struct ObjectProperties m_prop; struct ObjectProperties m_prop;
// Cached privileges for enforcement
std::set<std::string> m_privs;
public: public:
// Some flags used by Server // Some flags used by Server

View File

@ -496,7 +496,7 @@ void LocalPlayer::applyControl(float dtime)
v3f speed = v3f(0,0,0); v3f speed = v3f(0,0,0);
bool fly_allowed = m_gamedef->checkLocalPrivilege("fly"); 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 free_move = fly_allowed && g_settings->getBool("free_move");
bool fast_move = fast_allowed && g_settings->getBool("fast_move"); bool fast_move = fast_allowed && g_settings->getBool("fast_move");

View File

@ -4315,13 +4315,16 @@ void Server::reportPrivsModified(const std::string &name)
i = m_clients.getIterator(); i = m_clients.getIterator();
i.atEnd() == false; i++){ i.atEnd() == false; i++){
RemoteClient *client = i.getNode()->getValue(); RemoteClient *client = i.getNode()->getValue();
SendPlayerPrivileges(client->peer_id); Player *player = m_env->getPlayer(client->peer_id);
reportPrivsModified(player->getName());
} }
} else { } else {
Player *player = m_env->getPlayer(name.c_str()); Player *player = m_env->getPlayer(name.c_str());
if(!player) if(!player)
return; return;
SendPlayerPrivileges(player->peer_id); 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 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 */ /* Add object to environment */
m_env->addActiveObject(playersao); m_env->addActiveObject(playersao);