mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
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
This commit is contained in:
parent
a1346c916e
commit
52ba1f867e
13 changed files with 107 additions and 113 deletions
|
@ -2511,52 +2511,52 @@ void ClientEnvironment::step(float dtime)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Drowning
|
||||
*/
|
||||
if(m_drowning_interval.step(dtime, 2.0))
|
||||
{
|
||||
v3f pf = lplayer->getPosition();
|
||||
// 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);
|
||||
}
|
||||
|
||||
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;
|
||||
// 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue