Merge branch 'zesterer/anticheat' into 'master'

Emergency fixes to terrain persistence and anticheat

See merge request veloren/veloren!4006
This commit is contained in:
Marcel 2023-07-01 12:15:32 +00:00
commit 59e242dfb8
2 changed files with 7 additions and 3 deletions

View File

@ -409,6 +409,10 @@ impl<'a> System<'a> for Sys {
break 'rejection Some(Rejection::TooFast { vel: new_vel.0 });
}
// How far the player is permitted to stray from the correct position (perhaps due to
// latency problems).
const POSITION_THRESHOLD: f32 = 16.0;
// The position can either be sensible with respect to either the old or the new
// velocity such that we don't punish for edge cases after a sudden change
let is_position_ok = [old_vel.0, new_vel.0]
@ -424,7 +428,7 @@ impl<'a> System<'a> for Sys {
.projected_point(rpos)
// + 1.5 accounts for minor changes in position without corresponding
// velocity like block hopping/snapping
.distance_squared(rpos) < (rpos.magnitude() * 0.5 + 1.5).powi(2)
.distance_squared(rpos) < (rpos.magnitude() * 0.5 + 1.5 + POSITION_THRESHOLD).powi(2)
});
if !is_position_ok {
@ -436,8 +440,8 @@ impl<'a> System<'a> for Sys {
};
if let Some(rejection) = rejection {
// TODO: Log when false positives aren't generated often
let alias = maybe_player.map(|p| &p.alias);
match rejection {
Rejection::TooFar { old, new } => warn!("Rejected physics for player {alias:?} (new position {new:?} is too far from old position {old:?})"),
Rejection::TooFast { vel } => warn!("Rejected physics for player {alias:?} (new velocity {vel:?} is too fast)"),

View File

@ -294,7 +294,7 @@ impl Limiter<Vec2<i32>, Chunk> for ByBlockLimiter {
}
fn on_removed(&mut self, _key: &mut Vec2<i32>, chunk: &mut Chunk) {
self.counted_blocks -= chunk.len();
self.counted_blocks = self.counted_blocks.saturating_sub(chunk.len());
}
fn on_cleared(&mut self) { self.counted_blocks = 0; }