Merge phase 1 of network refactor - session handler rewrite

There are further changes that need to be done yet, but this section is now ready for showtime.
This commit is contained in:
Dylan K. Taylor 2018-07-21 10:03:17 +01:00
commit 25a5394152
136 changed files with 1879 additions and 1743 deletions

File diff suppressed because it is too large Load Diff

View File

@ -70,7 +70,8 @@ use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag; use pocketmine\nbt\tag\StringTag;
use pocketmine\network\AdvancedNetworkInterface; use pocketmine\network\AdvancedNetworkInterface;
use pocketmine\network\mcpe\CompressBatchedTask; use pocketmine\network\mcpe\CompressBatchedTask;
use pocketmine\network\mcpe\protocol\BatchPacket; use pocketmine\network\mcpe\NetworkCompression;
use pocketmine\network\mcpe\PacketStream;
use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\network\mcpe\protocol\DataPacket;
use pocketmine\network\mcpe\protocol\PlayerListPacket; use pocketmine\network\mcpe\protocol\PlayerListPacket;
use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\network\mcpe\protocol\ProtocolInfo;
@ -223,8 +224,6 @@ class Server{
private $network; private $network;
/** @var bool */ /** @var bool */
private $networkCompressionAsync = true; private $networkCompressionAsync = true;
/** @var int */
public $networkCompressionLevel = 7;
/** @var bool */ /** @var bool */
private $autoTickRate = true; private $autoTickRate = true;
@ -1517,15 +1516,15 @@ class Server{
$this->asyncPool = new AsyncPool($this, $poolSize, (int) max(-1, (int) $this->getProperty("memory.async-worker-hard-limit", 256)), $this->autoloader, $this->logger); $this->asyncPool = new AsyncPool($this, $poolSize, (int) max(-1, (int) $this->getProperty("memory.async-worker-hard-limit", 256)), $this->autoloader, $this->logger);
if($this->getProperty("network.batch-threshold", 256) >= 0){ if($this->getProperty("network.batch-threshold", 256) >= 0){
Network::$BATCH_THRESHOLD = (int) $this->getProperty("network.batch-threshold", 256); NetworkCompression::$THRESHOLD = (int) $this->getProperty("network.batch-threshold", 256);
}else{ }else{
Network::$BATCH_THRESHOLD = -1; NetworkCompression::$THRESHOLD = -1;
} }
$this->networkCompressionLevel = $this->getProperty("network.compression-level", 7); NetworkCompression::$LEVEL = $this->getProperty("network.compression-level", 7);
if($this->networkCompressionLevel < 1 or $this->networkCompressionLevel > 9){ if(NetworkCompression::$LEVEL < 1 or NetworkCompression::$LEVEL > 9){
$this->logger->warning("Invalid network compression level $this->networkCompressionLevel set, setting to default 7"); $this->logger->warning("Invalid network compression level " . NetworkCompression::$LEVEL . " set, setting to default 7");
$this->networkCompressionLevel = 7; NetworkCompression::$LEVEL = 7;
} }
$this->networkCompressionAsync = (bool) $this->getProperty("network.async-compression", true); $this->networkCompressionAsync = (bool) $this->getProperty("network.async-compression", true);
@ -1864,24 +1863,23 @@ class Server{
$targets = array_filter($players, function(Player $player) : bool{ return $player->isConnected(); }); $targets = array_filter($players, function(Player $player) : bool{ return $player->isConnected(); });
if(!empty($targets)){ if(!empty($targets)){
$pk = new BatchPacket(); $stream = new PacketStream();
foreach($packets as $p){ foreach($packets as $p){
$pk->addPacket($p); $stream->putPacket($p);
} }
if(Network::$BATCH_THRESHOLD >= 0 and strlen($pk->payload) >= Network::$BATCH_THRESHOLD){ $compressionLevel = NetworkCompression::$LEVEL;
$pk->setCompressionLevel($this->networkCompressionLevel); if(NetworkCompression::$THRESHOLD < 0 or strlen($stream->buffer) < NetworkCompression::$THRESHOLD){
}else{ $compressionLevel = 0; //Do not compress packets under the threshold
$pk->setCompressionLevel(0); //Do not compress packets under the threshold
$forceSync = true; $forceSync = true;
} }
if(!$forceSync and !$immediate and $this->networkCompressionAsync){ if(!$forceSync and !$immediate and $this->networkCompressionAsync){
$task = new CompressBatchedTask($pk, $targets); $task = new CompressBatchedTask($stream, $targets, $compressionLevel);
$this->asyncPool->submitTask($task); $this->asyncPool->submitTask($task);
}else{ }else{
$this->broadcastPacketsCallback($pk, $targets, $immediate); $this->broadcastPacketsCallback(NetworkCompression::compress($stream->buffer), $targets, $immediate);
} }
} }
@ -1889,17 +1887,13 @@ class Server{
} }
/** /**
* @param BatchPacket $pk * @param string $payload
* @param Player[] $players * @param Player[] $players
* @param bool $immediate * @param bool $immediate
*/ */
public function broadcastPacketsCallback(BatchPacket $pk, array $players, bool $immediate = false){ public function broadcastPacketsCallback(string $payload, array $players, bool $immediate = false){
if(!$pk->isEncoded){
$pk->encode();
}
foreach($players as $i){ foreach($players as $i){
$i->sendDataPacket($pk, false, $immediate); $i->getNetworkSession()->getInterface()->putPacket($i, $payload, $immediate);
} }
} }

View File

@ -25,9 +25,9 @@ namespace pocketmine\inventory;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory; use pocketmine\item\ItemFactory;
use pocketmine\network\mcpe\protocol\BatchPacket; use pocketmine\network\mcpe\NetworkCompression;
use pocketmine\network\mcpe\PacketStream;
use pocketmine\network\mcpe\protocol\CraftingDataPacket; use pocketmine\network\mcpe\protocol\CraftingDataPacket;
use pocketmine\Server;
use pocketmine\timings\Timings; use pocketmine\timings\Timings;
class CraftingManager{ class CraftingManager{
@ -38,7 +38,7 @@ class CraftingManager{
/** @var FurnaceRecipe[] */ /** @var FurnaceRecipe[] */
protected $furnaceRecipes = []; protected $furnaceRecipes = [];
/** @var BatchPacket */ /** @var string */
private $craftingDataCache; private $craftingDataCache;
public function __construct(){ public function __construct(){
@ -102,21 +102,19 @@ class CraftingManager{
$pk->encode(); $pk->encode();
$batch = new BatchPacket(); $batch = new PacketStream();
$batch->addPacket($pk); $batch->putPacket($pk);
$batch->setCompressionLevel(Server::getInstance()->networkCompressionLevel);
$batch->encode();
$this->craftingDataCache = $batch; $this->craftingDataCache = NetworkCompression::compress($batch->buffer);
Timings::$craftingDataCacheRebuildTimer->stopTiming(); Timings::$craftingDataCacheRebuildTimer->stopTiming();
} }
/** /**
* Returns a pre-compressed CraftingDataPacket for sending to players. Rebuilds the cache if it is not found. * Returns a pre-compressed CraftingDataPacket for sending to players. Rebuilds the cache if it is not found.
* *
* @return BatchPacket * @return string
*/ */
public function getCraftingDataPacket() : BatchPacket{ public function getCraftingDataPacket() : string{
if($this->craftingDataCache === null){ if($this->craftingDataCache === null){
$this->buildCraftingDataCache(); $this->buildCraftingDataCache();
} }

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace pocketmine\inventory; namespace pocketmine\inventory;
use pocketmine\entity\Human; use pocketmine\entity\Human;
use pocketmine\event\player\PlayerItemHeldEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\network\mcpe\protocol\InventoryContentPacket; use pocketmine\network\mcpe\protocol\InventoryContentPacket;
use pocketmine\network\mcpe\protocol\MobEquipmentPacket; use pocketmine\network\mcpe\protocol\MobEquipmentPacket;
@ -55,33 +54,7 @@ class PlayerInventory extends BaseInventory{
return 36; return 36;
} }
/** public function isHotbarSlot(int $slot) : bool{
* Called when a client equips a hotbar slot. This method should not be used by plugins.
* This method will call PlayerItemHeldEvent.
*
* @param int $hotbarSlot Number of the hotbar slot to equip.
*
* @return bool if the equipment change was successful, false if not.
*/
public function equipItem(int $hotbarSlot) : bool{
if(!$this->isHotbarSlot($hotbarSlot)){
$this->sendContents($this->getHolder());
return false;
}
$this->getHolder()->getLevel()->getServer()->getPluginManager()->callEvent($ev = new PlayerItemHeldEvent($this->getHolder(), $this->getItem($hotbarSlot), $hotbarSlot));
if($ev->isCancelled()){
$this->sendHeldItem($this->getHolder());
return false;
}
$this->setHeldItemIndex($hotbarSlot, false);
return true;
}
private function isHotbarSlot(int $slot) : bool{
return $slot >= 0 and $slot <= $this->getHotbarSize(); return $slot >= 0 and $slot <= $this->getHotbarSize();
} }

View File

@ -69,7 +69,6 @@ use pocketmine\metadata\MetadataValue;
use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\StringTag; use pocketmine\nbt\tag\StringTag;
use pocketmine\network\mcpe\ChunkRequestTask; use pocketmine\network\mcpe\ChunkRequestTask;
use pocketmine\network\mcpe\protocol\BatchPacket;
use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\network\mcpe\protocol\DataPacket;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
@ -123,7 +122,7 @@ class Level implements ChunkManager, Metadatable{
/** @var Block[][] */ /** @var Block[][] */
private $blockCache = []; private $blockCache = [];
/** @var BatchPacket[] */ /** @var string[] */
private $chunkCache = []; private $chunkCache = [];
/** @var int */ /** @var int */
@ -2498,7 +2497,7 @@ class Level implements ChunkManager, Metadatable{
} }
} }
public function chunkRequestCallback(int $x, int $z, BatchPacket $payload){ public function chunkRequestCallback(int $x, int $z, string $payload){
$this->timings->syncChunkSendTimer->startTiming(); $this->timings->syncChunkSendTimer->startTiming();
$index = Level::chunkHash($x, $z); $index = Level::chunkHash($x, $z);

View File

@ -33,9 +33,6 @@ use pocketmine\network\mcpe\protocol\PacketPool;
use pocketmine\Server; use pocketmine\Server;
class Network{ class Network{
public static $BATCH_THRESHOLD = 512;
/** @var Server */ /** @var Server */
private $server; private $server;

View File

@ -26,7 +26,6 @@ declare(strict_types=1);
*/ */
namespace pocketmine\network; namespace pocketmine\network;
use pocketmine\network\mcpe\protocol\DataPacket;
use pocketmine\Player; use pocketmine\Player;
/** /**
@ -43,13 +42,10 @@ interface NetworkInterface{
* Sends a DataPacket to the interface, returns an unique identifier for the packet if $needACK is true * Sends a DataPacket to the interface, returns an unique identifier for the packet if $needACK is true
* *
* @param Player $player * @param Player $player
* @param DataPacket $packet * @param string $payload
* @param bool $needACK
* @param bool $immediate * @param bool $immediate
*
* @return int|null
*/ */
public function putPacket(Player $player, DataPacket $packet, bool $needACK = false, bool $immediate = true) : ?int; public function putPacket(Player $player, string $payload, bool $immediate = true) : void;
/** /**
* Terminates the connection * Terminates the connection

View File

@ -25,7 +25,6 @@ namespace pocketmine\network\mcpe;
use pocketmine\level\format\Chunk; use pocketmine\level\format\Chunk;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\network\mcpe\protocol\BatchPacket;
use pocketmine\network\mcpe\protocol\FullChunkDataPacket; use pocketmine\network\mcpe\protocol\FullChunkDataPacket;
use pocketmine\scheduler\AsyncTask; use pocketmine\scheduler\AsyncTask;
use pocketmine\Server; use pocketmine\Server;
@ -47,7 +46,7 @@ class ChunkRequestTask extends AsyncTask{
public function __construct(Level $level, int $chunkX, int $chunkZ, Chunk $chunk){ public function __construct(Level $level, int $chunkX, int $chunkZ, Chunk $chunk){
$this->levelId = $level->getId(); $this->levelId = $level->getId();
$this->compressionLevel = $level->getServer()->networkCompressionLevel; $this->compressionLevel = NetworkCompression::$LEVEL;
$this->chunk = $chunk->fastSerialize(); $this->chunk = $chunk->fastSerialize();
$this->chunkX = $chunkX; $this->chunkX = $chunkX;
@ -72,22 +71,17 @@ class ChunkRequestTask extends AsyncTask{
$pk->chunkZ = $this->chunkZ; $pk->chunkZ = $this->chunkZ;
$pk->data = $chunk->networkSerialize() . $this->tiles; $pk->data = $chunk->networkSerialize() . $this->tiles;
$batch = new BatchPacket(); $stream = new PacketStream();
$batch->addPacket($pk); $stream->putPacket($pk);
$batch->setCompressionLevel($this->compressionLevel);
$batch->encode();
$this->setResult($batch->buffer, false); $this->setResult(NetworkCompression::compress($stream->buffer, $this->compressionLevel), false);
} }
public function onCompletion(Server $server) : void{ public function onCompletion(Server $server) : void{
$level = $server->getLevel($this->levelId); $level = $server->getLevel($this->levelId);
if($level instanceof Level){ if($level instanceof Level){
if($this->hasResult()){ if($this->hasResult()){
$batch = new BatchPacket($this->getResult()); $level->chunkRequestCallback($this->chunkX, $this->chunkZ, $this->getResult());
assert(strlen($batch->buffer) > 0);
$batch->isEncoded = true;
$level->chunkRequestCallback($this->chunkX, $this->chunkZ, $batch);
}else{ }else{
$server->getLogger()->error("Chunk request for level #" . $this->levelId . ", x=" . $this->chunkX . ", z=" . $this->chunkZ . " doesn't have any result data"); $server->getLogger()->error("Chunk request for level #" . $this->levelId . ", x=" . $this->chunkX . ", z=" . $this->chunkZ . " doesn't have any result data");
} }

View File

@ -23,44 +23,34 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe; namespace pocketmine\network\mcpe;
use pocketmine\network\mcpe\protocol\BatchPacket;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\scheduler\AsyncTask; use pocketmine\scheduler\AsyncTask;
use pocketmine\Server; use pocketmine\Server;
class CompressBatchedTask extends AsyncTask{ class CompressBatchedTask extends AsyncTask{
public $level = 7; private $level;
public $data; private $data;
/** /**
* @param BatchPacket $batch * @param PacketStream $stream
* @param string[] $targets * @param string[] $targets
* @param int $compressionLevel
*/ */
public function __construct(BatchPacket $batch, array $targets){ public function __construct(PacketStream $stream, array $targets, int $compressionLevel){
$this->data = $batch->payload; $this->data = $stream->buffer;
$this->level = $batch->getCompressionLevel(); $this->level = $compressionLevel;
$this->storeLocal($targets); $this->storeLocal($targets);
} }
public function onRun() : void{ public function onRun() : void{
$batch = new BatchPacket(); $this->setResult(NetworkCompression::compress($this->data, $this->level), false);
$batch->payload = $this->data;
$this->data = null;
$batch->setCompressionLevel($this->level);
$batch->encode();
$this->setResult($batch->buffer, false);
} }
public function onCompletion(Server $server) : void{ public function onCompletion(Server $server) : void{
$pk = new BatchPacket($this->getResult());
$pk->isEncoded = true;
/** @var Player[] $targets */ /** @var Player[] $targets */
$targets = $this->fetchLocal(); $targets = $this->fetchLocal();
$server->broadcastPacketsCallback($pk, $targets); $server->broadcastPacketsCallback($this->getResult(), $targets);
} }
} }

View File

@ -0,0 +1,47 @@
<?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;
final class NetworkCompression{
public static $LEVEL = 7;
public static $THRESHOLD = 256;
private function __construct(){
}
public static function decompress(string $payload) : string{
return zlib_decode($payload, 1024 * 1024 * 64); //Max 64MB
}
/**
* @param string $payload
* @param int $compressionLevel
*
* @return string
*/
public static function compress(string $payload, ?int $compressionLevel = null) : string{
return zlib_encode($payload, ZLIB_ENCODING_DEFLATE, $compressionLevel ?? self::$LEVEL);
}
}

View File

@ -23,569 +23,163 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe; namespace pocketmine\network\mcpe;
use pocketmine\network\mcpe\protocol\AddBehaviorTreePacket; use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\network\mcpe\protocol\AddEntityPacket; use pocketmine\event\server\DataPacketSendEvent;
use pocketmine\network\mcpe\protocol\AddHangingEntityPacket; use pocketmine\network\mcpe\handler\DeathSessionHandler;
use pocketmine\network\mcpe\protocol\AddItemEntityPacket; use pocketmine\network\mcpe\handler\LoginSessionHandler;
use pocketmine\network\mcpe\protocol\AddPaintingPacket; use pocketmine\network\mcpe\handler\PreSpawnSessionHandler;
use pocketmine\network\mcpe\protocol\AddPlayerPacket; use pocketmine\network\mcpe\handler\ResourcePacksSessionHandler;
use pocketmine\network\mcpe\protocol\AdventureSettingsPacket; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\network\mcpe\protocol\AnimatePacket; use pocketmine\network\mcpe\handler\SimpleSessionHandler;
use pocketmine\network\mcpe\protocol\AvailableCommandsPacket;
use pocketmine\network\mcpe\protocol\BlockEntityDataPacket;
use pocketmine\network\mcpe\protocol\BlockEventPacket;
use pocketmine\network\mcpe\protocol\BlockPickRequestPacket;
use pocketmine\network\mcpe\protocol\BookEditPacket;
use pocketmine\network\mcpe\protocol\BossEventPacket;
use pocketmine\network\mcpe\protocol\CameraPacket;
use pocketmine\network\mcpe\protocol\ChangeDimensionPacket;
use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket;
use pocketmine\network\mcpe\protocol\ClientToServerHandshakePacket;
use pocketmine\network\mcpe\protocol\ClientboundMapItemDataPacket;
use pocketmine\network\mcpe\protocol\CommandBlockUpdatePacket;
use pocketmine\network\mcpe\protocol\CommandOutputPacket;
use pocketmine\network\mcpe\protocol\CommandRequestPacket;
use pocketmine\network\mcpe\protocol\ContainerClosePacket;
use pocketmine\network\mcpe\protocol\ContainerOpenPacket;
use pocketmine\network\mcpe\protocol\ContainerSetDataPacket;
use pocketmine\network\mcpe\protocol\CraftingDataPacket;
use pocketmine\network\mcpe\protocol\CraftingEventPacket;
use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\network\mcpe\protocol\DataPacket;
use pocketmine\network\mcpe\protocol\DisconnectPacket; use pocketmine\network\mcpe\protocol\DisconnectPacket;
use pocketmine\network\mcpe\protocol\EntityEventPacket; use pocketmine\network\mcpe\protocol\PacketPool;
use pocketmine\network\mcpe\protocol\EntityFallPacket;
use pocketmine\network\mcpe\protocol\EntityPickRequestPacket;
use pocketmine\network\mcpe\protocol\EventPacket;
use pocketmine\network\mcpe\protocol\ExplodePacket;
use pocketmine\network\mcpe\protocol\FullChunkDataPacket;
use pocketmine\network\mcpe\protocol\GameRulesChangedPacket;
use pocketmine\network\mcpe\protocol\GuiDataPickItemPacket;
use pocketmine\network\mcpe\protocol\HurtArmorPacket;
use pocketmine\network\mcpe\protocol\InteractPacket;
use pocketmine\network\mcpe\protocol\InventoryContentPacket;
use pocketmine\network\mcpe\protocol\InventorySlotPacket;
use pocketmine\network\mcpe\protocol\InventoryTransactionPacket;
use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket;
use pocketmine\network\mcpe\protocol\LabTablePacket;
use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\LoginPacket;
use pocketmine\network\mcpe\protocol\MapInfoRequestPacket;
use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket;
use pocketmine\network\mcpe\protocol\MobEffectPacket;
use pocketmine\network\mcpe\protocol\MobEquipmentPacket;
use pocketmine\network\mcpe\protocol\ModalFormRequestPacket;
use pocketmine\network\mcpe\protocol\ModalFormResponsePacket;
use pocketmine\network\mcpe\protocol\MoveEntityAbsolutePacket;
use pocketmine\network\mcpe\protocol\MoveEntityDeltaPacket;
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
use pocketmine\network\mcpe\protocol\NpcRequestPacket;
use pocketmine\network\mcpe\protocol\PhotoTransferPacket;
use pocketmine\network\mcpe\protocol\PlaySoundPacket;
use pocketmine\network\mcpe\protocol\PlayStatusPacket; use pocketmine\network\mcpe\protocol\PlayStatusPacket;
use pocketmine\network\mcpe\protocol\PlayerActionPacket; use pocketmine\network\NetworkInterface;
use pocketmine\network\mcpe\protocol\PlayerHotbarPacket; use pocketmine\Player;
use pocketmine\network\mcpe\protocol\PlayerInputPacket; use pocketmine\Server;
use pocketmine\network\mcpe\protocol\PlayerListPacket; use pocketmine\timings\Timings;
use pocketmine\network\mcpe\protocol\PlayerSkinPacket;
use pocketmine\network\mcpe\protocol\PurchaseReceiptPacket;
use pocketmine\network\mcpe\protocol\RemoveEntityPacket;
use pocketmine\network\mcpe\protocol\RemoveObjectivePacket;
use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
use pocketmine\network\mcpe\protocol\ResourcePackChunkDataPacket;
use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket;
use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket;
use pocketmine\network\mcpe\protocol\ResourcePackDataInfoPacket;
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\ServerSettingsRequestPacket;
use pocketmine\network\mcpe\protocol\ServerSettingsResponsePacket;
use pocketmine\network\mcpe\protocol\ServerToClientHandshakePacket;
use pocketmine\network\mcpe\protocol\SetCommandsEnabledPacket;
use pocketmine\network\mcpe\protocol\SetDefaultGameTypePacket;
use pocketmine\network\mcpe\protocol\SetDifficultyPacket;
use pocketmine\network\mcpe\protocol\SetDisplayObjectivePacket;
use pocketmine\network\mcpe\protocol\SetEntityDataPacket;
use pocketmine\network\mcpe\protocol\SetEntityLinkPacket;
use pocketmine\network\mcpe\protocol\SetEntityMotionPacket;
use pocketmine\network\mcpe\protocol\SetHealthPacket;
use pocketmine\network\mcpe\protocol\SetLastHurtByPacket;
use pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket;
use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket;
use pocketmine\network\mcpe\protocol\SetScorePacket;
use pocketmine\network\mcpe\protocol\SetSpawnPositionPacket;
use pocketmine\network\mcpe\protocol\SetTimePacket;
use pocketmine\network\mcpe\protocol\SetTitlePacket;
use pocketmine\network\mcpe\protocol\ShowCreditsPacket;
use pocketmine\network\mcpe\protocol\ShowProfilePacket;
use pocketmine\network\mcpe\protocol\ShowStoreOfferPacket;
use pocketmine\network\mcpe\protocol\SimpleEventPacket;
use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket;
use pocketmine\network\mcpe\protocol\StartGamePacket;
use pocketmine\network\mcpe\protocol\StopSoundPacket;
use pocketmine\network\mcpe\protocol\StructureBlockUpdatePacket;
use pocketmine\network\mcpe\protocol\SubClientLoginPacket;
use pocketmine\network\mcpe\protocol\TakeItemEntityPacket;
use pocketmine\network\mcpe\protocol\TextPacket;
use pocketmine\network\mcpe\protocol\TransferPacket;
use pocketmine\network\mcpe\protocol\UpdateAttributesPacket;
use pocketmine\network\mcpe\protocol\UpdateBlockPacket;
use pocketmine\network\mcpe\protocol\UpdateBlockSyncedPacket;
use pocketmine\network\mcpe\protocol\UpdateEquipPacket;
use pocketmine\network\mcpe\protocol\UpdateTradePacket;
use pocketmine\network\mcpe\protocol\WSConnectPacket;
abstract class NetworkSession{ class NetworkSession{
abstract public function handleDataPacket(DataPacket $packet);
public function handleLogin(LoginPacket $packet) : bool{ /** @var Server */
return false; private $server;
} /** @var Player */
private $player;
public function handlePlayStatus(PlayStatusPacket $packet) : bool{ /** @var NetworkInterface */
return false; private $interface;
} /** @var string */
private $ip;
public function handleServerToClientHandshake(ServerToClientHandshakePacket $packet) : bool{ /** @var int */
return false; private $port;
}
public function handleClientToServerHandshake(ClientToServerHandshakePacket $packet) : bool{
return false;
}
public function handleDisconnect(DisconnectPacket $packet) : bool{
return false;
}
public function handleResourcePacksInfo(ResourcePacksInfoPacket $packet) : bool{
return false;
}
public function handleResourcePackStack(ResourcePackStackPacket $packet) : bool{
return false;
}
public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{
return false;
}
public function handleText(TextPacket $packet) : bool{
return false;
}
public function handleSetTime(SetTimePacket $packet) : bool{
return false;
}
public function handleStartGame(StartGamePacket $packet) : bool{ /** @var SessionHandler */
return false; private $handler;
}
public function handleAddPlayer(AddPlayerPacket $packet) : bool{ public function __construct(Server $server, Player $player, NetworkInterface $interface, string $ip, int $port){
return false; $this->server = $server;
} $this->player = $player;
$this->interface = $interface;
public function handleAddEntity(AddEntityPacket $packet) : bool{ $this->ip = $ip;
return false; $this->port = $port;
}
public function handleRemoveEntity(RemoveEntityPacket $packet) : bool{ $this->setHandler(new LoginSessionHandler($player, $this));
return false;
} }
public function handleAddItemEntity(AddItemEntityPacket $packet) : bool{ public function getInterface() : NetworkInterface{
return false; return $this->interface;
} }
public function handleAddHangingEntity(AddHangingEntityPacket $packet) : bool{ /**
return false; * @return string
*/
public function getIp() : string{
return $this->ip;
} }
public function handleTakeItemEntity(TakeItemEntityPacket $packet) : bool{ /**
return false; * @return int
*/
public function getPort() : int{
return $this->port;
} }
public function handleMoveEntityAbsolute(MoveEntityAbsolutePacket $packet) : bool{ public function getHandler() : SessionHandler{
return false; return $this->handler;
} }
public function handleMovePlayer(MovePlayerPacket $packet) : bool{ public function setHandler(SessionHandler $handler) : void{
return false; $this->handler = $handler;
$this->handler->setUp();
} }
public function handleRiderJump(RiderJumpPacket $packet) : bool{ public function handleEncoded(string $payload) : void{
return false; //TODO: decryption if enabled
}
public function handleUpdateBlock(UpdateBlockPacket $packet) : bool{ $stream = new PacketStream(NetworkCompression::decompress($payload));
return false; while(!$stream->feof()){
$this->handleDataPacket(PacketPool::getPacket($stream->getString()));
} }
public function handleAddPainting(AddPaintingPacket $packet) : bool{
return false;
} }
public function handleExplode(ExplodePacket $packet) : bool{ public function handleDataPacket(DataPacket $packet) : void{
return false; $timings = Timings::getReceiveDataPacketTimings($packet);
} $timings->startTiming();
public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{ $packet->decode();
return false; if(!$packet->feof() and !$packet->mayHaveUnreadBytes()){
$remains = substr($packet->buffer, $packet->offset);
$this->server->getLogger()->debug("Still " . strlen($remains) . " bytes unread in " . $packet->getName() . ": 0x" . bin2hex($remains));
} }
public function handleLevelEvent(LevelEventPacket $packet) : bool{ $this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this->player, $packet));
return false; if(!$ev->isCancelled() and !$packet->handle($this->handler)){
$this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->player->getName() . ": 0x" . bin2hex($packet->buffer));
} }
public function handleBlockEvent(BlockEventPacket $packet) : bool{ $timings->stopTiming();
return false;
} }
public function handleEntityEvent(EntityEventPacket $packet) : bool{ public function sendDataPacket(DataPacket $packet, bool $immediate = false) : bool{
$timings = Timings::getSendDataPacketTimings($packet);
$timings->startTiming();
try{
$this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this->player, $packet));
if($ev->isCancelled()){
return false; return false;
} }
public function handleMobEffect(MobEffectPacket $packet) : bool{ //TODO: implement buffering (this is just a quick fix)
return false; $this->server->batchPackets([$this->player], [$packet], true, $immediate);
}
public function handleUpdateAttributes(UpdateAttributesPacket $packet) : bool{ return true;
return false; }finally{
$timings->stopTiming();
} }
public function handleInventoryTransaction(InventoryTransactionPacket $packet) : bool{
return false;
} }
public function handleMobEquipment(MobEquipmentPacket $packet) : bool{ public function serverDisconnect(string $reason, bool $notify = true) : void{
return false; if($notify){
$pk = new DisconnectPacket();
$pk->message = $reason;
$pk->hideDisconnectionScreen = $reason === "";
$this->sendDataPacket($pk, true);
} }
$this->interface->close($this->player, $notify ? $reason : "");
public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{
return false;
} }
public function handleInteract(InteractPacket $packet) : bool{ //TODO: onEnableEncryption() step
return false;
}
public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{ public function onLoginSuccess() : void{
return false; $pk = new PlayStatusPacket();
} $pk->status = PlayStatusPacket::LOGIN_SUCCESS;
$this->sendDataPacket($pk);
public function handleEntityPickRequest(EntityPickRequestPacket $packet) : bool{ $this->setHandler(new ResourcePacksSessionHandler($this->player, $this, $this->server->getResourcePackManager()));
return false;
} }
public function handlePlayerAction(PlayerActionPacket $packet) : bool{ public function onResourcePacksDone() : void{
return false; $this->player->_actuallyConstruct();
}
public function handleEntityFall(EntityFallPacket $packet) : bool{ $this->setHandler(new PreSpawnSessionHandler($this->server, $this->player, $this));
return false;
} }
public function handleHurtArmor(HurtArmorPacket $packet) : bool{ public function onSpawn() : void{
return false; $pk = new PlayStatusPacket();
} $pk->status = PlayStatusPacket::PLAYER_SPAWN;
$this->sendDataPacket($pk);
public function handleSetEntityData(SetEntityDataPacket $packet) : bool{ //TODO: split this up even further
return false; $this->setHandler(new SimpleSessionHandler($this->player));
} }
public function handleSetEntityMotion(SetEntityMotionPacket $packet) : bool{ public function onDeath() : void{
return false; $this->setHandler(new DeathSessionHandler($this->player, $this));
}
public function handleSetEntityLink(SetEntityLinkPacket $packet) : bool{
return false;
}
public function handleSetHealth(SetHealthPacket $packet) : bool{
return false;
}
public function handleSetSpawnPosition(SetSpawnPositionPacket $packet) : bool{
return false;
}
public function handleAnimate(AnimatePacket $packet) : bool{
return false;
}
public function handleRespawn(RespawnPacket $packet) : bool{
return false;
}
public function handleContainerOpen(ContainerOpenPacket $packet) : bool{
return false;
}
public function handleContainerClose(ContainerClosePacket $packet) : bool{
return false;
}
public function handlePlayerHotbar(PlayerHotbarPacket $packet) : bool{
return false;
}
public function handleInventoryContent(InventoryContentPacket $packet) : bool{
return false;
}
public function handleInventorySlot(InventorySlotPacket $packet) : bool{
return false;
}
public function handleContainerSetData(ContainerSetDataPacket $packet) : bool{
return false;
}
public function handleCraftingData(CraftingDataPacket $packet) : bool{
return false;
}
public function handleCraftingEvent(CraftingEventPacket $packet) : bool{
return false;
}
public function handleGuiDataPickItem(GuiDataPickItemPacket $packet) : bool{
return false;
}
public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{
return false;
}
public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{
return false;
}
public function handlePlayerInput(PlayerInputPacket $packet) : bool{
return false;
}
public function handleFullChunkData(FullChunkDataPacket $packet) : bool{
return false;
}
public function handleSetCommandsEnabled(SetCommandsEnabledPacket $packet) : bool{
return false;
}
public function handleSetDifficulty(SetDifficultyPacket $packet) : bool{
return false;
}
public function handleChangeDimension(ChangeDimensionPacket $packet) : bool{
return false;
}
public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{
return false;
}
public function handlePlayerList(PlayerListPacket $packet) : bool{
return false;
}
public function handleSimpleEvent(SimpleEventPacket $packet) : bool{
return false;
} }
public function handleEvent(EventPacket $packet) : bool{ public function onRespawn() : void{
return false; $this->setHandler(new SimpleSessionHandler($this->player));
}
public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool{
return false;
}
public function handleClientboundMapItemData(ClientboundMapItemDataPacket $packet) : bool{
return false;
}
public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool{
return false;
}
public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{
return false;
}
public function handleChunkRadiusUpdated(ChunkRadiusUpdatedPacket $packet) : bool{
return false;
}
public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{
return false;
}
public function handleGameRulesChanged(GameRulesChangedPacket $packet) : bool{
return false;
}
public function handleCamera(CameraPacket $packet) : bool{
return false;
}
public function handleBossEvent(BossEventPacket $packet) : bool{
return false;
}
public function handleShowCredits(ShowCreditsPacket $packet) : bool{
return false;
}
public function handleAvailableCommands(AvailableCommandsPacket $packet) : bool{
return false;
}
public function handleCommandRequest(CommandRequestPacket $packet) : bool{
return false;
}
public function handleCommandBlockUpdate(CommandBlockUpdatePacket $packet) : bool{
return false;
}
public function handleCommandOutput(CommandOutputPacket $packet) : bool{
return false;
}
public function handleUpdateTrade(UpdateTradePacket $packet) : bool{
return false;
}
public function handleUpdateEquip(UpdateEquipPacket $packet) : bool{
return false;
}
public function handleResourcePackDataInfo(ResourcePackDataInfoPacket $packet) : bool{
return false;
}
public function handleResourcePackChunkData(ResourcePackChunkDataPacket $packet) : bool{
return false;
}
public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{
return false;
}
public function handleTransfer(TransferPacket $packet) : bool{
return false;
}
public function handlePlaySound(PlaySoundPacket $packet) : bool{
return false;
}
public function handleStopSound(StopSoundPacket $packet) : bool{
return false;
}
public function handleSetTitle(SetTitlePacket $packet) : bool{
return false;
}
public function handleAddBehaviorTree(AddBehaviorTreePacket $packet) : bool{
return false;
}
public function handleStructureBlockUpdate(StructureBlockUpdatePacket $packet) : bool{
return false;
}
public function handleShowStoreOffer(ShowStoreOfferPacket $packet) : bool{
return false;
}
public function handlePurchaseReceipt(PurchaseReceiptPacket $packet) : bool{
return false;
}
public function handlePlayerSkin(PlayerSkinPacket $packet) : bool{
return false;
}
public function handleSubClientLogin(SubClientLoginPacket $packet) : bool{
return false;
}
public function handleWSConnect(WSConnectPacket $packet) : bool{
return false;
}
public function handleSetLastHurtBy(SetLastHurtByPacket $packet) : bool{
return false;
}
public function handleBookEdit(BookEditPacket $packet) : bool{
return false;
}
public function handleNpcRequest(NpcRequestPacket $packet) : bool{
return false;
}
public function handlePhotoTransfer(PhotoTransferPacket $packet) : bool{
return false;
}
public function handleModalFormRequest(ModalFormRequestPacket $packet) : bool{
return false;
}
public function handleModalFormResponse(ModalFormResponsePacket $packet) : bool{
return false;
}
public function handleServerSettingsRequest(ServerSettingsRequestPacket $packet) : bool{
return false;
}
public function handleServerSettingsResponse(ServerSettingsResponsePacket $packet) : bool{
return false;
}
public function handleShowProfile(ShowProfilePacket $packet) : bool{
return false;
}
public function handleSetDefaultGameType(SetDefaultGameTypePacket $packet) : bool{
return false;
}
public function handleRemoveObjective(RemoveObjectivePacket $packet) : bool{
return false;
}
public function handleSetDisplayObjective(SetDisplayObjectivePacket $packet) : bool{
return false;
}
public function handleSetScore(SetScorePacket $packet) : bool{
return false;
}
public function handleLabTable(LabTablePacket $packet) : bool{
return false;
}
public function handleUpdateBlockSynced(UpdateBlockSyncedPacket $packet) : bool{
return false;
}
public function handleMoveEntityDelta(MoveEntityDeltaPacket $packet) : bool{
return false;
}
public function handleSetLocalPlayerAsInitialized(SetLocalPlayerAsInitializedPacket $packet) : bool{
return false;
} }
} }

View File

@ -0,0 +1,41 @@
<?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;
use pocketmine\network\mcpe\protocol\DataPacket;
use pocketmine\network\mcpe\protocol\PacketPool;
class PacketStream extends NetworkBinaryStream{
public function putPacket(DataPacket $packet) : void{
if(!$packet->isEncoded){
$packet->encode();
}
$this->putString($packet->buffer);
}
public function getPacket() : DataPacket{
return PacketPool::getPacket($this->getString());
}
}

View File

@ -25,9 +25,6 @@ namespace pocketmine\network\mcpe;
use pocketmine\event\player\PlayerCreationEvent; use pocketmine\event\player\PlayerCreationEvent;
use pocketmine\network\AdvancedNetworkInterface; use pocketmine\network\AdvancedNetworkInterface;
use pocketmine\network\mcpe\protocol\BatchPacket;
use pocketmine\network\mcpe\protocol\DataPacket;
use pocketmine\network\mcpe\protocol\PacketPool;
use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\network\Network; use pocketmine\network\Network;
use pocketmine\Player; use pocketmine\Player;
@ -48,6 +45,8 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
*/ */
private const MCPE_RAKNET_PROTOCOL_VERSION = 8; private const MCPE_RAKNET_PROTOCOL_VERSION = 8;
private const MCPE_RAKNET_PACKET_ID = "\xfe";
/** @var Server */ /** @var Server */
private $server; private $server;
@ -63,9 +62,6 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
/** @var string[] */ /** @var string[] */
private $identifiers = []; private $identifiers = [];
/** @var int[] */
private $identifiersACK = [];
/** @var ServerHandler */ /** @var ServerHandler */
private $interface; private $interface;
@ -112,7 +108,6 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
$player = $this->players[$identifier]; $player = $this->players[$identifier];
unset($this->identifiers[spl_object_hash($player)]); unset($this->identifiers[spl_object_hash($player)]);
unset($this->players[$identifier]); unset($this->players[$identifier]);
unset($this->identifiersACK[$identifier]);
$player->close($player->getLeaveMessage(), $reason); $player->close($player->getLeaveMessage(), $reason);
} }
} }
@ -120,7 +115,6 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
public function close(Player $player, string $reason = "unknown reason") : void{ public function close(Player $player, string $reason = "unknown reason") : void{
if(isset($this->identifiers[$h = spl_object_hash($player)])){ if(isset($this->identifiers[$h = spl_object_hash($player)])){
unset($this->players[$this->identifiers[$h]]); unset($this->players[$this->identifiers[$h]]);
unset($this->identifiersACK[$this->identifiers[$h]]);
$this->interface->closeSession($this->identifiers[$h], $reason); $this->interface->closeSession($this->identifiers[$h], $reason);
unset($this->identifiers[$h]); unset($this->identifiers[$h]);
} }
@ -143,7 +137,6 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
$player = new $class($this, $ev->getAddress(), $ev->getPort()); $player = new $class($this, $ev->getAddress(), $ev->getPort());
$this->players[$identifier] = $player; $this->players[$identifier] = $player;
$this->identifiersACK[$identifier] = 0;
$this->identifiers[spl_object_hash($player)] = $identifier; $this->identifiers[spl_object_hash($player)] = $identifier;
$this->server->addPlayer($player); $this->server->addPlayer($player);
} }
@ -153,13 +146,12 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
//get this now for blocking in case the player was closed before the exception was raised //get this now for blocking in case the player was closed before the exception was raised
$address = $this->players[$identifier]->getAddress(); $address = $this->players[$identifier]->getAddress();
try{ try{
if($packet->buffer !== ""){ if($packet->buffer !== "" and $packet->buffer{0} === self::MCPE_RAKNET_PACKET_ID){ //Batch
$pk = PacketPool::getPacket($packet->buffer); $this->players[$identifier]->getNetworkSession()->handleEncoded(substr($packet->buffer, 1));
$this->players[$identifier]->handleDataPacket($pk);
} }
}catch(\Throwable $e){ }catch(\Throwable $e){
$logger = $this->server->getLogger(); $logger = $this->server->getLogger();
$logger->debug("Packet " . (isset($pk) ? get_class($pk) : "unknown") . " 0x" . bin2hex($packet->buffer)); $logger->debug("EncapsulatedPacket 0x" . bin2hex($packet->buffer));
$logger->logException($e); $logger->logException($e);
$this->interface->blockAddress($address, 5); $this->interface->blockAddress($address, 5);
@ -216,42 +208,19 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{
} }
} }
public function putPacket(Player $player, DataPacket $packet, bool $needACK = false, bool $immediate = true) : ?int{ public function putPacket(Player $player, string $payload, bool $immediate = true) : void{
if(isset($this->identifiers[$h = spl_object_hash($player)])){ if(isset($this->identifiers[$h = spl_object_hash($player)])){
$identifier = $this->identifiers[$h]; $identifier = $this->identifiers[$h];
if(!$packet->isEncoded){
$packet->encode();
}
if($packet instanceof BatchPacket){
if($needACK){
$pk = new EncapsulatedPacket(); $pk = new EncapsulatedPacket();
$pk->identifierACK = $this->identifiersACK[$identifier]++; $pk->buffer = self::MCPE_RAKNET_PACKET_ID . $payload;
$pk->buffer = $packet->buffer;
$pk->reliability = PacketReliability::RELIABLE_ORDERED; $pk->reliability = PacketReliability::RELIABLE_ORDERED;
$pk->orderChannel = 0; $pk->orderChannel = 0;
}else{
if(!isset($packet->__encapsulatedPacket)){
$packet->__encapsulatedPacket = new CachedEncapsulatedPacket;
$packet->__encapsulatedPacket->identifierACK = null;
$packet->__encapsulatedPacket->buffer = $packet->buffer;
$packet->__encapsulatedPacket->reliability = PacketReliability::RELIABLE_ORDERED;
$packet->__encapsulatedPacket->orderChannel = 0;
}
$pk = $packet->__encapsulatedPacket;
}
$this->interface->sendEncapsulated($identifier, $pk, ($needACK ? RakLib::FLAG_NEED_ACK : 0) | ($immediate ? RakLib::PRIORITY_IMMEDIATE : RakLib::PRIORITY_NORMAL)); $this->interface->sendEncapsulated($identifier, $pk, ($immediate ? RakLib::PRIORITY_IMMEDIATE : RakLib::PRIORITY_NORMAL));
return $pk->identifierACK;
}else{
$this->server->batchPackets([$player], [$packet], true, $immediate);
return null;
} }
} }
return null;
}
public function updatePing(string $identifier, int $pingMS) : void{ public function updatePing(string $identifier, int $pingMS) : void{
if(isset($this->players[$identifier])){ if(isset($this->players[$identifier])){
$this->players[$identifier]->updatePing($pingMS); $this->players[$identifier]->updatePing($pingMS);

View File

@ -0,0 +1,61 @@
<?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\handler;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\PlayerActionPacket;
use pocketmine\network\mcpe\protocol\RespawnPacket;
use pocketmine\Player;
class DeathSessionHandler extends SessionHandler{
/** @var Player */
private $player;
/** @var NetworkSession */
private $session;
public function __construct(Player $player, NetworkSession $session){
$this->player = $player;
$this->session = $session;
}
public function setUp() : void{
$pk = new RespawnPacket();
$pk->position = $this->player->getOffsetPosition($this->player->getSpawn());
$this->session->sendDataPacket($pk);
}
public function handlePlayerAction(PlayerActionPacket $packet) : bool{
switch($packet->action){
case PlayerActionPacket::ACTION_RESPAWN:
$this->player->respawn();
return true;
case PlayerActionPacket::ACTION_DIMENSION_CHANGE_REQUEST:
//TODO: players send this when they die in another dimension
break;
}
return false;
}
}

View File

@ -0,0 +1,89 @@
<?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\handler;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\LoginPacket;
use pocketmine\network\mcpe\protocol\PlayStatusPacket;
use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\Player;
/**
* Handles the initial login phase of the session. This handler is used as the initial state.
*/
class LoginSessionHandler extends SessionHandler{
/** @var Player */
private $player;
/** @var NetworkSession */
private $session;
public function __construct(Player $player, NetworkSession $session){
$this->player = $player;
$this->session = $session;
}
public function handleLogin(LoginPacket $packet) : bool{
if(!$this->isCompatibleProtocol($packet->protocol)){
$pk = new PlayStatusPacket();
$pk->status = $packet->protocol < ProtocolInfo::CURRENT_PROTOCOL ?
PlayStatusPacket::LOGIN_FAILED_CLIENT : PlayStatusPacket::LOGIN_FAILED_SERVER;
$pk->protocol = $packet->protocol;
$this->session->sendDataPacket($pk, true);
//This pocketmine disconnect message will only be seen by the console (PlayStatusPacket causes the messages to be shown for the client)
$this->player->close(
"",
$this->player->getServer()->getLanguage()->translateString("pocketmine.disconnect.incompatibleProtocol", [$packet->protocol]),
false
);
return true;
}
if(!Player::isValidUserName($packet->username)){
$this->player->close("", "disconnectionScreen.invalidName");
return true;
}
if($packet->skin === null or !$packet->skin->isValid()){
$this->player->close("", "disconnectionScreen.invalidSkin");
return true;
}
if($this->player->handleLogin($packet)){
if($this->session->getHandler() === $this){ //when login verification is disabled, the handler will already have been replaced
$this->session->setHandler(new NullSessionHandler()); //drop packets received during login verification
}
return true;
}
return false;
}
protected function isCompatibleProtocol(int $protocolVersion) : bool{
return $protocolVersion === ProtocolInfo::CURRENT_PROTOCOL;
}
}

View File

@ -21,15 +21,11 @@
declare(strict_types=1); declare(strict_types=1);
namespace pocketmine\network\mcpe; namespace pocketmine\network\mcpe\handler;
use raklib\protocol\EncapsulatedPacket; /**
* Handler which simply ignores all packets received.
*/
class NullSessionHandler extends SessionHandler{
class CachedEncapsulatedPacket extends EncapsulatedPacket{
/** @var string|null */
private $internalData = null;
public function toInternalBinary() : string{
return $this->internalData ?? ($this->internalData = parent::toInternalBinary());
}
} }

View File

@ -0,0 +1,99 @@
<?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\handler;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
use pocketmine\network\mcpe\protocol\StartGamePacket;
use pocketmine\network\mcpe\protocol\types\DimensionIds;
use pocketmine\Player;
use pocketmine\Server;
/**
* Handler used for the pre-spawn phase of the session.
*/
class PreSpawnSessionHandler extends SessionHandler{
/** @var Server */
private $server;
/** @var Player */
private $player;
/** @var NetworkSession */
private $session;
public function __construct(Server $server, Player $player, NetworkSession $session){
$this->player = $player;
$this->server = $server;
$this->session = $session;
}
public function setUp() : void{
$spawnPosition = $this->player->getSpawn();
$pk = new StartGamePacket();
$pk->entityUniqueId = $this->player->getId();
$pk->entityRuntimeId = $this->player->getId();
$pk->playerGamemode = Player::getClientFriendlyGamemode($this->player->getGamemode());
$pk->playerPosition = $this->player->getOffsetPosition($this->player);
$pk->pitch = $this->player->pitch;
$pk->yaw = $this->player->yaw;
$pk->seed = -1;
$pk->dimension = DimensionIds::OVERWORLD; //TODO: implement this properly
$pk->worldGamemode = Player::getClientFriendlyGamemode($this->server->getGamemode());
$pk->difficulty = $this->player->getLevel()->getDifficulty();
$pk->spawnX = $spawnPosition->getFloorX();
$pk->spawnY = $spawnPosition->getFloorY();
$pk->spawnZ = $spawnPosition->getFloorZ();
$pk->hasAchievementsDisabled = true;
$pk->time = $this->player->getLevel()->getTime();
$pk->eduMode = false;
$pk->rainLevel = 0; //TODO: implement these properly
$pk->lightningLevel = 0;
$pk->commandsEnabled = true;
$pk->levelId = "";
$pk->worldName = $this->server->getMotd();
$this->session->sendDataPacket($pk);
$this->player->getLevel()->sendTime($this->player);
$this->player->sendAttributes(true);
$this->player->sendCommandData();
$this->player->sendSettings();
$this->player->sendPotionEffects($this->player);
$this->player->sendData($this->player);
$this->player->sendAllInventories();
$this->player->getInventory()->sendCreativeContents();
$this->player->getInventory()->sendHeldItem($this->player);
$this->session->getInterface()->putPacket($this->player, $this->server->getCraftingManager()->getCraftingDataPacket());
$this->server->sendFullPlayerListData($this->player);
}
public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{
$this->player->setViewDistance($packet->radius);
return true;
}
}

View File

@ -0,0 +1,125 @@
<?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\handler;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\ResourcePackChunkDataPacket;
use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket;
use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket;
use pocketmine\network\mcpe\protocol\ResourcePackDataInfoPacket;
use pocketmine\network\mcpe\protocol\ResourcePacksInfoPacket;
use pocketmine\network\mcpe\protocol\ResourcePackStackPacket;
use pocketmine\Player;
use pocketmine\resourcepacks\ResourcePack;
use pocketmine\resourcepacks\ResourcePackManager;
/**
* Handler used for the resource packs sequence phase of the session. This handler takes care of downloading resource
* packs to the client.
*/
class ResourcePacksSessionHandler extends SessionHandler{
private const PACK_CHUNK_SIZE = 1048576; //1MB
/** @var Player */
private $player;
/** @var NetworkSession */
private $session;
/** @var ResourcePackManager */
private $resourcePackManager;
public function __construct(Player $player, NetworkSession $session, ResourcePackManager $resourcePackManager){
$this->player = $player;
$this->session = $session;
$this->resourcePackManager = $resourcePackManager;
}
public function setUp() : void{
$pk = new ResourcePacksInfoPacket();
$pk->resourcePackEntries = $this->resourcePackManager->getResourceStack();
$pk->mustAccept = $this->resourcePackManager->resourcePacksRequired();
$this->session->sendDataPacket($pk);
}
public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{
switch($packet->status){
case ResourcePackClientResponsePacket::STATUS_REFUSED:
//TODO: add lang strings for this
$this->player->close("", "You must accept resource packs to join this server.", true);
break;
case ResourcePackClientResponsePacket::STATUS_SEND_PACKS:
foreach($packet->packIds as $uuid){
$pack = $this->resourcePackManager->getPackById($uuid);
if(!($pack instanceof ResourcePack)){
//Client requested a resource pack but we don't have it available on the server
$this->player->close("", "disconnectionScreen.resourcePack", true);
$this->player->getServer()->getLogger()->debug("Got a resource pack request for unknown pack with UUID " . $uuid . ", available packs: " . implode(", ", $this->resourcePackManager->getPackIdList()));
return false;
}
$pk = new ResourcePackDataInfoPacket();
$pk->packId = $pack->getPackId();
$pk->maxChunkSize = self::PACK_CHUNK_SIZE; //1MB
$pk->chunkCount = (int) ceil($pack->getPackSize() / self::PACK_CHUNK_SIZE);
$pk->compressedPackSize = $pack->getPackSize();
$pk->sha256 = $pack->getSha256();
$this->session->sendDataPacket($pk);
}
break;
case ResourcePackClientResponsePacket::STATUS_HAVE_ALL_PACKS:
$pk = new ResourcePackStackPacket();
$pk->resourcePackStack = $this->resourcePackManager->getResourceStack();
$pk->mustAccept = $this->resourcePackManager->resourcePacksRequired();
$this->session->sendDataPacket($pk);
break;
case ResourcePackClientResponsePacket::STATUS_COMPLETED:
$this->session->onResourcePacksDone();
break;
default:
return false;
}
return true;
}
public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{
$pack = $this->resourcePackManager->getPackById($packet->packId);
if(!($pack instanceof ResourcePack)){
$this->player->close("", "disconnectionScreen.resourcePack", true);
$this->player->getServer()->getLogger()->debug("Got a resource pack chunk request for unknown pack with UUID " . $packet->packId . ", available packs: " . implode(", ", $this->resourcePackManager->getPackIdList()));
return false;
}
$pk = new ResourcePackChunkDataPacket();
$pk->packId = $pack->getPackId();
$pk->chunkIndex = $packet->chunkIndex;
$pk->data = $pack->getPackChunk(self::PACK_CHUNK_SIZE * $packet->chunkIndex, self::PACK_CHUNK_SIZE);
$pk->progress = (self::PACK_CHUNK_SIZE * $packet->chunkIndex);
$this->session->sendDataPacket($pk);
return true;
}
}

View File

@ -0,0 +1,598 @@
<?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\handler;
use pocketmine\network\mcpe\protocol\AddBehaviorTreePacket;
use pocketmine\network\mcpe\protocol\AddEntityPacket;
use pocketmine\network\mcpe\protocol\AddHangingEntityPacket;
use pocketmine\network\mcpe\protocol\AddItemEntityPacket;
use pocketmine\network\mcpe\protocol\AddPaintingPacket;
use pocketmine\network\mcpe\protocol\AddPlayerPacket;
use pocketmine\network\mcpe\protocol\AdventureSettingsPacket;
use pocketmine\network\mcpe\protocol\AnimatePacket;
use pocketmine\network\mcpe\protocol\AvailableCommandsPacket;
use pocketmine\network\mcpe\protocol\BlockEntityDataPacket;
use pocketmine\network\mcpe\protocol\BlockEventPacket;
use pocketmine\network\mcpe\protocol\BlockPickRequestPacket;
use pocketmine\network\mcpe\protocol\BookEditPacket;
use pocketmine\network\mcpe\protocol\BossEventPacket;
use pocketmine\network\mcpe\protocol\CameraPacket;
use pocketmine\network\mcpe\protocol\ChangeDimensionPacket;
use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket;
use pocketmine\network\mcpe\protocol\ClientboundMapItemDataPacket;
use pocketmine\network\mcpe\protocol\ClientToServerHandshakePacket;
use pocketmine\network\mcpe\protocol\CommandBlockUpdatePacket;
use pocketmine\network\mcpe\protocol\CommandOutputPacket;
use pocketmine\network\mcpe\protocol\CommandRequestPacket;
use pocketmine\network\mcpe\protocol\ContainerClosePacket;
use pocketmine\network\mcpe\protocol\ContainerOpenPacket;
use pocketmine\network\mcpe\protocol\ContainerSetDataPacket;
use pocketmine\network\mcpe\protocol\CraftingDataPacket;
use pocketmine\network\mcpe\protocol\CraftingEventPacket;
use pocketmine\network\mcpe\protocol\DisconnectPacket;
use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\network\mcpe\protocol\EntityFallPacket;
use pocketmine\network\mcpe\protocol\EntityPickRequestPacket;
use pocketmine\network\mcpe\protocol\EventPacket;
use pocketmine\network\mcpe\protocol\ExplodePacket;
use pocketmine\network\mcpe\protocol\FullChunkDataPacket;
use pocketmine\network\mcpe\protocol\GameRulesChangedPacket;
use pocketmine\network\mcpe\protocol\GuiDataPickItemPacket;
use pocketmine\network\mcpe\protocol\HurtArmorPacket;
use pocketmine\network\mcpe\protocol\InteractPacket;
use pocketmine\network\mcpe\protocol\InventoryContentPacket;
use pocketmine\network\mcpe\protocol\InventorySlotPacket;
use pocketmine\network\mcpe\protocol\InventoryTransactionPacket;
use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket;
use pocketmine\network\mcpe\protocol\LabTablePacket;
use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\LoginPacket;
use pocketmine\network\mcpe\protocol\MapInfoRequestPacket;
use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket;
use pocketmine\network\mcpe\protocol\MobEffectPacket;
use pocketmine\network\mcpe\protocol\MobEquipmentPacket;
use pocketmine\network\mcpe\protocol\ModalFormRequestPacket;
use pocketmine\network\mcpe\protocol\ModalFormResponsePacket;
use pocketmine\network\mcpe\protocol\MoveEntityAbsolutePacket;
use pocketmine\network\mcpe\protocol\MoveEntityDeltaPacket;
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
use pocketmine\network\mcpe\protocol\NpcRequestPacket;
use pocketmine\network\mcpe\protocol\PhotoTransferPacket;
use pocketmine\network\mcpe\protocol\PlayerActionPacket;
use pocketmine\network\mcpe\protocol\PlayerHotbarPacket;
use pocketmine\network\mcpe\protocol\PlayerInputPacket;
use pocketmine\network\mcpe\protocol\PlayerListPacket;
use pocketmine\network\mcpe\protocol\PlayerSkinPacket;
use pocketmine\network\mcpe\protocol\PlaySoundPacket;
use pocketmine\network\mcpe\protocol\PlayStatusPacket;
use pocketmine\network\mcpe\protocol\PurchaseReceiptPacket;
use pocketmine\network\mcpe\protocol\RemoveEntityPacket;
use pocketmine\network\mcpe\protocol\RemoveObjectivePacket;
use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
use pocketmine\network\mcpe\protocol\ResourcePackChunkDataPacket;
use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket;
use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket;
use pocketmine\network\mcpe\protocol\ResourcePackDataInfoPacket;
use pocketmine\network\mcpe\protocol\ResourcePacksInfoPacket;
use pocketmine\network\mcpe\protocol\ResourcePackStackPacket;
use pocketmine\network\mcpe\protocol\RespawnPacket;
use pocketmine\network\mcpe\protocol\RiderJumpPacket;
use pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket;
use pocketmine\network\mcpe\protocol\ServerSettingsResponsePacket;
use pocketmine\network\mcpe\protocol\ServerToClientHandshakePacket;
use pocketmine\network\mcpe\protocol\SetCommandsEnabledPacket;
use pocketmine\network\mcpe\protocol\SetDefaultGameTypePacket;
use pocketmine\network\mcpe\protocol\SetDifficultyPacket;
use pocketmine\network\mcpe\protocol\SetDisplayObjectivePacket;
use pocketmine\network\mcpe\protocol\SetEntityDataPacket;
use pocketmine\network\mcpe\protocol\SetEntityLinkPacket;
use pocketmine\network\mcpe\protocol\SetEntityMotionPacket;
use pocketmine\network\mcpe\protocol\SetHealthPacket;
use pocketmine\network\mcpe\protocol\SetLastHurtByPacket;
use pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket;
use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket;
use pocketmine\network\mcpe\protocol\SetScorePacket;
use pocketmine\network\mcpe\protocol\SetSpawnPositionPacket;
use pocketmine\network\mcpe\protocol\SetTimePacket;
use pocketmine\network\mcpe\protocol\SetTitlePacket;
use pocketmine\network\mcpe\protocol\ShowCreditsPacket;
use pocketmine\network\mcpe\protocol\ShowProfilePacket;
use pocketmine\network\mcpe\protocol\ShowStoreOfferPacket;
use pocketmine\network\mcpe\protocol\SimpleEventPacket;
use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket;
use pocketmine\network\mcpe\protocol\StartGamePacket;
use pocketmine\network\mcpe\protocol\StopSoundPacket;
use pocketmine\network\mcpe\protocol\StructureBlockUpdatePacket;
use pocketmine\network\mcpe\protocol\SubClientLoginPacket;
use pocketmine\network\mcpe\protocol\TakeItemEntityPacket;
use pocketmine\network\mcpe\protocol\TextPacket;
use pocketmine\network\mcpe\protocol\TransferPacket;
use pocketmine\network\mcpe\protocol\UpdateAttributesPacket;
use pocketmine\network\mcpe\protocol\UpdateBlockPacket;
use pocketmine\network\mcpe\protocol\UpdateBlockSyncedPacket;
use pocketmine\network\mcpe\protocol\UpdateEquipPacket;
use pocketmine\network\mcpe\protocol\UpdateTradePacket;
use pocketmine\network\mcpe\protocol\WSConnectPacket;
/**
* Handlers are attached to sessions to handle packets received from their associated clients. A handler
* is mutable and may be removed/replaced at any time.
*
* This class is an automatically generated stub. Do not edit it manually.
*/
abstract class SessionHandler{
public function setUp() : void{
}
public function handleLogin(LoginPacket $packet) : bool{
return false;
}
public function handlePlayStatus(PlayStatusPacket $packet) : bool{
return false;
}
public function handleServerToClientHandshake(ServerToClientHandshakePacket $packet) : bool{
return false;
}
public function handleClientToServerHandshake(ClientToServerHandshakePacket $packet) : bool{
return false;
}
public function handleDisconnect(DisconnectPacket $packet) : bool{
return false;
}
public function handleResourcePacksInfo(ResourcePacksInfoPacket $packet) : bool{
return false;
}
public function handleResourcePackStack(ResourcePackStackPacket $packet) : bool{
return false;
}
public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{
return false;
}
public function handleText(TextPacket $packet) : bool{
return false;
}
public function handleSetTime(SetTimePacket $packet) : bool{
return false;
}
public function handleStartGame(StartGamePacket $packet) : bool{
return false;
}
public function handleAddPlayer(AddPlayerPacket $packet) : bool{
return false;
}
public function handleAddEntity(AddEntityPacket $packet) : bool{
return false;
}
public function handleRemoveEntity(RemoveEntityPacket $packet) : bool{
return false;
}
public function handleAddItemEntity(AddItemEntityPacket $packet) : bool{
return false;
}
public function handleAddHangingEntity(AddHangingEntityPacket $packet) : bool{
return false;
}
public function handleTakeItemEntity(TakeItemEntityPacket $packet) : bool{
return false;
}
public function handleMoveEntityAbsolute(MoveEntityAbsolutePacket $packet) : bool{
return false;
}
public function handleMovePlayer(MovePlayerPacket $packet) : bool{
return false;
}
public function handleRiderJump(RiderJumpPacket $packet) : bool{
return false;
}
public function handleUpdateBlock(UpdateBlockPacket $packet) : bool{
return false;
}
public function handleAddPainting(AddPaintingPacket $packet) : bool{
return false;
}
public function handleExplode(ExplodePacket $packet) : bool{
return false;
}
public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{
return false;
}
public function handleLevelEvent(LevelEventPacket $packet) : bool{
return false;
}
public function handleBlockEvent(BlockEventPacket $packet) : bool{
return false;
}
public function handleEntityEvent(EntityEventPacket $packet) : bool{
return false;
}
public function handleMobEffect(MobEffectPacket $packet) : bool{
return false;
}
public function handleUpdateAttributes(UpdateAttributesPacket $packet) : bool{
return false;
}
public function handleInventoryTransaction(InventoryTransactionPacket $packet) : bool{
return false;
}
public function handleMobEquipment(MobEquipmentPacket $packet) : bool{
return false;
}
public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{
return false;
}
public function handleInteract(InteractPacket $packet) : bool{
return false;
}
public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{
return false;
}
public function handleEntityPickRequest(EntityPickRequestPacket $packet) : bool{
return false;
}
public function handlePlayerAction(PlayerActionPacket $packet) : bool{
return false;
}
public function handleEntityFall(EntityFallPacket $packet) : bool{
return false;
}
public function handleHurtArmor(HurtArmorPacket $packet) : bool{
return false;
}
public function handleSetEntityData(SetEntityDataPacket $packet) : bool{
return false;
}
public function handleSetEntityMotion(SetEntityMotionPacket $packet) : bool{
return false;
}
public function handleSetEntityLink(SetEntityLinkPacket $packet) : bool{
return false;
}
public function handleSetHealth(SetHealthPacket $packet) : bool{
return false;
}
public function handleSetSpawnPosition(SetSpawnPositionPacket $packet) : bool{
return false;
}
public function handleAnimate(AnimatePacket $packet) : bool{
return false;
}
public function handleRespawn(RespawnPacket $packet) : bool{
return false;
}
public function handleContainerOpen(ContainerOpenPacket $packet) : bool{
return false;
}
public function handleContainerClose(ContainerClosePacket $packet) : bool{
return false;
}
public function handlePlayerHotbar(PlayerHotbarPacket $packet) : bool{
return false;
}
public function handleInventoryContent(InventoryContentPacket $packet) : bool{
return false;
}
public function handleInventorySlot(InventorySlotPacket $packet) : bool{
return false;
}
public function handleContainerSetData(ContainerSetDataPacket $packet) : bool{
return false;
}
public function handleCraftingData(CraftingDataPacket $packet) : bool{
return false;
}
public function handleCraftingEvent(CraftingEventPacket $packet) : bool{
return false;
}
public function handleGuiDataPickItem(GuiDataPickItemPacket $packet) : bool{
return false;
}
public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{
return false;
}
public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{
return false;
}
public function handlePlayerInput(PlayerInputPacket $packet) : bool{
return false;
}
public function handleFullChunkData(FullChunkDataPacket $packet) : bool{
return false;
}
public function handleSetCommandsEnabled(SetCommandsEnabledPacket $packet) : bool{
return false;
}
public function handleSetDifficulty(SetDifficultyPacket $packet) : bool{
return false;
}
public function handleChangeDimension(ChangeDimensionPacket $packet) : bool{
return false;
}
public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{
return false;
}
public function handlePlayerList(PlayerListPacket $packet) : bool{
return false;
}
public function handleSimpleEvent(SimpleEventPacket $packet) : bool{
return false;
}
public function handleEvent(EventPacket $packet) : bool{
return false;
}
public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool{
return false;
}
public function handleClientboundMapItemData(ClientboundMapItemDataPacket $packet) : bool{
return false;
}
public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool{
return false;
}
public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{
return false;
}
public function handleChunkRadiusUpdated(ChunkRadiusUpdatedPacket $packet) : bool{
return false;
}
public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{
return false;
}
public function handleGameRulesChanged(GameRulesChangedPacket $packet) : bool{
return false;
}
public function handleCamera(CameraPacket $packet) : bool{
return false;
}
public function handleBossEvent(BossEventPacket $packet) : bool{
return false;
}
public function handleShowCredits(ShowCreditsPacket $packet) : bool{
return false;
}
public function handleAvailableCommands(AvailableCommandsPacket $packet) : bool{
return false;
}
public function handleCommandRequest(CommandRequestPacket $packet) : bool{
return false;
}
public function handleCommandBlockUpdate(CommandBlockUpdatePacket $packet) : bool{
return false;
}
public function handleCommandOutput(CommandOutputPacket $packet) : bool{
return false;
}
public function handleUpdateTrade(UpdateTradePacket $packet) : bool{
return false;
}
public function handleUpdateEquip(UpdateEquipPacket $packet) : bool{
return false;
}
public function handleResourcePackDataInfo(ResourcePackDataInfoPacket $packet) : bool{
return false;
}
public function handleResourcePackChunkData(ResourcePackChunkDataPacket $packet) : bool{
return false;
}
public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{
return false;
}
public function handleTransfer(TransferPacket $packet) : bool{
return false;
}
public function handlePlaySound(PlaySoundPacket $packet) : bool{
return false;
}
public function handleStopSound(StopSoundPacket $packet) : bool{
return false;
}
public function handleSetTitle(SetTitlePacket $packet) : bool{
return false;
}
public function handleAddBehaviorTree(AddBehaviorTreePacket $packet) : bool{
return false;
}
public function handleStructureBlockUpdate(StructureBlockUpdatePacket $packet) : bool{
return false;
}
public function handleShowStoreOffer(ShowStoreOfferPacket $packet) : bool{
return false;
}
public function handlePurchaseReceipt(PurchaseReceiptPacket $packet) : bool{
return false;
}
public function handlePlayerSkin(PlayerSkinPacket $packet) : bool{
return false;
}
public function handleSubClientLogin(SubClientLoginPacket $packet) : bool{
return false;
}
public function handleWSConnect(WSConnectPacket $packet) : bool{
return false;
}
public function handleSetLastHurtBy(SetLastHurtByPacket $packet) : bool{
return false;
}
public function handleBookEdit(BookEditPacket $packet) : bool{
return false;
}
public function handleNpcRequest(NpcRequestPacket $packet) : bool{
return false;
}
public function handlePhotoTransfer(PhotoTransferPacket $packet) : bool{
return false;
}
public function handleModalFormRequest(ModalFormRequestPacket $packet) : bool{
return false;
}
public function handleModalFormResponse(ModalFormResponsePacket $packet) : bool{
return false;
}
public function handleServerSettingsRequest(ServerSettingsRequestPacket $packet) : bool{
return false;
}
public function handleServerSettingsResponse(ServerSettingsResponsePacket $packet) : bool{
return false;
}
public function handleShowProfile(ShowProfilePacket $packet) : bool{
return false;
}
public function handleSetDefaultGameType(SetDefaultGameTypePacket $packet) : bool{
return false;
}
public function handleRemoveObjective(RemoveObjectivePacket $packet) : bool{
return false;
}
public function handleSetDisplayObjective(SetDisplayObjectivePacket $packet) : bool{
return false;
}
public function handleSetScore(SetScorePacket $packet) : bool{
return false;
}
public function handleLabTable(LabTablePacket $packet) : bool{
return false;
}
public function handleUpdateBlockSynced(UpdateBlockSyncedPacket $packet) : bool{
return false;
}
public function handleMoveEntityDelta(MoveEntityDeltaPacket $packet) : bool{
return false;
}
public function handleSetLocalPlayerAsInitialized(SetLocalPlayerAsInitializedPacket $packet) : bool{
return false;
}
}

View File

@ -21,11 +21,9 @@
declare(strict_types=1); declare(strict_types=1);
namespace pocketmine\network\mcpe; namespace pocketmine\network\mcpe\handler;
use pocketmine\math\Vector3;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\event\server\DataPacketSendEvent;
use pocketmine\network\mcpe\protocol\AdventureSettingsPacket; use pocketmine\network\mcpe\protocol\AdventureSettingsPacket;
use pocketmine\network\mcpe\protocol\AnimatePacket; use pocketmine\network\mcpe\protocol\AnimatePacket;
use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; use pocketmine\network\mcpe\protocol\BlockEntityDataPacket;
@ -37,16 +35,14 @@ use pocketmine\network\mcpe\protocol\CommandBlockUpdatePacket;
use pocketmine\network\mcpe\protocol\CommandRequestPacket; use pocketmine\network\mcpe\protocol\CommandRequestPacket;
use pocketmine\network\mcpe\protocol\ContainerClosePacket; use pocketmine\network\mcpe\protocol\ContainerClosePacket;
use pocketmine\network\mcpe\protocol\CraftingEventPacket; use pocketmine\network\mcpe\protocol\CraftingEventPacket;
use pocketmine\network\mcpe\protocol\DataPacket;
use pocketmine\network\mcpe\protocol\DisconnectPacket;
use pocketmine\network\mcpe\protocol\EntityEventPacket; use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\network\mcpe\protocol\EntityFallPacket; use pocketmine\network\mcpe\protocol\EntityFallPacket;
use pocketmine\network\mcpe\protocol\EntityPickRequestPacket; use pocketmine\network\mcpe\protocol\EntityPickRequestPacket;
use pocketmine\network\mcpe\protocol\InteractPacket; use pocketmine\network\mcpe\protocol\InteractPacket;
use pocketmine\network\mcpe\protocol\InventoryTransactionPacket; use pocketmine\network\mcpe\protocol\InventoryTransactionPacket;
use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket; use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket;
use pocketmine\network\mcpe\protocol\LabTablePacket;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\LoginPacket;
use pocketmine\network\mcpe\protocol\MapInfoRequestPacket; use pocketmine\network\mcpe\protocol\MapInfoRequestPacket;
use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket; use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket;
use pocketmine\network\mcpe\protocol\MobEquipmentPacket; use pocketmine\network\mcpe\protocol\MobEquipmentPacket;
@ -57,90 +53,32 @@ use pocketmine\network\mcpe\protocol\PlayerHotbarPacket;
use pocketmine\network\mcpe\protocol\PlayerInputPacket; use pocketmine\network\mcpe\protocol\PlayerInputPacket;
use pocketmine\network\mcpe\protocol\PlayerSkinPacket; use pocketmine\network\mcpe\protocol\PlayerSkinPacket;
use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket; use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket;
use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket;
use pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket; use pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket;
use pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket;
use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket; use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket;
use pocketmine\network\mcpe\protocol\ShowCreditsPacket; use pocketmine\network\mcpe\protocol\ShowCreditsPacket;
use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket; use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket;
use pocketmine\network\mcpe\protocol\SubClientLoginPacket;
use pocketmine\network\mcpe\protocol\TextPacket; use pocketmine\network\mcpe\protocol\TextPacket;
use pocketmine\network\NetworkInterface;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\Server;
use pocketmine\timings\Timings;
class PlayerNetworkSessionAdapter extends NetworkSession{ /**
* Temporary session handler implementation
* TODO: split this up properly into different handlers
*/
class SimpleSessionHandler extends SessionHandler{
/** @var Server */
private $server;
/** @var Player */ /** @var Player */
private $player; private $player;
/** @var NetworkInterface */
private $interface;
public function __construct(Server $server, Player $player, NetworkInterface $interface){ public function __construct(Player $player){
$this->server = $server;
$this->player = $player; $this->player = $player;
$this->interface = $interface;
}
public function handleDataPacket(DataPacket $packet) : void{
$timings = Timings::getReceiveDataPacketTimings($packet);
$timings->startTiming();
$packet->decode();
if(!$packet->feof() and !$packet->mayHaveUnreadBytes()){
$remains = substr($packet->buffer, $packet->offset);
$this->server->getLogger()->debug("Still " . strlen($remains) . " bytes unread in " . $packet->getName() . ": 0x" . bin2hex($remains));
}
$this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this->player, $packet));
if(!$ev->isCancelled() and !$packet->handle($this)){
$this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->player->getName() . ": 0x" . bin2hex($packet->buffer));
}
$timings->stopTiming();
}
public function sendDataPacket(DataPacket $packet, bool $immediate = false) : bool{
$timings = Timings::getSendDataPacketTimings($packet);
$timings->startTiming();
try{
$this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this->player, $packet));
if($ev->isCancelled()){
return false;
}
$this->interface->putPacket($this->player, $packet, false, $immediate);
return true;
}finally{
$timings->stopTiming();
}
}
public function serverDisconnect(string $reason, bool $notify = true) : void{
if($notify){
$pk = new DisconnectPacket();
$pk->message = $reason;
$pk->hideDisconnectionScreen = $reason === "";
$this->sendDataPacket($pk, true);
}
$this->interface->close($this->player, $notify ? $reason : "");
}
public function handleLogin(LoginPacket $packet) : bool{
return $this->player->handleLogin($packet);
} }
public function handleClientToServerHandshake(ClientToServerHandshakePacket $packet) : bool{ public function handleClientToServerHandshake(ClientToServerHandshakePacket $packet) : bool{
return false; //TODO return false; //TODO
} }
public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{
return $this->player->handleResourcePackClientResponse($packet);
}
public function handleText(TextPacket $packet) : bool{ public function handleText(TextPacket $packet) : bool{
if($packet->type === TextPacket::TYPE_CHAT){ if($packet->type === TextPacket::TYPE_CHAT){
return $this->player->chat($packet->message); return $this->player->chat($packet->message);
@ -166,7 +104,7 @@ class PlayerNetworkSessionAdapter extends NetworkSession{
} }
public function handleMobEquipment(MobEquipmentPacket $packet) : bool{ public function handleMobEquipment(MobEquipmentPacket $packet) : bool{
return $this->player->handleMobEquipment($packet); return $this->player->equipItem($packet->hotbarSlot);
} }
public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{ public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{
@ -174,11 +112,11 @@ class PlayerNetworkSessionAdapter extends NetworkSession{
} }
public function handleInteract(InteractPacket $packet) : bool{ public function handleInteract(InteractPacket $packet) : bool{
return $this->player->handleInteract($packet); return false; //TODO
} }
public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{ public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{
return $this->player->handleBlockPickRequest($packet); return $this->player->pickBlock(new Vector3($packet->blockX, $packet->blockY, $packet->blockZ), $packet->addUserData);
} }
public function handleEntityPickRequest(EntityPickRequestPacket $packet) : bool{ public function handleEntityPickRequest(EntityPickRequestPacket $packet) : bool{
@ -186,7 +124,58 @@ class PlayerNetworkSessionAdapter extends NetworkSession{
} }
public function handlePlayerAction(PlayerActionPacket $packet) : bool{ public function handlePlayerAction(PlayerActionPacket $packet) : bool{
return $this->player->handlePlayerAction($packet); $pos = new Vector3($packet->x, $packet->y, $packet->z);
switch($packet->action){
case PlayerActionPacket::ACTION_START_BREAK:
$this->player->startBreakBlock($pos, $packet->face);
break;
case PlayerActionPacket::ACTION_ABORT_BREAK:
case PlayerActionPacket::ACTION_STOP_BREAK:
$this->player->stopBreakBlock($pos);
break;
case PlayerActionPacket::ACTION_START_SLEEPING:
//unused
break;
case PlayerActionPacket::ACTION_STOP_SLEEPING:
$this->player->stopSleep();
break;
case PlayerActionPacket::ACTION_JUMP:
$this->player->jump();
return true;
case PlayerActionPacket::ACTION_START_SPRINT:
$this->player->toggleSprint(true);
return true;
case PlayerActionPacket::ACTION_STOP_SPRINT:
$this->player->toggleSprint(false);
return true;
case PlayerActionPacket::ACTION_START_SNEAK:
$this->player->toggleSneak(true);
return true;
case PlayerActionPacket::ACTION_STOP_SNEAK:
$this->player->toggleSneak(false);
return true;
case PlayerActionPacket::ACTION_START_GLIDE:
case PlayerActionPacket::ACTION_STOP_GLIDE:
break; //TODO
case PlayerActionPacket::ACTION_CONTINUE_BREAK:
$this->player->continueBreakBlock($pos, $packet->face);
break;
case PlayerActionPacket::ACTION_START_SWIMMING:
break; //TODO
case PlayerActionPacket::ACTION_STOP_SWIMMING:
//TODO: handle this when it doesn't spam every damn tick (yet another spam bug!!)
break;
default:
$this->player->getServer()->getLogger()->debug("Unhandled/unknown player action type " . $packet->action . " from " . $this->player->getName());
return false;
}
$this->player->setUsingItem(false);
return true;
} }
public function handleEntityFall(EntityFallPacket $packet) : bool{ public function handleEntityFall(EntityFallPacket $packet) : bool{
@ -194,11 +183,11 @@ class PlayerNetworkSessionAdapter extends NetworkSession{
} }
public function handleAnimate(AnimatePacket $packet) : bool{ public function handleAnimate(AnimatePacket $packet) : bool{
return $this->player->handleAnimate($packet); return $this->player->animate($packet->action);
} }
public function handleContainerClose(ContainerClosePacket $packet) : bool{ public function handleContainerClose(ContainerClosePacket $packet) : bool{
return $this->player->handleContainerClose($packet); return $this->player->doCloseWindow($packet->windowId);
} }
public function handlePlayerHotbar(PlayerHotbarPacket $packet) : bool{ public function handlePlayerHotbar(PlayerHotbarPacket $packet) : bool{
@ -222,7 +211,12 @@ class PlayerNetworkSessionAdapter extends NetworkSession{
} }
public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{ public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{
return $this->player->handleSetPlayerGameType($packet); if($packet->gamemode !== $this->player->getGamemode()){
//Set this back to default. TODO: handle this properly
$this->player->sendGamemode();
$this->player->sendSettings();
}
return true;
} }
public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool{ public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool{
@ -259,14 +253,14 @@ class PlayerNetworkSessionAdapter extends NetworkSession{
return false; //TODO return false; //TODO
} }
public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{
return $this->player->handleResourcePackChunkRequest($packet);
}
public function handlePlayerSkin(PlayerSkinPacket $packet) : bool{ public function handlePlayerSkin(PlayerSkinPacket $packet) : bool{
return $this->player->changeSkin($packet->skin, $packet->newSkinName, $packet->oldSkinName); return $this->player->changeSkin($packet->skin, $packet->newSkinName, $packet->oldSkinName);
} }
public function handleSubClientLogin(SubClientLoginPacket $packet) : bool{
return false; //TODO
}
public function handleBookEdit(BookEditPacket $packet) : bool{ public function handleBookEdit(BookEditPacket $packet) : bool{
return $this->player->handleBookEdit($packet); return $this->player->handleBookEdit($packet);
} }
@ -278,4 +272,12 @@ class PlayerNetworkSessionAdapter extends NetworkSession{
public function handleServerSettingsRequest(ServerSettingsRequestPacket $packet) : bool{ public function handleServerSettingsRequest(ServerSettingsRequestPacket $packet) : bool{
return false; //TODO: GUI stuff return false; //TODO: GUI stuff
} }
public function handleLabTable(LabTablePacket $packet) : bool{
return false; //TODO
}
public function handleSetLocalPlayerAsInitialized(SetLocalPlayerAsInitializedPacket $packet) : bool{
return false; //TODO
}
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class AddBehaviorTreePacket extends DataPacket{ class AddBehaviorTreePacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::ADD_BEHAVIOR_TREE_PACKET; public const NETWORK_ID = ProtocolInfo::ADD_BEHAVIOR_TREE_PACKET;
@ -41,7 +41,7 @@ class AddBehaviorTreePacket extends DataPacket{
$this->putString($this->behaviorTreeJson); $this->putString($this->behaviorTreeJson);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleAddBehaviorTree($this); return $handler->handleAddBehaviorTree($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\entity\Attribute; use pocketmine\entity\Attribute;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\network\mcpe\protocol\types\EntityLink; use pocketmine\network\mcpe\protocol\types\EntityLink;
class AddEntityPacket extends DataPacket{ class AddEntityPacket extends DataPacket{
@ -117,7 +117,7 @@ class AddEntityPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleAddEntity($this); return $handler->handleAddEntity($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class AddHangingEntityPacket extends DataPacket{ class AddHangingEntityPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::ADD_HANGING_ENTITY_PACKET; public const NETWORK_ID = ProtocolInfo::ADD_HANGING_ENTITY_PACKET;
@ -57,7 +57,7 @@ class AddHangingEntityPacket extends DataPacket{
$this->putVarInt($this->direction); $this->putVarInt($this->direction);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleAddHangingEntity($this); return $handler->handleAddHangingEntity($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class AddItemEntityPacket extends DataPacket{ class AddItemEntityPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::ADD_ITEM_ENTITY_PACKET; public const NETWORK_ID = ProtocolInfo::ADD_ITEM_ENTITY_PACKET;
@ -67,7 +67,7 @@ class AddItemEntityPacket extends DataPacket{
$this->putBool($this->isFromFishing); $this->putBool($this->isFromFishing);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleAddItemEntity($this); return $handler->handleAddItemEntity($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class AddPaintingPacket extends AddHangingEntityPacket{ class AddPaintingPacket extends AddHangingEntityPacket{
public const NETWORK_ID = ProtocolInfo::ADD_PAINTING_PACKET; public const NETWORK_ID = ProtocolInfo::ADD_PAINTING_PACKET;
@ -44,7 +44,7 @@ class AddPaintingPacket extends AddHangingEntityPacket{
$this->putString($this->title); $this->putString($this->title);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleAddPainting($this); return $handler->handleAddPainting($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\network\mcpe\protocol\types\EntityLink; use pocketmine\network\mcpe\protocol\types\EntityLink;
use pocketmine\utils\UUID; use pocketmine\utils\UUID;
@ -135,7 +135,7 @@ class AddPlayerPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleAddPlayer($this); return $handler->handleAddPlayer($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\network\mcpe\protocol\types\PlayerPermissions; use pocketmine\network\mcpe\protocol\types\PlayerPermissions;
class AdventureSettingsPacket extends DataPacket{ class AdventureSettingsPacket extends DataPacket{
@ -116,7 +116,7 @@ class AdventureSettingsPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleAdventureSettings($this); return $handler->handleAdventureSettings($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class AnimatePacket extends DataPacket{ class AnimatePacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::ANIMATE_PACKET; public const NETWORK_ID = ProtocolInfo::ANIMATE_PACKET;
@ -59,7 +59,7 @@ class AnimatePacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleAnimate($this); return $handler->handleAnimate($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\network\mcpe\protocol\types\CommandData; use pocketmine\network\mcpe\protocol\types\CommandData;
use pocketmine\network\mcpe\protocol\types\CommandEnum; use pocketmine\network\mcpe\protocol\types\CommandEnum;
use pocketmine\network\mcpe\protocol\types\CommandParameter; use pocketmine\network\mcpe\protocol\types\CommandParameter;
@ -336,7 +336,7 @@ class AvailableCommandsPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleAvailableCommands($this); return $handler->handleAvailableCommands($this);
} }
} }

View File

@ -1,122 +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/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkBinaryStream;
use pocketmine\network\mcpe\NetworkSession;
#ifndef COMPILE
use pocketmine\utils\Binary;
#endif
class BatchPacket extends DataPacket{
public const NETWORK_ID = 0xfe;
/** @var string */
public $payload = "";
/** @var int */
protected $compressionLevel = 7;
public function canBeBatched() : bool{
return false;
}
public function canBeSentBeforeLogin() : bool{
return true;
}
protected function decodeHeader() : void{
$pid = $this->getByte();
assert($pid === static::NETWORK_ID);
}
protected function decodePayload() : void{
$data = $this->getRemaining();
try{
$this->payload = zlib_decode($data, 1024 * 1024 * 64); //Max 64MB
}catch(\ErrorException $e){ //zlib decode error
$this->payload = "";
}
}
protected function encodeHeader() : void{
$this->putByte(static::NETWORK_ID);
}
protected function encodePayload() : void{
$this->put(zlib_encode($this->payload, ZLIB_ENCODING_DEFLATE, $this->compressionLevel));
}
/**
* @param DataPacket $packet
*/
public function addPacket(DataPacket $packet) : void{
if(!$packet->canBeBatched()){
throw new \InvalidArgumentException(get_class($packet) . " cannot be put inside a BatchPacket");
}
if(!$packet->isEncoded){
$packet->encode();
}
$this->payload .= Binary::writeUnsignedVarInt(strlen($packet->buffer)) . $packet->buffer;
}
/**
* @return \Generator
*/
public function getPackets() : \Generator{
$stream = new NetworkBinaryStream($this->payload);
while(!$stream->feof()){
yield $stream->getString();
}
}
public function getCompressionLevel() : int{
return $this->compressionLevel;
}
public function setCompressionLevel(int $level) : void{
$this->compressionLevel = $level;
}
public function handle(NetworkSession $session) : bool{
if($this->payload === ""){
return false;
}
foreach($this->getPackets() as $buf){
$pk = PacketPool::getPacket($buf);
if(!$pk->canBeBatched()){
throw new \InvalidArgumentException("Received invalid " . get_class($pk) . " inside BatchPacket");
}
$session->handleDataPacket($pk);
}
return true;
}
}

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class BlockEntityDataPacket extends DataPacket{ class BlockEntityDataPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::BLOCK_ENTITY_DATA_PACKET; public const NETWORK_ID = ProtocolInfo::BLOCK_ENTITY_DATA_PACKET;
@ -50,7 +50,7 @@ class BlockEntityDataPacket extends DataPacket{
$this->put($this->namedtag); $this->put($this->namedtag);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleBlockEntityData($this); return $handler->handleBlockEntityData($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class BlockEventPacket extends DataPacket{ class BlockEventPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::BLOCK_EVENT_PACKET; public const NETWORK_ID = ProtocolInfo::BLOCK_EVENT_PACKET;
@ -54,7 +54,7 @@ class BlockEventPacket extends DataPacket{
$this->putVarInt($this->eventData); $this->putVarInt($this->eventData);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleBlockEvent($this); return $handler->handleBlockEvent($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class BlockPickRequestPacket extends DataPacket{ class BlockPickRequestPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::BLOCK_PICK_REQUEST_PACKET; public const NETWORK_ID = ProtocolInfo::BLOCK_PICK_REQUEST_PACKET;
@ -55,7 +55,7 @@ class BlockPickRequestPacket extends DataPacket{
$this->putByte($this->hotbarSlot); $this->putByte($this->hotbarSlot);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleBlockPickRequest($this); return $handler->handleBlockPickRequest($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class BookEditPacket extends DataPacket{ class BookEditPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::BOOK_EDIT_PACKET; public const NETWORK_ID = ProtocolInfo::BOOK_EDIT_PACKET;
@ -113,7 +113,7 @@ class BookEditPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleBookEdit($this); return $handler->handleBookEdit($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class BossEventPacket extends DataPacket{ class BossEventPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::BOSS_EVENT_PACKET; public const NETWORK_ID = ProtocolInfo::BOSS_EVENT_PACKET;
@ -126,7 +126,7 @@ class BossEventPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleBossEvent($this); return $handler->handleBossEvent($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class CameraPacket extends DataPacket{ class CameraPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::CAMERA_PACKET; public const NETWORK_ID = ProtocolInfo::CAMERA_PACKET;
@ -45,7 +45,7 @@ class CameraPacket extends DataPacket{
$this->putEntityUniqueId($this->playerUniqueId); $this->putEntityUniqueId($this->playerUniqueId);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleCamera($this); return $handler->handleCamera($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ChangeDimensionPacket extends DataPacket{ class ChangeDimensionPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::CHANGE_DIMENSION_PACKET; public const NETWORK_ID = ProtocolInfo::CHANGE_DIMENSION_PACKET;
@ -51,7 +51,7 @@ class ChangeDimensionPacket extends DataPacket{
$this->putBool($this->respawn); $this->putBool($this->respawn);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleChangeDimension($this); return $handler->handleChangeDimension($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ChunkRadiusUpdatedPacket extends DataPacket{ class ChunkRadiusUpdatedPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::CHUNK_RADIUS_UPDATED_PACKET; public const NETWORK_ID = ProtocolInfo::CHUNK_RADIUS_UPDATED_PACKET;
@ -42,7 +42,7 @@ class ChunkRadiusUpdatedPacket extends DataPacket{
$this->putVarInt($this->radius); $this->putVarInt($this->radius);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleChunkRadiusUpdated($this); return $handler->handleChunkRadiusUpdated($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ClientToServerHandshakePacket extends DataPacket{ class ClientToServerHandshakePacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::CLIENT_TO_SERVER_HANDSHAKE_PACKET; public const NETWORK_ID = ProtocolInfo::CLIENT_TO_SERVER_HANDSHAKE_PACKET;
@ -43,7 +43,7 @@ class ClientToServerHandshakePacket extends DataPacket{
//No payload //No payload
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleClientToServerHandshake($this); return $handler->handleClientToServerHandshake($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\network\mcpe\protocol\types\DimensionIds; use pocketmine\network\mcpe\protocol\types\DimensionIds;
use pocketmine\network\mcpe\protocol\types\MapTrackedObject; use pocketmine\network\mcpe\protocol\types\MapTrackedObject;
use pocketmine\utils\Color; use pocketmine\utils\Color;
@ -194,7 +194,7 @@ class ClientboundMapItemDataPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleClientboundMapItemData($this); return $handler->handleClientboundMapItemData($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class CommandBlockUpdatePacket extends DataPacket{ class CommandBlockUpdatePacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::COMMAND_BLOCK_UPDATE_PACKET; public const NETWORK_ID = ProtocolInfo::COMMAND_BLOCK_UPDATE_PACKET;
@ -99,7 +99,7 @@ class CommandBlockUpdatePacket extends DataPacket{
$this->putBool($this->shouldTrackOutput); $this->putBool($this->shouldTrackOutput);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleCommandBlockUpdate($this); return $handler->handleCommandBlockUpdate($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\network\mcpe\protocol\types\CommandOriginData; use pocketmine\network\mcpe\protocol\types\CommandOriginData;
use pocketmine\network\mcpe\protocol\types\CommandOutputMessage; use pocketmine\network\mcpe\protocol\types\CommandOutputMessage;
@ -95,7 +95,7 @@ class CommandOutputPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleCommandOutput($this); return $handler->handleCommandOutput($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\network\mcpe\protocol\types\CommandOriginData; use pocketmine\network\mcpe\protocol\types\CommandOriginData;
class CommandRequestPacket extends DataPacket{ class CommandRequestPacket extends DataPacket{
@ -50,7 +50,7 @@ class CommandRequestPacket extends DataPacket{
$this->putBool($this->isInternal); $this->putBool($this->isInternal);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleCommandRequest($this); return $handler->handleCommandRequest($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ContainerClosePacket extends DataPacket{ class ContainerClosePacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::CONTAINER_CLOSE_PACKET; public const NETWORK_ID = ProtocolInfo::CONTAINER_CLOSE_PACKET;
@ -42,7 +42,7 @@ class ContainerClosePacket extends DataPacket{
$this->putByte($this->windowId); $this->putByte($this->windowId);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleContainerClose($this); return $handler->handleContainerClose($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ContainerOpenPacket extends DataPacket{ class ContainerOpenPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::CONTAINER_OPEN_PACKET; public const NETWORK_ID = ProtocolInfo::CONTAINER_OPEN_PACKET;
@ -58,7 +58,7 @@ class ContainerOpenPacket extends DataPacket{
$this->putEntityUniqueId($this->entityUniqueId); $this->putEntityUniqueId($this->entityUniqueId);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleContainerOpen($this); return $handler->handleContainerOpen($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ContainerSetDataPacket extends DataPacket{ class ContainerSetDataPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::CONTAINER_SET_DATA_PACKET; public const NETWORK_ID = ProtocolInfo::CONTAINER_SET_DATA_PACKET;
@ -60,7 +60,7 @@ class ContainerSetDataPacket extends DataPacket{
$this->putVarInt($this->value); $this->putVarInt($this->value);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleContainerSetData($this); return $handler->handleContainerSetData($this);
} }
} }

View File

@ -30,8 +30,8 @@ use pocketmine\inventory\FurnaceRecipe;
use pocketmine\inventory\ShapedRecipe; use pocketmine\inventory\ShapedRecipe;
use pocketmine\inventory\ShapelessRecipe; use pocketmine\inventory\ShapelessRecipe;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\network\mcpe\NetworkBinaryStream; use pocketmine\network\mcpe\NetworkBinaryStream;
use pocketmine\network\mcpe\NetworkSession;
class CraftingDataPacket extends DataPacket{ class CraftingDataPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::CRAFTING_DATA_PACKET; public const NETWORK_ID = ProtocolInfo::CRAFTING_DATA_PACKET;
@ -215,7 +215,7 @@ class CraftingDataPacket extends DataPacket{
$this->putBool($this->cleanRecipes); $this->putBool($this->cleanRecipes);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleCraftingData($this); return $handler->handleCraftingData($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\utils\UUID; use pocketmine\utils\UUID;
class CraftingEventPacket extends DataPacket{ class CraftingEventPacket extends DataPacket{
@ -81,7 +81,7 @@ class CraftingEventPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleCraftingEvent($this); return $handler->handleCraftingEvent($this);
} }
} }

View File

@ -25,8 +25,8 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\network\mcpe\NetworkBinaryStream; use pocketmine\network\mcpe\NetworkBinaryStream;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\utils\Utils; use pocketmine\utils\Utils;
abstract class DataPacket extends NetworkBinaryStream{ abstract class DataPacket extends NetworkBinaryStream{
@ -49,10 +49,6 @@ abstract class DataPacket extends NetworkBinaryStream{
return (new \ReflectionClass($this))->getShortName(); return (new \ReflectionClass($this))->getShortName();
} }
public function canBeBatched() : bool{
return true;
}
public function canBeSentBeforeLogin() : bool{ public function canBeSentBeforeLogin() : bool{
return false; return false;
} }
@ -109,16 +105,20 @@ abstract class DataPacket extends NetworkBinaryStream{
} }
/** /**
* Performs handling for this packet. Usually you'll want an appropriately named method in the NetworkSession for this. * Performs handling for this packet. Usually you'll want an appropriately named method in the session handler for
* this.
* *
* This method returns a bool to indicate whether the packet was handled or not. If the packet was unhandled, a debug message will be logged with a hexdump of the packet. * This method returns a bool to indicate whether the packet was handled or not. If the packet was unhandled, a
* Typically this method returns the return value of the handler in the supplied NetworkSession. See other packets for examples how to implement this. * debug message will be logged with a hexdump of the packet.
* *
* @param NetworkSession $session * Typically this method returns the return value of the handler in the supplied SessionHandler. See other packets
* for examples how to implement this.
*
* @param SessionHandler $handler
* *
* @return bool true if the packet was handled successfully, false if not. * @return bool true if the packet was handled successfully, false if not.
*/ */
abstract public function handle(NetworkSession $session) : bool; abstract public function handle(SessionHandler $handler) : bool;
public function clean(){ public function clean(){
$this->buffer = null; $this->buffer = null;

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class DisconnectPacket extends DataPacket{ class DisconnectPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::DISCONNECT_PACKET; public const NETWORK_ID = ProtocolInfo::DISCONNECT_PACKET;
@ -54,7 +54,7 @@ class DisconnectPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleDisconnect($this); return $handler->handleDisconnect($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class EntityEventPacket extends DataPacket{ class EntityEventPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::ENTITY_EVENT_PACKET; public const NETWORK_ID = ProtocolInfo::ENTITY_EVENT_PACKET;
@ -102,7 +102,7 @@ class EntityEventPacket extends DataPacket{
$this->putVarInt($this->data); $this->putVarInt($this->data);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleEntityEvent($this); return $handler->handleEntityEvent($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class EntityFallPacket extends DataPacket{ class EntityFallPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::ENTITY_FALL_PACKET; public const NETWORK_ID = ProtocolInfo::ENTITY_FALL_PACKET;
@ -50,7 +50,7 @@ class EntityFallPacket extends DataPacket{
$this->putBool($this->isInVoid); $this->putBool($this->isInVoid);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleEntityFall($this); return $handler->handleEntityFall($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class EntityPickRequestPacket extends DataPacket{ class EntityPickRequestPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::ENTITY_PICK_REQUEST_PACKET; public const NETWORK_ID = ProtocolInfo::ENTITY_PICK_REQUEST_PACKET;
@ -45,7 +45,7 @@ class EntityPickRequestPacket extends DataPacket{
$this->putByte($this->hotbarSlot); $this->putByte($this->hotbarSlot);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleEntityPickRequest($this); return $handler->handleEntityPickRequest($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class EventPacket extends DataPacket{ class EventPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::EVENT_PACKET; public const NETWORK_ID = ProtocolInfo::EVENT_PACKET;
@ -64,7 +64,7 @@ class EventPacket extends DataPacket{
//TODO: also nice confusing mess //TODO: also nice confusing mess
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleEvent($this); return $handler->handleEvent($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ExplodePacket extends DataPacket{ class ExplodePacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::EXPLODE_PACKET; public const NETWORK_ID = ProtocolInfo::EXPLODE_PACKET;
@ -66,7 +66,7 @@ class ExplodePacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleExplode($this); return $handler->handleExplode($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class FullChunkDataPacket extends DataPacket{ class FullChunkDataPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::FULL_CHUNK_DATA_PACKET; public const NETWORK_ID = ProtocolInfo::FULL_CHUNK_DATA_PACKET;
@ -50,7 +50,7 @@ class FullChunkDataPacket extends DataPacket{
$this->putString($this->data); $this->putString($this->data);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleFullChunkData($this); return $handler->handleFullChunkData($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class GameRulesChangedPacket extends DataPacket{ class GameRulesChangedPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::GAME_RULES_CHANGED_PACKET; public const NETWORK_ID = ProtocolInfo::GAME_RULES_CHANGED_PACKET;
@ -41,7 +41,7 @@ class GameRulesChangedPacket extends DataPacket{
$this->putGameRules($this->gameRules); $this->putGameRules($this->gameRules);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleGameRulesChanged($this); return $handler->handleGameRulesChanged($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class GuiDataPickItemPacket extends DataPacket{ class GuiDataPickItemPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::GUI_DATA_PICK_ITEM_PACKET; public const NETWORK_ID = ProtocolInfo::GUI_DATA_PICK_ITEM_PACKET;
@ -41,7 +41,7 @@ class GuiDataPickItemPacket extends DataPacket{
$this->putLInt($this->hotbarSlot); $this->putLInt($this->hotbarSlot);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleGuiDataPickItem($this); return $handler->handleGuiDataPickItem($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class HurtArmorPacket extends DataPacket{ class HurtArmorPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::HURT_ARMOR_PACKET; public const NETWORK_ID = ProtocolInfo::HURT_ARMOR_PACKET;
@ -42,7 +42,7 @@ class HurtArmorPacket extends DataPacket{
$this->putVarInt($this->health); $this->putVarInt($this->health);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleHurtArmor($this); return $handler->handleHurtArmor($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class InteractPacket extends DataPacket{ class InteractPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::INTERACT_PACKET; public const NETWORK_ID = ProtocolInfo::INTERACT_PACKET;
@ -71,7 +71,7 @@ class InteractPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleInteract($this); return $handler->handleInteract($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class InventoryContentPacket extends DataPacket{ class InventoryContentPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::INVENTORY_CONTENT_PACKET; public const NETWORK_ID = ProtocolInfo::INVENTORY_CONTENT_PACKET;
@ -52,7 +52,7 @@ class InventoryContentPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleInventoryContent($this); return $handler->handleInventoryContent($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class InventorySlotPacket extends DataPacket{ class InventorySlotPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::INVENTORY_SLOT_PACKET; public const NETWORK_ID = ProtocolInfo::INVENTORY_SLOT_PACKET;
@ -50,7 +50,7 @@ class InventorySlotPacket extends DataPacket{
$this->putSlot($this->item); $this->putSlot($this->item);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleInventorySlot($this); return $handler->handleInventorySlot($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\network\mcpe\protocol\types\NetworkInventoryAction; use pocketmine\network\mcpe\protocol\types\NetworkInventoryAction;
class InventoryTransactionPacket extends DataPacket{ class InventoryTransactionPacket extends DataPacket{
@ -151,7 +151,7 @@ class InventoryTransactionPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleInventoryTransaction($this); return $handler->handleInventoryTransaction($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ItemFrameDropItemPacket extends DataPacket{ class ItemFrameDropItemPacket extends DataPacket{
@ -46,7 +46,7 @@ class ItemFrameDropItemPacket extends DataPacket{
$this->putBlockPosition($this->x, $this->y, $this->z); $this->putBlockPosition($this->x, $this->y, $this->z);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleItemFrameDropItem($this); return $handler->handleItemFrameDropItem($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class LabTablePacket extends DataPacket{ class LabTablePacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::LAB_TABLE_PACKET; public const NETWORK_ID = ProtocolInfo::LAB_TABLE_PACKET;
@ -55,7 +55,7 @@ class LabTablePacket extends DataPacket{
$this->putByte($this->reactionType); $this->putByte($this->reactionType);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleLabTable($this); return $handler->handleLabTable($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class LevelEventPacket extends DataPacket{ class LevelEventPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::LEVEL_EVENT_PACKET; public const NETWORK_ID = ProtocolInfo::LEVEL_EVENT_PACKET;
@ -130,7 +130,7 @@ class LevelEventPacket extends DataPacket{
$this->putVarInt($this->data); $this->putVarInt($this->data);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleLevelEvent($this); return $handler->handleLevelEvent($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class LevelSoundEventPacket extends DataPacket{ class LevelSoundEventPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::LEVEL_SOUND_EVENT_PACKET; public const NETWORK_ID = ProtocolInfo::LEVEL_SOUND_EVENT_PACKET;
@ -275,7 +275,7 @@ class LevelSoundEventPacket extends DataPacket{
$this->putBool($this->disableRelativeVolume); $this->putBool($this->disableRelativeVolume);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleLevelSoundEvent($this); return $handler->handleLevelSoundEvent($this);
} }
} }

View File

@ -26,7 +26,8 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\entity\Skin;
use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\utils\BinaryStream; use pocketmine\utils\BinaryStream;
use pocketmine\utils\MainLogger; use pocketmine\utils\MainLogger;
use pocketmine\utils\Utils; use pocketmine\utils\Utils;
@ -52,6 +53,8 @@ class LoginPacket extends DataPacket{
public $serverAddress; public $serverAddress;
/** @var string */ /** @var string */
public $locale; public $locale;
/** @var Skin|null */
public $skin;
/** @var array (the "chain" index contains one or more JWTs) */ /** @var array (the "chain" index contains one or more JWTs) */
public $chainData = []; public $chainData = [];
@ -136,14 +139,22 @@ class LoginPacket extends DataPacket{
$this->clientId = $this->clientData["ClientRandomId"] ?? null; $this->clientId = $this->clientData["ClientRandomId"] ?? null;
$this->serverAddress = $this->clientData["ServerAddress"] ?? null; $this->serverAddress = $this->clientData["ServerAddress"] ?? null;
$this->locale = $this->clientData["LanguageCode"] ?? null; $this->locale = $this->clientData["LanguageCode"] ?? "en_US";
$this->skin = new Skin(
$this->clientData["SkinId"] ?? "",
base64_decode($this->clientData["SkinData"] ?? ""),
base64_decode($this->clientData["CapeData"] ?? ""),
$this->clientData["SkinGeometryName"] ?? "",
base64_decode($this->clientData["SkinGeometry"] ?? "")
);
} }
protected function encodePayload() : void{ protected function encodePayload() : void{
//TODO //TODO
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleLogin($this); return $handler->handleLogin($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class MapInfoRequestPacket extends DataPacket{ class MapInfoRequestPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::MAP_INFO_REQUEST_PACKET; public const NETWORK_ID = ProtocolInfo::MAP_INFO_REQUEST_PACKET;
@ -43,7 +43,7 @@ class MapInfoRequestPacket extends DataPacket{
$this->putEntityUniqueId($this->mapId); $this->putEntityUniqueId($this->mapId);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleMapInfoRequest($this); return $handler->handleMapInfoRequest($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class MobArmorEquipmentPacket extends DataPacket{ class MobArmorEquipmentPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::MOB_ARMOR_EQUIPMENT_PACKET; public const NETWORK_ID = ProtocolInfo::MOB_ARMOR_EQUIPMENT_PACKET;
@ -51,7 +51,7 @@ class MobArmorEquipmentPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleMobArmorEquipment($this); return $handler->handleMobArmorEquipment($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class MobEffectPacket extends DataPacket{ class MobEffectPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::MOB_EFFECT_PACKET; public const NETWORK_ID = ProtocolInfo::MOB_EFFECT_PACKET;
@ -66,7 +66,7 @@ class MobEffectPacket extends DataPacket{
$this->putVarInt($this->duration); $this->putVarInt($this->duration);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleMobEffect($this); return $handler->handleMobEffect($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class MobEquipmentPacket extends DataPacket{ class MobEquipmentPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::MOB_EQUIPMENT_PACKET; public const NETWORK_ID = ProtocolInfo::MOB_EQUIPMENT_PACKET;
@ -59,7 +59,7 @@ class MobEquipmentPacket extends DataPacket{
$this->putByte($this->windowId); $this->putByte($this->windowId);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleMobEquipment($this); return $handler->handleMobEquipment($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ModalFormRequestPacket extends DataPacket{ class ModalFormRequestPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::MODAL_FORM_REQUEST_PACKET; public const NETWORK_ID = ProtocolInfo::MODAL_FORM_REQUEST_PACKET;
@ -45,7 +45,7 @@ class ModalFormRequestPacket extends DataPacket{
$this->putString($this->formData); $this->putString($this->formData);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleModalFormRequest($this); return $handler->handleModalFormRequest($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ModalFormResponsePacket extends DataPacket{ class ModalFormResponsePacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::MODAL_FORM_RESPONSE_PACKET; public const NETWORK_ID = ProtocolInfo::MODAL_FORM_RESPONSE_PACKET;
@ -45,7 +45,7 @@ class ModalFormResponsePacket extends DataPacket{
$this->putString($this->formData); $this->putString($this->formData);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleModalFormResponse($this); return $handler->handleModalFormResponse($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class MoveEntityAbsolutePacket extends DataPacket{ class MoveEntityAbsolutePacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::MOVE_ENTITY_ABSOLUTE_PACKET; public const NETWORK_ID = ProtocolInfo::MOVE_ENTITY_ABSOLUTE_PACKET;
@ -66,7 +66,7 @@ class MoveEntityAbsolutePacket extends DataPacket{
$this->putByteRotation($this->zRot); $this->putByteRotation($this->zRot);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleMoveEntityAbsolute($this); return $handler->handleMoveEntityAbsolute($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class MoveEntityDeltaPacket extends DataPacket{ class MoveEntityDeltaPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::MOVE_ENTITY_DELTA_PACKET; public const NETWORK_ID = ProtocolInfo::MOVE_ENTITY_DELTA_PACKET;
@ -98,7 +98,7 @@ class MoveEntityDeltaPacket extends DataPacket{
$this->maybeWriteRotation(self::FLAG_HAS_ROT_Z, $this->zRot); $this->maybeWriteRotation(self::FLAG_HAS_ROT_Z, $this->zRot);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleMoveEntityDelta($this); return $handler->handleMoveEntityDelta($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class MovePlayerPacket extends DataPacket{ class MovePlayerPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::MOVE_PLAYER_PACKET; public const NETWORK_ID = ProtocolInfo::MOVE_PLAYER_PACKET;
@ -88,7 +88,7 @@ class MovePlayerPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleMovePlayer($this); return $handler->handleMovePlayer($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class NpcRequestPacket extends DataPacket{ class NpcRequestPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::NPC_REQUEST_PACKET; public const NETWORK_ID = ProtocolInfo::NPC_REQUEST_PACKET;
@ -53,7 +53,7 @@ class NpcRequestPacket extends DataPacket{
$this->putByte($this->actionType); $this->putByte($this->actionType);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleNpcRequest($this); return $handler->handleNpcRequest($this);
} }
} }

View File

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol; namespace pocketmine\network\mcpe\protocol;
use pocketmine\utils\Binary;
class PacketPool{ class PacketPool{
/** @var \SplFixedArray<DataPacket> */ /** @var \SplFixedArray<DataPacket> */
protected static $pool = null; protected static $pool = null;
@ -30,7 +32,6 @@ class PacketPool{
public static function init() : void{ public static function init() : void{
static::$pool = new \SplFixedArray(256); static::$pool = new \SplFixedArray(256);
//Normal packets
static::registerPacket(new LoginPacket()); static::registerPacket(new LoginPacket());
static::registerPacket(new PlayStatusPacket()); static::registerPacket(new PlayStatusPacket());
static::registerPacket(new ServerToClientHandshakePacket()); static::registerPacket(new ServerToClientHandshakePacket());
@ -143,8 +144,6 @@ class PacketPool{
static::registerPacket(new UpdateBlockSyncedPacket()); static::registerPacket(new UpdateBlockSyncedPacket());
static::registerPacket(new MoveEntityDeltaPacket()); static::registerPacket(new MoveEntityDeltaPacket());
static::registerPacket(new SetLocalPlayerAsInitializedPacket()); static::registerPacket(new SetLocalPlayerAsInitializedPacket());
static::registerPacket(new BatchPacket());
} }
/** /**
@ -167,8 +166,9 @@ class PacketPool{
* @return DataPacket * @return DataPacket
*/ */
public static function getPacket(string $buffer) : DataPacket{ public static function getPacket(string $buffer) : DataPacket{
$pk = static::getPacketById(ord($buffer{0})); $offset = 0;
$pk->setBuffer($buffer); $pk = static::getPacketById(Binary::readUnsignedVarInt($buffer, $offset));
$pk->setBuffer($buffer, $offset);
return $pk; return $pk;
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class PhotoTransferPacket extends DataPacket{ class PhotoTransferPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::PHOTO_TRANSFER_PACKET; public const NETWORK_ID = ProtocolInfo::PHOTO_TRANSFER_PACKET;
@ -49,7 +49,7 @@ class PhotoTransferPacket extends DataPacket{
$this->putString($this->bookId); $this->putString($this->bookId);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handlePhotoTransfer($this); return $handler->handlePhotoTransfer($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class PlaySoundPacket extends DataPacket{ class PlaySoundPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::PLAY_SOUND_PACKET; public const NETWORK_ID = ProtocolInfo::PLAY_SOUND_PACKET;
@ -62,7 +62,7 @@ class PlaySoundPacket extends DataPacket{
$this->putLFloat($this->pitch); $this->putLFloat($this->pitch);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handlePlaySound($this); return $handler->handlePlaySound($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class PlayStatusPacket extends DataPacket{ class PlayStatusPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::PLAY_STATUS_PACKET; public const NETWORK_ID = ProtocolInfo::PLAY_STATUS_PACKET;
@ -69,7 +69,7 @@ class PlayStatusPacket extends DataPacket{
$this->putInt($this->status); $this->putInt($this->status);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handlePlayStatus($this); return $handler->handlePlayStatus($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class PlayerActionPacket extends DataPacket{ class PlayerActionPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::PLAYER_ACTION_PACKET; public const NETWORK_ID = ProtocolInfo::PLAYER_ACTION_PACKET;
@ -84,7 +84,7 @@ class PlayerActionPacket extends DataPacket{
$this->putVarInt($this->face); $this->putVarInt($this->face);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handlePlayerAction($this); return $handler->handlePlayerAction($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\network\mcpe\protocol\types\ContainerIds; use pocketmine\network\mcpe\protocol\types\ContainerIds;
/** /**
@ -53,7 +53,7 @@ class PlayerHotbarPacket extends DataPacket{
$this->putBool($this->selectHotbarSlot); $this->putBool($this->selectHotbarSlot);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handlePlayerHotbar($this); return $handler->handlePlayerHotbar($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class PlayerInputPacket extends DataPacket{ class PlayerInputPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::PLAYER_INPUT_PACKET; public const NETWORK_ID = ProtocolInfo::PLAYER_INPUT_PACKET;
@ -54,7 +54,7 @@ class PlayerInputPacket extends DataPacket{
$this->putBool($this->sneaking); $this->putBool($this->sneaking);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handlePlayerInput($this); return $handler->handlePlayerInput($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\entity\Skin; use pocketmine\entity\Skin;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\network\mcpe\protocol\types\PlayerListEntry; use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
class PlayerListPacket extends DataPacket{ class PlayerListPacket extends DataPacket{
@ -105,7 +105,7 @@ class PlayerListPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handlePlayerList($this); return $handler->handlePlayerList($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\entity\Skin; use pocketmine\entity\Skin;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\utils\UUID; use pocketmine\utils\UUID;
class PlayerSkinPacket extends DataPacket{ class PlayerSkinPacket extends DataPacket{
@ -68,7 +68,7 @@ class PlayerSkinPacket extends DataPacket{
$this->putString($this->skin->getGeometryData()); $this->putString($this->skin->getGeometryData());
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handlePlayerSkin($this); return $handler->handlePlayerSkin($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class PurchaseReceiptPacket extends DataPacket{ class PurchaseReceiptPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::PURCHASE_RECEIPT_PACKET; public const NETWORK_ID = ProtocolInfo::PURCHASE_RECEIPT_PACKET;
@ -47,7 +47,7 @@ class PurchaseReceiptPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handlePurchaseReceipt($this); return $handler->handlePurchaseReceipt($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class RemoveEntityPacket extends DataPacket{ class RemoveEntityPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::REMOVE_ENTITY_PACKET; public const NETWORK_ID = ProtocolInfo::REMOVE_ENTITY_PACKET;
@ -42,7 +42,7 @@ class RemoveEntityPacket extends DataPacket{
$this->putEntityUniqueId($this->entityUniqueId); $this->putEntityUniqueId($this->entityUniqueId);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleRemoveEntity($this); return $handler->handleRemoveEntity($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class RemoveObjectivePacket extends DataPacket{ class RemoveObjectivePacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::REMOVE_OBJECTIVE_PACKET; public const NETWORK_ID = ProtocolInfo::REMOVE_OBJECTIVE_PACKET;
@ -41,7 +41,7 @@ class RemoveObjectivePacket extends DataPacket{
$this->putString($this->objectiveName); $this->putString($this->objectiveName);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleRemoveObjective($this); return $handler->handleRemoveObjective($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class RequestChunkRadiusPacket extends DataPacket{ class RequestChunkRadiusPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::REQUEST_CHUNK_RADIUS_PACKET; public const NETWORK_ID = ProtocolInfo::REQUEST_CHUNK_RADIUS_PACKET;
@ -42,7 +42,7 @@ class RequestChunkRadiusPacket extends DataPacket{
$this->putVarInt($this->radius); $this->putVarInt($this->radius);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleRequestChunkRadius($this); return $handler->handleRequestChunkRadius($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ResourcePackChunkDataPacket extends DataPacket{ class ResourcePackChunkDataPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CHUNK_DATA_PACKET; public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CHUNK_DATA_PACKET;
@ -56,7 +56,7 @@ class ResourcePackChunkDataPacket extends DataPacket{
$this->put($this->data); $this->put($this->data);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleResourcePackChunkData($this); return $handler->handleResourcePackChunkData($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ResourcePackChunkRequestPacket extends DataPacket{ class ResourcePackChunkRequestPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CHUNK_REQUEST_PACKET; public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CHUNK_REQUEST_PACKET;
@ -47,7 +47,7 @@ class ResourcePackChunkRequestPacket extends DataPacket{
$this->putLInt($this->chunkIndex); $this->putLInt($this->chunkIndex);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleResourcePackChunkRequest($this); return $handler->handleResourcePackChunkRequest($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ResourcePackClientResponsePacket extends DataPacket{ class ResourcePackClientResponsePacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CLIENT_RESPONSE_PACKET; public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CLIENT_RESPONSE_PACKET;
@ -57,7 +57,7 @@ class ResourcePackClientResponsePacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleResourcePackClientResponse($this); return $handler->handleResourcePackClientResponse($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ResourcePackDataInfoPacket extends DataPacket{ class ResourcePackDataInfoPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_DATA_INFO_PACKET; public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_DATA_INFO_PACKET;
@ -59,7 +59,7 @@ class ResourcePackDataInfoPacket extends DataPacket{
$this->putString($this->sha256); $this->putString($this->sha256);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleResourcePackDataInfo($this); return $handler->handleResourcePackDataInfo($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\resourcepacks\ResourcePack; use pocketmine\resourcepacks\ResourcePack;
class ResourcePackStackPacket extends DataPacket{ class ResourcePackStackPacket extends DataPacket{
@ -76,7 +76,7 @@ class ResourcePackStackPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleResourcePackStack($this); return $handler->handleResourcePackStack($this);
} }
} }

View File

@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
use pocketmine\resourcepacks\ResourcePack; use pocketmine\resourcepacks\ResourcePack;
class ResourcePacksInfoPacket extends DataPacket{ class ResourcePacksInfoPacket extends DataPacket{
@ -81,7 +81,7 @@ class ResourcePacksInfoPacket extends DataPacket{
} }
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleResourcePacksInfo($this); return $handler->handleResourcePacksInfo($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class RespawnPacket extends DataPacket{ class RespawnPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::RESPAWN_PACKET; public const NETWORK_ID = ProtocolInfo::RESPAWN_PACKET;
@ -43,7 +43,7 @@ class RespawnPacket extends DataPacket{
$this->putVector3($this->position); $this->putVector3($this->position);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleRespawn($this); return $handler->handleRespawn($this);
} }
} }

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class RiderJumpPacket extends DataPacket{ class RiderJumpPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::RIDER_JUMP_PACKET; public const NETWORK_ID = ProtocolInfo::RIDER_JUMP_PACKET;
@ -43,7 +43,7 @@ class RiderJumpPacket extends DataPacket{
$this->putVarInt($this->jumpStrength); $this->putVarInt($this->jumpStrength);
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleRiderJump($this); return $handler->handleRiderJump($this);
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\handler\SessionHandler;
class ServerSettingsRequestPacket extends DataPacket{ class ServerSettingsRequestPacket extends DataPacket{
public const NETWORK_ID = ProtocolInfo::SERVER_SETTINGS_REQUEST_PACKET; public const NETWORK_ID = ProtocolInfo::SERVER_SETTINGS_REQUEST_PACKET;
@ -38,7 +38,7 @@ class ServerSettingsRequestPacket extends DataPacket{
//No payload //No payload
} }
public function handle(NetworkSession $session) : bool{ public function handle(SessionHandler $handler) : bool{
return $session->handleServerSettingsRequest($this); return $handler->handleServerSettingsRequest($this);
} }
} }

Some files were not shown because too many files have changed in this diff Show More