mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Added OPs and permission checks
This commit is contained in:
parent
c2e55941d8
commit
498c050da7
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,6 +7,7 @@ server.properties
|
||||
white-list.txt
|
||||
banned-ips.txt
|
||||
banned.txt
|
||||
ops.txt
|
||||
|
||||
#################
|
||||
## Eclipse
|
||||
|
@ -29,6 +29,7 @@ class BanAPI{
|
||||
private $server;
|
||||
private $whitelist;
|
||||
private $banned;
|
||||
private $ops;
|
||||
private $bannedIPs;
|
||||
function __construct(PocketMinecraftServer $server){
|
||||
$this->server = $server;
|
||||
@ -39,15 +40,57 @@ class BanAPI{
|
||||
$this->whitelist = new Config(FILE_PATH."white-list.txt", CONFIG_LIST);
|
||||
$this->bannedIPs = new Config(FILE_PATH."banned-ips.txt", CONFIG_LIST);
|
||||
$this->banned = new Config(FILE_PATH."banned.txt", CONFIG_LIST);
|
||||
$this->ops = new Config(FILE_PATH."ops.txt", CONFIG_LIST);
|
||||
$this->server->api->console->register("banip", "Manages IP Banning", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("ban", "Manages Bannning", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("kick", "Kicks a player", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("whitelist", "Manages White-listing", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("op", "Ops a player", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("deop", "Deops a player", array($this, "commandHandler"));
|
||||
$this->server->addHandler("console.command", array($this, "opCheck"), 1);
|
||||
}
|
||||
|
||||
public function isOp($username){
|
||||
if($this->server->api->dhandle("api.op.check", $username) === false){
|
||||
return true;
|
||||
}elseif($this->op->exists($username)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function opCheck($data, $event){
|
||||
if($data["issuer"] instanceof Player){
|
||||
if($this->isOp($data["issuer"]->username)){
|
||||
return true;
|
||||
}
|
||||
}elseif($data["issuer"] === "console"){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function commandHandler($cmd, $params, $issuer){
|
||||
$output = "";
|
||||
switch($cmd){
|
||||
case "op":
|
||||
$user = trim(implode(" ", $params));
|
||||
if($user == ""){
|
||||
break;
|
||||
}
|
||||
$this->ops->set($user);
|
||||
$this->ops->save();
|
||||
$output .= $user." is now op\n";
|
||||
break;
|
||||
case "deop":
|
||||
$user = trim(implode(" ", $params));
|
||||
if($user == ""){
|
||||
break;
|
||||
}
|
||||
$this->ops->remove($user);
|
||||
$this->ops->save();
|
||||
$output .= $user." is not longer op\n";
|
||||
break;
|
||||
case "kick":
|
||||
if(!isset($params[0])){
|
||||
$output .= "Usage: /kick <playername> [reason]\n";
|
||||
|
@ -77,7 +77,9 @@ class ConsoleAPI{
|
||||
break;
|
||||
case "status":
|
||||
case "lag":
|
||||
$this->server->debugInfo(true);
|
||||
if(!($issuer instanceof Player) and $issuer === "console"){
|
||||
$this->server->debugInfo(true);
|
||||
}
|
||||
$info = $this->server->debugInfo();
|
||||
$output .= "TPS: ".$info["tps"].", Memory usage: ".$info["memory_usage"]." (Peak ".$info["memory_peak_usage"].")\n";
|
||||
break;
|
||||
@ -192,7 +194,7 @@ class ConsoleAPI{
|
||||
if($this->loop->line !== false){
|
||||
$line = trim($this->loop->line);
|
||||
$this->loop->line = false;
|
||||
$this->run($line);
|
||||
$this->run($line, "console");
|
||||
}else{
|
||||
$this->loop->notify();
|
||||
}
|
||||
|
@ -42,5 +42,5 @@ define("MAJOR_VERSION", "Alpha_1.2dev");
|
||||
define("CURRENT_STRUCTURE", 5);
|
||||
define("CURRENT_PROTOCOL", 9);
|
||||
define("CURRENT_MINECRAFT_VERSION", "v0.6.1 alpha");
|
||||
define("CURRENT_API_VERSION", 1);
|
||||
define("CURRENT_API_VERSION", 2);
|
||||
define("CURRENT_PHP_VERSION", "5.4.11");
|
Loading…
x
Reference in New Issue
Block a user