Some protocol changes for 1.1.0.0

This commit is contained in:
Dylan K. Taylor 2017-04-01 19:20:30 +01:00
parent e47c7ea55f
commit 9c25ec3afd
13 changed files with 61 additions and 54 deletions

View File

@ -3249,8 +3249,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
} }
$this->craftingType = 0; $this->craftingType = 0;
$commandText = $packet->command; $commandText = $packet->command;
if($packet->args !== null){ if($packet->inputJson !== null){
foreach($packet->args as $arg){ //command ordering will be an issue foreach($packet->inputJson as $arg){ //command ordering will be an issue
$commandText .= " " . $arg; $commandText .= " " . $arg;
} }
} }
@ -3340,7 +3340,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet)); $this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet));
if(!$ev->isCancelled() and !$packet->handle($this)){ if(!$ev->isCancelled() and !$packet->handle($this)){
$this->server->getLogger()->debug("Unhandled " . get_class($packet) . " received from " . $this->getName()); $this->server->getLogger()->debug("Unhandled " . get_class($packet) . " received from " . $this->getName() . ": " . bin2hex($packet->buffer));
} }
$timings->stopTiming(); $timings->stopTiming();

View File

@ -125,34 +125,36 @@ abstract class Entity extends Location implements Metadatable{
const DATA_FLAG_SPRINTING = 3; const DATA_FLAG_SPRINTING = 3;
const DATA_FLAG_ACTION = 4; const DATA_FLAG_ACTION = 4;
const DATA_FLAG_INVISIBLE = 5; const DATA_FLAG_INVISIBLE = 5;
const DATA_FLAG_TEMPTED = 6; //??? const DATA_FLAG_TEMPTED = 6;
const DATA_FLAG_INLOVE = 7; const DATA_FLAG_INLOVE = 7;
const DATA_FLAG_SADDLED = 8; const DATA_FLAG_SADDLED = 8;
const DATA_FLAG_POWERED = 9; const DATA_FLAG_POWERED = 9;
const DATA_FLAG_IGNITED = 10; //for creepers? const DATA_FLAG_IGNITED = 10;
const DATA_FLAG_BABY = 11; const DATA_FLAG_BABY = 11;
const DATA_FLAG_CONVERTING = 12; //??? const DATA_FLAG_CONVERTING = 12;
const DATA_FLAG_CRITICAL = 13; const DATA_FLAG_CRITICAL = 13;
const DATA_FLAG_CAN_SHOW_NAMETAG = 14; const DATA_FLAG_CAN_SHOW_NAMETAG = 14;
const DATA_FLAG_ALWAYS_SHOW_NAMETAG = 15; const DATA_FLAG_ALWAYS_SHOW_NAMETAG = 15;
const DATA_FLAG_IMMOBILE = 16, DATA_FLAG_NO_AI = 16; const DATA_FLAG_IMMOBILE = 16, DATA_FLAG_NO_AI = 16;
const DATA_FLAG_SILENT = 17; const DATA_FLAG_SILENT = 17;
const DATA_FLAG_WALLCLIMBING = 18; const DATA_FLAG_WALLCLIMBING = 18;
const DATA_FLAG_RESTING = 19; //for bats?
const DATA_FLAG_SITTING = 20; const DATA_FLAG_RESTING = 22;
const DATA_FLAG_ANGRY = 21; const DATA_FLAG_SITTING = 23;
const DATA_FLAG_INTERESTED = 22; //for mobs following players with food? const DATA_FLAG_ANGRY = 24;
const DATA_FLAG_CHARGED = 23; const DATA_FLAG_INTERESTED = 25;
const DATA_FLAG_TAMED = 24; const DATA_FLAG_CHARGED = 26;
const DATA_FLAG_LEASHED = 25; const DATA_FLAG_TAMED = 27;
const DATA_FLAG_SHEARED = 26; //for sheep const DATA_FLAG_LEASHED = 28;
const DATA_FLAG_GLIDING = 27, DATA_FLAG_FALL_FLYING = 27; const DATA_FLAG_SHEARED = 29;
const DATA_FLAG_ELDER = 28; //elder guardian const DATA_FLAG_GLIDING = 30;
const DATA_FLAG_MOVING = 29; const DATA_FLAG_ELDER = 31;
const DATA_FLAG_BREATHING = 30; //hides bubbles if true const DATA_FLAG_MOVING = 32;
const DATA_FLAG_CHESTED = 31; //for mules? const DATA_FLAG_BREATHING = 33;
const DATA_FLAG_STACKABLE = 32; const DATA_FLAG_CHESTED = 34;
const DATA_FLAG_IDLING = 36; const DATA_FLAG_STACKABLE = 35;
const DATA_FLAG_IDLING = 39;
public static $entityCount = 1; public static $entityCount = 1;
/** @var Entity[] */ /** @var Entity[] */

View File

@ -32,7 +32,6 @@ abstract class ContainerInventory extends BaseInventory{
$pk = new ContainerOpenPacket(); $pk = new ContainerOpenPacket();
$pk->windowid = $who->getWindowId($this); $pk->windowid = $who->getWindowId($this);
$pk->type = $this->getType()->getNetworkType(); $pk->type = $this->getType()->getNetworkType();
$pk->slots = $this->getSize();
$holder = $this->getHolder(); $holder = $this->getHolder();
if($holder instanceof Vector3){ if($holder instanceof Vector3){
$pk->x = $holder->getX(); $pk->x = $holder->getX();

View File

@ -401,6 +401,7 @@ class PlayerInventory extends BaseInventory{
$pk2 = new ContainerSetContentPacket(); $pk2 = new ContainerSetContentPacket();
$pk2->windowid = ContainerSetContentPacket::SPECIAL_ARMOR; $pk2->windowid = ContainerSetContentPacket::SPECIAL_ARMOR;
$pk2->slots = $armor; $pk2->slots = $armor;
$pk2->targetEid = $player->getId();
$player->dataPacket($pk2); $player->dataPacket($pk2);
}else{ }else{
$player->dataPacket($pk); $player->dataPacket($pk);
@ -490,6 +491,7 @@ class PlayerInventory extends BaseInventory{
continue; continue;
} }
$pk->windowid = $id; $pk->windowid = $id;
$pk->targetEid = $player->getId(); //TODO: check if this is correct
$player->dataPacket(clone $pk); $player->dataPacket(clone $pk);
} }
} }
@ -502,6 +504,7 @@ class PlayerInventory extends BaseInventory{
$pk->slots[$i] = clone $item; $pk->slots[$i] = clone $item;
} }
} }
$pk->targetEid = $this->getHolder()->getId();
$this->getHolder()->dataPacket($pk); $this->getHolder()->dataPacket($pk);
} }

