Exemplo n.º 1
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();
 }