added privs

This commit is contained in:
tour 2024-01-03 16:42:21 +01:00
parent 2d193d092a
commit 4f1b6808c7
4 changed files with 12 additions and 4 deletions

View File

@ -1,7 +1,7 @@
minetest.register_chatcommand("chat_formspec", {
params = "",
description = "send a player who refuses communication attemps via public chat a formspec to chat",
privs = {},
privs = {[chat_formspec.predefined_priv] = true},
func = function(name, _)
chat_formspec.show_select_predefined(name)
end
@ -10,7 +10,7 @@ minetest.register_chatcommand("chat_formspec", {
minetest.register_chatcommand("chat_formspec_custom", {
params = "",
description = "send a player who refuses communication attemps via public chat a formspec to chat",
privs = {},
privs = {[chat_formspec.create_new_priv] = true},
func = function(name, _)
chat_formspec.show_create_new(name)
end

View File

@ -2,6 +2,9 @@ chat_formspec = {}
local modpath = minetest.get_modpath(minetest.get_current_modname())
chat_formspec.predefined_priv = minetest.settings:get("chat_formspec.predefined_priv") or "server"
chat_formspec.create_new_priv = minetest.settings:get("chat_formspec.create_new_priv") or "server"
dofile(modpath .. "/predefined_formspecs.lua")
dofile(modpath .. "/specs.lua")
dofile(modpath .. "/show-receive.lua")

2
settingtypes.txt Normal file
View File

@ -0,0 +1,2 @@
chat_formspec.predefined_priv (priv to allow the use of all prefedined formspecs) string bailiff
chat_formspec.create_new_priv (priv to allow to create new formspecs) string staff

View File

@ -64,6 +64,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
minetest.chat_send_player(playername, "Please provide a formspec")
return
end
if not minetest.check_player_privs(playername, chat_formspec.create_new_priv) then return true end
chat_formspec.show_to_target(playername, fields.target, fields.c_fs)
return true
end)
@ -71,7 +72,6 @@ end)
-- show predefined formspecs
function chat_formspec.show_predefined(name, id)
local context = get_context(name)
minetest.show_formspec(name, "chat_formspec:predefined", chat_formspec.get_predefined_template(id, nil))
end
@ -86,10 +86,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
context.replacement = fields.change_text_field or ""
minetest.show_formspec(name, "chat_formspec:predefined", chat_formspec.get_predefined_template(context.id, context.replacement))
elseif fields.send then
if not minetest.check_player_privs(name, chat_formspec.predefined_priv) then return true end
local fs = chat_formspec.create_targest_fs(context.id, context.replacement)
clear_context(name)
chat_formspec.show_to_target(name, fields.target, fs)
end
if fields.quit then
clear_context(name)
end
return true
end)