better max ack detection

This commit is contained in:
GameHerobrine 2026-11-01 22:49:58 +03:00
parent 81cfb6b705
commit f12315bd3f
3 changed files with 35 additions and 9 deletions

View file

@ -148,7 +148,8 @@ class PlayerAPI{
if($additional){
$arqCnt = count($p->packetAlwaysRecoverQueue);
$rqCnt = count($p->recoveryQueue);
$additionalInfo = "ARQ/RQ/EMPS: $arqCnt/$rqCnt";
$maxAck = $this->server->interface->maxACKsAllowed["{$p->ip}:{$p->port}"] ?? "???";
$additionalInfo = "ARQ/RQ/MAXACK: $arqCnt/$rqCnt/$maxAck";
}
$chunksCnt = count($p->chunkDataSent);
return "{$p->username}'s ping: {$ping}ms, packet loss {$pkLoss}%, $transfer KB/s. Chunks: $chunksCnt/256\n$additionalInfo";

View file

@ -83,8 +83,8 @@ class Player{
private $timeout;
private $connected = true;
private $clientID;
private $ip;
private $port;
public $ip;
public $port;
private $counter = [0, 0, 0, 0];
public $username;
public $iusername;
@ -188,6 +188,9 @@ class Player{
*/
public function __construct($clientID, $ip, $port, $MTU){
$this->bigCnt = 0;
//setting it above 1100 may cause issues for players on some servers
//(see 236e98be23c7f0d0654ae9af40703e4e4e89516a)
//(duplicated here cuz i wanted to remove it)
$this->MTU = min($MTU, 1100);
$this->server = ServerAPI::request();
$this->lastBreak = microtime(true);
@ -532,7 +535,7 @@ class Player{
$pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0);
$pk->data[] = $packet;
$pk->seqNumber = $this->counter[0]++;
$pk->seqNumber = $this->counter[0];
$pk->sendtime = microtime(true);
$packet->encode();
@ -541,6 +544,7 @@ class Player{
if($len > $MTU){
return $this->sendBigPacketAlwaysRecover($packet); //TODO fix
}
++$this->counter[0]; //sendBigPacketAlwaysRecover increments this counter which results in server not sending a seq number
$packet->messageIndex = $this->counter[3]++;
$packet->reliability = RakNetInfo::RELIABILITY_RELIABLE;
@ -1720,6 +1724,7 @@ class Player{
$this->lag[] = $time - $data->sendtime;
$data->sendtime = $time;
$this->send($data);
$data->incrementAllowedAck = true;
}
}
}
@ -2023,7 +2028,9 @@ class Player{
}
public function __destruct(){ //pwease dont leak memory >_<
unset($this->server->interface->maxACKsAllowed["{$this->ip}:{$this->port}"]);
$id = "{$this->ip}:{$this->port}";
unset($this->server->interface->maxACKsAllowed[$id]);
unset($this->server->interface->maxRecordedSeq[$id]);
}
public function save(){
@ -3576,7 +3583,7 @@ class Player{
$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] = $this->recoveryQueue[$count];
$this->resendQueue[$count]->incrementAllowedAck = false;
$this->lag[] = $time - $this->recoveryQueue[$count]->sendtime;
unset($this->recoveryQueue[$count]);

View file

@ -43,6 +43,12 @@ class MinecraftInterface{
* @var array
*/
public $maxACKsAllowed = [];
/**
* Stores max packet seq number. Used to determine allowed ack increment per packet
*
* @var array
*/
public $maxRecordedSeq = [];
private function parsePacket($buffer, $source, $port){
$pid = ord($buffer[0]);
@ -102,10 +108,22 @@ class MinecraftInterface{
RakNetCodec::encode($packet);
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];
$seq = $this->maxRecordedSeq[$id] ?? false;
$incr = 1;
if($seq === false){
$this->maxRecordedSeq[$id] = $packet->seqNumber;
}else{
$this->maxACKsAllowed[$id] = 1;
if($packet->seqNumber > $seq){
$incr = $packet->seqNumber - $seq;
$this->maxRecordedSeq[$id] = $packet->seqNumber;
}
}
if($incr != 1) console("ack incr: $incr");
if(isset($this->maxACKsAllowed[$id])){
$this->maxACKsAllowed[$id] += $incr;
}else{
$this->maxACKsAllowed[$id] = $incr;
}
}
}