Updated console texts and help

This commit is contained in:
Shoghi Cervantes Pueyo 2013-04-13 19:47:20 +02:00
parent 82d49b0343
commit d157299c7a
11 changed files with 62 additions and 78 deletions

View File

@ -37,18 +37,17 @@ class BanAPI{
} }
public function init(){ public function init(){
console("[INFO] Loading authentication lists...");
$this->whitelist = new Config(DATA_PATH."white-list.txt", CONFIG_LIST); $this->whitelist = new Config(DATA_PATH."white-list.txt", CONFIG_LIST);
$this->bannedIPs = new Config(DATA_PATH."banned-ips.txt", CONFIG_LIST); $this->bannedIPs = new Config(DATA_PATH."banned-ips.txt", CONFIG_LIST);
$this->banned = new Config(DATA_PATH."banned.txt", CONFIG_LIST); $this->banned = new Config(DATA_PATH."banned.txt", CONFIG_LIST);
$this->ops = new Config(DATA_PATH."ops.txt", CONFIG_LIST); $this->ops = new Config(DATA_PATH."ops.txt", CONFIG_LIST);
$this->server->api->console->register("banip", "Manages IP Banning", array($this, "commandHandler")); $this->server->api->console->register("banip", "<add|remove|list|reload> [IP|player]", array($this, "commandHandler"));
$this->server->api->console->register("ban", "Manages Bannning", array($this, "commandHandler")); $this->server->api->console->register("ban", "<add|remove|list|reload> [username]", array($this, "commandHandler"));
$this->server->api->console->register("kick", "Kicks a player", array($this, "commandHandler")); $this->server->api->console->register("kick", "<player> [reason ...]", array($this, "commandHandler"));
$this->server->api->console->register("whitelist", "Manages White-listing", array($this, "commandHandler")); $this->server->api->console->register("whitelist", "<on|off|list|add|remove|reload> [username]", array($this, "commandHandler"));
$this->server->api->console->register("op", "Ops a player", array($this, "commandHandler")); $this->server->api->console->register("op", "<player>", array($this, "commandHandler"));
$this->server->api->console->register("deop", "De-ops a player", array($this, "commandHandler")); $this->server->api->console->register("deop", "<player>", array($this, "commandHandler"));
$this->server->api->console->register("sudo", "Run a command as a player", array($this, "commandHandler")); $this->server->api->console->register("sudo", "<player>", array($this, "commandHandler"));
$this->server->api->console->alias("ban-ip", "banip add"); $this->server->api->console->alias("ban-ip", "banip add");
$this->server->api->console->alias("banlist", "ban list"); $this->server->api->console->alias("banlist", "ban list");
$this->server->api->console->alias("pardon", "ban remove"); $this->server->api->console->alias("pardon", "ban remove");
@ -147,7 +146,7 @@ class BanAPI{
break; break;
case "kick": case "kick":
if(!isset($params[0])){ if(!isset($params[0])){
$output .= "Usage: /kick <playername> [reason]\n"; $output .= "Usage: /kick <player> [reason ...]\n";
}else{ }else{
$name = strtolower(array_shift($params)); $name = strtolower(array_shift($params));
$player = $this->server->api->player->get($name); $player = $this->server->api->player->get($name);
@ -199,7 +198,7 @@ class BanAPI{
$this->server->api->setProperty("white-list", false); $this->server->api->setProperty("white-list", false);
break; break;
default: default:
$output .= "Usage: /whitelist <on | off | add | remove | reload | list> [username]\n"; $output .= "Usage: /whitelist <on|off|list|add|remove|reload> [username]\n";
break; break;
} }
break; break;
@ -232,7 +231,7 @@ class BanAPI{
$output .= "IP ban list: ".implode(", ", $this->bannedIPs->getAll(true))."\n"; $output .= "IP ban list: ".implode(", ", $this->bannedIPs->getAll(true))."\n";
break; break;
default: default:
$output .= "Usage: /banip <add | remove | list | reload> [IP | Player]\n"; $output .= "Usage: /banip <add|remove|list|reload> [IP|player]\n";
break; break;
} }
break; break;
@ -270,7 +269,7 @@ class BanAPI{
$output .= "Ban list: ".implode(", ", $this->banned->getAll(true))."\n"; $output .= "Ban list: ".implode(", ", $this->banned->getAll(true))."\n";
break; break;
default: default:
$output .= "Usage: /ban <add | remove | list | reload> [player]\n"; $output .= "Usage: /ban <add|remove|list|reload> [username]\n";
break; break;
} }
break; break;

View File

@ -118,7 +118,7 @@ class BlockAPI{
public function init(){ public function init(){
$this->server->addHandler("block.update", array($this, "updateBlockRemote"), 1); $this->server->addHandler("block.update", array($this, "updateBlockRemote"), 1);
$this->server->api->console->register("give", "Give items to a player", array($this, "commandHandler")); $this->server->api->console->register("give", "<player> <item[:damage]> [amount]", array($this, "commandHandler"));
} }
public function commandHandler($cmd, $params, $issuer, $alias){ public function commandHandler($cmd, $params, $issuer, $alias){
@ -126,7 +126,7 @@ class BlockAPI{
switch($cmd){ switch($cmd){
case "give": case "give":
if(!isset($params[0]) or !isset($params[1])){ if(!isset($params[0]) or !isset($params[1])){
$output .= "Usage: /give <username> <item> [amount] [damage]\n"; $output .= "Usage: /give <player> <item[:damage]> [amount]\n";
break; break;
} }
$player = $this->server->api->player->get($params[0]); $player = $this->server->api->player->get($params[0]);

View File

@ -32,8 +32,8 @@ class ChatAPI{
} }
public function init(){ public function init(){
$this->server->api->console->register("tell", "Sends a private message to a player", array($this, "commandHandler")); $this->server->api->console->register("tell", "<player> <private message ...>", array($this, "commandHandler"));
$this->server->api->console->register("me", "Broadcast an action", array($this, "commandHandler")); $this->server->api->console->register("me", "<action ...>", array($this, "commandHandler"));
$this->server->api->ban->cmdWhitelist("tell"); $this->server->api->ban->cmdWhitelist("tell");
$this->server->api->ban->cmdWhitelist("me"); $this->server->api->ban->cmdWhitelist("me");
} }
@ -85,7 +85,7 @@ class ChatAPI{
public function broadcast($message){ public function broadcast($message){
$this->send(false, $message); $this->send(false, $message);
console("[CHAT] ".$message); console($message);
} }
public function sendTo($owner, $text, $player){ public function sendTo($owner, $text, $player){

View File

@ -39,13 +39,13 @@ class ConsoleAPI{
$this->event = $this->server->event("server.tick", array($this, "handle")); $this->event = $this->server->event("server.tick", array($this, "handle"));
$this->loop = new ConsoleLoop; $this->loop = new ConsoleLoop;
$this->loop->start(); $this->loop->start();
$this->register("help", "Show available commands", array($this, "defaultCommands")); $this->register("help", "[page|command name]", array($this, "defaultCommands"));
$this->register("status", "Show server TPS and memory usage", array($this, "defaultCommands")); $this->register("status", "", array($this, "defaultCommands"));
$this->register("difficulty", "Changes server difficulty", array($this, "defaultCommands")); $this->register("difficulty", "<0|1>", array($this, "defaultCommands"));
$this->register("invisible", "Changes server visibility", array($this, "defaultCommands")); $this->register("invisible", "<on|off>", array($this, "defaultCommands"));
$this->register("say", "Broadcast a message", array($this, "defaultCommands")); $this->register("say", "<message ...>", array($this, "defaultCommands"));
$this->register("save-all", "Save pending changes to disk", array($this, "defaultCommands")); $this->register("save-all", "", array($this, "defaultCommands"));
$this->register("stop", "Stops the server gracefully", array($this, "defaultCommands")); $this->register("stop", "", array($this, "defaultCommands"));
$this->server->api->ban->cmdWhitelist("help"); $this->server->api->ban->cmdWhitelist("help");
} }
@ -120,6 +120,13 @@ class ConsoleAPI{
break; break;
} }
case "help": case "help":
if(isset($params[0]) and !is_numeric($params[0])){
$c = trim(strtolower($params[0]));
if(isset($this->help[$c])){
$output .= "Usage: /$c ".$this->help[$c]."\n";
break;
}
}
$max = ceil(count($this->help) / 5); $max = ceil(count($this->help) / 5);
$page = isset($params[0]) ? min($max - 1, max(0, intval($params[0]) - 1)):0; $page = isset($params[0]) ? min($max - 1, max(0, intval($params[0]) - 1)):0;
$output .= "- Showing help page ". ($page + 1) ." of $max (/help <page>) -\n"; $output .= "- Showing help page ". ($page + 1) ." of $max (/help <page>) -\n";
@ -127,7 +134,7 @@ class ConsoleAPI{
foreach($this->help as $c => $h){ foreach($this->help as $c => $h){
$curpage = (int) ($current / 5); $curpage = (int) ($current / 5);
if($curpage === $page){ if($curpage === $page){
$output .= "/$c: ".$h."\n"; $output .= "/$c ".$h."\n";
}elseif($curpage > $page){ }elseif($curpage > $page){
break; break;
} }
@ -167,7 +174,7 @@ class ConsoleAPI{
if($issuer instanceof Player){ if($issuer instanceof Player){
console("[INFO] \"".$issuer->username."\" issued server command: $alias /$cmd ".implode(" ", $params)); console("[INFO] \"".$issuer->username."\" issued server command: $alias /$cmd ".implode(" ", $params));
}else{ }else{
console("[INFO] Issued server command: $alias /$cmd ".implode(" ", $params)); console("[INFO] Issued server command: ".ltrim("$alias ")."/$cmd ".implode(" ", $params));
} }
if($this->server->api->dhandle("console.command.".$cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias)) === false if($this->server->api->dhandle("console.command.".$cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias)) === false
or $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias)) === false){ or $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias)) === false){

View File

@ -34,12 +34,12 @@ class PlayerAPI{
public function init(){ public function init(){
$this->server->addHandler("server.regeneration", array($this, "handle")); $this->server->addHandler("server.regeneration", array($this, "handle"));
$this->server->addHandler("player.death", array($this, "handle"), 1); $this->server->addHandler("player.death", array($this, "handle"), 1);
$this->server->api->console->register("list", "Shows connected player list", array($this, "commandHandler")); $this->server->api->console->register("list", "", array($this, "commandHandler"));
$this->server->api->console->register("kill", "Kills a player", array($this, "commandHandler")); $this->server->api->console->register("kill", "<player>", array($this, "commandHandler"));
$this->server->api->console->register("gamemode", "Changes the player gamemode", array($this, "commandHandler")); $this->server->api->console->register("gamemode", "<mode> [player]", array($this, "commandHandler"));
$this->server->api->console->register("tppos", "Teleports a player to a position", array($this, "commandHandler")); $this->server->api->console->register("tppos", "[target player] <x> <y> <z>", array($this, "commandHandler"));
$this->server->api->console->register("tp", "Teleports a player to another player", array($this, "commandHandler")); $this->server->api->console->register("tp", "[target player] <destination player>", array($this, "commandHandler"));
$this->server->api->console->register("lag", "Measure your connection lag", array($this, "commandHandler")); $this->server->api->console->register("lag", "", array($this, "commandHandler"));
$this->server->api->console->alias("suicide", "kill"); $this->server->api->console->alias("suicide", "kill");
$this->server->api->ban->cmdWhitelist("list"); $this->server->api->ban->cmdWhitelist("list");
$this->server->api->ban->cmdWhitelist("lag"); $this->server->api->ban->cmdWhitelist("lag");

View File

@ -58,7 +58,7 @@ class PluginAPI extends stdClass{
$info = strstr($content, "*/", true); $info = strstr($content, "*/", true);
$content = substr(strstr($content, "*/"),2); $content = substr(strstr($content, "*/"),2);
if(preg_match_all('#([a-zA-Z0-9\-_]*)=([^\r\n]*)#u', $info, $matches) == 0){ //false or 0 matches if(preg_match_all('#([a-zA-Z0-9\-_]*)=([^\r\n]*)#u', $info, $matches) == 0){ //false or 0 matches
console("[ERROR] [PluginAPI] Failed parsing of ".basename($file)); console("[ERROR] Failed parsing of ".basename($file));
return false; return false;
} }
$info = array(); $info = array();
@ -82,28 +82,28 @@ class PluginAPI extends stdClass{
$info["class"] = trim(strtolower($info["class"])); $info["class"] = trim(strtolower($info["class"]));
} }
if(!isset($info["name"]) or !isset($info["version"]) or !isset($info["class"]) or !isset($info["author"])){ if(!isset($info["name"]) or !isset($info["version"]) or !isset($info["class"]) or !isset($info["author"])){
console("[ERROR] [PluginAPI] Failed parsing of ".basename($file)); console("[ERROR] Failed parsing of ".basename($file));
return false; return false;
} }
console("[INFO] [PluginAPI] Loading plugin \"\x1b[32m".$info["name"]."\x1b[0m\" \x1b[35m".$info["version"]." \x1b[0mby \x1b[36m".$info["author"]."\x1b[0m"); console("[INFO] Loading plugin \"\x1b[32m".$info["name"]."\x1b[0m\" \x1b[35m".$info["version"]." \x1b[0mby \x1b[36m".$info["author"]."\x1b[0m");
if(class_exists($info["class"])){ if(class_exists($info["class"])){
console("[ERROR] [PluginAPI] Failed loading plugin: class exists"); console("[ERROR] Failed loading plugin: class already exists");
return false; return false;
} }
if(eval($info["code"]) === false or !class_exists($info["class"])){ if(eval($info["code"]) === false or !class_exists($info["class"])){
console("[ERROR] [PluginAPI] Failed loading plugin: evaluation error"); console("[ERROR] Failed loading plugin: evaluation error");
return false; return false;
} }
$className = $info["class"]; $className = $info["class"];
$apiversion = array_map("intval", explode(",", (string) $info["apiversion"])); $apiversion = array_map("intval", explode(",", (string) $info["apiversion"]));
if(!in_array((string) CURRENT_API_VERSION, $apiversion)){ if(!in_array((string) CURRENT_API_VERSION, $apiversion)){
console("[WARNING] [PluginAPI] Plugin \"".$info["name"]."\" may not be compatible with the API (".$info["apiversion"]." != ".CURRENT_API_VERSION.")! It can crash or corrupt the server!"); console("[WARNING] Plugin \"".$info["name"]."\" may not be compatible with the API (".$info["apiversion"]." != ".CURRENT_API_VERSION.")! It can crash or corrupt the server!");
} }
$object = new $className($this->server->api, false); $object = new $className($this->server->api, false);
if(!($object instanceof Plugin)){ if(!($object instanceof Plugin)){
console("[ERROR] [PluginAPI] Plugin \"\x1b[36m".$info["name"]."\x1b[0m\" doesn't use the Plugin Interface"); console("[ERROR] Plugin \"\x1b[36m".$info["name"]."\x1b[0m\" doesn't use the Plugin Interface");
if(method_exists($object, "__destruct")){ if(method_exists($object, "__destruct")){
$object->__destruct(); $object->__destruct();
} }
@ -172,7 +172,6 @@ class PluginAPI extends stdClass{
} }
public function loadAll(){ public function loadAll(){
console("[INFO] Loading Plugins...");
$dir = dir(DATA_PATH."plugins/"); $dir = dir(DATA_PATH."plugins/");
while(false !== ($file = $dir->read())){ while(false !== ($file = $dir->read())){
if($file{0} !== "."){ if($file{0} !== "."){
@ -185,6 +184,7 @@ class PluginAPI extends stdClass{
} }
public function initAll(){ public function initAll(){
console("[INFO] Starting plugins...");
foreach($this->plugins as $p){ foreach($this->plugins as $p){
$p[0]->init(); //ARGHHH!!! Plugin loading randomly fails!! $p[0]->init(); //ARGHHH!!! Plugin loading randomly fails!!
} }

View File

@ -52,8 +52,7 @@ class ServerAPI{
@mkdir(DATA_PATH."players/", 0755); @mkdir(DATA_PATH."players/", 0755);
@mkdir(DATA_PATH."worlds/", 0755); @mkdir(DATA_PATH."worlds/", 0755);
@mkdir(DATA_PATH."plugins/", 0755); @mkdir(DATA_PATH."plugins/", 0755);
console("[INFO] Starting ServerAPI server handler..."); console("[INFO] \x1b[33;1mPocketMine-MP ".MAJOR_VERSION.", LGPL License", true, true, 0);
file_put_contents(DATA_PATH."logs/packets.log", "");
if(!file_exists(DATA_PATH."logs/test.bin.log") or md5_file(DATA_PATH."logs/test.bin.log") !== TEST_MD5){ if(!file_exists(DATA_PATH."logs/test.bin.log") or md5_file(DATA_PATH."logs/test.bin.log") !== TEST_MD5){
console("[NOTICE] Executing tests..."); console("[NOTICE] Executing tests...");
console("[INFO] OS: ".PHP_OS.", ".Utils::getOS()); console("[INFO] OS: ".PHP_OS.", ".Utils::getOS());
@ -89,7 +88,7 @@ class ServerAPI{
} }
} }
console("[DEBUG] Loading server.properties...", true, true, 2); console("[INFO] Loading properties...");
$this->config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES, array( $this->config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES, array(
"server-name" => "Minecraft Server", "server-name" => "Minecraft Server",
"description" => "Server made using PocketMine-MP", "description" => "Server made using PocketMine-MP",
@ -213,8 +212,6 @@ class ServerAPI{
$this->loadProperties(); $this->loadProperties();
$this->server->loadMap(); $this->server->loadMap();
console("[INFO] Loading default APIs");
$this->loadAPI("console", "ConsoleAPI"); $this->loadAPI("console", "ConsoleAPI");
$this->loadAPI("level", "LevelAPI"); $this->loadAPI("level", "LevelAPI");
$this->loadAPI("block", "BlockAPI"); $this->loadAPI("block", "BlockAPI");
@ -254,7 +251,7 @@ class ServerAPI{
} }
public function sendUsage(){ public function sendUsage(){
console("[INTERNAL] Sending usage data...", true, true, 3); console("[DEBUG] Sending usage data...", true, true, 2);
$plist = ""; $plist = "";
foreach($this->plugin->getList() as $p){ foreach($this->plugin->getList() as $p){
$plist .= str_replace(array(";", ":"), "", $p["name"]).":".str_replace(array(";", ":"), "", $p["version"]).";"; $plist .= str_replace(array(";", ":"), "", $p["name"]).":".str_replace(array(";", ":"), "", $p["version"]).";";
@ -289,7 +286,7 @@ class ServerAPI{
$value = array("M" => 1, "G" => 1024); $value = array("M" => 1, "G" => 1024);
$real = ((int) substr($memory, 0, -1)) * $value[substr($memory, -1)]; $real = ((int) substr($memory, 0, -1)) * $value[substr($memory, -1)];
if($real < 128){ if($real < 128){
console("[ERROR] PocketMine doesn't work right with less than 128MB of RAM", true, true, 0); console("[WARNING] PocketMine-MP doesn't work right with less than 128MB of RAM", true, true, 0);
} }
@ini_set("memory_limit", $memory); @ini_set("memory_limit", $memory);
}else{ }else{
@ -398,7 +395,7 @@ class ServerAPI{
if($level["LevelName"] == ""){ if($level["LevelName"] == ""){
$level["LevelName"] = "world".time(); $level["LevelName"] = "world".time();
} }
console("[DEBUG] Importing map \"".$level["LevelName"]."\" gamemode ".$level["GameType"]." with seed ".$level["RandomSeed"], true, true, 2); console("[DEBUG] Importing level \"".$level["LevelName"]."\" gamemode ".$level["GameType"]." with seed ".$level["RandomSeed"], true, true, 2);
unset($level["Player"]); unset($level["Player"]);
$lvName = $level["LevelName"]."/"; $lvName = $level["LevelName"]."/";
@mkdir(DATA_PATH."worlds/".$lvName, 0755); @mkdir(DATA_PATH."worlds/".$lvName, 0755);
@ -428,7 +425,7 @@ class ServerAPI{
$this->server->spawn = array("x" => $level["SpawnX"], "y" => $level["SpawnY"], "z" => $level["SpawnZ"]); $this->server->spawn = array("x" => $level["SpawnX"], "y" => $level["SpawnY"], "z" => $level["SpawnZ"]);
$this->writeProperties(); $this->writeProperties();
} }
console("[INFO] Map \"".$level["LevelName"]."\" importing done!"); console("[INFO] Level \"".$level["LevelName"]."\" importing done!");
unset($level, $entities, $nbt); unset($level, $entities, $nbt);
return true; return true;
} }
@ -510,7 +507,7 @@ class ServerAPI{
} }
$this->$name = new $class(); $this->$name = new $class();
$this->apiList[] = $this->$name; $this->apiList[] = $this->$name;
console("[".($internal === true ? "DEBUG":"INFO")."] API \x1b[36m".$name."\x1b[0m [\x1b[30;1m".$class."\x1b[0m] loaded", true, true, ($internal === true ? 2:1)); console("[".($internal === true ? "INTERNAL":"DEBUG")."] API \x1b[36m".$name."\x1b[0m [\x1b[30;1m".$class."\x1b[0m] loaded", true, true, ($internal === true ? 2:1));
} }
} }

View File

@ -38,7 +38,7 @@ class TimeAPI{
} }
public function init(){ public function init(){
$this->server->api->console->register("time", "Manages server time", array($this, "commandHandler")); $this->server->api->console->register("time", "<check|set|add> [time]", array($this, "commandHandler"));
} }
public function commandHandler($cmd, $params, $issuer, $alias){ public function commandHandler($cmd, $params, $issuer, $alias){
@ -69,7 +69,7 @@ class TimeAPI{
$this->night(); $this->night();
break; break;
default: default:
$output .= "Usage: /time <check | set | add | sunrise | day | sunset | night> [time]\n"; $output .= "Usage: /time <check|set|add> [time]\n";
break; break;
} }
break; break;

View File

@ -766,7 +766,7 @@ class Player{
$this->server->api->entity->spawnToAll($this->eid); $this->server->api->entity->spawnToAll($this->eid);
$this->server->schedule(5, array($this->entity, "update"), array(), true); $this->server->schedule(5, array($this->entity, "update"), array(), true);
$this->server->api->dhandle("player.armor", array("eid" => $this->eid, "slot0" => ($this->armor[0][0] > 0 ? ($this->armor[0][0] - 256):AIR), "slot1" => ($this->armor[1][0] > 0 ? ($this->armor[1][0] - 256):AIR), "slot2" => ($this->armor[2][0] > 0 ? ($this->armor[2][0] - 256):AIR), "slot3" => ($this->armor[3][0] > 0 ? ($this->armor[3][0] - 256):AIR))); $this->server->api->dhandle("player.armor", array("eid" => $this->eid, "slot0" => ($this->armor[0][0] > 0 ? ($this->armor[0][0] - 256):AIR), "slot1" => ($this->armor[1][0] > 0 ? ($this->armor[1][0] - 256):AIR), "slot2" => ($this->armor[2][0] > 0 ? ($this->armor[2][0] - 256):AIR), "slot3" => ($this->armor[3][0] > 0 ? ($this->armor[3][0] - 256):AIR)));
console("[INFO] \x1b[33m".$this->username."\x1b[0m logged in with entity id ".$this->eid." at (".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 (".round($this->entity->x, 2).", ".round($this->entity->y, 2).", ".round($this->entity->z, 2).")");
$this->eventHandler(new Container($this->server->motd), "server.chat"); $this->eventHandler(new Container($this->server->motd), "server.chat");
if($this->MTU <= 548){ if($this->MTU <= 548){
$this->eventHandler("Your connection is bad, you may experience lag and slow map loading.", "server.chat"); $this->eventHandler("Your connection is bad, you may experience lag and slow map loading.", "server.chat");

View File

@ -33,18 +33,15 @@ class PocketMinecraftServer{
private function load(){ private function load(){
$this->version = new VersionString(); $this->version = new VersionString();
@cli_set_process_title("PocketMine-MP ".MAJOR_VERSION); @cli_set_process_title("PocketMine-MP ".MAJOR_VERSION);
console("[INFO] \x1b[33;1mPocketMine-MP ".MAJOR_VERSION." #".$this->version->getNumber()." by @shoghicp, LGPL License", true, true, 0);
console("[INFO] Target Minecraft PE: \x1b[36;1m".CURRENT_MINECRAFT_VERSION."\x1b[0m, protocol #".CURRENT_PROTOCOL, true, true, 0);
if($this->version->isDev()){ if($this->version->isDev()){
console("[INFO] \x1b[31;1mThis is a Development version"); console("[INFO] \x1b[31;1mThis is a Development version");
} }
console("[INFO] Starting Minecraft PE Server at ".$this->serverip.":".$this->port); console("[INFO] Starting \x1b[36;1m".CURRENT_MINECRAFT_VERSION."\x1b[0m #".CURRENT_PROTOCOL." Minecraft PE Server at ".$this->serverip.":".$this->port);
if($this->port < 19132 or $this->port > 19135){ //Mojang =( if($this->port < 19132 or $this->port > 19135){ //Mojang =(
console("[WARNING] You've selected a not-standard port. Normal port range is from 19132 to 19135 included"); console("[WARNING] You've selected a not-standard port. Normal port range is from 19132 to 19135 included");
} }
$this->serverID = $this->serverID === false ? Utils::readLong(Utils::getRandomBytes(8, false)):$this->serverID; $this->serverID = $this->serverID === false ? Utils::readLong(Utils::getRandomBytes(8, false)):$this->serverID;
$this->seed = $this->seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):$this->seed; $this->seed = $this->seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):$this->seed;
console("[INFO] Loading database...");
$this->startDatabase(); $this->startDatabase();
$this->api = false; $this->api = false;
$this->tCnt = 1; $this->tCnt = 1;
@ -76,8 +73,6 @@ class PocketMinecraftServer{
$this->setType("normal"); $this->setType("normal");
$this->interface = new MinecraftInterface("255.255.255.255", $this->port, true, false); $this->interface = new MinecraftInterface("255.255.255.255", $this->port, true, false);
$this->reloadConfig(); $this->reloadConfig();
console("[INFO] Server Name: \x1b[36m".$this->name."\x1b[0m");
console("[DEBUG] Server ID: ".$this->serverID, true, true, 2);
$this->stop = false; $this->stop = false;
} }
@ -223,7 +218,6 @@ class PocketMinecraftServer{
$handlers = $this->preparedSQL->selectHandlers->execute(); $handlers = $this->preparedSQL->selectHandlers->execute();
$result = null; $result = null;
if($handlers !== false and $handlers !== true){ if($handlers !== false and $handlers !== true){
console("[INTERNAL] Handling ".$event, true, true, 3);
$call = array(); $call = array();
while(($hn = $handlers->fetchArray(SQLITE3_ASSOC)) !== false){ while(($hn = $handlers->fetchArray(SQLITE3_ASSOC)) !== false){
$call[(int) $hn["ID"]] = true; $call[(int) $hn["ID"]] = true;
@ -270,7 +264,6 @@ class PocketMinecraftServer{
console("[ERROR] Invalid world data for \"".$this->mapDir."\. Please import the world correctly"); console("[ERROR] Invalid world data for \"".$this->mapDir."\. Please import the world correctly");
$this->close("invalid world data"); $this->close("invalid world data");
} }
console("[INFO] Map: ".$this->levelData["LevelName"]);
$this->time = (int) $this->levelData["Time"]; $this->time = (int) $this->levelData["Time"];
$this->seed = (int) $this->levelData["RandomSeed"]; $this->seed = (int) $this->levelData["RandomSeed"];
if(isset($this->levelData["SpawnX"])){ if(isset($this->levelData["SpawnX"])){
@ -281,13 +274,7 @@ class PocketMinecraftServer{
$this->levelData["SpawnZ"] = $this->spawn["z"]; $this->levelData["SpawnZ"] = $this->spawn["z"];
} }
$this->levelData["Time"] = $this->time; $this->levelData["Time"] = $this->time;
console("[INFO] Spawn: X \x1b[36m".$this->levelData["SpawnX"]."\x1b[0m Y \x1b[36m".$this->levelData["SpawnY"]."\x1b[0m Z \x1b[36m".$this->levelData["SpawnZ"]."\x1b[0m"); console("[INFO] Preparing level \"".$this->levelData["LevelName"]."\"");
console("[INFO] Time: \x1b[36m".$this->time."\x1b[0m");
console("[INFO] Seed: \x1b[36m".$this->seed."\x1b[0m");
console("[INFO] Gamemode: \x1b[36m".$this->getGamemode()."\x1b[0m");
$d = array(0 => "peaceful", 1 => "easy", 2 => "normal", 3 => "hard");
console("[INFO] Difficulty: \x1b[36m".$d[$this->difficulty]."\x1b[0m");
console("[INFO] Loading map...");
$this->map = new ChunkParser(); $this->map = new ChunkParser();
if(!$this->map->loadFile($this->mapDir."chunks.dat")){ if(!$this->map->loadFile($this->mapDir."chunks.dat")){
console("[ERROR] Couldn't load the map \"\x1b[32m".$this->levelData["LevelName"]."\x1b[0m\"!", true, true, 0); console("[ERROR] Couldn't load the map \"\x1b[32m".$this->levelData["LevelName"]."\x1b[0m\"!", true, true, 0);
@ -295,10 +282,6 @@ class PocketMinecraftServer{
}else{ }else{
$this->map->loadMap(); $this->map->loadMap();
} }
}else{
console("[INFO] Time: \x1b[36m".$this->time."\x1b[0m");
console("[INFO] Seed: \x1b[36m".$this->seed."\x1b[0m");
console("[INFO] Gamemode: \x1b[36m".$this->getGamemode()."\x1b[0m");
} }
} }
@ -315,7 +298,6 @@ class PocketMinecraftServer{
public function loadEntities(){ public function loadEntities(){
if($this->map !== false){ if($this->map !== false){
console("[INFO] Loading entities...");
$entities = unserialize(file_get_contents($this->mapDir."entities.dat")); $entities = unserialize(file_get_contents($this->mapDir."entities.dat"));
if($entities === false or !is_array($entities)){ if($entities === false or !is_array($entities)){
console("[ERROR] Invalid world data for \"".$this->mapDir."\. Please import the world correctly"); console("[ERROR] Invalid world data for \"".$this->mapDir."\. Please import the world correctly");
@ -364,7 +346,6 @@ class PocketMinecraftServer{
file_put_contents($this->mapDir."level.dat", serialize($this->levelData)); file_put_contents($this->mapDir."level.dat", serialize($this->levelData));
$this->map->saveMap($final); $this->map->saveMap($final);
$this->trigger("server.save", $final); $this->trigger("server.save", $final);
console("[INFO] Saving entities...");
if(count($this->entities) > 0){ if(count($this->entities) > 0){
$entities = array(); $entities = array();
foreach($this->entities as $entity){ foreach($this->entities as $entity){
@ -440,7 +421,6 @@ class PocketMinecraftServer{
$this->loadMap(); $this->loadMap();
$this->loadEntities(); $this->loadEntities();
} }
console("[INFO] Loading events...");
$this->loadEvents(); $this->loadEvents();
declare(ticks=40); declare(ticks=40);
register_tick_function(array($this, "tick")); register_tick_function(array($this, "tick"));
@ -451,8 +431,9 @@ class PocketMinecraftServer{
pcntl_signal(SIGINT, array($this, "close")); pcntl_signal(SIGINT, array($this, "close"));
pcntl_signal(SIGHUP, array($this, "close")); pcntl_signal(SIGHUP, array($this, "close"));
} }
console("[INFO] Default game type: ".strtoupper($this->getGamemode()));
$this->trigger("server.start", microtime(true)); $this->trigger("server.start", microtime(true));
console("[INFO] Server started!"); console('[INFO] Done ('.round(microtime(true) - START_TIME, 3).'s)! For help, type "help" or "?"');
$this->process(); $this->process();
} }
@ -627,7 +608,6 @@ class PocketMinecraftServer{
public function action($microseconds, $code, $repeat = true){ public function action($microseconds, $code, $repeat = true){
$this->query("INSERT INTO actions (interval, last, code, repeat) VALUES(".($microseconds / 1000000).", ".microtime(true).", '".base64_encode($code)."', ".($repeat === true ? 1:0).");"); $this->query("INSERT INTO actions (interval, last, code, repeat) VALUES(".($microseconds / 1000000).", ".microtime(true).", '".base64_encode($code)."', ".($repeat === true ? 1:0).");");
console("[INTERNAL] Attached to action ".$microseconds, true, true, 3);
} }
public function tickerFunction($time){ public function tickerFunction($time){

View File

@ -41,6 +41,7 @@ set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH);
ini_set("memory_limit", "256M"); //Default ini_set("memory_limit", "256M"); //Default
define("LOG", true); define("LOG", true);
define("START_TIME", microtime(true));
define("TEST_MD5", "1e0d28177b73dfd09f922502fe767bec"); define("TEST_MD5", "1e0d28177b73dfd09f922502fe767bec");
define("MAJOR_VERSION", "Alpha_1.3dev"); define("MAJOR_VERSION", "Alpha_1.3dev");
define("CURRENT_STRUCTURE", 5); define("CURRENT_STRUCTURE", 5);