mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-27 13:49:55 +00:00
Fixed DataPacketReceiveEvent, fixed packet receive timings, gave Player->handleDataPacket() a new use
This commit is contained in:
parent
be449b6106
commit
9c350dbe47
@ -3291,7 +3291,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: get rid of these remains, fix DataPacketReceiveEvent, fix timings
|
||||
* Called when a packet is received from the client. This method will call DataPacketReceiveEvent.
|
||||
*
|
||||
* @param DataPacket $packet
|
||||
*/
|
||||
@ -3300,18 +3300,14 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$timings = Timings::getReceiveDataPacketTimings($packet);
|
||||
|
||||
$timings->startTiming();
|
||||
|
||||
$this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet));
|
||||
if($ev->isCancelled()){
|
||||
$timings->stopTiming();
|
||||
return;
|
||||
if(!$ev->isCancelled() and !$packet->handle($this)){
|
||||
$this->server->getLogger()->debug("Unhandled " . get_class($packet) . " received from " . $this->getName());
|
||||
}
|
||||
|
||||
|
||||
$timings->stopTiming();
|
||||
}
|
||||
|
||||
|
@ -232,10 +232,22 @@ class Network{
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a batch packet and does handling for it.
|
||||
*
|
||||
* TODO: Move this out of here
|
||||
*
|
||||
* @param BatchPacket $packet
|
||||
* @param Player $player
|
||||
*
|
||||
* @throws \InvalidArgumentException|\InvalidStateException
|
||||
*/
|
||||
public function processBatch(BatchPacket $packet, Player $p){
|
||||
if(strlen($packet->payload) === 0){
|
||||
//prevent zlib_decode errors for incorrectly-decoded packets
|
||||
$rawLen = strlen($packet->payload);
|
||||
if($rawLen === 0){
|
||||
throw new \InvalidArgumentException("BatchPacket payload is empty or packet decode error");
|
||||
}elseif($rawLen < 3){
|
||||
throw new \InvalidArgumentException("Not enough bytes, expected zlib header");
|
||||
}
|
||||
|
||||
$str = zlib_decode($packet->payload, 1024 * 1024 * 64); //Max 64MB
|
||||
@ -259,10 +271,7 @@ class Network{
|
||||
|
||||
$pk->decode();
|
||||
assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread in " . get_class($pk));
|
||||
if(!$pk->handle($p)){
|
||||
$logger = $this->server->getLogger();
|
||||
$logger->debug("Unhandled " . get_class($pk) . " received from " . $p->getName());
|
||||
}
|
||||
$p->handleDataPacket($pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,10 +135,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
|
||||
if($pk !== null){
|
||||
$pk->decode();
|
||||
assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread!");
|
||||
if(!$pk->handle($this->players[$identifier])){
|
||||
$logger = $this->server->getLogger();
|
||||
$logger->debug("Unhandled " . get_class($pk) . " received from " . $this->players[$identifier]->getName());
|
||||
}
|
||||
$this->players[$identifier]->handleDataPacket($pk);
|
||||
}
|
||||
}
|
||||
}catch(\Throwable $e){
|
||||
|
Loading…
x
Reference in New Issue
Block a user