aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/luaentity_sao.cpp13
-rw-r--r--src/server/mods.cpp3
-rw-r--r--src/server/mods.h8
-rw-r--r--src/server/player_sao.cpp39
-rw-r--r--src/server/player_sao.h3
-rw-r--r--src/server/serveractiveobject.h3
-rw-r--r--src/server/serverinventorymgr.cpp12
-rw-r--r--src/server/serverinventorymgr.h2
-rw-r--r--src/server/unit_sao.cpp11
9 files changed, 51 insertions, 43 deletions
diff --git a/src/server/luaentity_sao.cpp b/src/server/luaentity_sao.cpp
index c7277491a..3bcbe107b 100644
--- a/src/server/luaentity_sao.cpp
+++ b/src/server/luaentity_sao.cpp
@@ -146,15 +146,11 @@ void LuaEntitySAO::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())
- {
- v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition();
- m_base_position = pos;
+ if (auto *parent = getParent()) {
+ m_base_position = parent->getBasePosition();
m_velocity = v3f(0,0,0);
m_acceleration = v3f(0,0,0);
- }
- else
- {
+ } else {
if(m_prop.physical){
aabb3f box = m_prop.collisionbox;
box.MinEdge *= BS;
@@ -492,6 +488,9 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
if(isAttached())
return;
+ // Send attachment updates instantly to the client prior updating position
+ sendOutdatedData();
+
m_last_sent_move_precision = m_base_position.getDistanceFrom(
m_last_sent_position);
m_last_sent_position_timer = 0;
diff --git a/src/server/mods.cpp b/src/server/mods.cpp
index cf1467648..83fa12da9 100644
--- a/src/server/mods.cpp
+++ b/src/server/mods.cpp
@@ -98,7 +98,8 @@ void ServerModManager::getModNames(std::vector<std::string> &modlist) const
void ServerModManager::getModsMediaPaths(std::vector<std::string> &paths) const
{
- for (const ModSpec &spec : m_sorted_mods) {
+ for (auto it = m_sorted_mods.crbegin(); it != m_sorted_mods.crend(); it++) {
+ const ModSpec &spec = *it;
fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "textures");
fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "sounds");
fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "media");
diff --git a/src/server/mods.h b/src/server/mods.h
index 54774bd86..8954bbf72 100644
--- a/src/server/mods.h
+++ b/src/server/mods.h
@@ -42,5 +42,13 @@ public:
void loadMods(ServerScripting *script);
const ModSpec *getModSpec(const std::string &modname) const;
void getModNames(std::vector<std::string> &modlist) const;
+ /**
+ * Recursively gets all paths of mod folders that can contain media files.
+ *
+ * Result is ordered in descending priority, ie. files from an earlier path
+ * should not be replaced by files from a latter one.
+ *
+ * @param paths result vector
+ */
void getModsMediaPaths(std::vector<std::string> &paths) const;
};
diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp
index 232c6a01d..0d31f2e0b 100644
--- a/src/server/player_sao.cpp
+++ b/src/server/player_sao.cpp
@@ -148,7 +148,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
void PlayerSAO::getStaticData(std::string * result) const
{
- FATAL_ERROR("Obsolete function");
+ FATAL_ERROR("This function shall not be called for PlayerSAO");
}
void PlayerSAO::step(float dtime, bool send_recommended)
@@ -260,10 +260,13 @@ void PlayerSAO::step(float dtime, bool send_recommended)
// otherwise it's calculated normally.
// If the object gets detached this comes into effect automatically from
// the last known origin.
- if (isAttached()) {
- v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition();
+ if (auto *parent = getParent()) {
+ v3f pos = parent->getBasePosition();
m_last_good_position = pos;
setBasePosition(pos);
+
+ if (m_player)
+ m_player->setSpeed(v3f());
}
if (!send_recommended)
@@ -456,6 +459,11 @@ u16 PlayerSAO::punch(v3f dir,
return hitparams.wear;
}
+void PlayerSAO::rightClick(ServerActiveObject *clicker)
+{
+ m_env->getScriptIface()->on_rightclickplayer(this, clicker);
+}
+
void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason)
{
if (hp == (s32)m_hp)
@@ -565,34 +573,11 @@ void PlayerSAO::setMaxSpeedOverride(const v3f &vel)
bool PlayerSAO::checkMovementCheat()
{
if (m_is_singleplayer ||
+ isAttached() ||
g_settings->getBool("disable_anticheat")) {
m_last_good_position = m_base_position;
return false;
}
- if (UnitSAO *parent = dynamic_cast<UnitSAO *>(getParent())) {
- v3f attachment_pos;
- {
- int parent_id;
- std::string bone;
- v3f attachment_rot;
- bool force_visible;
- getAttachment(&parent_id, &bone, &attachment_pos, &attachment_rot, &force_visible);
- }
-
- v3f parent_pos = parent->getBasePosition();
- f32 diff = m_base_position.getDistanceFromSQ(parent_pos) - attachment_pos.getLengthSQ();
- const f32 maxdiff = 4.0f * BS; // fair trade-off value for various latencies
-
- if (diff > maxdiff * maxdiff) {
- setBasePosition(parent_pos);
- actionstream << "Server: " << m_player->getName()
- << " moved away from parent; diff=" << sqrtf(diff) / BS
- << " resetting position." << std::endl;
- return true;
- }
- // Player movement is locked to the entity. Skip further checks
- return false;
- }
bool cheated = false;
/*
diff --git a/src/server/player_sao.h b/src/server/player_sao.h
index 3e178d4fc..8e2d8803f 100644
--- a/src/server/player_sao.h
+++ b/src/server/player_sao.h
@@ -111,10 +111,9 @@ public:
u16 punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher,
float time_from_last_punch);
- void rightClick(ServerActiveObject *clicker) {}
+ void rightClick(ServerActiveObject *clicker);
void setHP(s32 hp, const PlayerHPChangeReason &reason);
void setHPRaw(u16 hp) { m_hp = hp; }
- s16 readDamage();
u16 getBreath() const { return m_breath; }
void setBreath(const u16 breath, bool send = true);
diff --git a/src/server/serveractiveobject.h b/src/server/serveractiveobject.h
index 25653a1ad..51f445914 100644
--- a/src/server/serveractiveobject.h
+++ b/src/server/serveractiveobject.h
@@ -162,8 +162,6 @@ public:
{}
virtual const ItemGroupList &getArmorGroups() const
{ static ItemGroupList rv; return rv; }
- virtual void setPhysicsOverride(float physics_override_speed, float physics_override_jump, float physics_override_gravity)
- {}
virtual void setAnimation(v2f frames, float frame_speed, float frame_blend, bool frame_loop)
{}
virtual void getAnimation(v2f *frames, float *frame_speed, float *frame_blend, bool *frame_loop)
@@ -206,7 +204,6 @@ public:
}
std::string generateUpdateInfantCommand(u16 infant_id, u16 protocol_version);
- std::string generateUpdateNametagAttributesCommand(const video::SColor &color) const;
void dumpAOMessagesToQueue(std::queue<ActiveObjectMessage> &queue);
diff --git a/src/server/serverinventorymgr.cpp b/src/server/serverinventorymgr.cpp
index 555e01ec6..2a80c9bbe 100644
--- a/src/server/serverinventorymgr.cpp
+++ b/src/server/serverinventorymgr.cpp
@@ -168,6 +168,18 @@ bool ServerInventoryManager::removeDetachedInventory(const std::string &name)
return true;
}
+bool ServerInventoryManager::checkDetachedInventoryAccess(
+ const InventoryLocation &loc, const std::string &player) const
+{
+ SANITY_CHECK(loc.type == InventoryLocation::DETACHED);
+
+ const auto &inv_it = m_detached_inventories.find(loc.name);
+ if (inv_it == m_detached_inventories.end())
+ return false;
+
+ return inv_it->second.owner.empty() || inv_it->second.owner == player;
+}
+
void ServerInventoryManager::sendDetachedInventories(const std::string &peer_name,
bool incremental,
std::function<void(const std::string &, Inventory *)> apply_cb)
diff --git a/src/server/serverinventorymgr.h b/src/server/serverinventorymgr.h
index ccf6d3b2e..b6541bd3c 100644
--- a/src/server/serverinventorymgr.h
+++ b/src/server/serverinventorymgr.h
@@ -43,6 +43,8 @@ public:
Inventory *createDetachedInventory(const std::string &name, IItemDefManager *idef,
const std::string &player = "");
bool removeDetachedInventory(const std::string &name);
+ bool checkDetachedInventoryAccess(
+ const InventoryLocation &loc, const std::string &player) const;
void sendDetachedInventories(const std::string &peer_name, bool incremental,
std::function<void(const std::string &, Inventory *)> apply_cb);
diff --git a/src/server/unit_sao.cpp b/src/server/unit_sao.cpp
index 2371640ca..fa6c8f0f4 100644
--- a/src/server/unit_sao.cpp
+++ b/src/server/unit_sao.cpp
@@ -134,16 +134,21 @@ void UnitSAO::setAttachment(int parent_id, const std::string &bone, v3f position
int old_parent = m_attachment_parent_id;
m_attachment_parent_id = parent_id;
+
+ // The detach callbacks might call to setAttachment() again.
+ // Ensure the attachment params are applied after this callback is run.
+ if (parent_id != old_parent)
+ onDetach(old_parent);
+
+ m_attachment_parent_id = parent_id;
m_attachment_bone = bone;
m_attachment_position = position;
m_attachment_rotation = rotation;
m_force_visible = force_visible;
m_attachment_sent = false;
- if (parent_id != old_parent) {
- onDetach(old_parent);
+ if (parent_id != old_parent)
onAttach(parent_id);
- }
}
void UnitSAO::getAttachment(int *parent_id, std::string *bone, v3f *position,