mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-05 19:37:17 +00:00
Ticks per Second info
This commit is contained in:
parent
745c300840
commit
f42f2d5e82
3
TODO
3
TODO
@ -1,4 +1,5 @@
|
|||||||
- Save placed blocks and relay them to other players.
|
- Save placed blocks and relay them to other players.
|
||||||
- Fix spawn position resetting to 0,128,0
|
- Fix spawn position resetting to 0,128,0
|
||||||
- Mob spawning, item pick up
|
- Mob spawning, item pick up
|
||||||
- Fix metadata orientation
|
- Fix metadata orientation
|
||||||
|
- Proper session checks
|
@ -31,6 +31,7 @@ class ConsoleAPI{
|
|||||||
$this->help = array();
|
$this->help = array();
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
$this->input = fopen(FILE_PATH."console.in", "w+b");
|
$this->input = fopen(FILE_PATH."console.in", "w+b");
|
||||||
|
$this->last = microtime(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init(){
|
public function init(){
|
||||||
@ -44,6 +45,11 @@ class ConsoleAPI{
|
|||||||
|
|
||||||
public function defaultCommands($cmd, $params){
|
public function defaultCommands($cmd, $params){
|
||||||
switch($cmd){
|
switch($cmd){
|
||||||
|
case "status":
|
||||||
|
case "lag":
|
||||||
|
$info = $this->server->debugInfo();
|
||||||
|
console("[INFO] TPS: ".$info["tps"].", Memory usage: ".$info["memory_usage"]." (Peak ".$info["memory_peak_usage"].")");
|
||||||
|
break;
|
||||||
case "update-done":
|
case "update-done":
|
||||||
$this->server->api->setProperty("last-update", time());
|
$this->server->api->setProperty("last-update", time());
|
||||||
break;
|
break;
|
||||||
@ -175,6 +181,7 @@ class ConsoleAPI{
|
|||||||
case "help":
|
case "help":
|
||||||
case "?":
|
case "?":
|
||||||
console("[INFO] /help: Show available commands");
|
console("[INFO] /help: Show available commands");
|
||||||
|
console("[INFO] /status: Show server TPS and memory usage");
|
||||||
console("[INFO] /gamemode: Changes default gamemode");
|
console("[INFO] /gamemode: Changes default gamemode");
|
||||||
console("[INFO] /difficulty: Changes difficulty");
|
console("[INFO] /difficulty: Changes difficulty");
|
||||||
console("[INFO] /say: Broadcasts mesages");
|
console("[INFO] /say: Broadcasts mesages");
|
||||||
@ -197,7 +204,7 @@ class ConsoleAPI{
|
|||||||
$this->help[strtolower(trim($cmd))] = array($help, $callback);
|
$this->help[strtolower(trim($cmd))] = array($help, $callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(){
|
public function handle($time){
|
||||||
while(($line = fgets($this->input)) !== false){
|
while(($line = fgets($this->input)) !== false){
|
||||||
$line = trim($line);
|
$line = trim($line);
|
||||||
if($line === ""){
|
if($line === ""){
|
||||||
|
@ -66,7 +66,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
|||||||
console("[NOTICE] Pocket-PHP-Minecraft has been updated at ".date("Y-m-d H:i:s", $last));
|
console("[NOTICE] Pocket-PHP-Minecraft has been updated at ".date("Y-m-d H:i:s", $last));
|
||||||
console("[NOTICE] If you want to update, get the latest version at https://github.com/shoghicp/Pocket-Minecraft-PHP/archive/master.zip");
|
console("[NOTICE] If you want to update, get the latest version at https://github.com/shoghicp/Pocket-Minecraft-PHP/archive/master.zip");
|
||||||
console("[NOTICE] This message will dissapear when you issue the command \"/update-done\"");
|
console("[NOTICE] This message will dissapear when you issue the command \"/update-done\"");
|
||||||
sleep(5);
|
sleep(3);
|
||||||
}else{
|
}else{
|
||||||
$last = time();
|
$last = time();
|
||||||
$this->setProperty("last-update", $last);
|
$this->setProperty("last-update", $last);
|
||||||
|
@ -28,7 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
require_once("classes/Session.class.php");
|
require_once("classes/Session.class.php");
|
||||||
|
|
||||||
class PocketMinecraftServer extends stdClass{
|
class PocketMinecraftServer extends stdClass{
|
||||||
var $preparedSQL, $seed, $protocol, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $timePerSecond, $responses, $spawn, $entities, $mapDir, $mapName, $map, $level, $tileEntities;
|
var $tickMeasure, $preparedSQL, $seed, $protocol, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $timePerSecond, $responses, $spawn, $entities, $mapDir, $mapName, $map, $level, $tileEntities;
|
||||||
private $database, $interface, $evCnt, $handCnt, $events, $handlers, $version, $serverType, $lastTick;
|
private $database, $interface, $evCnt, $handCnt, $events, $handlers, $version, $serverType, $lastTick;
|
||||||
function __construct($name, $gamemode = 1, $seed = false, $protocol = CURRENT_PROTOCOL, $port = 19132, $serverID = false, $version = CURRENT_VERSION){
|
function __construct($name, $gamemode = 1, $seed = false, $protocol = CURRENT_PROTOCOL, $port = 19132, $serverID = false, $version = CURRENT_VERSION){
|
||||||
$this->port = (int) $port; //19132 - 19135
|
$this->port = (int) $port; //19132 - 19135
|
||||||
@ -67,6 +67,7 @@ class PocketMinecraftServer extends stdClass{
|
|||||||
$this->spawn = array("x" => 128.5,"y" => 100,"z" => 128.5);
|
$this->spawn = array("x" => 128.5,"y" => 100,"z" => 128.5);
|
||||||
$this->time = 0;
|
$this->time = 0;
|
||||||
$this->timePerSecond = 10;
|
$this->timePerSecond = 10;
|
||||||
|
$this->tickMeasure = array_fill(0, 40, 0);
|
||||||
$this->setType("normal");
|
$this->setType("normal");
|
||||||
$this->interface = new MinecraftInterface("255.255.255.255", $this->protocol, $this->port, true, false);
|
$this->interface = new MinecraftInterface("255.255.255.255", $this->protocol, $this->port, true, false);
|
||||||
$this->reloadConfig();
|
$this->reloadConfig();
|
||||||
@ -77,13 +78,19 @@ class PocketMinecraftServer extends stdClass{
|
|||||||
$this->stop = false;
|
$this->stop = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTPS(){
|
||||||
|
$v = array_values($this->tickMeasure);
|
||||||
|
$tps = 40/($v[39] - $v[0]);
|
||||||
|
return round($tps, 4);
|
||||||
|
}
|
||||||
|
|
||||||
public function loadEvents(){
|
public function loadEvents(){
|
||||||
$this->event("onChat", "eventHandler", true);
|
$this->event("onChat", "eventHandler", true);
|
||||||
$this->event("onPlayerDeath", "eventHandler", true);
|
$this->event("onPlayerDeath", "eventHandler", true);
|
||||||
$this->event("onPlayerAdd", "eventHandler", true);
|
$this->event("onPlayerAdd", "eventHandler", true);
|
||||||
$this->event("onHealthChange", "eventHandler", true);
|
$this->event("onHealthChange", "eventHandler", true);
|
||||||
|
|
||||||
$this->action(500000, '$this->time += ceil($this->timePerSecond / 2);$this->trigger("onTimeChange", $this->time);');
|
$this->action(500000, '$this->time += (int) ($this->timePerSecond / 2);$this->trigger("onTimeChange", $this->time);');
|
||||||
$this->action(5000000, '$this->trigger("onHealthRegeneration", 1);');
|
$this->action(5000000, '$this->trigger("onHealthRegeneration", 1);');
|
||||||
$this->action(1000000 * 60, '$this->reloadConfig();');
|
$this->action(1000000 * 60, '$this->reloadConfig();');
|
||||||
$this->action(1000000 * 60 * 10, '$this->custom = array();');
|
$this->action(1000000 * 60 * 10, '$this->custom = array();');
|
||||||
@ -130,6 +137,7 @@ class PocketMinecraftServer extends stdClass{
|
|||||||
|
|
||||||
public function debugInfo($console = false){
|
public function debugInfo($console = false){
|
||||||
$info = array();
|
$info = array();
|
||||||
|
$info["tps"] = $this->getTPS();
|
||||||
$info["memory_usage"] = round((memory_get_usage(true) / 1024) / 1024, 2)."MB";
|
$info["memory_usage"] = round((memory_get_usage(true) / 1024) / 1024, 2)."MB";
|
||||||
$info["memory_peak_usage"] = round((memory_get_peak_usage(true) / 1024) / 1024, 2)."MB";
|
$info["memory_peak_usage"] = round((memory_get_peak_usage(true) / 1024) / 1024, 2)."MB";
|
||||||
$info["entities"] = $this->query("SELECT count(EID) as count FROM entities;", true);
|
$info["entities"] = $this->query("SELECT count(EID) as count FROM entities;", true);
|
||||||
@ -140,7 +148,7 @@ class PocketMinecraftServer extends stdClass{
|
|||||||
$info["actions"] = $info["actions"]["count"];
|
$info["actions"] = $info["actions"]["count"];
|
||||||
$info["garbage"] = gc_collect_cycles();
|
$info["garbage"] = gc_collect_cycles();
|
||||||
if($console === true){
|
if($console === true){
|
||||||
console("[DEBUG] Memory usage: ".$info["memory_usage"]." (Peak ".$info["memory_peak_usage"]."), Entities: ".$info["entities"].", Events: ".$info["events"].", Actions: ".$info["actions"].", Garbage: ".$info["garbage"], true, true, 2);
|
console("[DEBUG] TPS: ".$info["tps"].", Memory usage: ".$info["memory_usage"]." (Peak ".$info["memory_peak_usage"]."), Entities: ".$info["entities"].", Events: ".$info["events"].", Actions: ".$info["actions"].", Garbage: ".$info["garbage"], true, true, 2);
|
||||||
}
|
}
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
@ -310,7 +318,8 @@ class PocketMinecraftServer extends stdClass{
|
|||||||
public function tick(){
|
public function tick(){
|
||||||
$time = microtime(true);
|
$time = microtime(true);
|
||||||
if($this->lastTick <= ($time - 0.05)){
|
if($this->lastTick <= ($time - 0.05)){
|
||||||
$this->lastTick = $time;
|
$this->tickMeasure[] = $this->lastTick = $time;
|
||||||
|
array_shift($this->tickMeasure);
|
||||||
$this->trigger("onTick", $time);
|
$this->trigger("onTick", $time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user