summaryrefslogtreecommitdiff
path: root/src/content_sao.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/content_sao.cpp')
-rw-r--r--src/content_sao.cpp404
1 files changed, 255 insertions, 149 deletions
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index 53bf3154f..77ab51a02 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serialization.h" // For compressZlib
#include "tool.h" // For ToolCapabilities
#include "gamedef.h"
-#include "player.h"
+#include "remoteplayer.h"
#include "server.h"
#include "scripting_game.h"
#include "genericobject.h"
@@ -118,14 +118,12 @@ LuaEntitySAO proto_LuaEntitySAO(NULL, v3f(0,0,0), "_prototype", "");
LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos,
const std::string &name, const std::string &state):
- ServerActiveObject(env, pos),
+ UnitSAO(env, pos),
m_init_name(name),
m_init_state(state),
m_registered(false),
- m_hp(-1),
m_velocity(0,0,0),
m_acceleration(0,0,0),
- m_yaw(0),
m_properties_sent(true),
m_last_sent_yaw(0),
m_last_sent_position(0,0,0),
@@ -156,6 +154,11 @@ LuaEntitySAO::~LuaEntitySAO()
if(m_registered){
m_env->getScriptIface()->luaentity_Remove(m_id);
}
+
+ for (UNORDERED_SET<u32>::iterator it = m_attached_particle_spawners.begin();
+ it != m_attached_particle_spawners.end(); ++it) {
+ m_env->deleteParticleSpawner(*it, false);
+ }
}
void LuaEntitySAO::addedToEnvironment(u32 dtime_s)
@@ -175,6 +178,8 @@ void LuaEntitySAO::addedToEnvironment(u32 dtime_s)
// Activate entity, supplying serialized state
m_env->getScriptIface()->
luaentity_Activate(m_id, m_init_state.c_str(), dtime_s);
+ } else {
+ m_prop.infotext = m_init_name;
}
}
@@ -345,8 +350,10 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
if(m_bone_position_sent == false){
m_bone_position_sent = true;
- for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
- std::string str = gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y);
+ for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
+ ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
+ std::string str = gob_cmd_update_bone_position((*ii).first,
+ (*ii).second.X, (*ii).second.Y);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push(aom);
@@ -376,15 +383,30 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
writeF1000(os, m_yaw);
writeS16(os, m_hp);
- writeU8(os, 4 + m_bone_position.size()); // number of messages stuffed in here
- os<<serializeLongString(getPropertyPacket()); // message 1
- os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
- os<<serializeLongString(gob_cmd_update_animation(
+ std::ostringstream msg_os(std::ios::binary);
+ msg_os << serializeLongString(getPropertyPacket()); // message 1
+ msg_os << serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
+ msg_os << serializeLongString(gob_cmd_update_animation(
m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3
- for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
- os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
+ for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
+ ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
+ msg_os << serializeLongString(gob_cmd_update_bone_position((*ii).first,
+ (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
+ }
+ msg_os << serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id,
+ m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
+ int message_count = 4 + m_bone_position.size();
+ for (UNORDERED_SET<int>::const_iterator ii = m_attachment_child_ids.begin();
+ (ii != m_attachment_child_ids.end()); ++ii) {
+ if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) {
+ message_count++;
+ msg_os << serializeLongString(gob_cmd_update_infant(*ii, obj->getSendType(),
+ obj->getClientInitializationData(protocol_version)));
+ }
}
- os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
+
+ writeU8(os, message_count);
+ os.write(msg_os.str().c_str(), msg_os.str().size());
}
else
{
@@ -492,7 +514,7 @@ void LuaEntitySAO::rightClick(ServerActiveObject *clicker)
m_env->getScriptIface()->luaentity_Rightclick(m_id, clicker);
}
-void LuaEntitySAO::setPos(v3f pos)
+void LuaEntitySAO::setPos(const v3f &pos)
{
if(isAttached())
return;
@@ -612,7 +634,7 @@ void LuaEntitySAO::removeAttachmentChild(int child_id)
m_attachment_child_ids.erase(child_id);
}
-std::set<int> LuaEntitySAO::getAttachmentChildIds()
+UNORDERED_SET<int> LuaEntitySAO::getAttachmentChildIds()
{
return m_attachment_child_ids;
}
@@ -647,16 +669,6 @@ v3f LuaEntitySAO::getAcceleration()
return m_acceleration;
}
-void LuaEntitySAO::setYaw(float yaw)
-{
- m_yaw = yaw;
-}
-
-float LuaEntitySAO::getYaw()
-{
- return m_yaw;
-}
-
void LuaEntitySAO::setTextureMod(const std::string &mod)
{
std::string str = gob_cmd_set_texture_mod(mod);
@@ -745,10 +757,9 @@ bool LuaEntitySAO::collideWithObjects(){
// No prototype, PlayerSAO does not need to be deserialized
-PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
- const std::set<std::string> &privs, bool is_singleplayer):
- ServerActiveObject(env_, v3f(0,0,0)),
- m_player(player_),
+PlayerSAO::PlayerSAO(ServerEnvironment *env_, u16 peer_id_, bool is_singleplayer):
+ UnitSAO(env_, v3f(0,0,0)),
+ m_player(NULL),
m_peer_id(peer_id_),
m_inventory(NULL),
m_damage(0),
@@ -760,7 +771,6 @@ 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),
m_is_singleplayer(is_singleplayer),
m_animation_speed(0),
m_animation_blend(0),
@@ -769,6 +779,10 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
m_bone_position_sent(false),
m_attachment_parent_id(0),
m_attachment_sent(false),
+ m_breath(PLAYER_MAX_BREATH),
+ m_pitch(0),
+ m_fov(0),
+ m_wanted_range(0),
// public
m_physics_override_speed(1),
m_physics_override_jump(1),
@@ -777,10 +791,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
m_physics_override_sneak_glitch(true),
m_physics_override_sent(false)
{
- assert(m_player); // pre-condition
assert(m_peer_id != 0); // pre-condition
- setBasePosition(m_player->getPosition());
- m_inventory = &m_player->inventory;
m_armor_groups["fleshy"] = 100;
m_prop.hp_max = PLAYER_MAX_HP;
@@ -799,13 +810,21 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
// end of default appearance
m_prop.is_visible = true;
m_prop.makes_footstep_sound = true;
+ m_hp = PLAYER_MAX_HP;
}
PlayerSAO::~PlayerSAO()
{
if(m_inventory != &m_player->inventory)
delete m_inventory;
+}
+void PlayerSAO::initialize(RemotePlayer *player, const std::set<std::string> &privs)
+{
+ assert(player);
+ m_player = player;
+ m_privs = privs;
+ m_inventory = &m_player->inventory;
}
std::string PlayerSAO::getDescription()
@@ -817,22 +836,22 @@ std::string PlayerSAO::getDescription()
void PlayerSAO::addedToEnvironment(u32 dtime_s)
{
ServerActiveObject::addedToEnvironment(dtime_s);
- ServerActiveObject::setBasePosition(m_player->getPosition());
+ ServerActiveObject::setBasePosition(m_base_position);
m_player->setPlayerSAO(this);
m_player->peer_id = m_peer_id;
- m_last_good_position = m_player->getPosition();
+ m_last_good_position = m_base_position;
}
// Called before removing from environment
void PlayerSAO::removingFromEnvironment()
{
ServerActiveObject::removingFromEnvironment();
- if(m_player->getPlayerSAO() == this)
- {
- m_player->setPlayerSAO(NULL);
- m_player->peer_id = 0;
- m_env->savePlayer((RemotePlayer*)m_player);
- m_env->removePlayer(m_player);
+ if (m_player->getPlayerSAO() == this) {
+ unlinkPlayerSessionAndSave();
+ for (UNORDERED_SET<u32>::iterator it = m_attached_particle_spawners.begin();
+ it != m_attached_particle_spawners.end(); ++it) {
+ m_env->deleteParticleSpawner(*it, false);
+ }
}
}
@@ -851,31 +870,47 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
os<<serializeString(m_player->getName()); // name
writeU8(os, 1); // is_player
writeS16(os, getId()); //id
- writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0));
- writeF1000(os, m_player->getYaw());
+ writeV3F1000(os, m_base_position + v3f(0,BS*1,0));
+ writeF1000(os, m_yaw);
writeS16(os, getHP());
- writeU8(os, 6 + m_bone_position.size()); // number of messages stuffed in here
- os<<serializeLongString(getPropertyPacket()); // message 1
- os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
- os<<serializeLongString(gob_cmd_update_animation(
+ std::ostringstream msg_os(std::ios::binary);
+ msg_os << serializeLongString(getPropertyPacket()); // message 1
+ msg_os << serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
+ msg_os << serializeLongString(gob_cmd_update_animation(
m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop)); // 3
- for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
- os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
+ for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
+ ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
+ msg_os << serializeLongString(gob_cmd_update_bone_position((*ii).first,
+ (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
}
- os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
- os<<serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed,
+ msg_os << serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id,
+ m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
+ msg_os << serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed,
m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak,
m_physics_override_sneak_glitch)); // 5
- os << serializeLongString(gob_cmd_update_nametag_attributes(m_prop.nametag_color)); // 6 (GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES) : Deprecated, for backwards compatibility only.
+ // (GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES) : Deprecated, for backwards compatibility only.
+ msg_os << serializeLongString(gob_cmd_update_nametag_attributes(m_prop.nametag_color)); // 6
+ int message_count = 6 + m_bone_position.size();
+ for (UNORDERED_SET<int>::const_iterator ii = m_attachment_child_ids.begin();
+ ii != m_attachment_child_ids.end(); ++ii) {
+ if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) {
+ message_count++;
+ msg_os << serializeLongString(gob_cmd_update_infant(*ii, obj->getSendType(),
+ obj->getClientInitializationData(protocol_version)));
+ }
+ }
+
+ writeU8(os, message_count);
+ os.write(msg_os.str().c_str(), msg_os.str().size());
}
else
{
writeU8(os, 0); // version
os<<serializeString(m_player->getName()); // name
writeU8(os, 1); // is_player
- writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0));
- writeF1000(os, m_player->getYaw());
+ writeV3F1000(os, m_base_position + v3f(0,BS*1,0));
+ writeF1000(os, m_yaw);
writeS16(os, getHP());
writeU8(os, 2); // number of messages stuffed in here
os<<serializeLongString(getPropertyPacket()); // message 1
@@ -921,7 +956,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
m_attachment_bone = "";
m_attachment_position = v3f(0,0,0);
m_attachment_rotation = v3f(0,0,0);
- m_player->setPosition(m_last_good_position);
+ setBasePosition(m_last_good_position);
((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id);
}
@@ -943,14 +978,13 @@ void PlayerSAO::step(float dtime, bool send_recommended)
// Each frame, parent position is copied if the object is attached, otherwise it's calculated normally
// If the object gets detached this comes into effect automatically from the last known origin
- if(isAttached())
- {
+ if (isAttached()) {
v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition();
m_last_good_position = pos;
- m_player->setPosition(pos);
+ setBasePosition(pos);
}
- if(send_recommended == false)
+ if (!send_recommended)
return;
// If the object is attached client-side, don't waste bandwidth sending its position to clients
@@ -962,12 +996,12 @@ void PlayerSAO::step(float dtime, bool send_recommended)
if(isAttached()) // Just in case we ever do send attachment position too
pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition();
else
- pos = m_player->getPosition() + v3f(0,BS*1,0);
+ pos = m_base_position + v3f(0,BS*1,0);
std::string str = gob_cmd_update_position(
pos,
v3f(0,0,0),
v3f(0,0,0),
- m_player->getYaw(),
+ m_yaw,
true,
false,
update_interval
@@ -977,7 +1011,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
m_messages_out.push(aom);
}
- if(m_armor_groups_sent == false) {
+ if (!m_armor_groups_sent) {
m_armor_groups_sent = true;
std::string str = gob_cmd_update_armor_groups(
m_armor_groups);
@@ -986,7 +1020,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
m_messages_out.push(aom);
}
- if(m_physics_override_sent == false){
+ if (!m_physics_override_sent) {
m_physics_override_sent = true;
std::string str = gob_cmd_update_physics_override(m_physics_override_speed,
m_physics_override_jump, m_physics_override_gravity,
@@ -996,7 +1030,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
m_messages_out.push(aom);
}
- if(m_animation_sent == false){
+ if (!m_animation_sent) {
m_animation_sent = true;
std::string str = gob_cmd_update_animation(
m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop);
@@ -1005,19 +1039,22 @@ void PlayerSAO::step(float dtime, bool send_recommended)
m_messages_out.push(aom);
}
- if(m_bone_position_sent == false){
+ if (!m_bone_position_sent) {
m_bone_position_sent = true;
- for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
- std::string str = gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y);
+ for (UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
+ ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
+ std::string str = gob_cmd_update_bone_position((*ii).first,
+ (*ii).second.X, (*ii).second.Y);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push(aom);
}
}
- if(m_attachment_sent == false){
+ if (!m_attachment_sent){
m_attachment_sent = true;
- std::string str = gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation);
+ std::string str = gob_cmd_update_attachment(m_attachment_parent_id,
+ m_attachment_bone, m_attachment_position, m_attachment_rotation);
// create message and add to list
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push(aom);
@@ -1026,16 +1063,20 @@ void PlayerSAO::step(float dtime, bool send_recommended)
void PlayerSAO::setBasePosition(const v3f &position)
{
+ if (m_player && position != m_base_position)
+ m_player->setDirty(true);
+
// This needs to be ran for attachments too
ServerActiveObject::setBasePosition(position);
m_position_not_sent = true;
}
-void PlayerSAO::setPos(v3f pos)
+void PlayerSAO::setPos(const v3f &pos)
{
if(isAttached())
return;
- m_player->setPosition(pos);
+
+ setBasePosition(pos);
// Movement caused by this command is always valid
m_last_good_position = pos;
((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id);
@@ -1045,21 +1086,54 @@ void PlayerSAO::moveTo(v3f pos, bool continuous)
{
if(isAttached())
return;
- m_player->setPosition(pos);
+
+ setBasePosition(pos);
// Movement caused by this command is always valid
m_last_good_position = pos;
((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id);
}
-void PlayerSAO::setYaw(float yaw)
+void PlayerSAO::setYaw(const float yaw)
+{
+ if (m_player && yaw != m_yaw)
+ m_player->setDirty(true);
+
+ UnitSAO::setYaw(yaw);
+}
+
+void PlayerSAO::setFov(const float fov)
+{
+ if (m_player && fov != m_fov)
+ m_player->setDirty(true);
+
+ m_fov = fov;
+}
+
+void PlayerSAO::setWantedRange(const s16 range)
+{
+ if (m_player && range != m_wanted_range)
+ m_player->setDirty(true);
+
+ m_wanted_range = range;
+}
+
+void PlayerSAO::setYawAndSend(const float yaw)
{
- m_player->setYaw(yaw);
+ setYaw(yaw);
((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id);
}
-void PlayerSAO::setPitch(float pitch)
+void PlayerSAO::setPitch(const float pitch)
+{
+ if (m_player && pitch != m_pitch)
+ m_player->setDirty(true);
+
+ m_pitch = pitch;
+}
+
+void PlayerSAO::setPitchAndSend(const float pitch)
{
- m_player->setPitch(pitch);
+ setPitch(pitch);
((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id);
}
@@ -1124,15 +1198,10 @@ int PlayerSAO::punch(v3f dir,
return hitparams.wear;
}
-void PlayerSAO::rightClick(ServerActiveObject *clicker)
+void PlayerSAO::rightClick(ServerActiveObject *)
{
}
-s16 PlayerSAO::getHP() const
-{
- return m_player->hp;
-}
-
s16 PlayerSAO::readDamage()
{
s16 damage = m_damage;
@@ -1142,10 +1211,9 @@ s16 PlayerSAO::readDamage()
void PlayerSAO::setHP(s16 hp)
{
- s16 oldhp = m_player->hp;
+ s16 oldhp = m_hp;
- s16 hp_change = m_env->getScriptIface()->on_player_hpchange(this,
- hp - oldhp);
+ s16 hp_change = m_env->getScriptIface()->on_player_hpchange(this, hp - oldhp);
if (hp_change == 0)
return;
hp = oldhp + hp_change;
@@ -1155,11 +1223,11 @@ void PlayerSAO::setHP(s16 hp)
else if (hp > PLAYER_MAX_HP)
hp = PLAYER_MAX_HP;
- if(hp < oldhp && g_settings->getBool("enable_damage") == false) {
+ if (hp < oldhp && !g_settings->getBool("enable_damage")) {
return;
}
- m_player->hp = hp;
+ m_hp = hp;
if (oldhp > hp)
m_damage += (oldhp - hp);
@@ -1169,14 +1237,12 @@ void PlayerSAO::setHP(s16 hp)
m_properties_sent = false;
}
-u16 PlayerSAO::getBreath() const
+void PlayerSAO::setBreath(const u16 breath)
{
- return m_player->getBreath();
-}
+ if (m_player && breath != m_breath)
+ m_player->setDirty(true);
-void PlayerSAO::setBreath(u16 breath)
-{
- m_player->setBreath(breath);
+ m_breath = breath;
}
void PlayerSAO::setArmorGroups(const ItemGroupList &armor_groups)
@@ -1257,7 +1323,7 @@ void PlayerSAO::removeAttachmentChild(int child_id)
m_attachment_child_ids.erase(child_id);
}
-std::set<int> PlayerSAO::getAttachmentChildIds()
+UNORDERED_SET<int> PlayerSAO::getAttachmentChildIds()
{
return m_attachment_child_ids;
}
@@ -1293,6 +1359,42 @@ std::string PlayerSAO::getWieldList() const
return "main";
}
+ItemStack PlayerSAO::getWieldedItem() const
+{
+ const Inventory *inv = getInventory();
+ ItemStack ret;
+ const InventoryList *mlist = inv->getList(getWieldList());
+ if (mlist && getWieldIndex() < (s32)mlist->getSize())
+ ret = mlist->getItem(getWieldIndex());
+ if (ret.name.empty()) {
+ const InventoryList *hlist = inv->getList("hand");
+ if (hlist)
+ ret = hlist->getItem(0);
+ }
+ return ret;
+}
+
+bool PlayerSAO::setWieldedItem(const ItemStack &item)
+{
+ Inventory *inv = getInventory();
+ if (inv) {
+ InventoryList *mlist = inv->getList(getWieldList());
+ if (mlist) {
+ ItemStack olditem = mlist->getItem(getWieldIndex());
+ if (olditem.name.empty()) {
+ InventoryList *hlist = inv->getList("hand");
+ if (hlist) {
+ hlist->changeItem(0, item);
+ return true;
+ }
+ }
+ mlist->changeItem(getWieldIndex(), item);
+ return true;
+ }
+ }
+ return false;
+}
+
int PlayerSAO::getWieldIndex() const
{
return m_wield_index;
@@ -1305,15 +1407,20 @@ void PlayerSAO::setWieldIndex(int i)
}
}
+// Erase the peer id and make the object for removal
void PlayerSAO::disconnected()
{
m_peer_id = 0;
m_removed = true;
- if(m_player->getPlayerSAO() == this)
- {
- m_player->setPlayerSAO(NULL);
- m_player->peer_id = 0;
- }
+}
+
+void PlayerSAO::unlinkPlayerSessionAndSave()
+{
+ assert(m_player->getPlayerSAO() == this);
+ m_player->peer_id = 0;
+ m_env->savePlayer(m_player);
+ m_player->setPlayerSAO(NULL);
+ m_env->removePlayer(m_player);
}
std::string PlayerSAO::getPropertyPacket()
@@ -1324,66 +1431,65 @@ std::string PlayerSAO::getPropertyPacket()
bool PlayerSAO::checkMovementCheat()
{
+ if (isAttached() || m_is_singleplayer ||
+ g_settings->getBool("disable_anticheat")) {
+ m_last_good_position = m_base_position;
+ return false;
+ }
+
bool cheated = false;
- if(isAttached() || m_is_singleplayer ||
- g_settings->getBool("disable_anticheat"))
- {
- m_last_good_position = m_player->getPosition();
+ /*
+ 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. Altough a node-based alternative might be possible
+ too, and much more lightweight.
+ */
+
+ float player_max_speed = 0;
+
+ if (m_privs.count("fast") != 0) {
+ // Fast speed
+ player_max_speed = m_player->movement_speed_fast * m_physics_override_speed;
+ } else {
+ // Normal speed
+ player_max_speed = m_player->movement_speed_walk * m_physics_override_speed;
}
- else
- {
- /*
- 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. Altough a node-based alternative might be possible
- too, and much more lightweight.
- */
-
- float player_max_speed = 0;
- if(m_privs.count("fast") != 0){
- // Fast speed
- player_max_speed = m_player->movement_speed_fast;
- } else {
- // Normal speed
- player_max_speed = m_player->movement_speed_walk;
- }
- // Tolerance. With the lag pool we shouldn't need it.
- //player_max_speed *= 2.5;
- //player_max_speed_up *= 2.5;
-
- v3f diff = (m_player->getPosition() - m_last_good_position);
- float d_vert = diff.Y;
- diff.Y = 0;
- float d_horiz = diff.getLength();
- float required_time = d_horiz/player_max_speed;
- if(d_vert > 0 && d_vert/player_max_speed > required_time)
- required_time = d_vert/player_max_speed;
- if(m_move_pool.grab(required_time)){
- 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);
- cheated = true;
- }
+ // Tolerance. The lag pool does this a bit.
+ //player_max_speed *= 2.5;
+
+ v3f diff = (m_base_position - m_last_good_position);
+ float d_vert = diff.Y;
+ diff.Y = 0;
+ float d_horiz = diff.getLength();
+ float required_time = d_horiz / player_max_speed;
+
+ if (d_vert > 0 && d_vert / player_max_speed > required_time)
+ required_time = d_vert / player_max_speed; // Moving upwards
+
+ if (m_move_pool.grab(required_time)) {
+ m_last_good_position = m_base_position;
+ } else {
+ actionstream << "Player " << m_player->getName()
+ << " moved too fast; resetting position"
+ << std::endl;
+ setBasePosition(m_last_good_position);
+ cheated = true;
}
return cheated;
}
-bool PlayerSAO::getCollisionBox(aabb3f *toset) {
- //update collision box
- *toset = m_player->getCollisionbox();
-
+bool PlayerSAO::getCollisionBox(aabb3f *toset)
+{
+ *toset = aabb3f(-BS * 0.30, 0.0, -BS * 0.30, BS * 0.30, BS * 1.75, BS * 0.30);
toset->MinEdge += m_base_position;
toset->MaxEdge += m_base_position;
-
return true;
}
-bool PlayerSAO::collideWithObjects(){
+bool PlayerSAO::collideWithObjects()
+{
return true;
}