View File

@ -45,20 +45,7 @@ class AdventureSettingsPacket extends DataPacket{
public $noClip = false; public $noClip = false;
public $worldBuilder = false; public $worldBuilder = false;
public $isFlying = false; public $isFlying = false;
public $muted = false;
/*
bit mask | flag name
0x00000001 world_immutable
0x00000002 no_pvp
0x00000004 no_pvm
0x00000008 no_mvp
0x00000010 ?
0x00000020 auto_jump
0x00000040 allow_fly
0x00000080 noclip
0x00000100 world_builder (seems to allow building even if the world_immutable flag is set (???))
0x00000200 is_flying
*/
public $flags = 0; public $flags = 0;
public $userPermission; public $userPermission;
@ -77,6 +64,7 @@ class AdventureSettingsPacket extends DataPacket{
$this->noClip = (bool) ($this->flags & (1 << 7)); $this->noClip = (bool) ($this->flags & (1 << 7));
$this->worldBuilder = (bool) ($this->flags & (1 << 8)); $this->worldBuilder = (bool) ($this->flags & (1 << 8));
$this->isFlying = (bool) ($this->flags & (1 << 9)); $this->isFlying = (bool) ($this->flags & (1 << 9));
$this->muted = (bool) ($this->flags & (1 << 10));
} }
public function encode(){ public function encode(){
@ -92,6 +80,7 @@ class AdventureSettingsPacket extends DataPacket{
$this->flags |= ((int) $this->noClip) << 7; $this->flags |= ((int) $this->noClip) << 7;
$this->flags |= ((int) $this->worldBuilder) << 8; $this->flags |= ((int) $this->worldBuilder) << 8;
$this->flags |= ((int) $this->isFlying) << 9; $this->flags |= ((int) $this->isFlying) << 9;
$this->flags |= ((int) $this->muted) << 10;
$this->putUnsignedVarInt($this->flags); $this->putUnsignedVarInt($this->flags);
$this->putUnsignedVarInt($this->userPermission); $this->putUnsignedVarInt($this->userPermission);

View File

@ -35,6 +35,7 @@ class AnimatePacket extends DataPacket{
public function decode(){ public function decode(){
$this->action = $this->getVarInt(); $this->action = $this->getVarInt();
$this->eid = $this->getEntityRuntimeId(); $this->eid = $this->getEntityRuntimeId();
//TODO: check extra float which appears when 0x80 bitflag is set
} }
public function encode(){ public function encode(){

View File

@ -31,21 +31,21 @@ class CommandStepPacket extends DataPacket{
public $command; public $command;
public $overload; public $overload;
public $uvarint1; public $uvarint1;
public $uvarint2; public $currentStep;
public $bool; public $done;
public $uvarint64; public $clientId;
public $args; public $inputJson;
public $string4; public $outputJson;
public function decode(){ public function decode(){
$this->command = $this->getString(); $this->command = $this->getString();
$this->overload = $this->getString(); $this->overload = $this->getString();
$this->uvarint1 = $this->getUnsignedVarInt(); $this->uvarint1 = $this->getUnsignedVarInt();
$this->uvarint2 = $this->getUnsignedVarInt(); $this->currentStep = $this->getUnsignedVarInt();
$this->bool = (bool) $this->getByte(); $this->done = (bool) $this->getByte();
$this->uvarint64 = $this->getUnsignedVarLong(); $this->clientId = $this->getUnsignedVarLong();
$this->args = json_decode($this->getString()); $this->inputJson = json_decode($this->getString());
$this->string4 = $this->getString(); $this->outputJson = $this->getString();
$this->get(true); //TODO: read command origin data $this->get(true); //TODO: read command origin data
} }

View File

@ -31,7 +31,6 @@ class ContainerOpenPacket extends DataPacket{
public $windowid; public $windowid;
public $type; public $type;
public $slots;
public $x; public $x;
public $y; public $y;
public $z; public $z;
@ -45,7 +44,6 @@ class ContainerOpenPacket extends DataPacket{
$this->reset(); $this->reset();
$this->putByte($this->windowid); $this->putByte($this->windowid);
$this->putByte($this->type); $this->putByte($this->type);
$this->putVarInt($this->slots);
$this->putBlockPosition($this->x, $this->y, $this->z); $this->putBlockPosition($this->x, $this->y, $this->z);
$this->putEntityUniqueId($this->entityId); $this->putEntityUniqueId($this->entityId);
} }

View File

@ -33,8 +33,10 @@ class ContainerSetContentPacket extends DataPacket{
const SPECIAL_ARMOR = 0x78; const SPECIAL_ARMOR = 0x78;
const SPECIAL_CREATIVE = 0x79; const SPECIAL_CREATIVE = 0x79;
const SPECIAL_HOTBAR = 0x7a; const SPECIAL_HOTBAR = 0x7a;
const SPECIAL_FIXED_INVENTORY = 0x7b;
public $windowid; public $windowid;
public $targetEid;
public $slots = []; public $slots = [];
public $hotbar = []; public $hotbar = [];
@ -45,7 +47,8 @@ class ContainerSetContentPacket extends DataPacket{
} }
public function decode(){ public function decode(){
$this->windowid = $this->getByte(); $this->windowid = $this->getUnsignedVarInt();
$this->targetEid = $this->getEntityUniqueId();
$count = $this->getUnsignedVarInt(); $count = $this->getUnsignedVarInt();
for($s = 0; $s < $count and !$this->feof(); ++$s){ for($s = 0; $s < $count and !$this->feof(); ++$s){
$this->slots[$s] = $this->getSlot(); $this->slots[$s] = $this->getSlot();
@ -60,7 +63,8 @@ class ContainerSetContentPacket extends DataPacket{
public function encode(){ public function encode(){
$this->reset(); $this->reset();
$this->putByte($this->windowid); $this->putUnsignedVarInt($this->windowid);
$this->putEntityUniqueId($this->targetEid);
$this->putUnsignedVarInt(count($this->slots)); $this->putUnsignedVarInt(count($this->slots));
foreach($this->slots as $slot){ foreach($this->slots as $slot){
$this->putSlot($slot); $this->putSlot($slot);

View File

@ -44,7 +44,9 @@ class DisconnectPacket extends DataPacket{
public function encode(){ public function encode(){
$this->reset(); $this->reset();
$this->putBool($this->hideDisconnectionScreen); $this->putBool($this->hideDisconnectionScreen);
$this->putString($this->message); if(!$this->hideDisconnectionScreen){
$this->putString($this->message);
}
} }
public function handle(NetworkSession $session) : bool{ public function handle(NetworkSession $session) : bool{

View File

@ -29,10 +29,14 @@ use pocketmine\network\mcpe\NetworkSession;
class EntityFallPacket extends DataPacket{ class EntityFallPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::ENTITY_FALL_PACKET; const NETWORK_ID = ProtocolInfo::ENTITY_FALL_PACKET;
public $eid;
public $fallDistance; public $fallDistance;
public $bool1;
public function decode(){ public function decode(){
$this->eid = $this->getEntityRuntimeId();
$this->fallDistance = $this->getLFloat(); $this->fallDistance = $this->getLFloat();
$this->bool1 = $this->getBool();
} }
public function encode(){ public function encode(){

View File

@ -28,16 +28,20 @@ use pocketmine\network\mcpe\NetworkSession;
class InventoryActionPacket extends DataPacket{ class InventoryActionPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::INVENTORY_ACTION_PACKET; const NETWORK_ID = ProtocolInfo::INVENTORY_ACTION_PACKET;
public $unknown; public $uvarint0;
public $item; public $item;
public $varint1;
public $varint2;
public function decode(){ public function decode(){
} }
public function encode(){ public function encode(){
$this->putUnsignedVarInt($this->unknown); $this->putUnsignedVarInt($this->uvarint0);
$this->putSlot($this->item); $this->putSlot($this->item);
$this->putVarInt($this->varint1);
$this->putVarInt($this->varint2);
} }
public function handle(NetworkSession $session) : bool{ public function handle(NetworkSession $session) : bool{

View File

@ -34,7 +34,8 @@ class PlayStatusPacket extends DataPacket{
const LOGIN_FAILED_SERVER = 2; const LOGIN_FAILED_SERVER = 2;
const PLAYER_SPAWN = 3; const PLAYER_SPAWN = 3;
const LOGIN_FAILED_INVALID_TENANT = 4; const LOGIN_FAILED_INVALID_TENANT = 4;
const LOGIN_FAILED_EDITION_MISMATCH = 5; const LOGIN_FAILED_VANILLA_EDU = 5;
const LOGIN_FAILED_EDU_VANILLA = 6;
public $status; public $status;