Skins, protocol changes, handle split packets

This commit is contained in:
Shoghi Cervantes
2015-04-08 13:00:15 +02:00
parent c9adc336ee
commit 141c0a297e
26 changed files with 292 additions and 507 deletions

View File

@ -26,7 +26,6 @@ namespace pocketmine\network;
use pocketmine\network\protocol\AddEntityPacket;
use pocketmine\network\protocol\AddItemEntityPacket;
use pocketmine\network\protocol\AddMobPacket;
use pocketmine\network\protocol\AddPaintingPacket;
use pocketmine\network\protocol\AddPlayerPacket;
use pocketmine\network\protocol\AdventureSettingsPacket;
@ -39,6 +38,8 @@ use pocketmine\network\protocol\ContainerSetDataPacket;
use pocketmine\network\protocol\ContainerSetSlotPacket;
use pocketmine\network\protocol\DataPacket;
use pocketmine\network\protocol\DropItemPacket;
use pocketmine\network\protocol\Info;
use pocketmine\network\protocol\SetEntityLinkPacket;
use pocketmine\network\protocol\TileEntityDataPacket;
use pocketmine\network\protocol\EntityEventPacket;
use pocketmine\network\protocol\ExplodePacket;
@ -72,6 +73,7 @@ use pocketmine\network\protocol\UpdateBlockPacket;
use pocketmine\network\protocol\UseItemPacket;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\MainLogger;
class Network{
@ -129,7 +131,20 @@ class Network{
public function processInterfaces(){
foreach($this->interfaces as $interface){
$interface->process();
try {
$interface->process();
}catch(\Exception $e){
$logger = $this->server->getLogger();
if(\pocketmine\DEBUG > 1){
if($logger instanceof MainLogger){
$logger->logException($e);
}
}
$interface->emergencyShutdown();
$this->unregisterInterface($interface);
$logger->critical("[Network] Stopped interface ". get_class($interface) ." due to ". $e->getMessage());
}
}
}
@ -186,10 +201,17 @@ class Network{
$len = strlen($str);
$offset = 0;
while($offset < $len){
if(($packetId = $this->getPacket(ord($str{$offset++}))) !== null){
$packetId->buffer = $str;
$packet->decode();
$p->handleDataPacket($packet);
if(($pk = $this->getPacket(ord($str{$offset++}))) !== null){
if($pk->pid() === Info::BATCH_PACKET){
return;
}
$pk->setBuffer(substr($str, $offset));
$pk->decode();
$p->handleDataPacket($pk);
$offset += $pk->getOffset();
if($pk->getOffset() <= 0){
return;
}
}
}
}
@ -241,7 +263,6 @@ class Network{
$this->registerPacket(ProtocolInfo::TEXT_PACKET, TextPacket::class);
$this->registerPacket(ProtocolInfo::SET_TIME_PACKET, SetTimePacket::class);
$this->registerPacket(ProtocolInfo::START_GAME_PACKET, StartGamePacket::class);
$this->registerPacket(ProtocolInfo::ADD_MOB_PACKET, AddMobPacket::class);
$this->registerPacket(ProtocolInfo::ADD_PLAYER_PACKET, AddPlayerPacket::class);
$this->registerPacket(ProtocolInfo::REMOVE_PLAYER_PACKET, RemovePlayerPacket::class);
$this->registerPacket(ProtocolInfo::ADD_ENTITY_PACKET, AddEntityPacket::class);
@ -265,6 +286,7 @@ class Network{
$this->registerPacket(ProtocolInfo::HURT_ARMOR_PACKET, HurtArmorPacket::class);
$this->registerPacket(ProtocolInfo::SET_ENTITY_DATA_PACKET, SetEntityDataPacket::class);
$this->registerPacket(ProtocolInfo::SET_ENTITY_MOTION_PACKET, SetEntityMotionPacket::class);
$this->registerPacket(ProtocolInfo::SET_ENTITY_LINK_PACKET, SetEntityLinkPacket::class);
$this->registerPacket(ProtocolInfo::SET_HEALTH_PACKET, SetHealthPacket::class);
$this->registerPacket(ProtocolInfo::SET_SPAWN_POSITION_PACKET, SetSpawnPositionPacket::class);
$this->registerPacket(ProtocolInfo::ANIMATE_PACKET, AnimatePacket::class);

View File

@ -22,53 +22,9 @@
namespace pocketmine\network;
use pocketmine\event\player\PlayerCreationEvent;
use pocketmine\network\protocol\AddEntityPacket;
use pocketmine\network\protocol\AddItemEntityPacket;
use pocketmine\network\protocol\AddMobPacket;
use pocketmine\network\protocol\AddPaintingPacket;
use pocketmine\network\protocol\AddPlayerPacket;
use pocketmine\network\protocol\AdventureSettingsPacket;
use pocketmine\network\protocol\AnimatePacket;
use pocketmine\network\protocol\BatchPacket;
use pocketmine\network\protocol\ContainerClosePacket;
use pocketmine\network\protocol\ContainerOpenPacket;
use pocketmine\network\protocol\ContainerSetContentPacket;
use pocketmine\network\protocol\ContainerSetDataPacket;
use pocketmine\network\protocol\ContainerSetSlotPacket;
use pocketmine\network\protocol\DataPacket;
use pocketmine\network\protocol\DropItemPacket;
use pocketmine\network\protocol\TileEntityDataPacket;
use pocketmine\network\protocol\EntityEventPacket;
use pocketmine\network\protocol\ExplodePacket;
use pocketmine\network\protocol\HurtArmorPacket;
use pocketmine\network\protocol\Info as ProtocolInfo;
use pocketmine\network\protocol\InteractPacket;
use pocketmine\network\protocol\LevelEventPacket;
use pocketmine\network\protocol\DisconnectPacket;
use pocketmine\network\protocol\LoginPacket;
use pocketmine\network\protocol\PlayStatusPacket;
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\RemoveBlockPacket;
use pocketmine\network\protocol\RemoveEntityPacket;
use pocketmine\network\protocol\RemovePlayerPacket;
use pocketmine\network\protocol\RespawnPacket;
use pocketmine\network\protocol\SetDifficultyPacket;
use pocketmine\network\protocol\SetEntityDataPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\network\protocol\SetHealthPacket;
use pocketmine\network\protocol\SetSpawnPositionPacket;
use pocketmine\network\protocol\SetTimePacket;
use pocketmine\network\protocol\StartGamePacket;
use pocketmine\network\protocol\TakeItemEntityPacket;
use pocketmine\network\protocol\TileEventPacket;
use pocketmine\network\protocol\UnknownPacket;
use pocketmine\network\protocol\UpdateBlockPacket;
use pocketmine\network\protocol\UseItemPacket;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\MainLogger;
@ -269,7 +225,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
and Network::$BATCH_THRESHOLD >= 0
and strlen($packet->buffer) >= Network::$BATCH_THRESHOLD){
$this->batchedPackets[$this->identifiers[$player]] .= $packet->buffer;
return;
return null;
}
if($pk === null){

View File

@ -24,6 +24,8 @@ namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
use pocketmine\utils\Binary;
class AddEntityPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
@ -33,10 +35,13 @@ class AddEntityPacket extends DataPacket{
public $x;
public $y;
public $z;
public $did;
public $speedX;
public $speedY;
public $speedZ;
public $yaw;
public $pitch;
public $metadata;
public $links = [];
public function pid(){
return Info::ADD_ENTITY_PACKET;
@ -53,11 +58,17 @@ class AddEntityPacket extends DataPacket{
$this->putFloat($this->x);
$this->putFloat($this->y);
$this->putFloat($this->z);
$this->putLong($this->did);
if($this->did > 0){
$this->putFloat($this->speedX);
$this->putFloat($this->speedY);
$this->putFloat($this->speedZ);
$this->putFloat($this->speedX);
$this->putFloat($this->speedY);
$this->putFloat($this->speedZ);
$this->putFloat($this->yaw);
$this->putFloat($this->pitch);
$this->put(Binary::writeMetadata($this->metadata));
$this->putShort(count($this->links));
foreach($this->links as $link){
$this->putLong($link[0]);
$this->putLong($link[1]);
$this->putByte($link[2]);
}
}

View File

@ -32,6 +32,8 @@ class AddPlayerPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
public $clientID;
public $username;
public $eid;
@ -44,6 +46,9 @@ class AddPlayerPacket extends DataPacket{
public $meta;
public $metadata;
public $slim = false;
public $skin = null;
public function pid(){
return Info::ADD_PLAYER_PACKET;
}
@ -61,9 +66,12 @@ class AddPlayerPacket extends DataPacket{
$this->putFloat($this->y);
$this->putFloat($this->z);
$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->put(Binary::writeMetadata($this->metadata));
}

View File

@ -52,6 +52,10 @@ abstract class DataPacket extends \stdClass{
$this->offset = 0;
}
public function getOffset(){
return $this->offset;
}
public function getBuffer(){
return $this->buffer;
}

View File

@ -31,66 +31,65 @@ interface Info{
* Actual Minecraft: PE protocol version
*/
const CURRENT_PROTOCOL = 21;
const LOGIN_PACKET = 0x82;
const PLAY_STATUS_PACKET = 0x83;
const DISCONNECT_PACKET = 0x84;
const TEXT_PACKET = 0x85;
const SET_TIME_PACKET = 0x86;
const START_GAME_PACKET = 0x87;
const ADD_MOB_PACKET = 0x88;
const ADD_PLAYER_PACKET = 0x89;
const REMOVE_PLAYER_PACKET = 0x8a;
const ADD_ENTITY_PACKET = 0x8b;
const REMOVE_ENTITY_PACKET = 0x8c;
const ADD_ITEM_ENTITY_PACKET = 0x8d;
const TAKE_ITEM_ENTITY_PACKET = 0x8e;
const MOVE_ENTITY_PACKET = 0x8f;
const MOVE_PLAYER_PACKET = 0x90;
const REMOVE_BLOCK_PACKET = 0x91;
const UPDATE_BLOCK_PACKET = 0x92;
const ADD_PAINTING_PACKET = 0x93;
const EXPLODE_PACKET = 0x94;
const LEVEL_EVENT_PACKET = 0x95;
const TILE_EVENT_PACKET = 0x96;
const ENTITY_EVENT_PACKET = 0x97;
const MOB_EFFECT_PACKET = 0x98;
const PLAYER_EQUIPMENT_PACKET = 0x99;
const PLAYER_ARMOR_EQUIPMENT_PACKET = 0x9a;
const INTERACT_PACKET = 0x9b;
const USE_ITEM_PACKET = 0x9c;
const PLAYER_ACTION_PACKET = 0x9d;
const HURT_ARMOR_PACKET = 0x9e;
const SET_ENTITY_DATA_PACKET = 0x9f;
const SET_ENTITY_MOTION_PACKET = 0xa0;
//const SET_ENTITY_LINK_PACKET = 0xa1;
const SET_HEALTH_PACKET = 0xa2;
const SET_SPAWN_POSITION_PACKET = 0xa3;
const ANIMATE_PACKET = 0xa4;
const RESPAWN_PACKET = 0xa5;
const DROP_ITEM_PACKET = 0xa6;
const CONTAINER_OPEN_PACKET = 0xa7;
const CONTAINER_CLOSE_PACKET = 0xa8;
const CONTAINER_SET_SLOT_PACKET = 0xa9;
const CONTAINER_SET_DATA_PACKET = 0xaa;
const CONTAINER_SET_CONTENT_PACKET = 0xab;
//const CONTAINER_ACK_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 BATCH_PACKET = 0xb2;
const ADD_PLAYER_PACKET = 0x88;
const REMOVE_PLAYER_PACKET = 0x89;
const ADD_ENTITY_PACKET = 0x8a;
const REMOVE_ENTITY_PACKET = 0x8b;
const ADD_ITEM_ENTITY_PACKET = 0x8c;
const TAKE_ITEM_ENTITY_PACKET = 0x8d;
const MOVE_ENTITY_PACKET = 0x8e;
const MOVE_PLAYER_PACKET = 0x8f;
const REMOVE_BLOCK_PACKET = 0x90;
const UPDATE_BLOCK_PACKET = 0x91;
const ADD_PAINTING_PACKET = 0x92;
const EXPLODE_PACKET = 0x93;
const LEVEL_EVENT_PACKET = 0x94;
const TILE_EVENT_PACKET = 0x95;
const ENTITY_EVENT_PACKET = 0x96;
const MOB_EFFECT_PACKET = 0x97;
const PLAYER_EQUIPMENT_PACKET = 0x98;
const PLAYER_ARMOR_EQUIPMENT_PACKET = 0x99;
const INTERACT_PACKET = 0x9a;
const USE_ITEM_PACKET = 0x9b;
const PLAYER_ACTION_PACKET = 0x9c;
const HURT_ARMOR_PACKET = 0x9d;
const SET_ENTITY_DATA_PACKET = 0x9e;
const SET_ENTITY_MOTION_PACKET = 0x9f;
const SET_ENTITY_LINK_PACKET = 0xa0;
const SET_HEALTH_PACKET = 0xa1;
const SET_SPAWN_POSITION_PACKET = 0xa2;
const ANIMATE_PACKET = 0xa3;
const RESPAWN_PACKET = 0xa4;
const DROP_ITEM_PACKET = 0xa5;
const CONTAINER_OPEN_PACKET = 0xa6;
const CONTAINER_CLOSE_PACKET = 0xa7;
const CONTAINER_SET_SLOT_PACKET = 0xa8;
const CONTAINER_SET_DATA_PACKET = 0xa9;
const CONTAINER_SET_CONTENT_PACKET = 0xaa;
//const CONTAINER_ACK_PACKET = 0xab;
const ADVENTURE_SETTINGS_PACKET = 0xac;
const TILE_ENTITY_DATA_PACKET = 0xad;
//const PLAYER_INPUT_PACKET = 0xae;
const FULL_CHUNK_DATA_PACKET = 0xaf;
const SET_DIFFICULTY_PACKET = 0xb0;
const BATCH_PACKET = 0xb1;
}

View File

@ -38,14 +38,12 @@ class InteractPacket extends DataPacket{
public function decode(){
$this->action = $this->getByte();
$this->eid = $this->getLong();
$this->target = $this->getLong();
}
public function encode(){
$this->reset();
$this->putByte($this->action);
$this->putLong($this->eid);
$this->putLong($this->target);
}

View File

@ -32,7 +32,9 @@ class LoginPacket extends DataPacket{
public $protocol1;
public $protocol2;
public $clientId;
public $loginData;
public $slim = false;
public $skin = null;
public function pid(){
return Info::LOGIN_PACKET;
@ -42,8 +44,12 @@ class LoginPacket extends DataPacket{
$this->username = $this->getString();
$this->protocol1 = $this->getInt();
$this->protocol2 = $this->getInt();
if(Info::CURRENT_PROTOCOL != $this->protocol1){
return;
}
$this->clientId = $this->getInt();
$this->loginData = $this->getString();
$this->slim = $this->getByte() > 0;
$this->skin = $this->getString();
}
public function encode(){

View File

@ -35,7 +35,7 @@ class MovePlayerPacket extends DataPacket{
public $yaw;
public $pitch;
public $bodyYaw;
public $teleport = false;
public $mode = 0;
public function pid(){
return Info::MOVE_PLAYER_PACKET;
@ -52,10 +52,9 @@ class MovePlayerPacket extends DataPacket{
$this->y = $this->getFloat();
$this->z = $this->getFloat();
$this->yaw = $this->getFloat();
$this->pitch = $this->getFloat();
$this->bodyYaw = $this->getFloat();
$flags = $this->getByte();
$this->teleport = (($flags & 0x80) > 0);
$this->pitch = $this->getFloat();
$this->mode = $this->getByte();
}
public function encode(){
@ -65,9 +64,9 @@ class MovePlayerPacket extends DataPacket{
$this->putFloat($this->y);
$this->putFloat($this->z);
$this->putFloat($this->yaw);
$this->putFloat($this->bodyYaw); //TODO
$this->putFloat($this->pitch);
$this->putFloat($this->bodyYaw);
$this->putByte($this->teleport == true ? 0x80 : 0x00);
$this->putByte($this->mode);
}
}

View File

@ -28,7 +28,6 @@ class RespawnPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
public $eid;
public $x;
public $y;
public $z;
@ -38,7 +37,6 @@ class RespawnPacket extends DataPacket{
}
public function decode(){
$this->eid = $this->getLong();
$this->x = $this->getFloat();
$this->y = $this->getFloat();
$this->z = $this->getFloat();
@ -46,7 +44,6 @@ class RespawnPacket extends DataPacket{
public function encode(){
$this->reset();
$this->putLong($this->eid);
$this->putFloat($this->x);
$this->putFloat($this->y);
$this->putFloat($this->z);

View File

@ -23,26 +23,17 @@ namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
#ifndef COMPILE
use pocketmine\utils\Binary;
#endif
class AddMobPacket extends DataPacket{
class SetEntityLinkPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
public $eid;
public $from;
public $to;
public $type;
public $x;
public $y;
public $z;
public $pitch;
public $yaw;
public $metadata;
public function pid(){
return Info::ADD_MOB_PACKET;
return Info::SET_ENTITY_LINK_PACKET;
}
public function decode(){
@ -51,14 +42,9 @@ class AddMobPacket extends DataPacket{
public function encode(){
$this->reset();
$this->putLong($this->eid);
$this->putInt($this->type);
$this->putFloat($this->x);
$this->putFloat($this->y);
$this->putFloat($this->z);
$this->putFloat($this->yaw);
$this->putFloat($this->pitch);
$this->put(Binary::writeMetadata($this->metadata));
$this->putLong($this->from);
$this->putLong($this->to);
$this->putByte($this->type);
}
}