summaryrefslogtreecommitdiff
path: root/src/environment.cpp
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2017-01-01 16:13:01 +0100
committerLoic Blot <loic.blot@unix-experience.fr>2017-01-01 23:11:26 +0100
commit52ba1f867e5edb579a59a44fbb8286d4f1e54931 (patch)
treed95e2032d3fcf18bd972cc018e6b44470664d75c /src/environment.cpp
parenta1346c916e1d0f0cde2ccecc680857896c717a3d (diff)
downloadminetest-52ba1f867e5edb579a59a44fbb8286d4f1e54931.tar.gz
minetest-52ba1f867e5edb579a59a44fbb8286d4f1e54931.tar.bz2
minetest-52ba1f867e5edb579a59a44fbb8286d4f1e54931.zip
Breath cheat fix: server side
Breath is now handled server side. Changing this behaviour required some modifications to core: * Ignore TOSERVER_BREATH package, marking it as obsolete * Clients doesn't send the breath to server anymore * Use PlayerSAO pointer instead of peer_id in Server::SendPlayerBreath to prevent a useless lookup (little perf gain) * drop a useless static_cast in emergePlayer
Diffstat (limited to 'src/environment.cpp')
-rw-r--r--src/environment.cpp84
1 files changed, 42 insertions, 42 deletions
diff --git a/src/environment.cpp b/src/environment.cpp
index 707d89659..ac9b5b079 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -2511,51 +2511,51 @@ void ClientEnvironment::step(float dtime)
}
}
- /*
- Drowning
- */
- if(m_drowning_interval.step(dtime, 2.0))
- {
- v3f pf = lplayer->getPosition();
-
- // head
- v3s16 p = floatToInt(pf + v3f(0, BS*1.6, 0), BS);
- MapNode n = m_map->getNodeNoEx(p);
- ContentFeatures c = m_gamedef->ndef()->get(n);
- u8 drowning_damage = c.drowning;
- if(drowning_damage > 0 && lplayer->hp > 0){
- u16 breath = lplayer->getBreath();
- if(breath > 10){
- breath = 11;
- }
- if(breath > 0){
- breath -= 1;
+ // Protocol v29 make this behaviour obsolete
+ if (((Client*) getGameDef())->getProtoVersion() < 29) {
+ /*
+ Drowning
+ */
+ if (m_drowning_interval.step(dtime, 2.0)) {
+ v3f pf = lplayer->getPosition();
+
+ // head
+ v3s16 p = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
+ MapNode n = m_map->getNodeNoEx(p);
+ ContentFeatures c = m_gamedef->ndef()->get(n);
+ u8 drowning_damage = c.drowning;
+ if (drowning_damage > 0 && lplayer->hp > 0) {
+ u16 breath = lplayer->getBreath();
+ if (breath > 10) {
+ breath = 11;
+ }
+ if (breath > 0) {
+ breath -= 1;
+ }
+ lplayer->setBreath(breath);
+ updateLocalPlayerBreath(breath);
}
- lplayer->setBreath(breath);
- updateLocalPlayerBreath(breath);
- }
- if(lplayer->getBreath() == 0 && drowning_damage > 0){
- damageLocalPlayer(drowning_damage, true);
+ if (lplayer->getBreath() == 0 && drowning_damage > 0) {
+ damageLocalPlayer(drowning_damage, true);
+ }
}
- }
- if(m_breathing_interval.step(dtime, 0.5))
- {
- v3f pf = lplayer->getPosition();
-
- // head
- v3s16 p = floatToInt(pf + v3f(0, BS*1.6, 0), BS);
- MapNode n = m_map->getNodeNoEx(p);
- ContentFeatures c = m_gamedef->ndef()->get(n);
- if (!lplayer->hp){
- lplayer->setBreath(11);
- }
- else if(c.drowning == 0){
- u16 breath = lplayer->getBreath();
- if(breath <= 10){
- breath += 1;
- lplayer->setBreath(breath);
- updateLocalPlayerBreath(breath);
+ if (m_breathing_interval.step(dtime, 0.5)) {
+ v3f pf = lplayer->getPosition();
+
+ // head
+ v3s16 p = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
+ MapNode n = m_map->getNodeNoEx(p);
+ ContentFeatures c = m_gamedef->ndef()->get(n);
+ if (!lplayer->hp) {
+ lplayer->setBreath(11);
+ } else if (c.drowning == 0) {
+ u16 breath = lplayer->getBreath();
+ if (breath <= 10) {
+ breath += 1;
+ lplayer->setBreath(breath);
+ updateLocalPlayerBreath(breath);
+ }
}
}
}