Partial damage cheat fix: node damages server side (#4981)
authorLoïc Blot <nerzhul@users.noreply.github.com>
Sat, 15 Apr 2017 07:25:43 +0000 (09:25 +0200)
committerGitHub <noreply@github.com>
Sat, 15 Apr 2017 07:25:43 +0000 (09:25 +0200)
* Damage cheat fix: server side

* Lava/Node damages overtime server side
* lava hurt interval is only for old protocol

src/clientenvironment.cpp
src/content_sao.cpp
src/content_sao.h

index 94c8e0dcb71f14ecfdaea18c027ba8994a4c8737..4a8bbb06651431c5f47f44b9f5c8ad8a88a0d41a 100644 (file)
@@ -252,37 +252,31 @@ void ClientEnvironment::step(float dtime)
                m_script->environment_step(dtime);
        }
 
-       /*
-               A quick draft of lava damage
-       */
-       if(m_lava_hurt_interval.step(dtime, 1.0))
-       {
-               v3f pf = lplayer->getPosition();
-
-               // Feet, middle and head
-               v3s16 p1 = floatToInt(pf + v3f(0, BS*0.1, 0), BS);
-               MapNode n1 = m_map->getNodeNoEx(p1);
-               v3s16 p2 = floatToInt(pf + v3f(0, BS*0.8, 0), BS);
-               MapNode n2 = m_map->getNodeNoEx(p2);
-               v3s16 p3 = floatToInt(pf + v3f(0, BS*1.6, 0), BS);
-               MapNode n3 = m_map->getNodeNoEx(p3);
-
-               u32 damage_per_second = 0;
-               damage_per_second = MYMAX(damage_per_second,
-                       m_client->ndef()->get(n1).damage_per_second);
-               damage_per_second = MYMAX(damage_per_second,
-                       m_client->ndef()->get(n2).damage_per_second);
-               damage_per_second = MYMAX(damage_per_second,
-                       m_client->ndef()->get(n3).damage_per_second);
-
-               if(damage_per_second != 0)
-               {
-                       damageLocalPlayer(damage_per_second, true);
-               }
-       }
-
        // Protocol v29 make this behaviour obsolete
        if (getGameDef()->getProtoVersion() < 29) {
+               if (m_lava_hurt_interval.step(dtime, 1.0)) {
+                       v3f pf = lplayer->getPosition();
+
+                       // Feet, middle and head
+                       v3s16 p1 = floatToInt(pf + v3f(0, BS * 0.1, 0), BS);
+                       MapNode n1 = m_map->getNodeNoEx(p1);
+                       v3s16 p2 = floatToInt(pf + v3f(0, BS * 0.8, 0), BS);
+                       MapNode n2 = m_map->getNodeNoEx(p2);
+                       v3s16 p3 = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
+                       MapNode n3 = m_map->getNodeNoEx(p3);
+
+                       u32 damage_per_second = 0;
+                       damage_per_second = MYMAX(damage_per_second,
+                               m_client->ndef()->get(n1).damage_per_second);
+                       damage_per_second = MYMAX(damage_per_second,
+                               m_client->ndef()->get(n2).damage_per_second);
+                       damage_per_second = MYMAX(damage_per_second,
+                               m_client->ndef()->get(n3).damage_per_second);
+
+                       if (damage_per_second != 0)
+                               damageLocalPlayer(damage_per_second, true);
+               }
+
                /*
                        Drowning
                */
index 282a6546c392b4d198c923d659748e2113e6b931..bb2387d1a9151ec395ff95b5fcc761b1c4cadad2 100644 (file)
@@ -941,6 +941,30 @@ void PlayerSAO::step(float dtime, bool send_recommended)
                        setBreath(m_breath + 1);
        }
 
+       if (m_node_hurt_interval.step(dtime, 1.0)) {
+               // Feet, middle and head
+               v3s16 p1 = floatToInt(m_base_position + v3f(0, BS*0.1, 0), BS);
+               MapNode n1 = m_env->getMap().getNodeNoEx(p1);
+               v3s16 p2 = floatToInt(m_base_position + v3f(0, BS*0.8, 0), BS);
+               MapNode n2 = m_env->getMap().getNodeNoEx(p2);
+               v3s16 p3 = floatToInt(m_base_position + v3f(0, BS*1.6, 0), BS);
+               MapNode n3 = m_env->getMap().getNodeNoEx(p3);
+
+               u32 damage_per_second = 0;
+               damage_per_second = MYMAX(damage_per_second,
+                       m_env->getGameDef()->ndef()->get(n1).damage_per_second);
+               damage_per_second = MYMAX(damage_per_second,
+                       m_env->getGameDef()->ndef()->get(n2).damage_per_second);
+               damage_per_second = MYMAX(damage_per_second,
+                       m_env->getGameDef()->ndef()->get(n3).damage_per_second);
+
+               if (damage_per_second != 0 && m_hp > 0) {
+                       s16 newhp = ((s32) damage_per_second > m_hp ? 0 : m_hp - damage_per_second);
+                       setHP(newhp);
+                       m_env->getGameDef()->SendPlayerHPOrDie(this);
+               }
+       }
+
        if (!m_properties_sent) {
                m_properties_sent = true;
                std::string str = getPropertyPacket();
index 918830266711fa50dd9f6f516a7c27e5da8a091d..c1b01b6ddb2906c5e73cb359abad14763b439cd1 100644 (file)
@@ -375,6 +375,7 @@ private:
        // Timers
        IntervalLimiter m_breathing_interval;
        IntervalLimiter m_drowning_interval;
+       IntervalLimiter m_node_hurt_interval;
 
        int m_wield_index;
        bool m_position_not_sent;