Add restrictions on packet send directions with interfaces

This prevents plugins sending wrong packets at the compiler level (or would, if we had a compiler). It's more robust than a getter for client/server and throwing an exception since a static analysis tool can detect faults created by sending wrong packets from the server. This is also used to deny service to dodgy clients which send wrong packets to the server to attack it.
This commit is contained in:
Dylan K. Taylor
2019-01-04 03:19:47 +00:00
parent b82e00ffdf
commit 76f1ee1827
130 changed files with 237 additions and 174 deletions

View File

@ -73,9 +73,9 @@ use pocketmine\nbt\tag\StringTag;
use pocketmine\network\mcpe\ChunkRequestTask;
use pocketmine\network\mcpe\CompressBatchPromise;
use pocketmine\network\mcpe\protocol\AddEntityPacket;
use pocketmine\network\mcpe\protocol\ClientboundPacket;
use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\Packet;
use pocketmine\network\mcpe\protocol\SetDifficultyPacket;
use pocketmine\network\mcpe\protocol\SetTimePacket;
use pocketmine\network\mcpe\protocol\UpdateBlockPacket;
@ -180,9 +180,9 @@ class Level implements ChunkManager, Metadatable{
/** @var Player[][] */
private $playerLoaders = [];
/** @var Packet[][] */
/** @var ClientboundPacket[][] */
private $chunkPackets = [];
/** @var Packet[] */
/** @var ClientboundPacket[] */
private $globalPackets = [];
/** @var float[] */
@ -598,11 +598,11 @@ class Level implements ChunkManager, Metadatable{
* Queues a packet to be sent to all players using the chunk at the specified X/Z coordinates at the end of the
* current tick.
*
* @param int $chunkX
* @param int $chunkZ
* @param Packet $packet
* @param int $chunkX
* @param int $chunkZ
* @param ClientboundPacket $packet
*/
public function addChunkPacket(int $chunkX, int $chunkZ, Packet $packet){
public function addChunkPacket(int $chunkX, int $chunkZ, ClientboundPacket $packet){
if(!isset($this->chunkPackets[$index = Level::chunkHash($chunkX, $chunkZ)])){
$this->chunkPackets[$index] = [$packet];
}else{
@ -613,19 +613,19 @@ class Level implements ChunkManager, Metadatable{
/**
* Broadcasts a packet to every player who has the target position within their view distance.
*
* @param Vector3 $pos
* @param Packet $packet
* @param Vector3 $pos
* @param ClientboundPacket $packet
*/
public function broadcastPacketToViewers(Vector3 $pos, Packet $packet) : void{
public function broadcastPacketToViewers(Vector3 $pos, ClientboundPacket $packet) : void{
$this->addChunkPacket($pos->getFloorX() >> 4, $pos->getFloorZ() >> 4, $packet);
}
/**
* Broadcasts a packet to every player in the level.
*
* @param Packet $packet
* @param ClientboundPacket $packet
*/
public function broadcastGlobalPacket(Packet $packet) : void{
public function broadcastGlobalPacket(ClientboundPacket $packet) : void{
$this->globalPackets[] = $packet;
}