Automatic updates!

This commit is contained in:
Shoghi Cervantes Pueyo 2012-12-11 20:24:32 +01:00
parent ba4d337a73
commit 7b17819ca4
3 changed files with 27 additions and 0 deletions

View File

@ -48,6 +48,9 @@ class ConsoleAPI{
$cmd = strtolower(array_shift($params));
console("[INFO] Issued server command: /$cmd ".implode(" ", $params));
switch($cmd){
case "update-done":
$this->server->api->setProperty("last-update", time());
break;
case "stop":
console("[INFO] Stopping server...");
$this->server->close();

View File

@ -57,6 +57,22 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
define("DEBUG", $this->config["debug"]);
$this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), $this->getProperty("seed"), $this->getProperty("protocol"), $this->getProperty("port"), $this->getProperty("server-id"));
$this->server->api = $this;
if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){
console("[INFO] Checking for new version...");
$info = json_decode(Utils::curl_get("https://api.github.com/repos/shoghicp/Pocket-Minecraft-PHP"), true);
$last = date_parse($info["updated_at"]);
$last = mktime($last["hour"], $last["minute"], $last["second"], $last["month"], $last["day"], $last["year"]);
if($last >= $this->getProperty("last-update") and $this->getProperty("last-update") !== false){
console("[NOTICE] Pocket-PHP-Minecraft has been updated at ".date("Y-m-d H:i:s", $last));
console("[NOTICE] If you want to update, download 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\"");
sleep(5);
}else{
$last = time();
$this->setProperty("last-update", $last);
console("[INFO] Last check at ".date("Y-m-d H:i:s", $last));
}
}
if(file_exists(FILE_PATH."data/maps/level.dat")){
console("[NOTICE] Detected unimported map data. Importing...");
$this->importMap(FILE_PATH."data/maps/", true);
@ -193,6 +209,13 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
$n = strtolower(array_shift($d));
$v = implode("=", $d);
switch($n){
case "last-update":
if(trim($v) == "false"){
$v = time();
}else{
$v = (int) $v;
}
break;
case "protocol":
if(trim($v) == "CURRENT"){
$v = CURRENT_PROTOCOL;

View File

@ -4,6 +4,7 @@ description= This is a Work in Progress custom server.
motd=Welcome to PHP Server
port=19132
protocol=CURRENT
last-update=false
white-list=false
debug=2
max-players=20