Disconnect 1.1 clients properly (HACK!)

This commit is contained in:
Dylan K. Taylor 2017-09-26 10:01:32 +01:00
parent ccbdb77618
commit e64076ec81
3 changed files with 24 additions and 0 deletions

View File

@ -204,6 +204,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
*/ */
protected $sessionAdapter; protected $sessionAdapter;
/** @var int */
protected $protocol = -1;
/** @var bool */ /** @var bool */
public $playedBefore; public $playedBefore;
public $spawned = false; public $spawned = false;
@ -1970,6 +1973,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return false; return false;
} }
$this->protocol = $packet->protocol;
if($packet->protocol !== ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol !== ProtocolInfo::CURRENT_PROTOCOL){
if($packet->protocol < ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol < ProtocolInfo::CURRENT_PROTOCOL){
$this->sendPlayStatus(PlayStatusPacket::LOGIN_FAILED_CLIENT, true); $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){ public function sendPlayStatus(int $status, bool $immediate = false){
$pk = new PlayStatusPacket(); $pk = new PlayStatusPacket();
$pk->status = $status; $pk->status = $status;
$pk->protocol = $this->protocol;
if($immediate){ if($immediate){
$this->directDataPacket($pk); $this->directDataPacket($pk);
}else{ }else{

View File

@ -72,6 +72,10 @@ class LoginPacket extends DataPacket{
$this->protocol = $this->getInt(); $this->protocol = $this->getInt();
if($this->protocol !== ProtocolInfo::CURRENT_PROTOCOL){ 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 return; //Do not attempt to continue decoding for non-accepted protocols
} }

View File

@ -42,6 +42,12 @@ class PlayStatusPacket extends DataPacket{
/** @var int */ /** @var int */
public $status; public $status;
/**
* @var int
* Used to determine how to write the packet when we disconnect incompatible clients.
*/
public $protocol;
protected function decodePayload(){ protected function decodePayload(){
$this->status = $this->getInt(); $this->status = $this->getInt();
} }
@ -50,6 +56,14 @@ class PlayStatusPacket extends DataPacket{
return true; return true;
} }
protected function encodeHeader(){
if($this->protocol < 130){ //MCPE <= 1.1
$this->putByte(static::NETWORK_ID);
}else{
parent::encodeHeader();
}
}
protected function encodePayload(){ protected function encodePayload(){
$this->putInt($this->status); $this->putInt($this->status);
} }