Initial commit

This commit is contained in:
rubenwardy 2018-04-02 21:26:27 +01:00
commit 7c21222205
3 changed files with 92 additions and 0 deletions

29
README.md Normal file
View File

@ -0,0 +1,29 @@
# Privilege Groups
Allows granting and modifying of privs in bulk
Note: only the /grant and /group add behaviour currently exist.
## Usage
By default, a group called "member" is created which has everything in default_privs.
You can see its properties like so:
/group info member
Groups can be created or expanded like so:
/group add groupname privs
Groups are then granted to users like so:
/grant username groupname
If the caller has the appropriate privileges to grant and privileges in the group,
then this will cause the player to enter the group and be granted all its privs.
You can remove privs from a group like so:
/group remove groupname privs
This will remove that priv from any members of that group.

60
init.lua Normal file
View File

@ -0,0 +1,60 @@
local storage = minetest.get_mod_storage()
privgroups = {
registered_chatcommands =
minetest.parse_json(storage:get_string("groups")) or {}
}
function privgroups.save()
storage:set_string("groups", minetest.write_json(privgroups.registered_chatcommands))
end
local old_grant = minetest.registered_chatcommands["grant"].func
minetest.registered_chatcommands["grant"].func = function(name, param)
local grantname, grantprivstr = string.match(param, "([^ ]+) (.+)")
if not grantname or not grantprivstr then
return false, "Invalid parameters (see /help grant)"
end
local ret_privs = {}
local privs = minetest.string_to_privs(grantprivstr)
for priv, _ in pairs(privs) do
local group = privgroups.registered_groups[priv]
if group then
for priv2add, _ in pairs(group.privs) do
ret_privs[priv2add] = true
end
else
ret_privs[priv] = true
end
end
return old_grant(name, grantname .. " " .. minetest.privs_to_string(ret_privs))
end
minetest.register_privilege("privgroups")
minetest.register_chatcommand("group", {
privs = { privgroups = true },
func = function(name, param)
local gname, gprivs = string.match(param, "add ([^ ]+) (.+)")
if gname and gprivs then
local group = privgroups.registered_groups[gname] or { new = true, privs = {} }
for priv, _ in pairs(minetest.string_to_privs(gprivs)) do
group.privs[priv] = true
end
if group.new then
group.new = nil
privgroups.registered_groups[gname] = group
privgroups.save()
return true, "Created group " .. gname .. " with privs: " ..minetest.privs_to_string(group.privs)
else
return true, "Added privs to " .. gname .. ", now has: " ..minetest.privs_to_string(group.privs)
end
end
return false, "Invalid subcommand.\nadd NAME PRIVS\nremove NAME PRIVS\ndelete NAME"
end
})

3
mod.conf Normal file
View File

@ -0,0 +1,3 @@
name = privgroups
description = Allows granting and modifying of privs in bulk
license = LGPLv2.1+