Added PlayerNetworkSessionAdapter to allow abstraction of NetworkSession base

This commit is contained in:
Dylan K. Taylor 2017-06-04 19:51:53 +01:00
parent fa58736360
commit 650afe2d94
3 changed files with 1049 additions and 279 deletions

View File

@ -67,7 +67,6 @@ use pocketmine\event\player\PlayerToggleFlightEvent;
use pocketmine\event\player\PlayerToggleSneakEvent;
use pocketmine\event\player\PlayerToggleSprintEvent;
use pocketmine\event\player\PlayerTransferEvent;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\event\server\DataPacketSendEvent;
use pocketmine\event\TextContainer;
use pocketmine\event\Timings;
@ -104,64 +103,39 @@ use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\LongTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\AddEntityPacket;
use pocketmine\network\mcpe\protocol\AddHangingEntityPacket;
use pocketmine\network\mcpe\protocol\AddItemEntityPacket;
use pocketmine\network\mcpe\protocol\AddItemPacket;
use pocketmine\network\mcpe\protocol\AddPaintingPacket;
use pocketmine\network\mcpe\protocol\AddPlayerPacket;
use pocketmine\network\mcpe\PlayerNetworkSessionAdapter;
use pocketmine\network\mcpe\protocol\AdventureSettingsPacket;
use pocketmine\network\mcpe\protocol\AnimatePacket;
use pocketmine\network\mcpe\protocol\AvailableCommandsPacket;
use pocketmine\network\mcpe\protocol\BatchPacket;
use pocketmine\network\mcpe\protocol\BlockEntityDataPacket;
use pocketmine\network\mcpe\protocol\BlockEventPacket;
use pocketmine\network\mcpe\protocol\BlockPickRequestPacket;
use pocketmine\network\mcpe\protocol\BossEventPacket;
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\CommandStepPacket;
use pocketmine\network\mcpe\protocol\ContainerClosePacket;
use pocketmine\network\mcpe\protocol\ContainerOpenPacket;
use pocketmine\network\mcpe\protocol\ContainerSetContentPacket;
use pocketmine\network\mcpe\protocol\ContainerSetDataPacket;
use pocketmine\network\mcpe\protocol\ContainerSetSlotPacket;
use pocketmine\network\mcpe\protocol\CraftingDataPacket;
use pocketmine\network\mcpe\protocol\CraftingEventPacket;
use pocketmine\network\mcpe\protocol\DataPacket;
use pocketmine\network\mcpe\protocol\DisconnectPacket;
use pocketmine\network\mcpe\protocol\DropItemPacket;
use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\network\mcpe\protocol\ExplodePacket;
use pocketmine\network\mcpe\protocol\FullChunkDataPacket;
use pocketmine\network\mcpe\protocol\GameRulesChangedPacket;
use pocketmine\network\mcpe\protocol\HurtArmorPacket;
use pocketmine\network\mcpe\protocol\InteractPacket;
use pocketmine\network\mcpe\protocol\InventoryActionPacket;
use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket;
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\MoveEntityPacket;
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
use pocketmine\network\mcpe\protocol\PlayerActionPacket;
use pocketmine\network\mcpe\protocol\EntityFallPacket;
use pocketmine\network\mcpe\protocol\PlayerInputPacket;
use pocketmine\network\mcpe\protocol\PlayerListPacket;
use pocketmine\network\mcpe\protocol\PlaySoundPacket;
use pocketmine\network\mcpe\protocol\PlayStatusPacket;
use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\network\mcpe\protocol\RemoveBlockPacket;
use pocketmine\network\mcpe\protocol\RemoveEntityPacket;
use pocketmine\network\mcpe\protocol\ReplaceItemInSlotPacket;
use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
use pocketmine\network\mcpe\protocol\ResourcePackChunkDataPacket;
use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket;
@ -170,28 +144,17 @@ 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\ServerToClientHandshakePacket;
use pocketmine\network\mcpe\protocol\SetCommandsEnabledPacket;
use pocketmine\network\mcpe\protocol\SetDifficultyPacket;
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\SetPlayerGameTypePacket;
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\SpawnExperienceOrbPacket;
use pocketmine\network\mcpe\protocol\StartGamePacket;
use pocketmine\network\mcpe\protocol\StopSoundPacket;
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\UpdateTradePacket;
use pocketmine\network\mcpe\protocol\UseItemPacket;
use pocketmine\network\SourceInterface;
use pocketmine\permission\PermissibleBase;
@ -208,7 +171,7 @@ use pocketmine\utils\UUID;
/**
* Main class that handles networking, recovery, and packet sending to the server part
*/
class Player extends Human implements CommandSender, InventoryHolder, ChunkLoader, IPlayer, NetworkSession{
class Player extends Human implements CommandSender, InventoryHolder, ChunkLoader, IPlayer{
const SURVIVAL = 0;
const CREATIVE = 1;
@ -241,6 +204,12 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
/** @var SourceInterface */
protected $interface;
/**
* @var PlayerNetworkSessionAdapter
* TODO: remove this once player and network are divorced properly
*/
protected $sessionAdapter;
/** @var bool */
public $playedBefore;
public $spawned = false;
@ -668,6 +637,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->allowMovementCheats = (bool) $this->server->getProperty("player.anti-cheat.allow-movement-cheats", false);
$this->allowInstaBreak = (bool) $this->server->getProperty("player.anti-cheat.allow-instabreak", false);
$this->sessionAdapter = new PlayerNetworkSessionAdapter($this->server, $this);
}
/**
@ -1970,10 +1941,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
public function handlePlayStatus(PlayStatusPacket $packet) : bool{
return false;
}
public function sendPlayStatus(int $status, bool $immediate = false){
$pk = new PlayStatusPacket();
$pk->status = $status;
@ -1984,26 +1951,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
}
}
public function handleServerToClientHandshake(ServerToClientHandshakePacket $packet) : bool{
return false;
}
public function handleClientToServerHandshake(ClientToServerHandshakePacket $packet) : bool{
return false; //TODO
}
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{
switch($packet->status){
case ResourcePackClientResponsePacket::STATUS_REFUSED:
@ -2090,42 +2041,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
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 handleMoveEntity(MoveEntityPacket $packet) : bool{
return false;
}
public function handleMovePlayer(MovePlayerPacket $packet) : bool{
$newPos = new Vector3($packet->x, $packet->y - $this->baseOffset, $packet->z);
@ -2155,10 +2070,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
public function handleRiderJump(RiderJumpPacket $packet) : bool{
return false;
}
public function handleRemoveBlock(RemoveBlockPacket $packet) : bool{
if($this->spawned === false or !$this->isAlive()){
return true;
@ -2198,32 +2109,12 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
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{
//TODO: add events so plugins can change this
$this->getLevel()->addChunkPacket($this->chunk->getX(), $this->chunk->getZ(), $packet);
return true;
}
public function handleLevelEvent(LevelEventPacket $packet) : bool{
return false;
}
public function handleBlockEvent(BlockEventPacket $packet) : bool{
return false;
}
public function handleEntityEvent(EntityEventPacket $packet) : bool{
if($this->spawned === false or !$this->isAlive()){
return true;
@ -2256,14 +2147,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
public function handleMobEffect(MobEffectPacket $packet) : bool{
return false;
}
public function handleUpdateAttributes(UpdateAttributesPacket $packet) : bool{
return false;
}
public function handleMobEquipment(MobEquipmentPacket $packet) : bool{
if($this->spawned === false or !$this->isAlive()){
return true;
@ -2295,10 +2178,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{
return false;
}
public function handleInteract(InteractPacket $packet) : bool{
if($this->spawned === false or !$this->isAlive()){
return true;
@ -2809,34 +2688,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
public function handleEntityFall(EntityFallPacket $packet) : bool{
return true; //not used
}
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{
if($this->spawned === false or !$this->isAlive()){
return true;
@ -2855,10 +2706,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
public function handleRespawn(RespawnPacket $packet) : bool{
return false;
}
public function handleDropItem(DropItemPacket $packet) : bool{
if($this->spawned === false or !$this->isAlive()){
return true;
@ -2887,14 +2734,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
public function handleInventoryAction(InventoryActionPacket $packet) : bool{
return false;
}
public function handleContainerOpen(ContainerOpenPacket $packet) : bool{
return false;
}
public function handleContainerClose(ContainerClosePacket $packet) : bool{
if($this->spawned === false or $packet->windowid === 0){
return true;
@ -2997,18 +2836,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
public function handleContainerSetData(ContainerSetDataPacket $packet) : bool{
return false;
}
public function handleContainerSetContent(ContainerSetContentPacket $packet) : bool{
return false;
}
public function handleCraftingData(CraftingDataPacket $packet) : bool{
return false;
}
public function handleCraftingEvent(CraftingEventPacket $packet) : bool{
if($this->spawned === false or !$this->isAlive()){
return true;
@ -3226,22 +3053,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return false; //TODO
}
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{
if($packet->gamemode !== $this->gamemode){
//Set this back to default. TODO: handle this properly
@ -3251,18 +3062,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
public function handlePlayerList(PlayerListPacket $packet) : bool{
return false;
}
public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool{
return false; //TODO
}
public function handleClientboundMapItemData(ClientboundMapItemDataPacket $packet) : bool{
return false;
}
public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool{
return false; //TODO
}
@ -3273,10 +3076,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
public function handleChunkRadiusUpdated(ChunkRadiusUpdatedPacket $packet) : bool{
return false;
}
public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{
if($this->spawned === false or !$this->isAlive()){
return true;
@ -3306,18 +3105,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
public function handleReplaceItemInSlot(ReplaceItemInSlotPacket $packet) : bool{
return false;
}
public function handleGameRulesChanged(GameRulesChangedPacket $packet) : bool{
return false;
}
public function handleAddItem(AddItemPacket $packet) : bool{
return false;
}
public function handleBossEvent(BossEventPacket $packet) : bool{
return false; //TODO
}
@ -3326,10 +3113,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return false; //TODO: handle resume
}
public function handleAvailableCommands(AvailableCommandsPacket $packet) : bool{
return false;
}
public function handleCommandStep(CommandStepPacket $packet) : bool{
if($this->spawned === false or !$this->isAlive()){
return true;
@ -3357,18 +3140,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return false; //TODO
}
public function handleUpdateTrade(UpdateTradePacket $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{
$manager = $this->server->getResourceManager();
$pack = $manager->getPackById($packet->packId);
@ -3388,52 +3159,13 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
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;
}
/**
* Called when a packet is received from the client. This method will call DataPacketReceiveEvent.
*
* @param DataPacket $packet
*/
public function handleDataPacket(DataPacket $packet){
if($this->connected === false){
return;
}
//TODO: Remove this hack once InteractPacket spam issue is fixed
if($packet->buffer === "\x21\x04\x00"){
return;
}
$timings = Timings::getReceiveDataPacketTimings($packet);
$timings->startTiming();
$packet->decode();
if(!$packet->feof()){
$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, $packet));
if(!$ev->isCancelled() and !$packet->handle($this)){
$this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->getName() . ": 0x" . bin2hex($packet->buffer));
}
$timings->stopTiming();
$this->sessionAdapter->handleDataPacket($packet);
}
/**
@ -3657,6 +3389,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->directDataPacket($pk);
}
$this->sessionAdapter->connected = false;
$this->connected = false;
$this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this);

View File

@ -0,0 +1,794 @@
<?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\AddEntityPacket;
use pocketmine\network\mcpe\protocol\AddHangingEntityPacket;
use pocketmine\network\mcpe\protocol\AddItemEntityPacket;
use pocketmine\network\mcpe\protocol\AddItemPacket;
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\BossEventPacket;
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\CommandStepPacket;
use pocketmine\network\mcpe\protocol\ContainerClosePacket;
use pocketmine\network\mcpe\protocol\ContainerOpenPacket;
use pocketmine\network\mcpe\protocol\ContainerSetContentPacket;
use pocketmine\network\mcpe\protocol\ContainerSetDataPacket;
use pocketmine\network\mcpe\protocol\ContainerSetSlotPacket;
use pocketmine\network\mcpe\protocol\CraftingDataPacket;
use pocketmine\network\mcpe\protocol\CraftingEventPacket;
use pocketmine\network\mcpe\protocol\DisconnectPacket;
use pocketmine\network\mcpe\protocol\DropItemPacket;
use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\network\mcpe\protocol\EntityFallPacket;
use pocketmine\network\mcpe\protocol\ExplodePacket;
use pocketmine\network\mcpe\protocol\FullChunkDataPacket;
use pocketmine\network\mcpe\protocol\GameRulesChangedPacket;
use pocketmine\network\mcpe\protocol\HurtArmorPacket;
use pocketmine\network\mcpe\protocol\InteractPacket;
use pocketmine\network\mcpe\protocol\InventoryActionPacket;
use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket;
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\MoveEntityPacket;
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
use pocketmine\network\mcpe\protocol\PlayerActionPacket;
use pocketmine\network\mcpe\protocol\PlayerInputPacket;
use pocketmine\network\mcpe\protocol\PlayerListPacket;
use pocketmine\network\mcpe\protocol\PlaySoundPacket;
use pocketmine\network\mcpe\protocol\PlayStatusPacket;
use pocketmine\network\mcpe\protocol\RemoveBlockPacket;
use pocketmine\network\mcpe\protocol\RemoveEntityPacket;
use pocketmine\network\mcpe\protocol\ReplaceItemInSlotPacket;
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\ServerToClientHandshakePacket;
use pocketmine\network\mcpe\protocol\SetCommandsEnabledPacket;
use pocketmine\network\mcpe\protocol\SetDifficultyPacket;
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\SetPlayerGameTypePacket;
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\SpawnExperienceOrbPacket;
use pocketmine\network\mcpe\protocol\StartGamePacket;
use pocketmine\network\mcpe\protocol\StopSoundPacket;
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\UpdateTradePacket;
use pocketmine\network\mcpe\protocol\UseItemPacket;
abstract class BaseNetworkSession implements NetworkSession{
/**
* @param LoginPacket $packet
* @return bool
*/
public function handleLogin(LoginPacket $packet) : bool{
return false;
}
/**
* @param PlayStatusPacket $packet
* @return bool
*/
public function handlePlayStatus(PlayStatusPacket $packet) : bool{
return false;
}
/**
* @param ServerToClientHandshakePacket $packet
* @return bool
*/
public function handleServerToClientHandshake(ServerToClientHandshakePacket $packet) : bool{
return false;
}
/**
* @param ClientToServerHandshakePacket $packet
* @return bool
*/
public function handleClientToServerHandshake(ClientToServerHandshakePacket $packet) : bool{
return false;
}
/**
* @param DisconnectPacket $packet
* @return bool
*/
public function handleDisconnect(DisconnectPacket $packet) : bool{
return false;
}
/**
* @param ResourcePacksInfoPacket $packet
* @return bool
*/
public function handleResourcePacksInfo(ResourcePacksInfoPacket $packet) : bool{
return false;
}
/**
* @param ResourcePackStackPacket $packet
* @return bool
*/
public function handleResourcePackStack(ResourcePackStackPacket $packet) : bool{
return false;
}
/**
* @param ResourcePackClientResponsePacket $packet
* @return bool
*/
public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{
return false;
}
/**
* @param TextPacket $packet
* @return bool
*/
public function handleText(TextPacket $packet) : bool{
return false;
}
/**
* @param SetTimePacket $packet
* @return bool
*/
public function handleSetTime(SetTimePacket $packet) : bool{
return false;
}
/**
* @param StartGamePacket $packet
* @return bool
*/
public function handleStartGame(StartGamePacket $packet) : bool{
return false;
}
/**
* @param AddPlayerPacket $packet
* @return bool
*/
public function handleAddPlayer(AddPlayerPacket $packet) : bool{
return false;
}
/**
* @param AddEntityPacket $packet
* @return bool
*/
public function handleAddEntity(AddEntityPacket $packet) : bool{
return false;
}
/**
* @param RemoveEntityPacket $packet
* @return bool
*/
public function handleRemoveEntity(RemoveEntityPacket $packet) : bool{
return false;
}
/**
* @param AddItemEntityPacket $packet
* @return bool
*/
public function handleAddItemEntity(AddItemEntityPacket $packet) : bool{
return false;
}
/**
* @param AddHangingEntityPacket $packet
* @return bool
*/
public function handleAddHangingEntity(AddHangingEntityPacket $packet) : bool{
return false;
}
/**
* @param TakeItemEntityPacket $packet
* @return bool
*/
public function handleTakeItemEntity(TakeItemEntityPacket $packet) : bool{
return false;
}
/**
* @param MoveEntityPacket $packet
* @return bool
*/
public function handleMoveEntity(MoveEntityPacket $packet) : bool{
return false;
}
/**
* @param MovePlayerPacket $packet
* @return bool
*/
public function handleMovePlayer(MovePlayerPacket $packet) : bool{
return false;
}
/**
* @param RiderJumpPacket $packet
* @return bool
*/
public function handleRiderJump(RiderJumpPacket $packet) : bool{
return false;
}
/**
* @param RemoveBlockPacket $packet
* @return bool
*/
public function handleRemoveBlock(RemoveBlockPacket $packet) : bool{
return false;
}
/**
* @param UpdateBlockPacket $packet
* @return bool
*/
public function handleUpdateBlock(UpdateBlockPacket $packet) : bool{
return false;
}
/**
* @param AddPaintingPacket $packet
* @return bool
*/
public function handleAddPainting(AddPaintingPacket $packet) : bool{
return false;
}
/**
* @param ExplodePacket $packet
* @return bool
*/
public function handleExplode(ExplodePacket $packet) : bool{
return false;
}
/**
* @param LevelSoundEventPacket $packet
* @return bool
*/
public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{
return false;
}
/**
* @param LevelEventPacket $packet
* @return bool
*/
public function handleLevelEvent(LevelEventPacket $packet) : bool{
return false;
}
/**
* @param BlockEventPacket $packet
* @return bool
*/
public function handleBlockEvent(BlockEventPacket $packet) : bool{
return false;
}
/**
* @param EntityEventPacket $packet
* @return bool
*/
public function handleEntityEvent(EntityEventPacket $packet) : bool{
return false;
}
/**
* @param MobEffectPacket $packet
* @return bool
*/
public function handleMobEffect(MobEffectPacket $packet) : bool{
return false;
}
/**
* @param UpdateAttributesPacket $packet
* @return bool
*/
public function handleUpdateAttributes(UpdateAttributesPacket $packet) : bool{
return false;
}
/**
* @param MobEquipmentPacket $packet
* @return bool
*/
public function handleMobEquipment(MobEquipmentPacket $packet) : bool{
return false;
}
/**
* @param MobArmorEquipmentPacket $packet
* @return bool
*/
public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{
return false;
}
/**
* @param InteractPacket $packet
* @return bool
*/
public function handleInteract(InteractPacket $packet) : bool{
return false;
}
/**
* @param BlockPickRequestPacket $packet
* @return bool
*/
public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{
return false;
}
/**
* @param UseItemPacket $packet
* @return bool
*/
public function handleUseItem(UseItemPacket $packet) : bool{
return false;
}
/**
* @param PlayerActionPacket $packet
* @return bool
*/
public function handlePlayerAction(PlayerActionPacket $packet) : bool{
return false;
}
/**
* @param EntityFallPacket $packet
* @return bool
*/
public function handleEntityFall(EntityFallPacket $packet) : bool{
return false;
}
/**
* @param HurtArmorPacket $packet
* @return bool
*/
public function handleHurtArmor(HurtArmorPacket $packet) : bool{
return false;
}
/**
* @param SetEntityDataPacket $packet
* @return bool
*/
public function handleSetEntityData(SetEntityDataPacket $packet) : bool{
return false;
}
/**
* @param SetEntityMotionPacket $packet
* @return bool
*/
public function handleSetEntityMotion(SetEntityMotionPacket $packet) : bool{
return false;
}
/**
* @param SetEntityLinkPacket $packet
* @return bool
*/
public function handleSetEntityLink(SetEntityLinkPacket $packet) : bool{
return false;
}
/**
* @param SetHealthPacket $packet
* @return bool
*/
public function handleSetHealth(SetHealthPacket $packet) : bool{
return false;
}
/**
* @param SetSpawnPositionPacket $packet
* @return bool
*/
public function handleSetSpawnPosition(SetSpawnPositionPacket $packet) : bool{
return false;
}
/**
* @param AnimatePacket $packet
* @return bool
*/
public function handleAnimate(AnimatePacket $packet) : bool{
return false;
}
/**
* @param RespawnPacket $packet
* @return bool
*/
public function handleRespawn(RespawnPacket $packet) : bool{
return false;
}
/**
* @param DropItemPacket $packet
* @return bool
*/
public function handleDropItem(DropItemPacket $packet) : bool{
return false;
}
/**
* @param InventoryActionPacket $packet
* @return bool
*/
public function handleInventoryAction(InventoryActionPacket $packet) : bool{
return false;
}
/**
* @param ContainerOpenPacket $packet
* @return bool
*/
public function handleContainerOpen(ContainerOpenPacket $packet) : bool{
return false;
}
/**
* @param ContainerClosePacket $packet
* @return bool
*/
public function handleContainerClose(ContainerClosePacket $packet) : bool{
return false;
}
/**
* @param ContainerSetSlotPacket $packet
* @return bool
*/
public function handleContainerSetSlot(ContainerSetSlotPacket $packet) : bool{
return false;
}
/**
* @param ContainerSetDataPacket $packet
* @return bool
*/
public function handleContainerSetData(ContainerSetDataPacket $packet) : bool{
return false;
}
/**
* @param ContainerSetContentPacket $packet
* @return bool
*/
public function handleContainerSetContent(ContainerSetContentPacket $packet) : bool{
return false;
}
/**
* @param CraftingDataPacket $packet
* @return bool
*/
public function handleCraftingData(CraftingDataPacket $packet) : bool{
return false;
}
/**
* @param CraftingEventPacket $packet
* @return bool
*/
public function handleCraftingEvent(CraftingEventPacket $packet) : bool{
return false;
}
/**
* @param AdventureSettingsPacket $packet
* @return bool
*/
public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{
return false;
}
/**
* @param BlockEntityDataPacket $packet
* @return bool
*/
public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{
return false;
}
/**
* @param PlayerInputPacket $packet
* @return bool
*/
public function handlePlayerInput(PlayerInputPacket $packet) : bool{
return false;
}
/**
* @param FullChunkDataPacket $packet
* @return bool
*/
public function handleFullChunkData(FullChunkDataPacket $packet) : bool{
return false;
}
/**
* @param SetCommandsEnabledPacket $packet
* @return bool
*/
public function handleSetCommandsEnabled(SetCommandsEnabledPacket $packet) : bool{
return false;
}
/**
* @param SetDifficultyPacket $packet
* @return bool
*/
public function handleSetDifficulty(SetDifficultyPacket $packet) : bool{
return false;
}
/**
* @param ChangeDimensionPacket $packet
* @return bool
*/
public function handleChangeDimension(ChangeDimensionPacket $packet) : bool{
return false;
}
/**
* @param SetPlayerGameTypePacket $packet
* @return bool
*/
public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{
return false;
}
/**
* @param PlayerListPacket $packet
* @return bool
*/
public function handlePlayerList(PlayerListPacket $packet) : bool{
return false;
}
/**
* @param SpawnExperienceOrbPacket $packet
* @return bool
*/
public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool{
return false;
}
/**
* @param ClientboundMapItemDataPacket $packet
* @return bool
*/
public function handleClientboundMapItemData(ClientboundMapItemDataPacket $packet) : bool{
return false;
}
/**
* @param MapInfoRequestPacket $packet
* @return bool
*/
public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool{
return false;
}
/**
* @param RequestChunkRadiusPacket $packet
* @return bool
*/
public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{
return false;
}
/**
* @param ChunkRadiusUpdatedPacket $packet
* @return bool
*/
public function handleChunkRadiusUpdated(ChunkRadiusUpdatedPacket $packet) : bool{
return false;
}
/**
* @param ItemFrameDropItemPacket $packet
* @return bool
*/
public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{
return false;
}
/**
* @param ReplaceItemInSlotPacket $packet
* @return bool
*/
public function handleReplaceItemInSlot(ReplaceItemInSlotPacket $packet) : bool{
return false;
}
/**
* @param GameRulesChangedPacket $packet
* @return bool
*/
public function handleGameRulesChanged(GameRulesChangedPacket $packet) : bool{
return false;
}
/**
* @param AddItemPacket $packet
* @return bool
*/
public function handleAddItem(AddItemPacket $packet) : bool{
return false;
}
/**
* @param BossEventPacket $packet
* @return bool
*/
public function handleBossEvent(BossEventPacket $packet) : bool{
return false;
}
/**
* @param ShowCreditsPacket $packet
* @return bool
*/
public function handleShowCredits(ShowCreditsPacket $packet) : bool{
return false;
}
/**
* @param AvailableCommandsPacket $packet
* @return bool
*/
public function handleAvailableCommands(AvailableCommandsPacket $packet) : bool{
return false;
}
/**
* @param CommandStepPacket $packet
* @return bool
*/
public function handleCommandStep(CommandStepPacket $packet) : bool{
return false;
}
/**
* @param CommandBlockUpdatePacket $packet
* @return bool
*/
public function handleCommandBlockUpdate(CommandBlockUpdatePacket $packet) : bool{
return false;
}
/**
* @param UpdateTradePacket $packet
* @return bool
*/
public function handleUpdateTrade(UpdateTradePacket $packet) : bool{
return false;
}
/**
* @param ResourcePackDataInfoPacket $packet
* @return bool
*/
public function handleResourcePackDataInfo(ResourcePackDataInfoPacket $packet) : bool{
return false;
}
/**
* @param ResourcePackChunkDataPacket $packet
* @return bool
*/
public function handleResourcePackChunkData(ResourcePackChunkDataPacket $packet) : bool{
return false;
}
/**
* @param ResourcePackChunkRequestPacket $packet
* @return bool
*/
public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{
return false;
}
/**
* @param TransferPacket $packet
* @return bool
*/
public function handleTransfer(TransferPacket $packet) : bool{
return false;
}
/**
* @param PlaySoundPacket $packet
* @return bool
*/
public function handlePlaySound(PlaySoundPacket $packet) : bool{
return false;
}
/**
* @param StopSoundPacket $packet
* @return bool
*/
public function handleStopSound(StopSoundPacket $packet) : bool{
return false;
}
/**
* @param SetTitlePacket $packet
* @return bool
*/
public function handleSetTitle(SetTitlePacket $packet) : bool{
return false;
}
}

