Protocol changes for 1.7

there's also some new cases in stats, but we don't care about those anyway.
This commit is contained in:
Dylan K. Taylor 2018-10-16 17:13:52 +01:00
parent 78923177f9
commit 839d5eab7b
18 changed files with 155 additions and 72 deletions

View File

@ -2309,7 +2309,7 @@ class Server{
$pk = new PlayerListPacket();
$pk->type = PlayerListPacket::TYPE_ADD;
$pk->entries[] = PlayerListEntry::createAdditionEntry($uuid, $entityId, $name, "", 0, $skin, $xboxUserId);
$pk->entries[] = PlayerListEntry::createAdditionEntry($uuid, $entityId, $name, $skin, $xboxUserId);
$this->broadcastPacket($players ?? $this->playerList, $pk);
}
@ -2332,7 +2332,7 @@ class Server{
$pk = new PlayerListPacket();
$pk->type = PlayerListPacket::TYPE_ADD;
foreach($this->playerList as $player){
$pk->entries[] = PlayerListEntry::createAdditionEntry($player->getUniqueId(), $player->getId(), $player->getDisplayName(), "", 0, $player->getSkin(), $player->getXuid());
$pk->entries[] = PlayerListEntry::createAdditionEntry($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkin(), $player->getXuid());
}
$p->dataPacket($pk);

View File

@ -206,34 +206,38 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
public const DATA_FLAG_INTERESTED = 26;
public const DATA_FLAG_CHARGED = 27;
public const DATA_FLAG_TAMED = 28;
public const DATA_FLAG_LEASHED = 29;
public const DATA_FLAG_SHEARED = 30;
public const DATA_FLAG_GLIDING = 31;
public const DATA_FLAG_ELDER = 32;
public const DATA_FLAG_MOVING = 33;
public const DATA_FLAG_BREATHING = 34;
public const DATA_FLAG_CHESTED = 35;
public const DATA_FLAG_STACKABLE = 36;
public const DATA_FLAG_SHOWBASE = 37;
public const DATA_FLAG_REARING = 38;
public const DATA_FLAG_VIBRATING = 39;
public const DATA_FLAG_IDLING = 40;
public const DATA_FLAG_EVOKER_SPELL = 41;
public const DATA_FLAG_CHARGE_ATTACK = 42;
public const DATA_FLAG_WASD_CONTROLLED = 43;
public const DATA_FLAG_CAN_POWER_JUMP = 44;
public const DATA_FLAG_LINGER = 45;
public const DATA_FLAG_HAS_COLLISION = 46;
public const DATA_FLAG_AFFECTED_BY_GRAVITY = 47;
public const DATA_FLAG_FIRE_IMMUNE = 48;
public const DATA_FLAG_DANCING = 49;
public const DATA_FLAG_ENCHANTED = 50;
public const DATA_FLAG_SHOW_TRIDENT_ROPE = 51; // tridents show an animated rope when enchanted with loyalty after they are thrown and return to their owner. To be combined with DATA_OWNER_EID
public const DATA_FLAG_CONTAINER_PRIVATE = 52; //inventory is private, doesn't drop contents when killed if true
//53 TransformationComponent
public const DATA_FLAG_SPIN_ATTACK = 54;
public const DATA_FLAG_SWIMMING = 55;
public const DATA_FLAG_BRIBED = 56; //dolphins have this set when they go to find treasure for the player
public const DATA_FLAG_ORPHANED = 29;
public const DATA_FLAG_LEASHED = 30;
public const DATA_FLAG_SHEARED = 31;
public const DATA_FLAG_GLIDING = 32;
public const DATA_FLAG_ELDER = 33;
public const DATA_FLAG_MOVING = 34;
public const DATA_FLAG_BREATHING = 35;
public const DATA_FLAG_CHESTED = 36;
public const DATA_FLAG_STACKABLE = 37;
public const DATA_FLAG_SHOWBASE = 38;
public const DATA_FLAG_REARING = 39;
public const DATA_FLAG_VIBRATING = 40;
public const DATA_FLAG_IDLING = 41;
public const DATA_FLAG_EVOKER_SPELL = 42;
public const DATA_FLAG_CHARGE_ATTACK = 43;
public const DATA_FLAG_WASD_CONTROLLED = 44;
public const DATA_FLAG_CAN_POWER_JUMP = 45;
public const DATA_FLAG_LINGER = 46;
public const DATA_FLAG_HAS_COLLISION = 47;
public const DATA_FLAG_AFFECTED_BY_GRAVITY = 48;
public const DATA_FLAG_FIRE_IMMUNE = 49;
public const DATA_FLAG_DANCING = 50;
public const DATA_FLAG_ENCHANTED = 51;
public const DATA_FLAG_SHOW_TRIDENT_ROPE = 52; // tridents show an animated rope when enchanted with loyalty after they are thrown and return to their owner. To be combined with DATA_OWNER_EID
public const DATA_FLAG_CONTAINER_PRIVATE = 53; //inventory is private, doesn't drop contents when killed if true
//54 TransformationComponent
public const DATA_FLAG_SPIN_ATTACK = 55;
public const DATA_FLAG_SWIMMING = 56;
public const DATA_FLAG_BRIBED = 57; //dolphins have this set when they go to find treasure for the player
public const DATA_FLAG_PREGNANT = 58;
public const DATA_FLAG_LAYING_EGG = 59;
//60 ??
public static $entityCount = 1;
/** @var Entity[] */

View File

@ -841,7 +841,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
/* we don't use Server->updatePlayerListData() because that uses batches, which could cause race conditions in async compression mode */
$pk = new PlayerListPacket();
$pk->type = PlayerListPacket::TYPE_ADD;
$pk->entries = [PlayerListEntry::createAdditionEntry($this->uuid, $this->id, $this->getName(), $this->getName(), 0, $this->skin)];
$pk->entries = [PlayerListEntry::createAdditionEntry($this->uuid, $this->id, $this->getName(), $this->skin)];
$player->dataPacket($pk);
}

