Kick players on high packet loss

This commit is contained in:
Shoghi Cervantes 2013-06-03 18:27:17 +02:00
parent f55fb8d490
commit dc22e1b81c
2 changed files with 13 additions and 1 deletions

View File

@ -62,6 +62,7 @@ class Player{
private $chunksOrder = array(); private $chunksOrder = array();
private $lag = array(0, 0); private $lag = array(0, 0);
private $spawnPosition; private $spawnPosition;
private $packetLoss = 0;
public $itemEnforcement; public $itemEnforcement;
public $lastCorrect; public $lastCorrect;
private $bigCnt; private $bigCnt;
@ -716,16 +717,26 @@ class Player{
if($this->connected === false){ if($this->connected === false){
return false; return false;
} }
$this->packetLoss = $this->packetStats[1] / max(1, $this->packetStats[0]);
$this->packetStats = array(0, 0);
$this->lag[0] = microtime(true) * 1000; $this->lag[0] = microtime(true) * 1000;
$this->dataPacket(MC_PING, array( $this->dataPacket(MC_PING, array(
"time" => (int) $this->lag[0], "time" => (int) $this->lag[0],
)); ));
$this->sendBuffer(); $this->sendBuffer();
if($this->packetLoss >= PLAYER_MAX_PACKET_LOSS){
$this->sendChat("Your connection suffers high packet loss");
$this->close("packet.loss");
}
} }
public function getLag(){ public function getLag(){
return $this->lag[1] - $this->lag[0]; return $this->lag[1] - $this->lag[0];
} }
public function getPacketLoss(){
return $this->packetLoss;
}
public function handle($pid, $data){ public function handle($pid, $data){
if($this->connected === true){ if($this->connected === true){
@ -957,7 +968,7 @@ class Player{
$this->evid[] = $this->server->event("player.pickup", array($this, "eventHandler")); $this->evid[] = $this->server->event("player.pickup", array($this, "eventHandler"));
$this->evid[] = $this->server->event("tile.container.slot", array($this, "eventHandler")); $this->evid[] = $this->server->event("tile.container.slot", array($this, "eventHandler"));
$this->evid[] = $this->server->event("tile.update", array($this, "eventHandler")); $this->evid[] = $this->server->event("tile.update", array($this, "eventHandler"));
$this->server->schedule(40, array($this, "measureLag"), array(), true); $this->server->schedule(100, array($this, "measureLag"), array(), true);
console("[INFO] \x1b[33m".$this->username."\x1b[0m[/".$this->ip.":".$this->port."] logged in with entity id ".$this->eid." at (".$this->entity->level->getName().", ".round($this->entity->x, 2).", ".round($this->entity->y, 2).", ".round($this->entity->z, 2).")"); console("[INFO] \x1b[33m".$this->username."\x1b[0m[/".$this->ip.":".$this->port."] logged in with entity id ".$this->eid." at (".$this->entity->level->getName().", ".round($this->entity->x, 2).", ".round($this->entity->y, 2).", ".round($this->entity->z, 2).")");
break; break;
case MC_READY: case MC_READY:

View File

@ -35,6 +35,7 @@ define("VIEWER", 3);
//Players //Players
define("PLAYER_RECOVERY_BUFFER", 2048); define("PLAYER_RECOVERY_BUFFER", 2048);
define("PLAYER_MAX_PACKET_LOSS", 0.20);
//Block Updates //Block Updates