mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
View connection lag in-game
This commit is contained in:
parent
1ef0a41944
commit
1129df6194
@ -41,7 +41,6 @@ class ConsoleAPI{
|
|||||||
$this->loop->start();
|
$this->loop->start();
|
||||||
$this->register("help", "Show available commands", array($this, "defaultCommands"));
|
$this->register("help", "Show available commands", array($this, "defaultCommands"));
|
||||||
$this->register("status", "Show server TPS and memory usage", array($this, "defaultCommands"));
|
$this->register("status", "Show server TPS and memory usage", array($this, "defaultCommands"));
|
||||||
$this->alias("lag", "status");
|
|
||||||
$this->register("difficulty", "Changes server difficulty", array($this, "defaultCommands"));
|
$this->register("difficulty", "Changes server difficulty", array($this, "defaultCommands"));
|
||||||
$this->register("invisible", "Changes server visibility", array($this, "defaultCommands"));
|
$this->register("invisible", "Changes server visibility", array($this, "defaultCommands"));
|
||||||
$this->register("say", "Broadcast a message", array($this, "defaultCommands"));
|
$this->register("say", "Broadcast a message", array($this, "defaultCommands"));
|
||||||
@ -86,7 +85,6 @@ class ConsoleAPI{
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "status":
|
case "status":
|
||||||
case "lag":
|
|
||||||
if(!($issuer instanceof Player) and $issuer === "console"){
|
if(!($issuer instanceof Player) and $issuer === "console"){
|
||||||
$this->server->debugInfo(true);
|
$this->server->debugInfo(true);
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ class PlayerAPI{
|
|||||||
$this->server->api->console->register("gamemode", "Changes the player gamemode", array($this, "commandHandler"));
|
$this->server->api->console->register("gamemode", "Changes the player gamemode", array($this, "commandHandler"));
|
||||||
$this->server->api->console->register("tppos", "Teleports a player to a position", array($this, "commandHandler"));
|
$this->server->api->console->register("tppos", "Teleports a player to a position", array($this, "commandHandler"));
|
||||||
$this->server->api->console->register("tp", "Teleports a player to another player", array($this, "commandHandler"));
|
$this->server->api->console->register("tp", "Teleports a player to another player", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("lag", "Measure your connection lag", array($this, "commandHandler"));
|
||||||
$this->server->api->console->alias("suicide", "kill");
|
$this->server->api->console->alias("suicide", "kill");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +114,13 @@ class PlayerAPI{
|
|||||||
public function commandHandler($cmd, $params, $issuer, $alias){
|
public function commandHandler($cmd, $params, $issuer, $alias){
|
||||||
$output = "";
|
$output = "";
|
||||||
switch($cmd){
|
switch($cmd){
|
||||||
|
case "lag":
|
||||||
|
if(!($issuer instanceof Player)){
|
||||||
|
$output .= "Please run this command in-game.\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$output .= "Lag: ".round($issuer->getLag(), 2)."\n";
|
||||||
|
break;
|
||||||
case "gamemode":
|
case "gamemode":
|
||||||
$gm = -1;
|
$gm = -1;
|
||||||
$player = false;
|
$player = false;
|
||||||
|
@ -60,6 +60,7 @@ class Player{
|
|||||||
public $blocked = true;
|
public $blocked = true;
|
||||||
private $chunksLoaded = array();
|
private $chunksLoaded = array();
|
||||||
private $chunksOrder = array();
|
private $chunksOrder = array();
|
||||||
|
private $lag = array(0, 0);
|
||||||
|
|
||||||
function __construct($clientID, $ip, $port, $MTU){
|
function __construct($clientID, $ip, $port, $MTU){
|
||||||
$this->MTU = $MTU;
|
$this->MTU = $MTU;
|
||||||
@ -529,6 +530,18 @@ class Player{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function measureLag(){
|
||||||
|
$this->lag[0] = microtime(true) * 1000;
|
||||||
|
$this->dataPacket(MC_PING, array(
|
||||||
|
"time" => (int) $this->lag[0],
|
||||||
|
));
|
||||||
|
$this->sendBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLag(){
|
||||||
|
return $this->lag[1] - $this->lag[0];
|
||||||
|
}
|
||||||
|
|
||||||
public function handle($pid, $data){
|
public function handle($pid, $data){
|
||||||
if($this->connected === true){
|
if($this->connected === true){
|
||||||
$this->timeout = microtime(true) + 20;
|
$this->timeout = microtime(true) + 20;
|
||||||
@ -606,11 +619,16 @@ class Player{
|
|||||||
switch($data["id"]){
|
switch($data["id"]){
|
||||||
case 0x01:
|
case 0x01:
|
||||||
break;
|
break;
|
||||||
|
case MC_PONG:
|
||||||
|
$this->lag[1] = microtime(true) * 1000;
|
||||||
|
break;
|
||||||
case MC_PING:
|
case MC_PING:
|
||||||
|
$t = (int) (microtime(true) * 1000);
|
||||||
$this->dataPacket(MC_PONG, array(
|
$this->dataPacket(MC_PONG, array(
|
||||||
"ptime" => $data["time"],
|
"ptime" => $data["time"],
|
||||||
"time" => (int) (microtime(true) * 1000),
|
"time" => (int) (microtime(true) * 1000),
|
||||||
));
|
));
|
||||||
|
$this->sendBuffer();
|
||||||
break;
|
break;
|
||||||
case MC_DISCONNECT:
|
case MC_DISCONNECT:
|
||||||
$this->close("client disconnect");
|
$this->close("client disconnect");
|
||||||
@ -724,6 +742,7 @@ class Player{
|
|||||||
$this->evid[] = $this->server->event("block.change", array($this, "eventHandler"));
|
$this->evid[] = $this->server->event("block.change", array($this, "eventHandler"));
|
||||||
$this->evid[] = $this->server->event("player.block.place", array($this, "eventHandler"));
|
$this->evid[] = $this->server->event("player.block.place", 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->server->schedule(40, array($this, "measureLag"), array(), true);
|
||||||
break;
|
break;
|
||||||
case MC_READY:
|
case MC_READY:
|
||||||
if($this->loggedIn === false){
|
if($this->loggedIn === false){
|
||||||
|
@ -97,7 +97,7 @@ define("MC_ADVENTURE_SETTINGS", 0xb6);
|
|||||||
|
|
||||||
class Protocol{
|
class Protocol{
|
||||||
public static $dataName = array(
|
public static $dataName = array(
|
||||||
MC_KEEP_ALIVE => "Keep Alive",
|
MC_PING => "Ping",
|
||||||
|
|
||||||
MC_CLIENT_CONNECT => "Client Connect",
|
MC_CLIENT_CONNECT => "Client Connect",
|
||||||
MC_SERVER_HANDSHAKE => "Server Handshake",
|
MC_SERVER_HANDSHAKE => "Server Handshake",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user