diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index ce40e04fb9..d0d3ea45ca 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -204,6 +204,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ */ protected $sessionAdapter; + /** @var int */ + protected $protocol = -1; + /** @var bool */ public $playedBefore; public $spawned = false; @@ -1970,6 +1973,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return false; } + $this->protocol = $packet->protocol; + if($packet->protocol !== ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol < ProtocolInfo::CURRENT_PROTOCOL){ $this->sendPlayStatus(PlayStatusPacket::LOGIN_FAILED_CLIENT, true); @@ -2035,6 +2040,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ public function sendPlayStatus(int $status, bool $immediate = false){ $pk = new PlayStatusPacket(); $pk->status = $status; + $pk->protocol = $this->protocol; if($immediate){ $this->directDataPacket($pk); }else{ diff --git a/src/pocketmine/network/mcpe/protocol/LoginPacket.php b/src/pocketmine/network/mcpe/protocol/LoginPacket.php index 0e9eb77ecd..f74f48df13 100644 --- a/src/pocketmine/network/mcpe/protocol/LoginPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LoginPacket.php @@ -72,6 +72,10 @@ class LoginPacket extends DataPacket{ $this->protocol = $this->getInt(); if($this->protocol !== ProtocolInfo::CURRENT_PROTOCOL){ + if($this->protocol > 0xffff){ //guess MCPE <= 1.1 + $this->offset -= 6; + $this->protocol = $this->getInt(); + } return; //Do not attempt to continue decoding for non-accepted protocols } diff --git a/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php b/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php index 38b48e60ed..225540b8cc 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php @@ -42,6 +42,12 @@ class PlayStatusPacket extends DataPacket{ /** @var int */ public $status; + /** + * @var int + * Used to determine how to write the packet when we disconnect incompatible clients. + */ + public $protocol; + protected function decodePayload(){ $this->status = $this->getInt(); } @@ -50,6 +56,14 @@ class PlayStatusPacket extends DataPacket{ return true; } + protected function encodeHeader(){ + if($this->protocol < 130){ //MCPE <= 1.1 + $this->putByte(static::NETWORK_ID); + }else{ + parent::encodeHeader(); + } + } + protected function encodePayload(){ $this->putInt($this->status); }