Implement DataPacketPreReceiveEvent (#5559)

closes #5554

This is called just before the packet is decoded, allowing the event to be used to drop packets from clients without wasting CPU time decoding them. This can be particularly useful for mitigating denial-of-service attacks.
This commit is contained in:
Armen Deroian
2023-03-15 18:47:19 -04:00
committed by GitHub
parent 08ee825d91
commit 183d1f4038
2 changed files with 61 additions and 0 deletions

View File

@ -25,6 +25,7 @@ namespace pocketmine\network\mcpe;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\event\player\PlayerDuplicateLoginEvent;
use pocketmine\event\server\DataPacketPreReceiveEvent;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\event\server\DataPacketSendEvent;
use pocketmine\form\Form;
@ -412,6 +413,12 @@ class NetworkSession{
$timings->startTiming();
try{
$ev = new DataPacketPreReceiveEvent($this, $packet->pid(), $buffer);
$ev->call();
if($ev->isCancelled()){
return;
}
$decodeTimings = Timings::getDecodeDataPacketTimings($packet);
$decodeTimings->startTiming();
try{