Merge changes from master

This commit is contained in:
Dylan K. Taylor 2017-05-24 09:54:11 +01:00
commit af06d78725
10 changed files with 67 additions and 38 deletions

View File

@ -1918,6 +1918,15 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return false;
}
$this->username = TextFormat::clean($packet->username);
$this->displayName = $this->username;
$this->iusername = strtolower($this->username);
$this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $this->username, false);
if(count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)){
return true;
}
if($packet->protocol !== ProtocolInfo::CURRENT_PROTOCOL){
if($packet->protocol < ProtocolInfo::CURRENT_PROTOCOL){
$message = "disconnectionScreen.outdatedClient";
@ -1931,19 +1940,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
$packet->decodeAdditional();
//TODO: check MCEE
$this->username = TextFormat::clean($packet->username);
$this->displayName = $this->username;
$this->iusername = strtolower($this->username);
$this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $this->username, false);
if(count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)){
return true;
}
$this->randomClientId = $packet->clientId;
$this->uuid = UUID::fromString($packet->clientUUID);
@ -2437,18 +2433,21 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
}
public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{
$tile = $this->getLevel()->getTile($this->temporalVector->setComponents($packet->tileX, $packet->tileY, $packet->tileZ));
if($tile instanceof Tile){ //TODO: check if the held item matches the target tile
$nbt = $tile->getCleanedNBT();
if($nbt instanceof CompoundTag){
$item = $this->inventory->getItemInHand();
$item->setCustomBlockData($nbt);
$item->setLore(["+(DATA)"]);
$this->inventory->setItemInHand($item);
}
if($this->isCreative()){
$tile = $this->getLevel()->getTile($this->temporalVector->setComponents($packet->tileX, $packet->tileY, $packet->tileZ));
if($tile instanceof Tile){ //TODO: check if the held item matches the target tile
$nbt = $tile->getCleanedNBT();
if($nbt instanceof CompoundTag){
$item = $this->inventory->getItemInHand();
$item->setCustomBlockData($nbt);
$item->setLore(["+(DATA)"]);
$this->inventory->setItemInHand($item);
}
return true;
return true;
}
}
return false;
}
@ -3403,16 +3402,13 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$timings->startTiming();
$packet->decode();
assert($packet->feof(), "Still " . strlen(substr($packet->buffer, $packet->offset)) . " bytes unread in " . get_class($packet));
$this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet));
if(!$ev->isCancelled() and !$packet->handle($this)){
$this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->getName() . ": 0x" . bin2hex($packet->buffer));
}
if(!$packet->feof()){
$this->server->getLogger()->debug("Still " . strlen(substr($packet->buffer, $packet->offset)) . " bytes unread in " . get_class($packet) . " from " . $this->getName() . ": " . bin2hex($packet->get(true)));
}
$timings->stopTiming();
}

View File

@ -498,6 +498,7 @@ namespace pocketmine {
$killer = new ServerKiller(8);
$killer->start();
usleep(10000); //Fixes ServerKiller not being able to start on single-core machines
$erroredThreads = 0;
foreach(ThreadManager::getInstance()->getAll() as $id => $thread){

View File

@ -76,7 +76,7 @@ abstract class Entity extends Location implements Metadatable{
const DATA_FLAGS = 0;
const DATA_HEALTH = 1; //int (minecart/boat)
const DATA_VARIANT = 2; //int
const DATA_COLOUR = 3; //byte
const DATA_COLOR = 3, DATA_COLOUR = 3; //byte
const DATA_NAMETAG = 4; //string
const DATA_OWNER_EID = 5; //long
const DATA_TARGET_EID = 6; //long

View File

@ -112,7 +112,8 @@ class FallingSand extends Entity{
if($this->onGround){
$this->kill();
$block = $this->level->getBlock($pos);
if($block->getId() > 0 and !$block->isSolid() and !($block instanceof Liquid)){
if($block->getId() > 0 and $block->isTransparent() and !$block->canBeReplaced()){
//FIXME: anvils are supposed to destroy torches
$this->getLevel()->dropItem($this, ItemItem::get($this->getBlock(), $this->getDamage(), 1));
}else{
$this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, Block::get($this->getBlock(), $this->getDamage())));

View File

@ -156,6 +156,10 @@ class Anvil extends McRegion{
return "anvil";
}
public static function getPcWorldFormatVersion() : int{
return 19133; //anvil
}
public function getWorldHeight() : int{
//TODO: add world height options
return 256;

View File

@ -210,6 +210,14 @@ class McRegion extends BaseLevelProvider{
return "mcregion";
}
/**
* Returns the storage version as per Minecraft PC world formats.
* @return int
*/
public static function getPcWorldFormatVersion() : int{
return 19132; //mcregion
}
public function getWorldHeight() : int{
//TODO: add world height options
return 128;
@ -251,7 +259,7 @@ class McRegion extends BaseLevelProvider{
"SpawnX" => new IntTag("SpawnX", 256),
"SpawnY" => new IntTag("SpawnY", 70),
"SpawnZ" => new IntTag("SpawnZ", 256),
"version" => new IntTag("version", 19133),
"version" => new IntTag("version", static::getPcWorldFormatVersion()),
"DayTime" => new IntTag("DayTime", 0),
"LastPlayed" => new LongTag("LastPlayed", microtime(true) * 1000),
"RandomSeed" => new LongTag("RandomSeed", $seed),

View File

@ -150,4 +150,8 @@ class PMAnvil extends Anvil{
public static function getProviderName() : string{
return "pmanvil";
}
public static function getPcWorldFormatVersion() : int{
return -1; //Not a PC format, only PocketMine-MP
}
}

View File

@ -50,9 +50,12 @@ class LoginPacket extends DataPacket{
public function decode(){
$this->protocol = $this->getInt();
}
public function decodeAdditional(){
if($this->protocol !== ProtocolInfo::CURRENT_PROTOCOL){
$this->buffer = null;
return; //Do not attempt to decode for non-accepted protocols
}
$this->gameEdition = $this->getByte();
$this->setBuffer($this->getString(), 0);

View File

@ -16,23 +16,35 @@
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
* This file is generated automatically, do not edit it manually.
*
*/
/**
* Minecraft: PE multiplayer protocol implementation
*/
namespace pocketmine\network\mcpe\protocol;
/**
* Version numbers and packet IDs for the current Minecraft PE protocol
*/
interface ProtocolInfo{
/**
* NOTE TO DEVELOPERS
* Do not waste your time or ours submitting pull requests changing game and/or protocol version numbers.
* Pull requests changing game and/or protocol version numbers will be closed.
*
* This file is generated automatically, do not edit it manually.
*/
/**
* Actual Minecraft: PE protocol version
*/
const CURRENT_PROTOCOL = 112;
/**
* Current Minecraft PE version reported by the server. This is usually the earliest currently supported version.
*/
const MINECRAFT_VERSION = 'v1.1.0.9 beta';
/**
* Version number sent to clients in ping responses.
*/
const MINECRAFT_VERSION_NETWORK = '1.1.0.9';
const LOGIN_PACKET = 0x01;

View File

@ -139,7 +139,7 @@ abstract class AsyncTask extends Collectable{
*/
public function getFromThreadStore($identifier){
global $store;
return $this->isGarbage() ? null : $store[$identifier];
return ($this->isGarbage() or !isset($store[$identifier])) ? null : $store[$identifier];
}
/**