From c8a0315c526ce735099c59167ea98c0c75e00dda Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Wed, 26 Dec 2012 20:25:39 +0100 Subject: [PATCH] Update channels! --- README.md | 1 + TODO.md | 1 - classes/API/ServerAPI.php | 53 ++++++++++++++++++++++++++++----------- common/config.php | 2 +- common/default.properties | 1 + 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index f59e40402..eaf062d4e 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Current features of the server: * Full Creative mode! * Plugin API * Custom world generation +* Update Channels!! (stable / dev) How to contact me diff --git a/TODO.md b/TODO.md index a2cd45166..821e2eaf6 100644 --- a/TODO.md +++ b/TODO.md @@ -17,7 +17,6 @@ __Check Milestones [here](https://github.com/shoghicp/PocketMine-MP/issues/miles ### Alpha v1.1 - ## Beta (Survival) - Random Chunk Updates - Mob spawning, item pick up diff --git a/classes/API/ServerAPI.php b/classes/API/ServerAPI.php index 91942f7e8..725d2e11a 100644 --- a/classes/API/ServerAPI.php +++ b/classes/API/ServerAPI.php @@ -95,22 +95,47 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){ console("[INFO] Checking for new server version"); console("[INFO] Last check: ".date("Y-m-d H:i:s", $this->getProperty("last-update"))); - $info = json_decode(Utils::curl_get("https://api.github.com/repos/shoghicp/PocketMine-MP"), true); - if($info === false or !isset($info["updated_at"])){ - console("[ERROR] GitHub API Error"); - }else{ - $last = new DateTime($info["updated_at"]); - $last = $last->getTimestamp(); - if($last >= $this->getProperty("last-update") and $this->getProperty("last-update") !== false){ - console("[NOTICE] PocketMine-MP 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/PocketMine-MP/archive/master.zip"); - console("[NOTICE] This message will dissapear when you issue the command \"/update-done\""); - sleep(3); + $channel = "stable"; + if($this->getProperty("update-channel") == "dev" or $this->getProperty("update-channel") == "development"){ + $channel = "dev"; + } + + if($channel === "dev"){ + $info = json_decode(Utils::curl_get("https://api.github.com/repos/shoghicp/PocketMine-MP"), true); + if($info === false or !isset($info["updated_at"])){ + console("[ERROR] GitHub API Error"); }else{ - $last = time(); - $this->setProperty("last-update", $last); - console("[INFO] This is the latest version"); + $last = new DateTime($info["updated_at"]); + $last = $last->getTimestamp(); + if($last >= $this->getProperty("last-update") and $this->getProperty("last-update") !== false){ + console("[NOTICE] A new DEVELOPMENT version of PocketMine-MP has been released"); + console("[NOTICE] If you want to update, get the latest version at https://github.com/shoghicp/PocketMine-MP/archive/master.zip"); + console("[NOTICE] This message will dissapear when you issue the command \"/update-done\""); + sleep(3); + }else{ + $this->setProperty("last-update", time()); + console("[INFO] This is the latest DEVELOPMENT version"); + } } + }else{ + $info = json_decode(Utils::curl_get("https://api.github.com/repos/shoghicp/PocketMine-MP/tags"), true); + if($info === false or !isset($info[0])){ + console("[ERROR] GitHub API Error"); + }else{ + $info = $info[0]; + var_dump($info); + if($info["name"] != MAJOR_VERSION){ + console("[NOTICE] A new STABLE version of PocketMine-MP has been released"); + console("[NOTICE] Version \"".$info["name"]."\" [".substr($info["commit"]["sha"], 0, 10)."]"); + console("[NOTICE] Download it at ".$info["zipball_url"]); + console("[NOTICE] This message will dissapear as soon as you update\""); + sleep(5); + }else{ + $this->setProperty("last-update", time()); + console("[INFO] This is the latest STABLE version"); + } + } + } } if(file_exists(FILE_PATH."data/maps/level.dat")){ diff --git a/common/config.php b/common/config.php index 1d8cadf88..94fa54e27 100644 --- a/common/config.php +++ b/common/config.php @@ -40,4 +40,4 @@ define("CURRENT_VERSION", 1); define("LOG", true); define("MAGIC", "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78"); define("TEST_MD5", "5ca8eced50a5801619f7ae86d631a4e7"); -define("MAJOR_VERSION", "Alpha v1.0"); \ No newline at end of file +define("MAJOR_VERSION", "Alpha_1.0"); \ No newline at end of file diff --git a/common/default.properties b/common/default.properties index 9eadc7176..d37eef6e5 100644 --- a/common/default.properties +++ b/common/default.properties @@ -6,6 +6,7 @@ invisible=false port=19132 memory-limit=512M last-update=false +update-channel=stable white-list=false debug=2 max-players=20