View File

@ -95,7 +95,7 @@ class FloatingTextParticle extends Particle{
$add = new PlayerListPacket();
$add->type = PlayerListPacket::TYPE_ADD;
$add->entries = [PlayerListEntry::createAdditionEntry($uuid, $this->entityId, $name, $name, 0, new Skin("Standard_Custom", str_repeat("\x00", 8192)))];
$add->entries = [PlayerListEntry::createAdditionEntry($uuid, $this->entityId, $name, new Skin("Standard_Custom", str_repeat("\x00", 8192)))];
$p[] = $add;
$pk = new AddPlayerPacket();

View File

@ -101,6 +101,7 @@ use pocketmine\network\mcpe\protocol\ResourcePackStackPacket;
use pocketmine\network\mcpe\protocol\ResourcePacksInfoPacket;
use pocketmine\network\mcpe\protocol\RespawnPacket;
use pocketmine\network\mcpe\protocol\RiderJumpPacket;
use pocketmine\network\mcpe\protocol\ScriptCustomEventPacket;
use pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket;
use pocketmine\network\mcpe\protocol\ServerSettingsResponsePacket;
use pocketmine\network\mcpe\protocol\ServerToClientHandshakePacket;
@ -603,4 +604,8 @@ abstract class NetworkSession{
public function handleNetworkStackLatency(NetworkStackLatencyPacket $packet) : bool{
return false;
}
public function handleScriptCustomEvent(ScriptCustomEventPacket $packet) : bool{
return false;
}
}

View File

@ -38,10 +38,6 @@ class AddPlayerPacket extends DataPacket{
public $uuid;
/** @var string */
public $username;
/** @var string */
public $thirdPartyName = "";
/** @var int */
public $platform = 0;
/** @var int|null */
public $entityUniqueId = null; //TODO
/** @var int */
@ -81,8 +77,6 @@ class AddPlayerPacket extends DataPacket{
protected function decodePayload(){
$this->uuid = $this->getUUID();
$this->username = $this->getString();
$this->thirdPartyName = $this->getString();
$this->platform = $this->getVarInt();
$this->entityUniqueId = $this->getEntityUniqueId();
$this->entityRuntimeId = $this->getEntityRuntimeId();
$this->platformChatId = $this->getString();
@ -113,8 +107,6 @@ class AddPlayerPacket extends DataPacket{
protected function encodePayload(){
$this->putUUID($this->uuid);
$this->putString($this->username);
$this->putString($this->thirdPartyName);
$this->putVarInt($this->platform);
$this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId);
$this->putEntityRuntimeId($this->entityRuntimeId);
$this->putString($this->platformChatId);

View File

@ -40,6 +40,9 @@ class EventPacket extends DataPacket{
public const TYPE_BOSS_KILLED = 7;
public const TYPE_AGENT_COMMAND = 8;
public const TYPE_AGENT_CREATED = 9;
public const TYPE_PATTERN_REMOVED = 10; //???
public const TYPE_COMMANED_EXECUTED = 11;
public const TYPE_FISH_BUCKETED = 12;
/** @var int */
public $playerRuntimeId;

View File

@ -146,6 +146,7 @@ class PacketPool{
static::registerPacket(new SetLocalPlayerAsInitializedPacket());
static::registerPacket(new UpdateSoftEnumPacket());
static::registerPacket(new NetworkStackLatencyPacket());
static::registerPacket(new ScriptCustomEventPacket());
static::registerPacket(new BatchPacket());
}

View File

@ -56,8 +56,6 @@ class PlayerListPacket extends DataPacket{
$entry->uuid = $this->getUUID();
$entry->entityUniqueId = $this->getEntityUniqueId();
$entry->username = $this->getString();
$entry->thirdPartyName = $this->getString();
$entry->platform = $this->getVarInt();
$skinId = $this->getString();
$skinData = $this->getString();
@ -90,8 +88,6 @@ class PlayerListPacket extends DataPacket{
$this->putUUID($entry->uuid);
$this->putEntityUniqueId($entry->entityUniqueId);
$this->putString($entry->username);
$this->putString($entry->thirdPartyName);
$this->putVarInt($entry->platform);
$this->putString($entry->skin->getSkinId());
$this->putString($entry->skin->getSkinData());
$this->putString($entry->skin->getCapeData());

View File

@ -39,15 +39,15 @@ interface ProtocolInfo{
/**
* Actual Minecraft: PE protocol version
*/
public const CURRENT_PROTOCOL = 282;
public const CURRENT_PROTOCOL = 291;
/**
* Current Minecraft PE version reported by the server. This is usually the earliest currently supported version.
*/
public const MINECRAFT_VERSION = 'v1.6.0';
public const MINECRAFT_VERSION = 'v1.7.0.5 beta';
/**
* Version number sent to clients in ping responses.
*/
public const MINECRAFT_VERSION_NETWORK = '1.6.0';
public const MINECRAFT_VERSION_NETWORK = '1.7.0.5';
public const LOGIN_PACKET = 0x01;
public const PLAY_STATUS_PACKET = 0x02;
@ -164,5 +164,6 @@ interface ProtocolInfo{
public const SET_LOCAL_PLAYER_AS_INITIALIZED_PACKET = 0x71;
public const UPDATE_SOFT_ENUM_PACKET = 0x72;
public const NETWORK_STACK_LATENCY_PACKET = 0x73;
public const SCRIPT_CUSTOM_EVENT_PACKET = 0x75;
}

View File

@ -0,0 +1,51 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession;
class ScriptCustomEventPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::SCRIPT_CUSTOM_EVENT_PACKET;
/** @var string */
public $eventName;
/** @var string json data */
public $eventData;
protected function decodePayload(){
$this->eventName = $this->getString();
$this->eventData = $this->getString();
}
protected function encodePayload(){
$this->putString($this->eventName);
$this->putString($this->eventData);
}
public function handle(NetworkSession $session) : bool{
return $session->handleScriptCustomEvent($this);
}
}

View File

@ -31,8 +31,8 @@ use pocketmine\network\mcpe\protocol\types\ScorePacketEntry;
class SetScorePacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::SET_SCORE_PACKET;
public const TYPE_MODIFY_SCORE = 0;
public const TYPE_RESET_SCORE = 1;
public const TYPE_CHANGE = 0;
public const TYPE_REMOVE = 1;
/** @var int */
public $type;
@ -43,9 +43,23 @@ class SetScorePacket extends DataPacket{
$this->type = $this->getByte();
for($i = 0, $i2 = $this->getUnsignedVarInt(); $i < $i2; ++$i){
$entry = new ScorePacketEntry();
$entry->uuid = $this->getUUID();
$entry->scoreboardId = $this->getVarLong();
$entry->objectiveName = $this->getString();
$entry->score = $this->getLInt();
if($this->type !== self::TYPE_REMOVE){
$entry->type = $this->getByte();
switch($entry->type){
case ScorePacketEntry::TYPE_PLAYER:
case ScorePacketEntry::TYPE_ENTITY:
$entry->entityUniqueId = $this->getEntityUniqueId();
break;
case ScorePacketEntry::TYPE_FAKE_PLAYER:
$entry->customName = $this->getString();
break;
default:
throw new \UnexpectedValueException("Unknown entry type $entry->type");
}
}
}
}
@ -53,9 +67,23 @@ class SetScorePacket extends DataPacket{
$this->putByte($this->type);
$this->putUnsignedVarInt(count($this->entries));
foreach($this->entries as $entry){
$this->putUUID($entry->uuid);
$this->putVarLong($entry->scoreboardId);
$this->putString($entry->objectiveName);
$this->putLInt($entry->score);
if($this->type !== self::TYPE_REMOVE){
$this->putByte($entry->type);
switch($entry->type){
case ScorePacketEntry::TYPE_PLAYER:
case ScorePacketEntry::TYPE_ENTITY:
$this->putEntityUniqueId($entry->entityUniqueId);
break;
case ScorePacketEntry::TYPE_FAKE_PLAYER:
$this->putString($entry->customName);
break;
default:
throw new \UnexpectedValueException("Unknown entry type $entry->type");
}
}
}
}

View File

@ -45,7 +45,7 @@ class SetScoreboardIdentityPacket extends DataPacket{
$entry = new ScoreboardIdentityPacketEntry();
$entry->scoreboardId = $this->getVarLong();
if($this->type === self::TYPE_REGISTER_IDENTITY){
$entry->uuid = $this->getUUID();
$entry->entityUniqueId = $this->getEntityUniqueId();
}
$this->entries[] = $entry;
@ -58,7 +58,7 @@ class SetScoreboardIdentityPacket extends DataPacket{
foreach($this->entries as $entry){
$this->putVarLong($entry->scoreboardId);
if($this->type === self::TYPE_REGISTER_IDENTITY){
$this->putUUID($entry->uuid);
$this->putEntityUniqueId($entry->entityUniqueId);
}
}
}

View File

@ -116,6 +116,8 @@ class StartGamePacket extends DataPacket{
public $hasLockedResourcePack = false;
/** @var bool */
public $isFromLockedWorldTemplate = false;
/** @var bool */
public $useMsaGamertagsOnly = false;
/** @var string */
public $levelId = ""; //base64 string, usually the same as world folder name in vanilla
@ -173,6 +175,7 @@ class StartGamePacket extends DataPacket{
$this->hasLockedBehaviorPack = $this->getBool();
$this->hasLockedResourcePack = $this->getBool();
$this->isFromLockedWorldTemplate = $this->getBool();
$this->useMsaGamertagsOnly = $this->getBool();
$this->levelId = $this->getString();
$this->worldName = $this->getString();
@ -232,6 +235,7 @@ class StartGamePacket extends DataPacket{
$this->putBool($this->hasLockedBehaviorPack);
$this->putBool($this->hasLockedResourcePack);
$this->putBool($this->isFromLockedWorldTemplate);
$this->putBool($this->useMsaGamertagsOnly);
$this->putString($this->levelId);
$this->putString($this->worldName);

View File

@ -48,10 +48,6 @@ class TextPacket extends DataPacket{
/** @var string */
public $sourceName;
/** @var string */
public $sourceThirdPartyName = "";
/** @var int */
public $sourcePlatform = 0;
/** @var string */
public $message;
/** @var string[] */
public $parameters = [];
@ -69,8 +65,6 @@ class TextPacket extends DataPacket{
/** @noinspection PhpMissingBreakStatementInspection */
case self::TYPE_ANNOUNCEMENT:
$this->sourceName = $this->getString();
$this->sourceThirdPartyName = $this->getString();
$this->sourcePlatform = $this->getVarInt();
case self::TYPE_RAW:
case self::TYPE_TIP:
case self::TYPE_SYSTEM:
@ -101,8 +95,6 @@ class TextPacket extends DataPacket{
/** @noinspection PhpMissingBreakStatementInspection */
case self::TYPE_ANNOUNCEMENT:
$this->putString($this->sourceName);
$this->putString($this->sourceThirdPartyName);
$this->putVarInt($this->sourcePlatform);
case self::TYPE_RAW:
case self::TYPE_TIP:
case self::TYPE_SYSTEM:

View File

@ -52,13 +52,11 @@ class PlayerListEntry{
return $entry;
}
public static function createAdditionEntry(UUID $uuid, int $entityUniqueId, string $username, string $thirdPartyName, int $platform, Skin $skin, string $xboxUserId = "", string $platformChatId = "") : PlayerListEntry{
public static function createAdditionEntry(UUID $uuid, int $entityUniqueId, string $username, Skin $skin, string $xboxUserId = "", string $platformChatId = "") : PlayerListEntry{
$entry = new PlayerListEntry();
$entry->uuid = $uuid;
$entry->entityUniqueId = $entityUniqueId;
$entry->username = $username;
$entry->thirdPartyName = $thirdPartyName;
$entry->platform = $platform;
$entry->skin = $skin;
$entry->xboxUserId = $xboxUserId;
$entry->platformChatId = $platformChatId;

View File

@ -23,13 +23,23 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\types;
use pocketmine\utils\UUID;
class ScorePacketEntry{
/** @var UUID */
public $uuid;
public const TYPE_PLAYER = 1;
public const TYPE_ENTITY = 2;
public const TYPE_FAKE_PLAYER = 3;
/** @var int */
public $scoreboardId;
/** @var string */
public $objectiveName;
/** @var int */
public $score;
/** @var int */
public $type;
/** @var int|null (if type entity or player) */
public $entityUniqueId;
/** @var string|null (if type fake player) */
public $customName;
}

View File

@ -23,12 +23,10 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\types;
use pocketmine\utils\UUID;
class ScoreboardIdentityPacketEntry{
/** @var int */
public $scoreboardId;
/** @var UUID|null */
public $uuid;
/** @var int|null */
public $entityUniqueId;
}