From 81cfb6b7054e658834b8e87418c3e7dc9d1668b3 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Tue, 27 Oct 2026 17:46:18 +0300 Subject: [PATCH] better multiack handling, fixed ack negative ranges --- src/Player.php | 4 +++- src/network/MinecraftInterface.php | 4 ++-- src/network/raknet/RakNetPacket.php | 1 + src/network/raknet/RakNetParser.php | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Player.php b/src/Player.php index 0b34a8c8..626c7160 100755 --- a/src/Player.php +++ b/src/Player.php @@ -3574,8 +3574,10 @@ class Player{ foreach($packet->packets as $count){ if(isset($this->packetAlwaysRecoverQueue[$count])){ $this->resendQueue[$count] = $this->packetAlwaysRecoverQueue[$count]; + $this->resendQueue[$count]->incrementAllowedAck = false; }else if(isset($this->recoveryQueue[$count])){ $this->resendQueue[$count] =& $this->recoveryQueue[$count]; + $this->resendQueue[$count]->incrementAllowedAck = false; $this->lag[] = $time - $this->recoveryQueue[$count]->sendtime; unset($this->recoveryQueue[$count]); }else{ //lost and wont be recovered @@ -3595,8 +3597,8 @@ class Player{ }else if(isset($this->recoveryQueue[$count])){ $this->lag[] = $time - $this->recoveryQueue[$count]->sendtime; unset($this->recoveryQueue[$count]); - unset($this->resendQueue[$count]); } + unset($this->resendQueue[$count]); ++$this->packetStats[0]; } break; diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index 7f4b84f0..087a0630 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -54,7 +54,7 @@ class MinecraftInterface{ $packet = RakNetParser::parse($buffer, $acks, $ackCnt); if($packet !== false){ - if($ackCnt != 0 && isset($this->maxACKsAllowed[$id])){ + if($ackCnt != 0 && isset($this->maxACKsAllowed[$id]) && $packet->pid() != RakNetInfo::NACK){ $this->maxACKsAllowed[$id] = $acks - $ackCnt; } $packet->ip = $source; @@ -100,7 +100,7 @@ class MinecraftInterface{ return 0; }elseif($packet instanceof RakNetPacket){ RakNetCodec::encode($packet); - if($packet->pid() >= RakNetInfo::DATA_PACKET_0 && $packet->pid() <= RakNetInfo::DATA_PACKET_F){ + if($packet->pid() >= RakNetInfo::DATA_PACKET_0 && $packet->pid() <= RakNetInfo::DATA_PACKET_F && $packet->incrementAllowedAck){ $id = "{$packet->ip}:{$packet->port}"; if(isset($this->maxACKsAllowed[$id])){ ++$this->maxACKsAllowed[$id]; diff --git a/src/network/raknet/RakNetPacket.php b/src/network/raknet/RakNetPacket.php index 870a2733..81ab86d2 100644 --- a/src/network/raknet/RakNetPacket.php +++ b/src/network/raknet/RakNetPacket.php @@ -5,6 +5,7 @@ class RakNetPacket extends Packet{ public $packetID; public $seqNumber; public $sendtime; + public $incrementAllowedAck = true; public function __construct($packetID){ $this->packetID = (int) $packetID; diff --git a/src/network/raknet/RakNetParser.php b/src/network/raknet/RakNetParser.php index 27ec561e..8ee4d362 100644 --- a/src/network/raknet/RakNetParser.php +++ b/src/network/raknet/RakNetParser.php @@ -69,7 +69,7 @@ class RakNetParser{ $offset += 3; $end = Utils::readTriad(strrev(substr($buffer, $offset - 3, 3))); $acks += ($end - $start)+1; - if($maxACKAllowed >= 0 && ($maxACKAllowed - $acks) < 0){ + if($acks <= 0 || $maxACKAllowed >= 0 && ($maxACKAllowed - $acks) < 0){ $packet = false; break; }