Update PluginManager, add PluginBase and add SetRole() function
This commit is contained in:
parent
5463e173a5
commit
57f32af71a
30
src/LonaDB/Plugins/PluginBase.php
Normal file
30
src/LonaDB/Plugins/PluginBase.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace LonaDB\Plugins;
|
||||
|
||||
use LonaDB\LonaDB;
|
||||
use LonaDB\Logger;
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
class PluginBase{
|
||||
private string $Name;
|
||||
private LonaDB $LonaDB;
|
||||
|
||||
public function __construct(LonaDB $LonaDB, string $name) {
|
||||
$this->LonaDB = $LonaDB;
|
||||
$this->Name = $name;
|
||||
|
||||
$this->GetLogger()->Load("Loading Plugin '" . $this->Name . "'");
|
||||
}
|
||||
|
||||
public function onEnable() : void {
|
||||
$this->GetLogger()->Info("Plugin '" . $this->Name . "' has been loaded");
|
||||
}
|
||||
|
||||
final public function GetLonaDB() : LonaDB { return $this->LonaDB; }
|
||||
|
||||
final public function GetName() : string { return $this->Name; }
|
||||
|
||||
final private function GetLogger() : Logger { return $this->LonaDB->Logger; }
|
||||
}
|
@ -39,9 +39,9 @@ class PluginManager{
|
||||
try{
|
||||
$this->load_classphp($path, $phar);
|
||||
|
||||
eval("\$this->Plugins[\$conf['name']] = new " . $conf['main']['namespace'] . "\\" . $conf['main']['class'] . "();");
|
||||
eval("\$this->Plugins[\$conf['name']] = new " . $conf['main']['namespace'] . "\\" . $conf['main']['class'] . "(\$this->LonaDB, \$conf['name']);");
|
||||
|
||||
$this->Plugins[$conf['name']]->onEnable($this->LonaDB);
|
||||
$this->Plugins[$conf['name']]->onEnable();
|
||||
}
|
||||
catch(e){
|
||||
$this->LonaDB->Logger->Error("Could not load main file for plugin '" . $conf['name'] . "'");
|
||||
@ -76,9 +76,9 @@ class PluginManager{
|
||||
$phar->stopBuffering();
|
||||
}
|
||||
|
||||
eval("\$this->Plugins[\$conf['name']] = new " . $conf['main']['namespace'] . "\\" . $conf['main']['class'] . "();");
|
||||
eval("\$this->Plugins[\$conf['name']] = new " . $conf['main']['namespace'] . "\\" . $conf['main']['class'] . "(\$this->LonaDB, \$conf['name']);");
|
||||
|
||||
$this->Plugins[$conf['name']]->onEnable($this->LonaDB);
|
||||
$this->Plugins[$conf['name']]->onEnable();
|
||||
}
|
||||
catch(e){
|
||||
$this->LonaDB->Logger->Error("Could not load main file for plugin '" . $conf['name'] . "'");
|
||||
|
@ -30,7 +30,7 @@ class UserManager{
|
||||
$this->Users = json_decode(openssl_decrypt($parts[0], AES_256_CBC, $this->LonaDB->config["encryptionKey"], 0, base64_decode($parts[1])), true);
|
||||
}
|
||||
|
||||
public function CheckPassword(string $name, string $password) : bool {
|
||||
public function CheckPassword(string $name = "", string $password = "") : bool {
|
||||
if($name === "root" && $password === $this->LonaDB->config["root"]) return true;
|
||||
|
||||
if(!$this->Users[$name]) {
|
||||
@ -52,7 +52,7 @@ class UserManager{
|
||||
$users = [];
|
||||
|
||||
foreach($this->Users as $name => $user){
|
||||
array_push($users, $name);
|
||||
$users[$name] = $this->GetRole($name);
|
||||
}
|
||||
|
||||
return $users;
|
||||
@ -95,6 +95,15 @@ class UserManager{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function SetRole(string $name, string $role) : bool {
|
||||
if($name === "root") return false;
|
||||
if(!$this->CheckUser($name)) return false;
|
||||
|
||||
$this->Users[$name]['role'] = $role;
|
||||
$this->Save();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetRole(string $name) : string {
|
||||
if($name === "root") return "Superuser";
|
||||
if(!$this->CheckUser($name)) return "";
|
||||
|
Loading…
Reference in New Issue
Block a user