Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refine movement anticheat again (#7004)
* Account for walking speed in vertical dir
* Avoid undefined behaviour due to division-by-zero
  • Loading branch information
sfan5 authored and SmallJoker committed Feb 2, 2018
1 parent 49b65a5 commit cf0bceb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/content_sao.cpp
Expand Up @@ -1414,6 +1414,12 @@ bool PlayerSAO::checkMovementCheat()
// until this can be verified correctly, tolerate higher jumping speeds
player_max_jump *= 2.0;

// Don't divide by zero!
if (player_max_walk < 0.0001f)
player_max_walk = 0.0001f;
if (player_max_jump < 0.0001f)
player_max_jump = 0.0001f;

v3f diff = (m_base_position - m_last_good_position);
float d_vert = diff.Y;
diff.Y = 0;
Expand All @@ -1422,8 +1428,11 @@ bool PlayerSAO::checkMovementCheat()

// FIXME: Checking downwards movement is not easily possible currently,
// the server could calculate speed differences to examine the gravity
if (d_vert > 0)
required_time = MYMAX(required_time, d_vert / player_max_jump);
if (d_vert > 0) {
// In certain cases (water, ladders) walking speed is applied vertically
float s = MYMAX(player_max_jump, player_max_walk);
required_time = MYMAX(required_time, d_vert / s);
}

if (m_move_pool.grab(required_time)) {
m_last_good_position = m_base_position;
Expand Down

0 comments on commit cf0bceb

Please sign in to comment.