Updated composed packets

This commit is contained in:
Shoghi Cervantes 2014-06-30 23:52:33 +02:00
parent d4881260da
commit f5a74a87e3
13 changed files with 58 additions and 209 deletions

View File

@ -69,7 +69,6 @@ use pocketmine\network\protocol\Info as ProtocolInfo;
use pocketmine\network\protocol\LoginStatusPacket;
use pocketmine\network\protocol\MessagePacket;
use pocketmine\network\protocol\MovePlayerPacket;
use pocketmine\network\protocol\ReadyPacket;
use pocketmine\network\protocol\SetSpawnPositionPacket;
use pocketmine\network\protocol\SetTimePacket;
use pocketmine\network\protocol\StartGamePacket;
@ -1227,6 +1226,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$pk->time = $this->getLevel()->getTime();
$this->directDataPacket($pk);
$pk = new SetSpawnPositionPacket;
$pk->x = (int) $this->spawnPosition->x;
$pk->y = (int) $this->spawnPosition->y;
$pk->z = (int) $this->spawnPosition->z;
$this->directDataPacket($pk);
$this->server->getLogger()->info(TextFormat::AQUA . $this->username . TextFormat::WHITE . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->id . " at (" . $this->getLevel()->getName() . ", " . round($this->x, 4) . ", " . round($this->y, 4) . ", " . round($this->z, 4) . ")");
@ -1235,25 +1240,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->sendNextChunk();
$this->tasks[] = $this->chunkLoadTask = $this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "sendNextChunk")), 1);
$pk = new ReadyPacket();
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$this->dataPacket($pk);
break;
case ProtocolInfo::READY_PACKET:
//TODO: check
if($this->loggedIn === false){
break;
}
switch($packet->status){
case 1: //Spawn!!
break;
case 2: //Chunk loaded?
break;
}
break;
case ProtocolInfo::ROTATE_HEAD_PACKET:
if($this->spawned === false){
@ -1338,8 +1324,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
//$this->entity->updateMetadata();
}
break;
case ProtocolInfo::REQUEST_CHUNK_PACKET:
break;
case ProtocolInfo::USE_ITEM_PACKET:
$blockVector = new Vector3($packet->x, $packet->y, $packet->z);

View File

@ -205,10 +205,9 @@ class DroppedItem extends Entity{
$player->dataPacket($pk);
$pk = new SetEntityMotionPacket;
$pk->eid = $this->getID();
$pk->speedX = $this->motionX;
$pk->speedY = $this->motionY;
$pk->speedZ = $this->motionZ;
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
$player->dataPacket($pk);
parent::spawnTo($player);

View File

@ -42,7 +42,7 @@ use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Float;
use pocketmine\nbt\tag\Short;
use pocketmine\network\protocol\MoveEntityPacket_PosRot;
use pocketmine\network\protocol\MoveEntityPacket;
use pocketmine\network\protocol\MovePlayerPacket;
use pocketmine\network\protocol\RemoveEntityPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
@ -442,13 +442,11 @@ abstract class Entity extends Position implements Metadatable{
$pk->pitch = $this->pitch;
$pk->bodyYaw = $this->yaw;
}else{
$pk = new MoveEntityPacket_PosRot;
$pk->eid = $this->id;
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->yaw = $this->yaw;
$pk->pitch = $this->pitch;
//TODO: add to move list
$pk = new MoveEntityPacket();
$pk->entities = [
[$this->id, $this->x, $this->y, $this->z, $this->yaw, $this->pitch]
];
}
$this->server->broadcastPacket($this->hasSpawned, $pk);
}
@ -459,10 +457,9 @@ abstract class Entity extends Position implements Metadatable{
$this->lastMotionZ = $this->motionZ;
$pk = new SetEntityMotionPacket;
$pk->eid = $this->id;
$pk->speedX = $this->motionX;
$pk->speedY = $this->motionY;
$pk->speedZ = $this->motionZ;
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
$this->server->broadcastPacket($this->hasSpawned, $pk);
}
}

View File

