From 92143d523cc0c073026f01a31995905a204cd99c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 6 Nov 2014 19:07:24 +0100 Subject: [PATCH] Added SetDifficultyPacket --- src/pocketmine/Player.php | 5 ++ .../command/defaults/DifficultyCommand.php | 4 ++ src/pocketmine/network/RakLibInterface.php | 2 + src/pocketmine/network/protocol/Info.php | 1 + .../network/protocol/SetDifficultyPacket.php | 46 +++++++++++++++++++ 5 files changed, 58 insertions(+) create mode 100644 src/pocketmine/network/protocol/SetDifficultyPacket.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index cbd52cbf6..2b05bd4f5 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -94,6 +94,7 @@ use pocketmine\network\protocol\Info as ProtocolInfo; use pocketmine\network\protocol\LoginStatusPacket; use pocketmine\network\protocol\MessagePacket; use pocketmine\network\protocol\MovePlayerPacket; +use pocketmine\network\protocol\SetDifficultyPacket; use pocketmine\network\protocol\SetHealthPacket; use pocketmine\network\protocol\SetSpawnPositionPacket; use pocketmine\network\protocol\SetTimePacket; @@ -1447,6 +1448,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->dead = true; } + $pk = new SetDifficultyPacket(); + $pk->difficulty = $this->server->getDifficulty(); + $this->dataPacket($pk); + $this->server->getLogger()->info(TextFormat::AQUA . $this->username . TextFormat::WHITE . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->id . " at (" . $this->level->getName() . ", " . round($this->x, 4) . ", " . round($this->y, 4) . ", " . round($this->z, 4) . ")"); diff --git a/src/pocketmine/command/defaults/DifficultyCommand.php b/src/pocketmine/command/defaults/DifficultyCommand.php index 29e770bad..892e91cb4 100644 --- a/src/pocketmine/command/defaults/DifficultyCommand.php +++ b/src/pocketmine/command/defaults/DifficultyCommand.php @@ -22,6 +22,7 @@ namespace pocketmine\command\defaults; use pocketmine\command\CommandSender; +use pocketmine\network\protocol\SetDifficultyPacket; use pocketmine\Server; use pocketmine\utils\TextFormat; @@ -55,6 +56,9 @@ class DifficultyCommand extends VanillaCommand{ if($difficulty !== -1){ $sender->getServer()->setConfigInt("difficulty", $difficulty); + $pk = new SetDifficultyPacket(); + $pk->difficulty = $sender->getServer()->getDifficulty(); + Server::broadcastPacket($sender->getServer()->getOnlinePlayers(), $pk); $sender->sendMessage("Set difficulty to " . $difficulty); }else{ $sender->sendMessage("Unknown difficulty"); diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index c0632a483..b389581a2 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -60,6 +60,7 @@ use pocketmine\network\protocol\RemovePlayerPacket; use pocketmine\network\protocol\RespawnPacket; use pocketmine\network\protocol\RotateHeadPacket; use pocketmine\network\protocol\SendInventoryPacket; +use pocketmine\network\protocol\SetDifficultyPacket; use pocketmine\network\protocol\SetEntityDataPacket; use pocketmine\network\protocol\SetEntityMotionPacket; use pocketmine\network\protocol\SetHealthPacket; @@ -328,6 +329,7 @@ class RakLibInterface implements ServerInstance, SourceInterface{ $this->registerPacket(ProtocolInfo::ADVENTURE_SETTINGS_PACKET, AdventureSettingsPacket::class); $this->registerPacket(ProtocolInfo::ENTITY_DATA_PACKET, EntityDataPacket::class); $this->registerPacket(ProtocolInfo::UNLOAD_CHUNK_PACKET, UnloadChunkPacket::class); + $this->registerPacket(ProtocolInfo::SET_DIFFICULTY_PACKET, SetDifficultyPacket::class); } private function getPacket($buffer){ diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/protocol/Info.php index fda76bcb1..953c7f200 100644 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/protocol/Info.php @@ -88,5 +88,6 @@ interface Info{ //const PLAYER_INPUT_PACKET = 0xb9; const FULL_CHUNK_DATA_PACKET = 0xba; const UNLOAD_CHUNK_PACKET = 0xbb; + const SET_DIFFICULTY_PACKET = 0xbc; } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/SetDifficultyPacket.php b/src/pocketmine/network/protocol/SetDifficultyPacket.php new file mode 100644 index 000000000..9608c3b72 --- /dev/null +++ b/src/pocketmine/network/protocol/SetDifficultyPacket.php @@ -0,0 +1,46 @@ + + + +class SetDifficultyPacket extends DataPacket{ + public static $pool = []; + public static $next = 0; + + public $difficulty; + + public function pid(){ + return Info::SET_DIFFICULTY_PACKET; + } + + public function decode(){ + $this->difficulty = $this->getInt(); + } + + public function encode(){ + $this->reset(); + $this->putInt($this->difficulty); + } + +} \ No newline at end of file