mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-03 18:42:37 +00:00
PMF Plugin Reading
This commit is contained in:
parent
6dfe348767
commit
1bfef261ab
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,7 @@ worlds/*
|
||||
plugins/*
|
||||
logs/*
|
||||
*.log
|
||||
*.pmf
|
||||
server.properties
|
||||
white-list.txt
|
||||
banned-ips.txt
|
||||
|
@ -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){
|
||||
|
@ -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);
|
||||
}
|
61
src/pmf/Plugin.php
Normal file
61
src/pmf/Plugin.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/***REM_START***/
|
||||
require_once(FILE_PATH."/src/pmf/PMF.php");
|
||||
/***REM_END***/
|
||||
|
||||
define("PMF_CURRENT_PLUGIN_VERSION", 0x00);
|
||||
|
||||
class PMFPlugin extends PMF{
|
||||
private $pluginData = array();
|
||||
public function __construct($file){
|
||||
$this->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"]);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user