Add basic_privs privilege
authorPerttu Ahola <celeron55@gmail.com>
Mon, 9 Apr 2012 15:57:41 +0000 (18:57 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Mon, 9 Apr 2012 15:57:41 +0000 (18:57 +0300)
builtin/chatcommands.lua
builtin/privileges.lua

index d2bf62c6aee1ce2df368aac30993435ce7795202..047cfc69218a0acd2010749e3cf95d1810427040 100644 (file)
@@ -111,8 +111,13 @@ minetest.register_chatcommand("privs", {
 minetest.register_chatcommand("grant", {
        params = "<name> <privilege>|all",
        description = "Give privilege to player",
-       privs = {privs=true},
+       privs = {},
        func = function(name, param)
+               if not minetest.check_player_privs(name, {privs=true}) and 
+                               not minetest.check_player_privs(name, {basic_privs=true}) then
+                       minetest.chat_send_player(name, "Your privileges are insufficient.")
+                       return
+               end
                local grantname, grantprivstr = string.match(param, "([^ ]+) (.+)")
                if not grantname or not grantprivstr then
                        minetest.chat_send_player(name, "Invalid parameters (see /help grant)")
@@ -125,6 +130,10 @@ minetest.register_chatcommand("grant", {
                local privs = minetest.get_player_privs(grantname)
                local privs_known = true
                for priv, _ in pairs(grantprivs) do
+                       if priv ~= "interact" and priv ~= "shout" and not minetest.check_player_privs(name, {privs=true}) then
+                               minetest.chat_send_player(name, "Your privileges are insufficient.")
+                               return
+                       end
                        if not minetest.registered_privileges[priv] then
                                minetest.chat_send_player(name, "Unknown privilege: "..priv)
                                privs_known = false
@@ -144,8 +153,13 @@ minetest.register_chatcommand("grant", {
 minetest.register_chatcommand("revoke", {
        params = "<name> <privilege>|all",
        description = "Remove privilege from player",
-       privs = {privs=true},
+       privs = {},
        func = function(name, param)
+               if not minetest.check_player_privs(name, {privs=true}) and 
+                               not minetest.check_player_privs(name, {basic_privs=true}) then
+                       minetest.chat_send_player(name, "Your privileges are insufficient.")
+                       return
+               end
                local revokename, revokeprivstr = string.match(param, "([^ ]+) (.+)")
                if not revokename or not revokeprivstr then
                        minetest.chat_send_player(name, "Invalid parameters (see /help revoke)")
@@ -153,6 +167,12 @@ minetest.register_chatcommand("revoke", {
                end
                local revokeprivs = minetest.string_to_privs(revokeprivstr)
                local privs = minetest.get_player_privs(revokename)
+               for priv, _ in pairs(revokeprivs) do
+                       if priv ~= "interact" and priv ~= "shout" and not minetest.check_player_privs(name, {privs=true}) then
+                               minetest.chat_send_player(name, "Your privileges are insufficient.")
+                               return
+                       end
+               end
                if revokeprivstr == "all" then
                        privs = {}
                else
index 5db0ca942293820ab6ed15f10a2a151cd288f544..6cb42c103c2dfe53c4a0ffd7f93a6ce4853a3eb8 100644 (file)
@@ -30,6 +30,7 @@ minetest.register_privilege("teleport", "Can use /teleport command")
 minetest.register_privilege("bring", "Can teleport other players")
 minetest.register_privilege("settime", "Can use /time")
 minetest.register_privilege("privs", "Can modify privileges")
+minetest.register_privilege("basic_privs", "Can modify 'shout' and 'interact' privileges")
 minetest.register_privilege("server", "Can do server maintenance stuff")
 minetest.register_privilege("shout", "Can speak in chat")
 minetest.register_privilege("ban", "Can ban and unban players")