mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
Updated packet handling to eliminate loops
This commit is contained in:
parent
3fed63b248
commit
7f0693e7e7
@ -560,7 +560,7 @@ class PocketMinecraftServer{
|
||||
$lastLoop = 0;
|
||||
while($this->stop === false){
|
||||
$packet = $this->interface->readPacket();
|
||||
if($packet !== false){
|
||||
if($packet instanceof Packet){
|
||||
$this->packetHandler($packet);
|
||||
$lastLoop = 0;
|
||||
}else{
|
||||
|
@ -41,20 +41,18 @@ class MinecraftInterface{
|
||||
}
|
||||
|
||||
public function readPacket(){
|
||||
$pk = $this->popPacket();
|
||||
if($this->socket->connected === false){
|
||||
return $pk;
|
||||
return false;
|
||||
}
|
||||
$buf = "";
|
||||
$source = false;
|
||||
$port = 1;
|
||||
$len = $this->socket->read($buf, $source, $port);
|
||||
if($len === false or $len === 0){
|
||||
return $pk;
|
||||
return false;
|
||||
}
|
||||
$this->bandwidth[0] += $len;
|
||||
$this->parsePacket($buf, $source, $port);
|
||||
return ($pk !== false ? $pk : $this->popPacket());
|
||||
return $this->parsePacket($buf, $source, $port);
|
||||
}
|
||||
|
||||
private function parsePacket($buffer, $source, $port){
|
||||
@ -64,8 +62,9 @@ class MinecraftInterface{
|
||||
if($parser->packet !== false){
|
||||
$parser->packet->ip = $source;
|
||||
$parser->packet->port = $port;
|
||||
$this->packets[] = $parser->packet;
|
||||
return $parser->packet;
|
||||
}
|
||||
return false;
|
||||
}else{
|
||||
$packet = new Packet();
|
||||
$packet->ip = $source;
|
||||
@ -76,16 +75,6 @@ class MinecraftInterface{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function popPacket(){
|
||||
if(count($this->packets) > 0){
|
||||
$p = each($this->packets);
|
||||
unset($this->packets[$p[0]]);
|
||||
return $p[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function writePacket(Packet $packet){
|
||||
|
Loading…
x
Reference in New Issue
Block a user