aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsavilli <78875209+savilli@users.noreply.github.com>2021-10-12 21:12:49 +0300
committerGitHub <noreply@github.com>2021-10-12 20:12:49 +0200
commit6ea558f8ac57a391b6f54c534441f930b0609cea (patch)
tree7d995996bfb6acfa9fb13a76419c3d09dd72a40e
parentecc6f4ba25cd49599922333a5f8d4b4ce368992d (diff)
downloadminetest-6ea558f8ac57a391b6f54c534441f930b0609cea.tar.gz
minetest-6ea558f8ac57a391b6f54c534441f930b0609cea.tar.bz2
minetest-6ea558f8ac57a391b6f54c534441f930b0609cea.zip
Fix player HP desync between client and server
-rw-r--r--src/network/serverpackethandler.cpp3
-rw-r--r--src/server/player_sao.cpp5
-rw-r--r--src/server/player_sao.h6
3 files changed, 10 insertions, 4 deletions
diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp
index 4c609644f..dc7be0e23 100644
--- a/src/network/serverpackethandler.cpp
+++ b/src/network/serverpackethandler.cpp
@@ -826,7 +826,8 @@ void Server::handleCommand_Damage(NetworkPacket* pkt)
<< std::endl;
PlayerHPChangeReason reason(PlayerHPChangeReason::FALL);
- playersao->setHP((s32)playersao->getHP() - (s32)damage, reason);
+ playersao->setHP((s32)playersao->getHP() - (s32)damage, reason, false);
+ SendPlayerHPOrDie(playersao, reason); // correct client side prediction
}
}
diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp
index d4d036726..690823bb7 100644
--- a/src/server/player_sao.cpp
+++ b/src/server/player_sao.cpp
@@ -462,7 +462,7 @@ void PlayerSAO::rightClick(ServerActiveObject *clicker)
m_env->getScriptIface()->on_rightclickplayer(this, clicker);
}
-void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason)
+void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason, bool send)
{
if (hp == (s32)m_hp)
return; // Nothing to do
@@ -490,7 +490,8 @@ void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason)
if ((hp == 0) != (oldhp == 0))
m_properties_sent = false;
- m_env->getGameDef()->SendPlayerHPOrDie(this, reason);
+ if (send)
+ m_env->getGameDef()->SendPlayerHPOrDie(this, reason);
}
void PlayerSAO::setBreath(const u16 breath, bool send)
diff --git a/src/server/player_sao.h b/src/server/player_sao.h
index 8e2d8803f..1429d7129 100644
--- a/src/server/player_sao.h
+++ b/src/server/player_sao.h
@@ -112,7 +112,11 @@ public:
u16 punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher,
float time_from_last_punch);
void rightClick(ServerActiveObject *clicker);
- void setHP(s32 hp, const PlayerHPChangeReason &reason);
+ void setHP(s32 hp, const PlayerHPChangeReason &reason) override
+ {
+ return setHP(hp, reason, true);
+ }
+ void setHP(s32 hp, const PlayerHPChangeReason &reason, bool send);
void setHPRaw(u16 hp) { m_hp = hp; }
u16 getBreath() const { return m_breath; }
void setBreath(const u16 breath, bool send = true);