@ -30,8 +30,6 @@ use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Short;
use pocketmine\network\protocol\AddPlayerPacket;
use pocketmine\network\protocol\MoveEntityPacket_PosRot;
use pocketmine\network\protocol\MovePlayerPacket;
use pocketmine\network\protocol\RemovePlayerPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\Network;
@ -155,10 +153,9 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$player->dataPacket($pk);
$pk = new SetEntityMotionPacket;
$pk->eid = $this->getID();
$pk->speedX = $this->motionX;
$pk->speedY = $this->motionY;
$pk->speedZ = $this->motionZ;
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
$player->dataPacket($pk);
$this->inventory->sendHeldItem($player);

View File

@ -50,16 +50,13 @@ use pocketmine\network\protocol\LoginPacket;
use pocketmine\network\protocol\LoginStatusPacket;
use pocketmine\network\protocol\MessagePacket;
use pocketmine\network\protocol\MoveEntityPacket;
use pocketmine\network\protocol\MoveEntityPacket_PosRot;
use pocketmine\network\protocol\MovePlayerPacket;
use pocketmine\network\protocol\PlayerActionPacket;
use pocketmine\network\protocol\PlayerArmorEquipmentPacket;
use pocketmine\network\protocol\PlayerEquipmentPacket;
use pocketmine\network\protocol\ReadyPacket;
use pocketmine\network\protocol\RemoveBlockPacket;
use pocketmine\network\protocol\RemoveEntityPacket;
use pocketmine\network\protocol\RemovePlayerPacket;
use pocketmine\network\protocol\RequestChunkPacket;
use pocketmine\network\protocol\RespawnPacket;
use pocketmine\network\protocol\RotateHeadPacket;
use pocketmine\network\protocol\SendInventoryPacket;
@ -197,9 +194,6 @@ class RakLibInterface implements ServerInstance, SourceInterface{
case ProtocolInfo::LOGIN_STATUS_PACKET:
$data = new LoginStatusPacket();
break;
case ProtocolInfo::READY_PACKET:
$data = new ReadyPacket();
break;
case ProtocolInfo::MESSAGE_PACKET:
$data = new MessagePacket();
break;
@ -233,9 +227,6 @@ class RakLibInterface implements ServerInstance, SourceInterface{
case ProtocolInfo::MOVE_ENTITY_PACKET:
$data = new MoveEntityPacket();
break;
case ProtocolInfo::MOVE_ENTITY_PACKET_POSROT:
$data = new MoveEntityPacket_PosRot();
break;
case ProtocolInfo::ROTATE_HEAD_PACKET:
$data = new RotateHeadPacket();
break;
@ -263,9 +254,6 @@ class RakLibInterface implements ServerInstance, SourceInterface{
case ProtocolInfo::ENTITY_EVENT_PACKET:
$data = new EntityEventPacket();
break;
case ProtocolInfo::REQUEST_CHUNK_PACKET:
$data = new RequestChunkPacket();
break;
case ProtocolInfo::PLAYER_EQUIPMENT_PACKET:
$data = new PlayerEquipmentPacket();
break;

View File

@ -57,6 +57,8 @@ class ContainerSetContentPacket extends DataPacket{
foreach($this->hotbar as $slot){
$this->putInt($slot);
}
}else{
$this->putShort(0);
}
}

View File

@ -30,12 +30,12 @@ interface Info{
/**
* Actual Minecraft: PE protocol version
*/
const CURRENT_PROTOCOL = 16;
const CURRENT_PROTOCOL = 17;
const LOGIN_PACKET = 0x82;
const LOGIN_STATUS_PACKET = 0x83;
const READY_PACKET = 0x84;
const MESSAGE_PACKET = 0x85;
const SET_TIME_PACKET = 0x86;
const START_GAME_PACKET = 0x87;
@ -49,7 +49,6 @@ interface Info{
const TAKE_ITEM_ENTITY_PACKET = 0x8f;
const MOVE_ENTITY_PACKET = 0x90;
const MOVE_ENTITY_PACKET_POSROT = 0x93;
const ROTATE_HEAD_PACKET = 0x94;
const MOVE_PLAYER_PACKET = 0x95;
//const PLACE_BLOCK_PACKET = 0x96;
@ -60,7 +59,6 @@ interface Info{
const LEVEL_EVENT_PACKET = 0x9b;
const TILE_EVENT_PACKET = 0x9c;
const ENTITY_EVENT_PACKET = 0x9d;
const REQUEST_CHUNK_PACKET = 0x9e;
const PLAYER_EQUIPMENT_PACKET = 0xa0;
const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa1;

View File

@ -24,6 +24,10 @@ namespace pocketmine\network\protocol;
class MoveEntityPacket extends DataPacket{
// eid, x, y, z, yaw, pitch
/** @var array[] */
public $entities = [];
public function pid(){
return Info::MOVE_ENTITY_PACKET;
}
@ -34,6 +38,15 @@ class MoveEntityPacket extends DataPacket{
public function encode(){
$this->reset();
$this->putInt(count($this->entities));
foreach($this->entities as $d){
$this->putInt($d[0]); //eid
$this->putFloat($d[1]); //x
$this->putFloat($d[2]); //y
$this->putFloat($d[3]); //z
$this->putFloat($d[4]); //yaw
$this->putFloat($d[5]); //pitch
}
}
}

View File

@ -1,51 +0,0 @@
<?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;
class MoveEntityPacket_PosRot extends DataPacket{
public $eid;
public $x;
public $y;
public $z;
public $yaw;
public $pitch;
public function pid(){
return Info::MOVE_ENTITY_PACKET_POSROT;
}
public function decode(){
}
public function encode(){
$this->reset();
$this->putInt($this->eid);
$this->putFloat($this->x);
$this->putFloat($this->y);
$this->putFloat($this->z);
$this->putFloat($this->yaw);
$this->putFloat($this->pitch);
}
}

View File

@ -1,44 +0,0 @@
<?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;
class ReadyPacket extends DataPacket{
public $status;
public function pid(){
return Info::READY_PACKET;
}
public function decode(){
$this->x = $this->getFloat();
$this->y = $this->getFloat();
$this->z = $this->getFloat();
}
public function encode(){
$this->putFloat($this->x);
$this->putFloat($this->y);
$this->putFloat($this->z);
}
}

View File

@ -1,42 +0,0 @@
<?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;
class RequestChunkPacket extends DataPacket{
public $chunkX;
public $chunkZ;
public function pid(){
return Info::REQUEST_CHUNK_PACKET;
}
public function decode(){
$this->chunkX = $this->getInt();
$this->chunkZ = $this->getInt();
}
public function encode(){
}
}

View File

@ -23,8 +23,10 @@ namespace pocketmine\network\protocol;
class RotateHeadPacket extends DataPacket{
public $eid;
public $yaw;
// eid, yaw
/** @var array[] */
public $entities = [];
public function pid(){
return Info::ROTATE_HEAD_PACKET;
@ -36,8 +38,11 @@ class RotateHeadPacket extends DataPacket{
public function encode(){
$this->reset();
$this->putInt($this->eid);
$this->putByte((int) ($this->yaw / 360));
$this->putInt(count($this->entities));
foreach($this->entities as $d){
$this->putInt($d[0]); //eid
$this->putByte((int) ($d[1] / 360));
}
}
}

View File

@ -23,10 +23,10 @@ namespace pocketmine\network\protocol;
class SetEntityMotionPacket extends DataPacket{
public $eid;
public $speedX;
public $speedY;
public $speedZ;
// eid, motX, motY, motZ
/** @var array[] */
public $entities = [];
public function pid(){
return Info::SET_ENTITY_MOTION_PACKET;
@ -38,10 +38,13 @@ class SetEntityMotionPacket extends DataPacket{
public function encode(){
$this->reset();
$this->putInt($this->eid);
$this->putShort((int) ($this->speedX * 400));
$this->putShort((int) ($this->speedY * 400));
$this->putShort((int) ($this->speedZ * 400));
$this->putInt(count($this->entities));
foreach($this->entities as $d){
$this->putInt($d[0]); //eid
$this->putShort((int) ($d[1] * 400)); //motX
$this->putShort((int) ($d[2] * 400)); //motY
$this->putShort((int) ($d[3] * 400)); //motZ
}
}
}