CODE (htmlphp):
скопировать код в буфер обмена
скопировать код в буфер обмена
- <?php
- define("FORBIDDEN", -"Забаненный");
- define("GUEST_AUTH", "Игрок");
- define("PLAYER_AUTH", "VIP");
- define("BUILDER_AUTH", "Premium");
- define("MODERATOR_AUTH", "Модератор");
- define("ADMIN_AUTH", "Администратор");
- define("CONSOLE_AUTH", "Консоль");
- define("DEFAULT_AUTH", GUEST_AUTH);
- class PermissionSuite implements Plugin{
- private $api, $sapi, $config, $permissions, $chests;
- private $ranklist;
- public function __construct(ServerAPI $api, $server = false){
- $this->api = $api;
- if(!class_exists("SimpleAuthAPI")){$this->api->plugin->load('./plugins/PermissionSuite/SimpleAuth.php');}
- $this->sapi = SimpleAuthAPI::get();
- $this->ranklist = array(
- 5 =>"Консоль",
- 4 =>"Модератор",
- 3 =>"Premium",
- 2 =>"VIP",
- 1 =>"Игрок",
- 0 =>"Гость",
- -1=>"Забанен");
- }
- public function init(){
- if(!file_exists("./plugins/PermissionSuite/SimpleAuth.php")){
- console("[ERROR][PermissionSuite] SimpleAuth Plugin is missing, it's strictly necessary for the proper functionality of this plugin.");
- return false;
- }
- elseif(file_exists("./plugins/SimpleAuth.php")){
- console("[WARNING][P.Suite] Theres a duplicated SimpleAuth Plugin, make sure to remove SimpleAuth from plugins folder if you had it installed before installing P.Suite.");
- }
- $this->config = new Config($this->api->plugin->configPath ($this)."config.yml", CONFIG_YAML, array(
- "PluginEnabled" => true,
- "defaultAction" => "allowed",
- "Permissions" => array(
- "login" => GUEST_AUTH,
- "register" => GUEST_AUTH,
- "permission" => ADMIN_AUTH,
- "help" => GUEST_AUTH,
- "banip" => MODERATOR_AUTH,
- "give" => MODERATOR_AUTH,
- "ban" => MODERATOR_AUTH,
- "op" => -1, /*Forbidden command due to permissions conflict. enabling it may permit ops to use commands above their auth*/
- "defaultgamemode" => MODERATOR_AUTH,
- "gamemode" => MODERATOR_AUTH,
- "kill" => MODERATOR_AUTH,
- "kick" => MODERATOR_AUTH
- )));
- $this->permissions = new Config($this->api->plugin->configPath ($this)."permissions.yml", CONFIG_YAML, array());
- $this->chests = new Config($this->api->plugin->configPath($this)."chests.yml", CONFIG_YAML, array());
- $this->api->addHandler("console.command", array($this, "eventHandler"));
- $this->api->addHandler("player.block.touch", array($this, "eventHandler"));
- $this->api
- ->addHandler("op.check", array($this, "eventHandler"));
- $this->api->console->register("permission","PermissionSuite Master command.", array($this, "commandHandler"));
- }
- public function eventHandler(&$data, $event){
- switch($event){
- case "op.check":
- $P = $this->api->player->get($data);
- if($P instanceof Player){
- $p = $this->permissions->get($P->iusername);
- if($this->getNum($p["permission"]) > 2){
- return true;
- }else{return false;}
- }return false;
- break;
- /*case "player.block.touch":
- if($this->sapi->isAuthed($data["player"]->CID) === true){
- $tile = $this->api->tile->get(new Position($data["target"]->x, $data["target"]->y, $data["target"]->z, $data["target"]->level));
- if($tile === false){break;}
- $class = $tile->class;
- switch($class){
- case TILE_CHEST:
- switch($data["type"]){
- case "place":
- $toSave = arra(array("owner"=$data["creator"], "chestX" = $data["target"]->x, "chestY" = $data["target"]->y,
- "chestZ" = $data["target"]->z,
- "chestLevel" = $data["target"]->level));
- $this->chests->set($data["player"]->iusername, $toSave);
- break;
- case "break":
- }
- }
- }
- break;
- */
- case "console.command":
- if($data["issuer"] === "console"){break;}
- elseif($data["issuer"] instanceof Player){
- $c = $this->config->get("Permissions");
- $p = $this->permissions->get($data["issuer"]->iusername);
- if($p === false){
- if($this->sapi->isAuthed($data["issuer"]->CID) !== true){
- $this->api->chat->sendTo(false, "Пожалуйста войдите используя команду /login или /register. Подробнее на сайте Ravage.su", $data["issuer"]->iusername);
- return false;
- }
- else{
- $this->permissions->set($data["issuer"]->iusername, array("permission" => DEFAULT_AUTH));
- $p = $this->permissions->get($data["issuer"]->iusername);
- }
- }
- if($this->sapi->isAuthed($data["issuer"]->CID) !== true){
- $this->api->chat->sendTo(false, "Пожалуйста войдите используя команду /login или /register. Подробнее на сайте Ravage.su", $data["issuer"]->iusername);
- return false;
- }
- elseif(!isset($c[$data["cmd"]])){
- if($this->config->get("defaultAction") === "allowed"){
- console("[PermissionSuite] ".($data["cmd"])." has not been assigned a permission level! Consider setting one up now.");
- break;
- }
- console("[PermissionSuite] Blocked execution of '".($data["cmd"])."' as default action.");
- return false;
- }
- elseif($this->getNum($c[$data["cmd"]]) > $this->getNum($p["permission"])){if($this->getNum($c[$data["cmd"]]) === 5){
- $this->api->chat->sendTo(false, "[PermissionSuite] This command can only be executed on the console.",$data["issuer"]->iusername);
- return false;
- }return false;
- }
- }
- break;
- }
- }
- public function getNum($rank){
- if(!$rank){return false;}
- switch($rank){
- case "Консоль":
- return 5;
- case "Модератор":
- return 4;
- case "Premium":
- return 3;
- case "VIP":
- return 2;
- case "Игрок":
- return 1;
- case "Гость":
- return 0;
- case "Забанен":
- return -1;
- }
- }
- public function commandHandler($cmd, $params, $issuer, $alias){
- $output = "";
- $cmd = strtolower($cmd);
- switch($cmd){
- case "issueReboot":
- $this->api = new ServerAPI();
- break;
- case "permission":
- $subcmd = strtolower($params[0]);
- switch($subcmd){
- case "":
- $output .= "permission set <command> <-1 | 0 | 1 | 2 | 3 | 4 | 5> | Rank required to run <command>.\n\n";
- $output .= "/permission remove <command> | Removes the permission requirement of a command. When executed, the default action takes place.\n";
- $output .= "/permission auth <playername> <-1 | 0 | 1 | 2 | 3 | 4> | Grants the specified permission level to an user.";
- break;
- case "set":
- $command = strtolower($params[1]);
- $c = $this->config->get("Permissions");
- if($command !== false and is_numeric($params[2]) and $c !== false){
- if($params[2] < 0 or $params[2] > 5){
- $output = "[P.Suite] Wrong permission set. Please enter a value between 0 and 5 inclusive.";
- break;
- }
- $c[$command] = $this->ranklist[$params[2]];
- $this->config->set("Permissions", $c);
- $this->config->save();
- $output .= "[P.Suite] '".($command)."' has been set a permission of level '".($params[2])."'!";
- break;
- }
- else{
- $output = "Что-то не так. Свяжитесь с администратором Ravage.su";
- }
- break;
- case "remove":
- $c = $this->config->get("Permissions");
- if($c === false){
- $output = "Что-то не так. Свяжитесь с администратором Ravage.su";
- break;
- }
- unset($c[$params[1]]);
- $this->config->set("Permissions", $c);
- $output = "[PermissionSuite] '".($params[1])."' removed from permission list. It's usage will now be '".($this->config->get("defaultAction"))."' by default.";
- $this->config->save();
- break;
- case "auth":
- if($params[1] !== false and $params[2] !== false){
- if(!is_numeric($params[2])){
- $output = "[PermissionsSuite] Permission must be a number between 0 and 4 inclusive.";
- break;
- }
- $this->permissions->set($params[1], array("permission" => $this->ranklist[$params[2]]));
- $this->permissions->save();
- $output = "".($params[1])."' теперь имеет группу '".($params[2])."'";
- break;
- }
- }
- }
- return $output;
- }
- public function __destruct(){
- $this->config->save();
- $this->permissions->save();
- $this->chests->save();
- }
- }