Updated some packets for 0.12, UUIDs, other stuff!

This commit is contained in:
Shoghi Cervantes
2015-08-02 01:22:36 +02:00
parent 4258e22c02
commit 5621ab0c49
27 changed files with 951 additions and 380 deletions

View File

@ -36,6 +36,8 @@ use pocketmine\network\protocol\ContainerOpenPacket;
use pocketmine\network\protocol\ContainerSetContentPacket;
use pocketmine\network\protocol\ContainerSetDataPacket;
use pocketmine\network\protocol\ContainerSetSlotPacket;
use pocketmine\network\protocol\CraftingDataPacket;
use pocketmine\network\protocol\CraftingEventPacket;
use pocketmine\network\protocol\DataPacket;
use pocketmine\network\protocol\DropItemPacket;
use pocketmine\network\protocol\FullChunkDataPacket;
@ -55,8 +57,8 @@ use pocketmine\network\protocol\TextPacket;
use pocketmine\network\protocol\MoveEntityPacket;
use pocketmine\network\protocol\MovePlayerPacket;
use pocketmine\network\protocol\PlayerActionPacket;
use pocketmine\network\protocol\PlayerArmorEquipmentPacket;
use pocketmine\network\protocol\PlayerEquipmentPacket;
use pocketmine\network\protocol\MobArmorEquipmentPacket;
use pocketmine\network\protocol\MobEquipmentPacket;
use pocketmine\network\protocol\RemoveBlockPacket;
use pocketmine\network\protocol\RemoveEntityPacket;
use pocketmine\network\protocol\RemovePlayerPacket;
@ -72,6 +74,7 @@ use pocketmine\network\protocol\TakeItemEntityPacket;
use pocketmine\network\protocol\TileEventPacket;
use pocketmine\network\protocol\UpdateBlockPacket;
use pocketmine\network\protocol\UseItemPacket;
use pocketmine\network\protocol\PlayerListPacket;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\Binary;
@ -296,6 +299,7 @@ class Network{
$this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class);
$this->registerPacket(ProtocolInfo::PLAY_STATUS_PACKET, PlayStatusPacket::class);
$this->registerPacket(ProtocolInfo::DISCONNECT_PACKET, DisconnectPacket::class);
$this->registerPacket(ProtocolInfo::BATCH_PACKET, BatchPacket::class);
$this->registerPacket(ProtocolInfo::TEXT_PACKET, TextPacket::class);
$this->registerPacket(ProtocolInfo::SET_TIME_PACKET, SetTimePacket::class);
$this->registerPacket(ProtocolInfo::START_GAME_PACKET, StartGamePacket::class);
@ -314,8 +318,8 @@ class Network{
$this->registerPacket(ProtocolInfo::LEVEL_EVENT_PACKET, LevelEventPacket::class);
$this->registerPacket(ProtocolInfo::TILE_EVENT_PACKET, TileEventPacket::class);
$this->registerPacket(ProtocolInfo::ENTITY_EVENT_PACKET, EntityEventPacket::class);
$this->registerPacket(ProtocolInfo::PLAYER_EQUIPMENT_PACKET, PlayerEquipmentPacket::class);
$this->registerPacket(ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET, PlayerArmorEquipmentPacket::class);
$this->registerPacket(ProtocolInfo::MOB_EQUIPMENT_PACKET, MobEquipmentPacket::class);
$this->registerPacket(ProtocolInfo::MOB_ARMOR_EQUIPMENT_PACKET, MobArmorEquipmentPacket::class);
$this->registerPacket(ProtocolInfo::INTERACT_PACKET, InteractPacket::class);
$this->registerPacket(ProtocolInfo::USE_ITEM_PACKET, UseItemPacket::class);
$this->registerPacket(ProtocolInfo::PLAYER_ACTION_PACKET, PlayerActionPacket::class);
@ -333,10 +337,12 @@ class Network{
$this->registerPacket(ProtocolInfo::CONTAINER_SET_SLOT_PACKET, ContainerSetSlotPacket::class);
$this->registerPacket(ProtocolInfo::CONTAINER_SET_DATA_PACKET, ContainerSetDataPacket::class);
$this->registerPacket(ProtocolInfo::CONTAINER_SET_CONTENT_PACKET, ContainerSetContentPacket::class);
$this->registerPacket(ProtocolInfo::CRAFTING_DATA_PACKET, CraftingDataPacket::class);
$this->registerPacket(ProtocolInfo::CRAFTING_EVENT_PACKET, CraftingEventPacket::class);
$this->registerPacket(ProtocolInfo::ADVENTURE_SETTINGS_PACKET, AdventureSettingsPacket::class);
$this->registerPacket(ProtocolInfo::TILE_ENTITY_DATA_PACKET, TileEntityDataPacket::class);
$this->registerPacket(ProtocolInfo::FULL_CHUNK_DATA_PACKET, FullChunkDataPacket::class);
$this->registerPacket(ProtocolInfo::SET_DIFFICULTY_PACKET, SetDifficultyPacket::class);
$this->registerPacket(ProtocolInfo::BATCH_PACKET, BatchPacket::class);
$this->registerPacket(ProtocolInfo::PLAYER_LIST_PACKET, PlayerListPacket::class);
}
}

