From 1bfef261abb1703253a11d3496794a38620e720c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sat, 16 Mar 2013 12:27:23 +0100 Subject: [PATCH] PMF Plugin Reading --- .gitignore | 1 + src/API/PluginAPI.php | 5 +++- src/{ => pmf}/PMF.php | 11 +++++--- src/pmf/Plugin.php | 61 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 5 deletions(-) rename src/{ => pmf}/PMF.php (94%) create mode 100644 src/pmf/Plugin.php diff --git a/.gitignore b/.gitignore index b04e0a75b..16650046c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ worlds/* plugins/* logs/* *.log +*.pmf server.properties white-list.txt banned-ips.txt diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index 881bb191d..8021726a9 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -41,6 +41,7 @@ class PluginAPI extends stdClass{ } public function getInfo($className){ + $className = strtolower($className); if(!isset($this->plugins[$className])){ return false; } @@ -83,7 +84,9 @@ class PluginAPI extends stdClass{ if(eval($content) === false or !class_exists($info["class"])){ console("[ERROR] [PluginAPI] Failed loading plugin: evaluation error"); } - $className = trim($info["class"]); + $info["code"] = $content; + $info["class"] = trim(strtolower($info["class"])); + $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){ diff --git a/src/PMF.php b/src/pmf/PMF.php similarity index 94% rename from src/PMF.php rename to src/pmf/PMF.php index 50f35eb01..a9b1dcfdd 100644 --- a/src/PMF.php +++ b/src/pmf/PMF.php @@ -38,7 +38,7 @@ class PMF{ $this->create($file, $type, $version); }else{ if($this->load($file) !== true){ - $this->parse(); + $this->parseInfo(); } } } @@ -51,7 +51,7 @@ class PMF{ return $this->type; } - private function load($file){ + public function load($file){ $this->close(); $this->file = realpath($file); if(($this->fp = @fopen($file, "c+b")) !== false){ @@ -64,7 +64,7 @@ class PMF{ return false; } - public function parse(){ + public function parseInfo(){ if(fread($this->fp, 3) !== "PMF"){ return false; } @@ -92,7 +92,7 @@ class PMF{ public function create($file, $type, $version = PMF_CURRENT_VERSION){ $this->file = realpath($file); - if(!is_resource($this->fp)){ + if(!is_resource($this->fp)){ if(($this->fp = @fopen($file, "c+b")) === false){ return false; } @@ -102,6 +102,9 @@ class PMF{ } public function read($length){ + if($length <= 0){ + return ""; + } if(is_resource($this->fp)){ return fread($this->fp, (int) $length); } diff --git a/src/pmf/Plugin.php b/src/pmf/Plugin.php new file mode 100644 index 000000000..cefd95957 --- /dev/null +++ b/src/pmf/Plugin.php @@ -0,0 +1,61 @@ +load($file); + $this->parseInfo(); + $this->parsePlugin(); + } + + protected function parsePlugin(){ + if($this->type !== 0x01){ + return false; + } + + $this->pluginData["fversion"] = ord($this->read(1)); + $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["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"] = $this->read(Utils::readShort($this->read(2), false)); //Additional custom plugin data + $this->pluginData["code"] = ""; + while(!feof($this->fp)){ + $this->pluginData["code"] .= fread($this->fp, 4096); + } + $this->pluginData["code"] = gzinflate($this->pluginData["code"]); + } + +} \ No newline at end of file