granting and revoking of all privileges at once

master
Perttu Ahola 2012-04-01 01:10:06 +03:00
parent 7bfa2d4da6
commit d5594e431c
1 changed files with 11 additions and 4 deletions

View File

@ -994,7 +994,7 @@ minetest.register_chatcommand("privs", {
end, end,
}) })
minetest.register_chatcommand("grant", { minetest.register_chatcommand("grant", {
params = "<name> <privilege>", params = "<name> <privilege>|all",
description = "Give privilege to player", description = "Give privilege to player",
privs = {privs=true}, privs = {privs=true},
func = function(name, param) func = function(name, param)
@ -1004,6 +1004,9 @@ minetest.register_chatcommand("grant", {
return return
end end
local grantprivs = minetest.string_to_privs(grantprivstr) local grantprivs = minetest.string_to_privs(grantprivstr)
if grantprivstr == "all" then
grantprivs = minetest.registered_privileges
end
local privs = minetest.get_player_privs(grantname) local privs = minetest.get_player_privs(grantname)
for priv, _ in pairs(grantprivs) do for priv, _ in pairs(grantprivs) do
privs[priv] = true privs[priv] = true
@ -1016,7 +1019,7 @@ minetest.register_chatcommand("grant", {
end, end,
}) })
minetest.register_chatcommand("revoke", { minetest.register_chatcommand("revoke", {
params = "<name> <privilege>", params = "<name> <privilege>|all",
description = "Remove privilege from player", description = "Remove privilege from player",
privs = {privs=true}, privs = {privs=true},
func = function(name, param) func = function(name, param)
@ -1027,9 +1030,13 @@ minetest.register_chatcommand("revoke", {
end end
local revokeprivs = minetest.string_to_privs(revokeprivstr) local revokeprivs = minetest.string_to_privs(revokeprivstr)
local privs = minetest.get_player_privs(revokename) local privs = minetest.get_player_privs(revokename)
if revokeprivstr == "all" then
privs = {}
else
for priv, _ in pairs(revokeprivs) do for priv, _ in pairs(revokeprivs) do
privs[priv] = nil privs[priv] = nil
end end
end
minetest.set_player_privs(revokename, privs) minetest.set_player_privs(revokename, privs)
minetest.chat_send_player(name, "Privileges of "..revokename..": "..minetest.privs_to_string(minetest.get_player_privs(revokename), ' ')) minetest.chat_send_player(name, "Privileges of "..revokename..": "..minetest.privs_to_string(minetest.get_player_privs(revokename), ' '))
if revokename ~= name then if revokename ~= name then