View File

@ -31,7 +31,7 @@ use pocketmine\utils\Binary;
class AddPlayerPacket extends DataPacket{
const NETWORK_ID = Info::ADD_PLAYER_PACKET;
public $clientID;
public $uuid;
public $username;
public $eid;
public $x;
@ -43,19 +43,15 @@ class AddPlayerPacket extends DataPacket{
public $pitch;
public $yaw;
public $item;
public $meta;
public $metadata;
public $slim = false;
public $skin = null;
public function decode(){
}
public function encode(){
$this->reset();
$this->putLong($this->clientID);
$this->putUUID($this->uuid);
$this->putString($this->username);
$this->putLong($this->eid);
$this->putFloat($this->x);
@ -67,10 +63,8 @@ class AddPlayerPacket extends DataPacket{
$this->putFloat($this->yaw);
$this->putFloat($this->yaw); //TODO headrot
$this->putFloat($this->pitch);
$this->putShort($this->item);
$this->putShort($this->meta);
$this->putByte($this->slim ? 1 : 0);
$this->putString($this->skin);
$this->putSlot($this->item);
$meta = Binary::writeMetadata($this->metadata);
$this->put($meta);
}

View File

@ -30,7 +30,6 @@ class ContainerSetContentPacket extends DataPacket{
const SPECIAL_INVENTORY = 0;
const SPECIAL_ARMOR = 0x78;
const SPECIAL_CREATIVE = 0x79;
const SPECIAL_CRAFTING = 0x7a;
public $windowid;
public $slots = [];

View File

@ -0,0 +1,122 @@
<?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/
*
*
*/
namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
use pocketmine\inventory\FurnaceRecipe;
use pocketmine\inventory\ShapedRecipe;
use pocketmine\inventory\ShapelessRecipe;
use pocketmine\utils\Binary;
class CraftingDataPacket extends DataPacket{
const NETWORK_ID = Info::CRAFTING_DATA_PACKET;
const ENTRY_SHAPELESS = 0;
const ENTRY_SHAPED = 1;
const ENTRY_FURNACE = 2;
const ENTRY_FURNACE_DATA = 3;
const ENTRY_ENCHANT = 4;
/** @var object[] */
public $entries = [];
public $cleanRecipes = false;
public function writeEntry($entry){
if($entry instanceof ShapelessRecipe){
$this->writeShapelessRecipe($entry);
}elseif($entry instanceof ShapedRecipe){
$this->writeShapedRecipe($entry);
}elseif($entry instanceof FurnaceRecipe){
$this->writeFurnaceRecipe($entry);
}
}
private function writeShapelessRecipe(ShapelessRecipe $recipe){
$this->putInt(CraftingDataPacket::ENTRY_SHAPELESS);
$this->putInt($recipe->getIngredientCount());
foreach($recipe->getIngredientList() as $item){
$this->putSlot($item);
}
$this->putInt(1);
$this->putSlot($recipe->getResult());
}
private function writeShapedRecipe(ShapedRecipe $recipe){
$this->putInt(CraftingDataPacket::ENTRY_SHAPED);
}
private function writeFurnaceRecipe(FurnaceRecipe $recipe){
if($recipe->getInput()->getDamage() !== 0){ //Data recipe
$this->putInt(CraftingDataPacket::ENTRY_FURNACE_DATA);
$this->putInt(($recipe->getInput()->getId() << 16) | ($recipe->getInput()->getDamage()));
$this->putSlot($recipe->getResult());
}else{
$this->putInt(CraftingDataPacket::ENTRY_FURNACE);
$this->putInt($recipe->getInput()->getId());
$this->putSlot($recipe->getResult());
}
}
private function writeEnchant(){
$entry = Binary::writeInt(CraftingDataPacket::ENTRY_ENCHANT);
//TODO
}
public function addShapelessRecipe(ShapelessRecipe $recipe){
$this->entries[] = $recipe;
}
public function addShapedRecipe(ShapedRecipe $recipe){
$this->entries[] = $recipe;
}
public function addFurnaceRecipe(FurnaceRecipe $recipe){
$this->entries[] = $recipe;
}
public function addEnchant(){
//TODO
}
public function clean(){
$this->entries = [];
return parent::clean();
}
public function decode(){
}
public function encode(){
$this->reset();
$this->putByte($this->type);
$this->putInt(count($this->entries));
foreach($this->entries as $d){
}
}
}

View File

@ -0,0 +1,62 @@
<?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/
*
*
*/
namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class CraftingEventPacket extends DataPacket{
const NETWORK_ID = Info::CRAFTING_EVENT_PACKET;
public $windowId;
public $type;
public $id;
public $input = [];
public $output = [];
public function clean(){
$this->input = [];
$this->output = [];
return parent::clean();
}
public function decode(){
$this->windowId = $this->getByte();
$this->type = $this->getInt();
$this->id = $this->getUUID();
$size = $this->getInt();
for($i = 0; $i < $size and $i < 128; ++$i){
$this->input[] = $this->getSlot();
}
$size = $this->getInt();
for($i = 0; $i < $size and $i < 128; ++$i){
$this->output[] = $this->getSlot();
}
}
public function encode(){
}
}

View File

@ -28,6 +28,7 @@ use pocketmine\utils\Binary;
#endif
use pocketmine\item\Item;
use pocketmine\utils\UUID;
abstract class DataPacket extends \stdClass{
@ -162,10 +163,18 @@ abstract class DataPacket extends \stdClass{
}
}
protected function getUUID(){
return UUID::fromBinary($this->get(16));
}
protected function putUUID(UUID $uuid){
$this->put($uuid->toBinary());
}
protected function getSlot(){
$id = $this->getShort(false);
$id = $this->getShort(true);
if($id == 0xffff){
if($id <= 0){
return Item::get(0, 0, 0);
}
@ -191,7 +200,7 @@ abstract class DataPacket extends \stdClass{
protected function putSlot(Item $item){
if($item->getId() === 0){
$this->putShort(0xffff);
$this->putShort(0);
return;
}

View File

@ -43,6 +43,8 @@ class EntityEventPacket extends DataPacket{
const AMBIENT_SOUND = 16;
const RESPAWN = 17;
//TODO add new events
public $eid;
public $event;

View File

@ -30,7 +30,7 @@ interface Info{
/**
* Actual Minecraft: PE protocol version
*/
const CURRENT_PROTOCOL = 28;
const CURRENT_PROTOCOL = 30;
const LOGIN_PACKET = 0x82;
const PLAY_STATUS_PACKET = 0x83;
@ -56,8 +56,8 @@ interface Info{
const ENTITY_EVENT_PACKET = 0x97;
const MOB_EFFECT_PACKET = 0x98;
const UPDATE_ATTRIBUTES_PACKET = 0x99;
const PLAYER_EQUIPMENT_PACKET = 0x9a;
const PLAYER_ARMOR_EQUIPMENT_PACKET = 0x9b;
const MOB_EQUIPMENT_PACKET = 0x9a;
const MOB_ARMOR_EQUIPMENT_PACKET = 0x9b;
const INTERACT_PACKET = 0x9c;
const USE_ITEM_PACKET = 0x9d;
const PLAYER_ACTION_PACKET = 0x9e;
@ -75,14 +75,17 @@ interface Info{
const CONTAINER_SET_SLOT_PACKET = 0xaa;
const CONTAINER_SET_DATA_PACKET = 0xab;
const CONTAINER_SET_CONTENT_PACKET = 0xac;
const ADVENTURE_SETTINGS_PACKET = 0xad;
const TILE_ENTITY_DATA_PACKET = 0xae;
//const PLAYER_INPUT_PACKET = 0xaf;
const FULL_CHUNK_DATA_PACKET = 0xb0;
const SET_DIFFICULTY_PACKET = 0xb1;
//const CHANGE_DIMENSION_PACKET = 0xb2;
//const SET_PLAYER_GAMETYPE_PACKET = 0xb3;
//const PLAYER_LIST_PACKET = 0xb4;
const CRAFTING_DATA_PACKET = 0xad;
const CRAFTING_EVENT_PACKET = 0xae;
const ADVENTURE_SETTINGS_PACKET = 0xaf;
const TILE_ENTITY_DATA_PACKET = 0xb0;
//const PLAYER_INPUT_PACKET = 0xb1;
const FULL_CHUNK_DATA_PACKET = 0xb2;
const SET_DIFFICULTY_PACKET = 0xb3;
//const CHANGE_DIMENSION_PACKET = 0xb4;
//const SET_PLAYER_GAMETYPE_PACKET = 0xb5;
const PLAYER_LIST_PACKET = 0xb6;
//const TELEMETRY_EVENT_PACKET = 0xb7;
}

View File

@ -32,6 +32,10 @@ class LoginPacket extends DataPacket{
public $protocol2;
public $clientId;
public $clientUUID;
public $serverAddress;
public $clientSecret;
public $slim = false;
public $skin = null;
@ -39,11 +43,15 @@ class LoginPacket extends DataPacket{
$this->username = $this->getString();
$this->protocol1 = $this->getInt();
$this->protocol2 = $this->getInt();
if($this->protocol1 < 22){ //New fields!
if($this->protocol1 < Info::CURRENT_PROTOCOL){ //New fields!
$this->setBuffer(null, 0); //Skip batch packet handling
return;
}
$this->clientId = $this->getLong();
$this->clientUUID = $this->getUUID();
$this->serverAddress = $this->getString();
$this->clientSecret = $this->getString();
$this->slim = $this->getByte() > 0;
$this->skin = $this->getString();
}

View File

@ -24,27 +24,27 @@ namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class PlayerArmorEquipmentPacket extends DataPacket{
const NETWORK_ID = Info::PLAYER_ARMOR_EQUIPMENT_PACKET;
class MobArmorEquipmentPacket extends DataPacket{
const NETWORK_ID = Info::MOB_ARMOR_EQUIPMENT_PACKET;
public $eid;
public $slots = [];
public function decode(){
$this->eid = $this->getLong();
$this->slots[0] = $this->getByte();
$this->slots[1] = $this->getByte();
$this->slots[2] = $this->getByte();
$this->slots[3] = $this->getByte();
$this->slots[0] = $this->getSlot();
$this->slots[1] = $this->getSlot();
$this->slots[2] = $this->getSlot();
$this->slots[3] = $this->getSlot();
}
public function encode(){
$this->reset();
$this->putLong($this->eid);
$this->putByte($this->slots[0]);
$this->putByte($this->slots[1]);
$this->putByte($this->slots[2]);
$this->putByte($this->slots[3]);
$this->putSlot($this->slots[0]);
$this->putSlot($this->slots[1]);
$this->putSlot($this->slots[2]);
$this->putSlot($this->slots[3]);
}
}

View File

@ -24,19 +24,17 @@ namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class PlayerEquipmentPacket extends DataPacket{
const NETWORK_ID = Info::PLAYER_EQUIPMENT_PACKET;
class MobEquipmentPacket extends DataPacket{
const NETWORK_ID = Info::MOB_EQUIPMENT_PACKET;
public $eid;
public $item;
public $meta;
public $slot;
public $selectedSlot;
public function decode(){
$this->eid = $this->getLong();
$this->item = $this->getShort();
$this->meta = $this->getShort();
$this->item = $this->getSlot();
$this->slot = $this->getByte();
$this->selectedSlot = $this->getByte();
}
@ -44,8 +42,7 @@ class PlayerEquipmentPacket extends DataPacket{
public function encode(){
$this->reset();
$this->putLong($this->eid);
$this->putShort($this->item);
$this->putShort($this->meta);
$this->putSlot($this->item);
$this->putByte($this->slot);
$this->putByte($this->selectedSlot);
}

View File

@ -0,0 +1,64 @@
<?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/
*
*
*/
namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class PlayerListPacket extends DataPacket{
const NETWORK_ID = Info::PLAYER_LIST_PACKET;
const TYPE_ADD = 0;
const TYPE_REMOVE = 1;
//REMOVE: UUID, ADD: UUID, entity id, name, isSlim, skin
/** @var array[] */
public $entries = [];
public $type;
public function clean(){
$this->entries = [];
return parent::clean();
}
public function decode(){
}
public function encode(){
$this->reset();
$this->putByte($this->type);
$this->putInt(count($this->entries));
foreach($this->entries as $d){
if($this->type === self::TYPE_ADD){
$this->putUUID($d[0]);
$this->putLong($d[1]);
$this->putString($d[2]);
$this->putByte($d[3] ? 1 : 0);
$this->putString($d[4]);
}else{
$this->putUUID($d[0]);
}
}
}
}

View File

@ -28,7 +28,7 @@ class RemovePlayerPacket extends DataPacket{
const NETWORK_ID = Info::REMOVE_PLAYER_PACKET;
public $eid;
public $clientID;
public $clientId;
public function decode(){
@ -37,7 +37,7 @@ class RemovePlayerPacket extends DataPacket{
public function encode(){
$this->reset();
$this->putLong($this->eid);
$this->putLong($this->clientID);
$this->putUUID($this->clientId);
}
}