aboutsummaryrefslogtreecommitdiff
path: root/src/network/packethandlers
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2015-03-02 17:31:31 +0100
committerLoic Blot <loic.blot@unix-experience.fr>2015-03-03 16:06:04 +0100
commit64ff966bae99813229dff6629fd9131a91ba7484 (patch)
treead63765181af40910873520fc45cfe56a1380779 /src/network/packethandlers
parent056e8f7839d72dfc2e8aa0a68c5d19d7cc30a282 (diff)
downloadminetest-64ff966bae99813229dff6629fd9131a91ba7484.tar.gz
minetest-64ff966bae99813229dff6629fd9131a91ba7484.tar.bz2
minetest-64ff966bae99813229dff6629fd9131a91ba7484.zip
Send Player HP when setHP (or a setHP caller) is called instead of looping and testing the state change.
Diffstat (limited to 'src/network/packethandlers')
-rw-r--r--src/network/packethandlers/server.cpp27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/network/packethandlers/server.cpp b/src/network/packethandlers/server.cpp
index 137327e0b..d9ba8c314 100644
--- a/src/network/packethandlers/server.cpp
+++ b/src/network/packethandlers/server.cpp
@@ -893,12 +893,7 @@ void Server::handleCommand_Damage(NetworkPacket* pkt)
<< std::endl;
playersao->setHP(playersao->getHP() - damage);
-
- if (playersao->getHP() == 0 && playersao->m_hp_not_sent)
- DiePlayer(pkt->getPeerId());
-
- if (playersao->m_hp_not_sent)
- SendPlayerHP(pkt->getPeerId());
+ SendPlayerHPOrDie(playersao->getPeerID(), playersao->getHP() == 0);
}
}
@@ -1048,8 +1043,8 @@ void Server::handleCommand_Respawn(NetworkPacket* pkt)
RespawnPlayer(pkt->getPeerId());
- actionstream<<player->getName()<<" respawns at "
- <<PP(player->getPosition()/BS)<<std::endl;
+ actionstream << player->getName() << " respawns at "
+ << PP(player->getPosition()/BS) << std::endl;
// ActiveObject is added to environment in AsyncRunStep after
// the previous addition has been succesfully removed
@@ -1234,8 +1229,24 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
).normalize();
float time_from_last_punch =
playersao->resetTimeFromLastPunch();
+
+ s16 src_original_hp = pointed_object->getHP();
+ s16 dst_origin_hp = playersao->getHP();
+
pointed_object->punch(dir, &toolcap, playersao,
time_from_last_punch);
+
+ // If the object is a player and its HP changed
+ if (src_original_hp != pointed_object->getHP() &&
+ pointed_object->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
+ SendPlayerHPOrDie(((PlayerSAO*)pointed_object)->getPeerID(),
+ pointed_object->getHP() == 0);
+ }
+
+ // If the puncher is a player and its HP changed
+ if (dst_origin_hp != playersao->getHP()) {
+ SendPlayerHPOrDie(playersao->getPeerID(), playersao->getHP() == 0);
+ }
}
} // action == 0