From 67c9181a069cc908a87b6bbd8d2e1c908d3d29ed Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sun, 23 Dec 2012 02:19:39 +0100 Subject: [PATCH] Github API error handling --- classes/API/ServerAPI.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/classes/API/ServerAPI.php b/classes/API/ServerAPI.php index fd0876a60..03948a5ff 100644 --- a/classes/API/ServerAPI.php +++ b/classes/API/ServerAPI.php @@ -93,19 +93,24 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run $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..."); + 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); - $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); + if($info === false or !isset($info["updated_at"])){ + console("[ERROR] GitHub API Error"); }else{ - $last = time(); - $this->setProperty("last-update", $last); - console("[INFO] Last check at ".date("Y-m-d H:i:s", $last)); + $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); + }else{ + $last = time(); + $this->setProperty("last-update", $last); + console("[INFO] This is the latest version"); + } } } if(file_exists(FILE_PATH."data/maps/level.dat")){