Ejemplo n.º 1
0
 public function compare($target, $diff = false)
 {
     if ($target instanceof VersionString === false) {
         $target = new VersionString($target);
     }
     $number = $this->getNumber();
     $tNumber = $target->getNumber();
     if ($diff === true) {
         return $tNumber - $number;
     }
     if ($number > $tNumber) {
         return -1;
         //Target is older
     } elseif ($number < $tNumber) {
         return 1;
         //Target is newer
     } elseif ($target->getBuild() > $this->getBuild()) {
         return 1;
     } elseif ($target->getBuild() < $this->getBuild()) {
         return -1;
     } else {
         return 0;
         //Same version
     }
 }
 public function dumpError()
 {
     if ($this->stop === true) {
         return;
     }
     console("[SEVERE] An unrecovereable has ocurred and the server has crashed. Creating an error dump");
     $dump = "```\r\n# PocketMine-MP Error Dump " . date("D M j H:i:s T Y") . "\r\n";
     $er = error_get_last();
     $errorConversion = array(E_ERROR => "E_ERROR", E_WARNING => "E_WARNING", E_PARSE => "E_PARSE", E_NOTICE => "E_NOTICE", E_CORE_ERROR => "E_CORE_ERROR", E_CORE_WARNING => "E_CORE_WARNING", E_COMPILE_ERROR => "E_COMPILE_ERROR", E_COMPILE_WARNING => "E_COMPILE_WARNING", E_USER_ERROR => "E_USER_ERROR", E_USER_WARNING => "E_USER_WARNING", E_USER_NOTICE => "E_USER_NOTICE", E_STRICT => "E_STRICT", E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", E_DEPRECATED => "E_DEPRECATED", E_USER_DEPRECATED => "E_USER_DEPRECATED");
     $er["type"] = isset($errorConversion[$er["type"]]) ? $errorConversion[$er["type"]] : $er["type"];
     $dump .= "Error: " . var_export($er, true) . "\r\n\r\n";
     if (stripos($er["file"], "plugin") !== false) {
         $dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n";
     }
     $dump .= "Code: \r\n";
     $file = @file($er["file"], FILE_IGNORE_NEW_LINES);
     for ($l = max(0, $er["line"] - 10); $l < $er["line"] + 10; ++$l) {
         $dump .= "[" . ($l + 1) . "] " . @$file[$l] . "\r\n";
     }
     $dump .= "\r\n\r\n";
     $version = new VersionString();
     $dump .= "PocketMine-MP version: " . $version . " #" . $version->getNumber() . " [Protocol " . ProtocolInfo::CURRENT_PROTOCOL . "; API " . CURRENT_API_VERSION . "]\r\n";
     $dump .= "Git commit: " . GIT_COMMIT . "\r\n";
     $dump .= "Source SHA1 sum: " . SOURCE_SHA1SUM . "\r\n";
     $dump .= "uname -a: " . php_uname("a") . "\r\n";
     $dump .= "PHP Version: " . phpversion() . "\r\n";
     $dump .= "Zend version: " . zend_version() . "\r\n";
     $dump .= "OS : " . PHP_OS . ", " . Utils::getOS() . "\r\n";
     $dump .= "Debug Info: " . var_export($this->debugInfo(false), true) . "\r\n\r\n\r\n";
     global $arguments;
     $dump .= "Parameters: " . var_export($arguments, true) . "\r\n\r\n\r\n";
     $p = $this->api->getProperties();
     if ($p["rcon.password"] != "") {
         $p["rcon.password"] = "******";
     }
     $dump .= "server.properties: " . var_export($p, true) . "\r\n\r\n\r\n";
     if ($this->api->plugin instanceof PluginAPI) {
         $plist = $this->api->plugin->getList();
         $dump .= "Loaded plugins:\r\n";
         foreach ($plist as $p) {
             $dump .= $p["name"] . " " . $p["version"] . " by " . $p["author"] . "\r\n";
         }
         $dump .= "\r\n\r\n";
     }
     $extensions = array();
     foreach (get_loaded_extensions() as $ext) {
         $extensions[$ext] = phpversion($ext);
     }
     $dump .= "Loaded Modules: " . var_export($extensions, true) . "\r\n";
     $dump .= "Memory Usage Tracking: \r\n" . chunk_split(base64_encode(gzdeflate(implode(";", $this->memoryStats), 9))) . "\r\n";
     ob_start();
     phpinfo();
     $dump .= "\r\nphpinfo(): \r\n" . chunk_split(base64_encode(gzdeflate(ob_get_contents(), 9))) . "\r\n";
     ob_end_clean();
     $dump .= "\r\n```";
     $name = "Error_Dump_" . date("D_M_j-H.i.s-T_Y");
     logg($dump, $name, true, 0, true);
     console("[SEVERE] Please submit the \"{$name}.log\" file to the Bug Reporting page. Give as much info as you can.", true, true, 0);
 }
Ejemplo n.º 3
0
 public function load()
 {
     @mkdir(DATA_PATH . "players/", 0755);
     @mkdir(DATA_PATH . "worlds/", 0755);
     @mkdir(DATA_PATH . "plugins/", 0755);
     //Init all the events
     foreach (get_declared_classes() as $class) {
         if (is_subclass_of($class, "BaseEvent") and property_exists($class, "handlers") and property_exists($class, "handlerPriority")) {
             $class::unregisterAll();
         }
     }
     $version = new VersionString();
     console("[INFO] Starting Minecraft PE server version " . FORMAT_AQUA . CURRENT_MINECRAFT_VERSION);
     console("[INFO] Loading properties...");
     $this->config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES, array("server-name" => "Minecraft: PE Server", "description" => "Server made using PocketMine-MP", "motd" => "Welcome @player to this server!", "server-ip" => "", "server-port" => 19132, "server-type" => "normal", "memory-limit" => "128M", "last-update" => false, "white-list" => false, "announce-player-achievements" => true, "spawn-protection" => 16, "view-distance" => 10, "max-players" => 20, "allow-flight" => false, "spawn-animals" => true, "spawn-mobs" => true, "gamemode" => SURVIVAL, "hardcore" => false, "pvp" => true, "difficulty" => 1, "generator-settings" => "", "level-name" => "world", "level-seed" => "", "level-type" => "DEFAULT", "enable-query" => true, "enable-rcon" => false, "rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10), "send-usage" => true, "auto-save" => true));
     $this->parseProperties();
     //Load advanced properties
     define("DEBUG", $this->getProperty("debug", 1));
     define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false));
     define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 8));
     //Default rate ~512 kB/s
     if (ADVANCED_CACHE == true) {
         console("[INFO] Advanced cache enabled");
     }
     if ($this->getProperty("upnp-forwarding") == true) {
         console("[INFO] [UPnP] Trying to port forward...");
         UPnP_PortForward($this->getProperty("server-port"));
     }
     $this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed : false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip : "0.0.0.0");
     $this->server->api = $this;
     self::$serverRequest = $this->server;
     console("[INFO] This server is running PocketMine-MP version " . ($version->isDev() ? FORMAT_YELLOW : "") . MAJOR_VERSION . FORMAT_RESET . " \"" . CODENAME . "\" (MCPE: " . CURRENT_MINECRAFT_VERSION . ") (API " . CURRENT_API_VERSION . ")", true, true, 0);
     console("[INFO] PocketMine-MP is distributed under the LGPL License", true, true, 0);
     if ($this->getProperty("last-update") === false or $this->getProperty("last-update") + 3600 < time()) {
         console("[INFO] Checking for new server version");
         console("[INFO] Last check: " . FORMAT_AQUA . date("Y-m-d H:i:s", $this->getProperty("last-update")) . "");
         if ($this->server->version->isDev()) {
             $info = json_decode(Utils::curl_get("https://api.github.com/repos/PocketMine/PocketMine-MP/commits"), true);
             if ($info === false or !isset($info[0])) {
                 console("[ERROR] Github API error");
             } else {
                 $last = new DateTime($info[0]["commit"]["committer"]["date"]);
                 $last = $last->getTimestamp();
                 if ($last >= $this->getProperty("last-update") and $this->getProperty("last-update") !== false and GIT_COMMIT != $info[0]["sha"]) {
                     console("[NOTICE] " . FORMAT_YELLOW . "A new DEVELOPMENT version of PocketMine-MP has been released!");
                     console("[NOTICE] " . FORMAT_YELLOW . "Commit \"" . $info[0]["commit"]["message"] . "\" [" . substr($info[0]["sha"], 0, 10) . "] by " . $info[0]["commit"]["committer"]["name"]);
                     console("[NOTICE] " . FORMAT_YELLOW . "Get it at PocketMine.net or at https://github.com/PocketMine/PocketMine-MP/archive/" . $info[0]["sha"] . ".zip");
                     console("[NOTICE] This message will dissapear after issuing the command \"/update-done\"");
                 } else {
                     $this->setProperty("last-update", time());
                     console("[INFO] " . FORMAT_AQUA . "This is the latest DEVELOPMENT version");
                 }
             }
         } else {
             $info = json_decode(Utils::curl_get("https://api.github.com/repos/PocketMine/PocketMine-MP/tags"), true);
             if ($info === false or !isset($info[0])) {
                 console("[ERROR] Github API error");
             } else {
                 $newest = new VersionString(MAJOR_VERSION);
                 $newestN = $newest->getNumber();
                 $update = new VersionString($info[0]["name"]);
                 $updateN = $update->getNumber();
                 if ($updateN > $newestN) {
                     console("[NOTICE] " . FORMAT_GREEN . "A new STABLE version of PocketMine-MP has been released!");
                     console("[NOTICE] " . FORMAT_GREEN . "Version \"" . $info[0]["name"] . "\" #" . $updateN);
                     console("[NOTICE] Get it at PocketMine.net or at " . $info[0]["zipball_url"]);
                     console("[NOTICE] This message will dissapear as soon as you update");
                 } else {
                     $this->setProperty("last-update", time());
                     console("[INFO] " . FORMAT_AQUA . "This is the latest STABLE version");
                 }
             }
         }
     }
     $this->loadProperties();
     $this->loadAPI("console", "ConsoleAPI");
     $this->loadAPI("level", "LevelAPI");
     $this->loadAPI("block", "BlockAPI");
     $this->loadAPI("chat", "ChatAPI");
     $this->loadAPI("ban", "BanAPI");
     $this->loadAPI("entity", "EntityAPI");
     $this->loadAPI("tile", "TileAPI");
     $this->loadAPI("player", "PlayerAPI");
     $this->loadAPI("time", "TimeAPI");
     foreach ($this->apiList as $ob) {
         if (is_callable(array($ob, "init"))) {
             $ob->init();
             //Fails sometimes!!!
         }
     }
     $this->loadAPI("plugin", "PluginAPI");
     //fix :(
     $this->plugin->init();
 }