Player: Revert invalid attempts to toggle flight, instead of kicking (#4139)

If allowFlight was toggled by the server (e.g. due to gamemode change), a race could occur due to network latency where the client could try to enable flight, and then get kicked for cheating.

Since this can happen in legitimate, non-cheating cases, we can't make any assumptions about whether a player is cheating, so instead we just revert it, like we do with every other bad input.
This commit is contained in:
Ali 2021-04-01 19:57:26 +03:00 committed by GitHub
parent b03212053c
commit 609dff1aae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3134,11 +3134,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$handled = false;
$isFlying = $packet->getFlag(AdventureSettingsPacket::FLYING);
if($isFlying and !$this->allowFlight){
$this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.flight"]));
return true;
}elseif($isFlying !== $this->isFlying()){
if($isFlying !== $this->isFlying()){
$ev = new PlayerToggleFlightEvent($this, $isFlying);
if($isFlying and !$this->allowFlight){
$ev->setCancelled();
}
$ev->call();
if($ev->isCancelled()){
$this->sendSettings();