mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Use short class names for unhandled packet logging, added some documentation
This commit is contained in:
parent
6ef132e468
commit
84ec944b6b
@ -3346,11 +3346,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
return false;
|
||||
}
|
||||
|
||||
public function handleUnknown(UnknownPacket $packet) : bool{
|
||||
$this->server->getLogger()->debug("Received unknown packet from " . $this->getName() . ": 0x" . bin2hex($packet->payload));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a packet is received from the client. This method will call DataPacketReceiveEvent.
|
||||
*
|
||||
@ -3369,7 +3364,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
|
||||
$this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet));
|
||||
if(!$ev->isCancelled() and !$packet->handle($this)){
|
||||
$this->server->getLogger()->debug("Unhandled " . get_class($packet) . " received from " . $this->getName() . ": 0x" . bin2hex($packet->buffer));
|
||||
$this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->getName() . ": 0x" . bin2hex($packet->buffer));
|
||||
}
|
||||
|
||||
$timings->stopTiming();
|
||||
|
@ -292,6 +292,4 @@ interface NetworkSession{
|
||||
public function handleStopSound(StopSoundPacket $packet) : bool;
|
||||
|
||||
public function handleSetTitle(SetTitlePacket $packet) : bool;
|
||||
|
||||
public function handleUnknown(UnknownPacket $packet) : bool;
|
||||
}
|
@ -40,6 +40,10 @@ abstract class DataPacket extends BinaryStream{
|
||||
return $this::NETWORK_ID;
|
||||
}
|
||||
|
||||
public function getName() : string{
|
||||
return (new \ReflectionClass($this))->getShortName();
|
||||
}
|
||||
|
||||
public function canBeBatched() : bool{
|
||||
return true;
|
||||
}
|
||||
@ -52,6 +56,16 @@ abstract class DataPacket extends BinaryStream{
|
||||
|
||||
abstract public function decode();
|
||||
|
||||
/**
|
||||
* Performs handling for this packet. Usually you'll want an appropriately named method in the NetworkSession 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.
|
||||
* Typically this method returns the return value of the handler in the supplied NetworkSession. See other packets for examples how to implement this.
|
||||
*
|
||||
* @param NetworkSession $session
|
||||
*
|
||||
* @return bool true if the packet was handled successfully, false if not.
|
||||
*/
|
||||
abstract public function handle(NetworkSession $session) : bool;
|
||||
|
||||
public function reset(){
|
||||
|
@ -37,6 +37,10 @@ class UnknownPacket extends DataPacket{
|
||||
return self::NETWORK_ID;
|
||||
}
|
||||
|
||||
public function getName() : string{
|
||||
return "unknown packet";
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->offset -= 1; //Rewind one byte so we can read the PID
|
||||
$this->payload = $this->get(true);
|
||||
@ -48,6 +52,6 @@ class UnknownPacket extends DataPacket{
|
||||
}
|
||||
|
||||
public function handle(NetworkSession $session) : bool{
|
||||
return $session->handleUnknown($this);
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user