View File

@ -0,0 +1,243 @@
<?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\event\server\DataPacketReceiveEvent;
use pocketmine\event\Timings;
use pocketmine\network\mcpe\protocol\AdventureSettingsPacket;
use pocketmine\network\mcpe\protocol\AnimatePacket;
use pocketmine\network\mcpe\protocol\BlockEntityDataPacket;
use pocketmine\network\mcpe\protocol\BlockPickRequestPacket;
use pocketmine\network\mcpe\protocol\BossEventPacket;
use pocketmine\network\mcpe\protocol\ClientToServerHandshakePacket;
use pocketmine\network\mcpe\protocol\CommandBlockUpdatePacket;
use pocketmine\network\mcpe\protocol\CommandStepPacket;
use pocketmine\network\mcpe\protocol\ContainerClosePacket;
use pocketmine\network\mcpe\protocol\ContainerSetSlotPacket;
use pocketmine\network\mcpe\protocol\CraftingEventPacket;
use pocketmine\network\mcpe\protocol\DataPacket;
use pocketmine\network\mcpe\protocol\DropItemPacket;
use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\network\mcpe\protocol\EntityFallPacket;
use pocketmine\network\mcpe\protocol\InteractPacket;
use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket;
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\MobEquipmentPacket;
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
use pocketmine\network\mcpe\protocol\PlayerActionPacket;
use pocketmine\network\mcpe\protocol\PlayerInputPacket;
use pocketmine\network\mcpe\protocol\RemoveBlockPacket;
use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket;
use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket;
use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket;
use pocketmine\network\mcpe\protocol\ShowCreditsPacket;
use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket;
use pocketmine\network\mcpe\protocol\TextPacket;
use pocketmine\network\mcpe\protocol\UseItemPacket;
use pocketmine\Player;
use pocketmine\Server;
class PlayerNetworkSessionAdapter extends BaseNetworkSession{
/** @var Server */
private $server;
/** @var Player */
private $player;
/** @var bool */
public $connected = true;
public function __construct(Server $server, Player $player){
$this->server = $server;
$this->player = $player;
}
public function getServer(){
return $this->server;
}
public function handleDataPacket(DataPacket $packet){
if($this->connected === false){
return;
}
//TODO: Remove this hack once InteractPacket spam issue is fixed
if($packet->buffer === "\x21\x04\x00"){
return;
}
$timings = Timings::getReceiveDataPacketTimings($packet);
$timings->startTiming();
$packet->decode();
if(!$packet->feof()){
$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 handleLogin(LoginPacket $packet) : bool{
return $this->player->handleLogin($packet);
}
public function handleClientToServerHandshake(ClientToServerHandshakePacket $packet) : bool{
return $this->player->handleClientToServerHandshake($packet);
}
public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{
return $this->player->handleResourcePackClientResponse($packet);
}
public function handleText(TextPacket $packet) : bool{
return $this->player->handleText($packet);
}
public function handleMovePlayer(MovePlayerPacket $packet) : bool{
return $this->player->handleMovePlayer($packet);
}
public function handleRemoveBlock(RemoveBlockPacket $packet) : bool{
return $this->player->handleRemoveBlock($packet);
}
public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{
return $this->player->handleLevelSoundEvent($packet);
}
public function handleEntityEvent(EntityEventPacket $packet) : bool{
return $this->player->handleEntityEvent($packet);
}
public function handleMobEquipment(MobEquipmentPacket $packet) : bool{
return $this->player->handleMobEquipment($packet);
}
public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{
return true; //Not used
}
public function handleInteract(InteractPacket $packet) : bool{
return $this->player->handleInteract($packet);
}
public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{
return $this->player->handleBlockPickRequest($packet);
}
public function handleUseItem(UseItemPacket $packet) : bool{
return $this->player->handleUseItem($packet);
}
public function handlePlayerAction(PlayerActionPacket $packet) : bool{
return $this->player->handlePlayerAction($packet);
}
public function handleEntityFall(EntityFallPacket $packet) : bool{
return true; //Not used
}
public function handleAnimate(AnimatePacket $packet) : bool{
return $this->player->handleAnimate($packet);
}
public function handleDropItem(DropItemPacket $packet) : bool{
return $this->player->handleDropItem($packet);
}
public function handleContainerClose(ContainerClosePacket $packet) : bool{
return $this->player->handleContainerClose($packet);
}
public function handleContainerSetSlot(ContainerSetSlotPacket $packet) : bool{
return $this->player->handleContainerSetSlot($packet);
}
public function handleCraftingEvent(CraftingEventPacket $packet) : bool{
return $this->player->handleCraftingEvent($packet);
}
public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{
return $this->player->handleAdventureSettings($packet);
}
public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{
return $this->player->handleBlockEntityData($packet);
}
public function handlePlayerInput(PlayerInputPacket $packet) : bool{
return $this->player->handlePlayerInput($packet);
}
public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{
return $this->player->handleSetPlayerGameType($packet);
}
public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool{
return $this->player->handleSpawnExperienceOrb($packet);
}
public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool{
return $this->player->handleMapInfoRequest($packet);
}
public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{
return $this->player->handleRequestChunkRadius($packet);
}
public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{
return $this->player->handleItemFrameDropItem($packet);
}
public function handleBossEvent(BossEventPacket $packet) : bool{
return $this->player->handleBossEvent($packet);
}
public function handleShowCredits(ShowCreditsPacket $packet) : bool{
return $this->player->handleShowCredits($packet);
}
public function handleCommandStep(CommandStepPacket $packet) : bool{
return $this->player->handleCommandStep($packet);
}
public function handleCommandBlockUpdate(CommandBlockUpdatePacket $packet) : bool{
return $this->player->handleCommandBlockUpdate($packet);
}
public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{
return $this->player->handleResourcePackChunkRequest($packet);
}
}