mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 16:49:53 +00:00
Fixed NACK handling - Works even with 90% packet loss
This commit is contained in:
parent
42d5296533
commit
98976ac56c
@ -530,32 +530,42 @@ class Player{
|
|||||||
switch($pid){
|
switch($pid){
|
||||||
case 0xa0: //NACK
|
case 0xa0: //NACK
|
||||||
if(isset($this->recovery[$data[2]])){
|
if(isset($this->recovery[$data[2]])){
|
||||||
$this->directDataPacket($this->recovery[$data[2]]["id"], $this->recovery[$data[2]]);
|
$this->directDataPacket($this->recovery[$data[2]]["id"], $this->recovery[$data[2]], $data[2]);
|
||||||
}
|
}
|
||||||
if(isset($data[3])){
|
if(isset($data[3])){
|
||||||
if(isset($this->recovery[$data[3]])){
|
if(isset($this->recovery[$data[3]])){
|
||||||
$this->directDataPacket($this->recovery[$data[3]]["id"], $this->recovery[$data[3]]);
|
$this->directDataPacket($this->recovery[$data[3]]["id"], $this->recovery[$data[3]], $data[3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0xc0: //ACK
|
case 0xc0: //ACK
|
||||||
$diff = $data[2] - $this->counter[2];
|
/*$diff = $data[2] - $this->counter[2];
|
||||||
if($diff > 8){ //Packet recovery
|
if($diff > 8){ //Packet recovery
|
||||||
$this->directDataPacket($this->recovery[$this->counter[2]]["id"], $this->recovery[$this->counter[2]]);
|
$this->directDataPacket($this->recovery[$this->counter[2]]["id"], $this->recovery[$this->counter[2]]);
|
||||||
}
|
}*/
|
||||||
$this->counter[2] = $data[2];
|
$this->counter[2] = $data[2];
|
||||||
$this->recovery[$data[2]] = null;
|
$this->recovery[$data[2]] = null;
|
||||||
unset($this->recovery[$data[2]]);
|
unset($this->recovery[$data[2]]);
|
||||||
|
|
||||||
if(isset($data[3])){
|
if(isset($data[3])){
|
||||||
$diff = $data[3] - $this->counter[2];
|
/*$diff = $data[3] - $this->counter[2];
|
||||||
if($diff > 8){ //Packet recovery
|
if($diff > 8){ //Packet recovery
|
||||||
$this->directDataPacket($this->recovery[$this->counter[2]]["id"], $this->recovery[$this->counter[2]]);
|
$this->directDataPacket($this->recovery[$this->counter[2]]["id"], $this->recovery[$this->counter[2]]);
|
||||||
}
|
}*/
|
||||||
$this->counter[2] = $data[3];
|
$this->counter[2] = $data[3];
|
||||||
$this->recovery[$data[3]] = null;
|
$this->recovery[$data[3]] = null;
|
||||||
unset($this->recovery[$data[3]]);
|
unset($this->recovery[$data[3]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cnt = 0;
|
||||||
|
foreach($this->recovery as $count => $d){
|
||||||
|
$diff = $this->counter[2] - $count;
|
||||||
|
if($diff > 16 and $cnt < 16){
|
||||||
|
++$cnt;
|
||||||
|
$this->directDataPacket($d["id"], $d, $count);
|
||||||
|
}else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 0x07:
|
case 0x07:
|
||||||
if($this->loggedIn === true){
|
if($this->loggedIn === true){
|
||||||
@ -1029,27 +1039,26 @@ class Player{
|
|||||||
|
|
||||||
public function sendBuffer(){
|
public function sendBuffer(){
|
||||||
if(strlen($this->buffer) > 0){
|
if(strlen($this->buffer) > 0){
|
||||||
$count = $this->counter[0];
|
$this->directDataPacket(false, array("raw" => $this->buffer));
|
||||||
++$this->counter[0];
|
|
||||||
if(count($this->recovery) >= 512){
|
|
||||||
array_shift($this->recovery);
|
|
||||||
}
|
}
|
||||||
$this->recovery[$count] = array("id" => false, "raw" => $this->buffer);
|
|
||||||
$this->send(0x80, array(
|
|
||||||
$count,
|
|
||||||
0x00,
|
|
||||||
$this->recovery[$count],
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->buffer = "";
|
$this->buffer = "";
|
||||||
$this->nextBuffer = microtime(true) + 0.1;
|
$this->nextBuffer = microtime(true) + 0.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function directDataPacket($id, $data){
|
public function directDataPacket($id, $data, $count = false){
|
||||||
$data["id"] = $id;
|
$data["id"] = $id;
|
||||||
|
if($count === false){
|
||||||
$count = $this->counter[0];
|
$count = $this->counter[0];
|
||||||
++$this->counter[0];
|
++$this->counter[0];
|
||||||
|
if(count($this->recovery) >= 1024){
|
||||||
|
reset($this->recovery);
|
||||||
|
$k = key($this->recovery);
|
||||||
|
$this->recovery[$k] = null;
|
||||||
|
unset($this->recovery[$k]);
|
||||||
|
end($this->recovery);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->recovery[$count] = $data;
|
||||||
$this->send(0x80, array(
|
$this->send(0x80, array(
|
||||||
$count,
|
$count,
|
||||||
0x00,
|
0x00,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user