ANTI CHEAT DOESN'T TRIP ON STAIRS ANYMORE 🎉

This commit fixes the 5+ years-old bug with the movement anti-cheat that everyone has complained about: sprinting on stairs causes rubberbanding.
This commit addresses this problem at long last, along with a handful of precursor commits that were necessary to fix this problem:
- dac76f0e0f14d9beae3e55491ab9f61353db1b68
- 89fe8f7f10716fed6193646984a7e2d28f6f6ce5
- 2d77b1e3649d11a6072fbd1dbf88574b6ebf1af3

Additionally, these changes now allow the anti-cheat to be accurate to at least 0.001 of a block, perhaps even better. I didn't commit a change to the threshold here, but it was instrumental to pinning down the exact nature of these bugs.

This closes #1475, at long last.
This commit is contained in:
Dylan K. Taylor 2020-09-03 14:27:11 +01:00
parent 17bee5e349
commit 9365525efa
2 changed files with 9 additions and 3 deletions

View File

@ -1601,10 +1601,15 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$dy = $newPos->y - $this->y;
$dz = $newPos->z - $this->z;
//the client likes to clip into blocks like stairs, but we do full server-side prediction of that without
//help from the client's position changes, so we deduct the expected clip height from the moved distance.
$expectedClipDistance = $this->ySize * (1 - self::STEP_CLIP_MULTIPLIER);
$dy -= $expectedClipDistance;
$this->move($dx, $dy, $dz);
$diff = $this->distanceSquared($newPos);
//TODO: Explore lowering this threshold now that stairs work properly.
if($this->isSurvival() and $diff > 0.0625){
$ev = new PlayerIllegalMoveEvent($this, $newPos, new Vector3($this->lastX, $this->lastY, $this->lastZ));
$ev->setCancelled($this->allowMovementCheats);
@ -1614,7 +1619,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if(!$ev->isCancelled()){
$revert = true;
$this->server->getLogger()->debug($this->getServer()->getLanguage()->translateString("pocketmine.player.invalidMove", [$this->getName()]));
$this->server->getLogger()->debug("Old position: " . $this->asVector3() . ", new position: " . $newPos);
$this->server->getLogger()->debug("Old position: " . $this->asVector3() . ", new position: " . $newPos . ", expected clip distance: $expectedClipDistance");
}
}

View File

@ -94,6 +94,7 @@ use const M_PI_2;
abstract class Entity extends Location implements Metadatable, EntityIds{
public const MOTION_THRESHOLD = 0.00001;
protected const STEP_CLIP_MULTIPLIER = 0.4;
public const NETWORK_ID = -1;
@ -1538,7 +1539,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
if($this->keepMovement){
$this->boundingBox->offset($dx, $dy, $dz);
}else{
$this->ySize *= 0.4;
$this->ySize *= self::STEP_CLIP_MULTIPLIER;
/*
if($this->isColliding){ //With cobweb?
@ -1605,7 +1606,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->boundingBox->offset(0, 0, $dz);
if($this->stepHeight > 0 and $fallingFlag and $this->ySize < 0.05 and ($movX != $dx or $movZ != $dz)){
if($this->stepHeight > 0 and $fallingFlag and ($movX != $dx or $movZ != $dz)){
$cx = $dx;
$cy = $dy;
$cz = $dz;