mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
PMF Plugin Loading
This commit is contained in:
parent
d46a61d0c4
commit
ce8724c5ed
@ -50,6 +50,10 @@ class PluginAPI extends stdClass{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function load($file){
|
public function load($file){
|
||||||
|
if(strtolower(substr($file, -3)) === "pmf"){
|
||||||
|
$pmf = new PMFPlugin($file);
|
||||||
|
$info = $pmf->getPluginInfo();
|
||||||
|
}else{
|
||||||
$content = file_get_contents($file);
|
$content = file_get_contents($file);
|
||||||
$info = strstr($content, "*/", true);
|
$info = strstr($content, "*/", true);
|
||||||
$content = substr(strstr($content, "*/"),2);
|
$content = substr(strstr($content, "*/"),2);
|
||||||
@ -74,18 +78,23 @@ class PluginAPI extends stdClass{
|
|||||||
}
|
}
|
||||||
$info[$i] = $v;
|
$info[$i] = $v;
|
||||||
}
|
}
|
||||||
|
$info["code"] = $content;
|
||||||
|
$info["class"] = trim(strtolower($info["class"]));
|
||||||
|
}
|
||||||
if(!isset($info["name"]) or !isset($info["version"]) or !isset($info["class"]) or !isset($info["author"])){
|
if(!isset($info["name"]) or !isset($info["version"]) or !isset($info["class"]) or !isset($info["author"])){
|
||||||
console("[ERROR] [PluginAPI] Failed parsing of ".basename($file));
|
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"]." #".intval($info["apiversion"])."\x1b[0m by \x1b[36m".$info["author"]."\x1b[0m");
|
||||||
if(class_exists($info["class"])){
|
if(class_exists($info["class"])){
|
||||||
console("[ERROR] [PluginAPI] Failed loading plugin: class exists");
|
console("[ERROR] [PluginAPI] Failed loading plugin: class exists");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if(eval($content) === false or !class_exists($info["class"])){
|
if(eval($info["code"]) === false or !class_exists($info["class"])){
|
||||||
console("[ERROR] [PluginAPI] Failed loading plugin: evaluation error");
|
console("[ERROR] [PluginAPI] Failed loading plugin: evaluation error");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
$info["code"] = $content;
|
|
||||||
$info["class"] = trim(strtolower($info["class"]));
|
|
||||||
$className = $info["class"];
|
$className = $info["class"];
|
||||||
if(isset($info["apiversion"]) and intval($info["apiversion"]) > CURRENT_API_VERSION){
|
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!");
|
console("[ERROR] [PluginAPI] Plugin \"".$info["name"]."\" uses a newer API! It can crash or corrupt the server!");
|
||||||
@ -168,7 +177,8 @@ class PluginAPI extends stdClass{
|
|||||||
$dir = dir(DATA_PATH."plugins/");
|
$dir = dir(DATA_PATH."plugins/");
|
||||||
while(false !== ($file = $dir->read())){
|
while(false !== ($file = $dir->read())){
|
||||||
if($file{0} !== "."){
|
if($file{0} !== "."){
|
||||||
if(strtolower(substr($file, -3)) === "php"){
|
$ext = strtolower(substr($file, -3));
|
||||||
|
if($ext === "php" or $ext === "pmf"){
|
||||||
$this->load(DATA_PATH."plugins/" . $file);
|
$this->load(DATA_PATH."plugins/" . $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,16 +59,16 @@ class PMF{
|
|||||||
if($stat["size"] >= 5){ //Header + 2 Bytes
|
if($stat["size"] >= 5){ //Header + 2 Bytes
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
fclose($this->fp);
|
$this->close();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseInfo(){
|
public function parseInfo(){
|
||||||
|
$this->seek(0);
|
||||||
if(fread($this->fp, 3) !== "PMF"){
|
if(fread($this->fp, 3) !== "PMF"){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->seek(0);
|
|
||||||
$this->version = ord($this->read(1));
|
$this->version = ord($this->read(1));
|
||||||
switch($this->version){
|
switch($this->version){
|
||||||
case 0x01:
|
case 0x01:
|
||||||
@ -87,8 +87,10 @@ class PMF{
|
|||||||
|
|
||||||
public function close(){
|
public function close(){
|
||||||
unset($this->version, $this->type, $this->file);
|
unset($this->version, $this->type, $this->file);
|
||||||
|
if(is_object($this->fp)){
|
||||||
fclose($this->fp);
|
fclose($this->fp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function create($file, $type, $version = PMF_CURRENT_VERSION){
|
public function create($file, $type, $version = PMF_CURRENT_VERSION){
|
||||||
$this->file = realpath($file);
|
$this->file = realpath($file);
|
||||||
@ -98,7 +100,7 @@ class PMF{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->seek(0);
|
$this->seek(0);
|
||||||
$this->write("PMF" . chr((int) $type) . chr((int) $version));
|
$this->write("PMF" . chr((int) $version) . chr((int) $type));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function read($length){
|
public function read($length){
|
||||||
|
@ -39,8 +39,12 @@ class PMFPlugin extends PMF{
|
|||||||
$this->parsePlugin();
|
$this->parsePlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPluginInfo(){
|
||||||
|
return $this->pluginData;
|
||||||
|
}
|
||||||
|
|
||||||
protected function parsePlugin(){
|
protected function parsePlugin(){
|
||||||
if($this->type !== 0x01){
|
if($this->getType() !== 0x01){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,12 +52,13 @@ class PMFPlugin extends PMF{
|
|||||||
$this->pluginData["name"] = $this->read(Utils::readShort($this->read(2), false));
|
$this->pluginData["name"] = $this->read(Utils::readShort($this->read(2), false));
|
||||||
$this->pluginData["version"] = $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["author"] = $this->read(Utils::readShort($this->read(2), false));
|
||||||
|
$this->pluginData["apiversion"] = Utils::readShort($this->read(2), false);
|
||||||
$this->pluginData["class"] = $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["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["extra"] = gzinflate($this->read(Utils::readShort($this->read(2), false))); //Additional custom plugin data
|
||||||
$this->pluginData["code"] = "";
|
$this->pluginData["code"] = "";
|
||||||
while(!feof($this->fp)){
|
while(!feof($this->fp)){
|
||||||
$this->pluginData["code"] .= fread($this->fp, 4096);
|
$this->pluginData["code"] .= $this->read(4096);
|
||||||
}
|
}
|
||||||
$this->pluginData["code"] = gzinflate($this->pluginData["code"]);
|
$this->pluginData["code"] = gzinflate($this->pluginData["code"]);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user