From 2861fe07034a2f16f2c76b90206ccf7cbaba9cfc Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Wed, 27 Mar 2013 18:02:10 +0100 Subject: [PATCH] New Plugin format includes multiple API versions --- src/API/PluginAPI.php | 10 +++++----- src/pmf/Plugin.php | 8 ++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index d30ad3473..cd2aea29f 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -85,7 +85,7 @@ class PluginAPI extends stdClass{ console("[ERROR] [PluginAPI] Failed parsing of ".basename($file)); return false; } - console("[INFO] [PluginAPI] Loading plugin \"\x1b[32m".$info["name"]."\x1b[0m\" \x1b[35m".$info["version"]." #".intval($info["apiversion"])."\x1b[0m by \x1b[36m".$info["author"]."\x1b[0m"); + console("[INFO] [PluginAPI] Loading plugin \"\x1b[32m".$info["name"]."\x1b[0m\" \x1b[35m".$info["version"]." \x1b[0m by \x1b[36m".$info["author"]."\x1b[0m"); if(class_exists($info["class"])){ console("[ERROR] [PluginAPI] Failed loading plugin: class exists"); return false; @@ -96,11 +96,11 @@ class PluginAPI extends stdClass{ } $className = $info["class"]; - if(isset($info["apiversion"]) and intval($info["apiversion"]) > CURRENT_API_VERSION){ - console("[ERROR] [PluginAPI] Plugin \"".$info["name"]."\" uses a newer API! It can crash or corrupt the server!"); - }elseif(!isset($info["apiversion"]) or intval($info["apiversion"]) < CURRENT_API_VERSION){ - console("[DEBUG] [PluginAPI] Plugin \"".$info["name"]."\" uses an old API", true, true, 2); + $apiversion = array_map("intval", explode(",", (string) $info["apiversion"])); + if(!in_array((string) CURRENT_API_VERSION, $apiversion)){ + console("[ERROR] [PluginAPI] Plugin \"".$info["name"]."\" is not compatible with the API (".$info["apiversion"]." != ".CURRENT_API_VERSION.")! It can crash or corrupt the server!"); } + $object = new $className($this->server->api, false); if(!($object instanceof Plugin)){ console("[ERROR] [PluginAPI] Plugin \"\x1b[36m".$info["name"]."\x1b[0m\" doesn't use the Plugin Interface"); diff --git a/src/pmf/Plugin.php b/src/pmf/Plugin.php index 64cd5409b..d433a9209 100644 --- a/src/pmf/Plugin.php +++ b/src/pmf/Plugin.php @@ -29,7 +29,7 @@ the Free Software Foundation, either version 3 of the License, or require_once(FILE_PATH."/src/pmf/PMF.php"); /***REM_END***/ -define("PMF_CURRENT_PLUGIN_VERSION", 0x00); +define("PMF_CURRENT_PLUGIN_VERSION", 0x01); class PMFPlugin extends PMF{ private $pluginData = array(); @@ -52,7 +52,11 @@ class PMFPlugin extends PMF{ $this->pluginData["name"] = $this->read(Utils::readShort($this->read(2), false)); $this->pluginData["version"] = $this->read(Utils::readShort($this->read(2), false)); $this->pluginData["author"] = $this->read(Utils::readShort($this->read(2), false)); - $this->pluginData["apiversion"] = Utils::readShort($this->read(2), false); + if($this->pluginData["fversion"] >= 0x01){ + $this->pluginData["apiversion"] = $this->read(Utils::readShort($this->read(2), false)); + }else{ + $this->pluginData["apiversion"] = Utils::readShort($this->read(2), false); + } $this->pluginData["class"] = $this->read(Utils::readShort($this->read(2), false)); $this->pluginData["identifier"] = $this->read(Utils::readShort($this->read(2), false)); //Will be used to check for updates $this->pluginData["extra"] = gzinflate($this->read(Utils::readShort($this->read(2), false))); //Additional custom plugin data