cleanup of privs; used yl_speak_up.npc_privs_priv instead of npc_master for npc priv maintenance; npc_master REMAINS necessary for executing lua code!

This commit is contained in:
Sokomine 2023-07-24 12:24:35 +02:00
parent 675af7b256
commit 9e09712781
7 changed files with 68 additions and 49 deletions

View File

@ -418,7 +418,8 @@ and usually set to 5.
There are several ways of giving items to the NPC: trade, using an action where the There are several ways of giving items to the NPC: trade, using an action where the
NPC wants a more or less special item, or an effect/result where the NPC just removes NPC wants a more or less special item, or an effect/result where the NPC just removes
the item from the player's inventory and thrashes it (requires `npc_master` priv). the item from the player's inventory and thrashes it (requires `npc_talk_admin` priv
- or whichever priv you set in config.lua as `yl_speak_up.npc_privs_priv`).
Using an action might work in many situations. There may be situations where it Using an action might work in many situations. There may be situations where it
would be far more convenient for the player to just give the items to the NPC and let would be far more convenient for the player to just give the items to the NPC and let
it deal with it. it deal with it.
@ -518,7 +519,7 @@ and
You can also react to or limit normal property changes this way. You can also react to or limit normal property changes this way.
Properties starting with "server" can only be changed by players who have Properties starting with "server" can only be changed by players who have
the npc_master priv. the `npc_talk_admin` priv.
Example for a property: mood of the NPC (raises when treated well, gets Example for a property: mood of the NPC (raises when treated well, gets
lowered when treated badly). lowered when treated badly).

View File

@ -149,6 +149,16 @@ yl_speak_up.player_vars_min_save_time = 60
-- created. This option exists to avoid them. Any small value will do. -- created. This option exists to avoid them. Any small value will do.
yl_speak_up.max_allowed_recursion_depth = 5 yl_speak_up.max_allowed_recursion_depth = 5
-- * set the name of the priv that allows to add, edit and change preconditions, actions and
-- effects listed in yl_speak_up.npc_priv_names in npc_privs.lua
-- * this also allows the player to use the "/npc_talk privs" command to assign these privs
-- to NPC
-- * it does *NOT* include the "precon_exec_lua" and "effect_exec_lua" priv - just
-- "effect_give_item", "effect_take_item" and "effect_move_player"
-- * default: "npc_talk_admin" (but can also be set to "npc_master" or "privs" if you want)
yl_speak_up.npc_privs_priv = "npc_talk_admin"
-- Texts -- Texts
yl_speak_up.message_button_option_exit = "Farewell!" yl_speak_up.message_button_option_exit = "Farewell!"

View File

@ -54,13 +54,13 @@
-- r_value chat message sent to all players -- r_value chat message sent to all players
-- --
-- --
-- give item to player ("give_item"): requires npc_master priv -- give item to player ("give_item"): requires yl_speak_up.npc_privs_priv priv
-- r_value the itemstack that shall be added to the player's inventory -- r_value the itemstack that shall be added to the player's inventory
-- --
-- take item from player's inventory ("take_item"): requires npc_master priv -- take item from player's inventory ("take_item"): requires yl_speak_up.npc_privs_priv priv
-- r_value the itemstack that will be removed from the player's inventory -- r_value the itemstack that will be removed from the player's inventory
-- --
-- move the player to a position ("move"): requires npc_master priv -- move the player to a position ("move"): requires yl_speak_up.npc_privs_priv priv
-- r_value the position where the player shall be moved to -- r_value the position where the player shall be moved to
-- --
-- execute lua code ("function"): requires npc_master priv -- execute lua code ("function"): requires npc_master priv
@ -87,9 +87,12 @@ local check_what = {
"NPC crafts something", -- 6 "NPC crafts something", -- 6
"go to other dialog if the previous effect failed", -- 7 "go to other dialog if the previous effect failed", -- 7
"send a chat message to all players", -- 8 "send a chat message to all players", -- 8
"give item (created out of thin air) to player (requires npc_master priv)", -- 9 "give item (created out of thin air) to player (requires "..
"take item from player and destroy it (requires npc_master priv)", -- 10 tostring(yl_speak_up.npc_privs_priv).." priv)", -- 9
"move the player to a given position (requires npc_master priv)", -- 11 "take item from player and destroy it (requires "..
tostring(yl_speak_up.npc_privs_priv).." priv)", -- 10
"move the player to a given position (requires "..
tostring(yl_speak_up.npc_privs_priv).." priv)", -- 11
"execute Lua code (requires npc_master priv)", -- 12 "execute Lua code (requires npc_master priv)", -- 12
} }
@ -102,8 +105,10 @@ local values_what = {"", "state",
"deal_with_offered_item", "deal_with_offered_item",
-- crafting, handling failure, send chat message to all -- crafting, handling failure, send chat message to all
"craft", "on_failure", "chat_all", "craft", "on_failure", "chat_all",
-- the following require the yl_speak_up.npc_privs_priv priv:
"give_item", "take_item", "move",
-- the following require the npc_master priv: -- the following require the npc_master priv:
"give_item", "take_item", "move", "function", "function",
} }
-- unlike in the preconditions, the "I cannot punch it" option is -- unlike in the preconditions, the "I cannot punch it" option is

View File

@ -88,6 +88,23 @@ yl_speak_up.delete_element_p_or_a_or_e = function(
end end
-- helper function for yl_speak_up.save_element_p_or_a_or_e
yl_speak_up.save_element_check_priv = function(player, priv_name, formspec_input_to, explanation)
local priv_list = {}
priv_list[priv_name] = true
if(not(minetest.check_player_privs(player, priv_list))) then
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:"..formspec_input_to,
formspec = "size[9,2]"..
"label[0.2,0.5;Error: You need the \""..
tostring(priv_name).."\" priv"..
tostring(explanation)..".]"..
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
return false
end
return true
end
-- helper function for yl_speak_up.input_fs_edit_option_related -- helper function for yl_speak_up.input_fs_edit_option_related
yl_speak_up.save_element_p_or_a_or_e = function( yl_speak_up.save_element_p_or_a_or_e = function(
player, pname, n_id, d_id, o_id, x_id, id_prefix, tmp_data_cache, player, pname, n_id, d_id, o_id, x_id, id_prefix, tmp_data_cache,
@ -288,8 +305,8 @@ yl_speak_up.save_element_p_or_a_or_e = function(
v[ id_prefix.."pos" ] = {x = data.block_pos.x, y = data.block_pos.y, z = data.block_pos.z } v[ id_prefix.."pos" ] = {x = data.block_pos.x, y = data.block_pos.y, z = data.block_pos.z }
end end
-- "give item (created out of thin air) to player (requires npc_master priv)", -- 9 -- "give item (created out of thin air) to player (requires yl_speak_up.npc_privs_priv priv)", -- 9
-- "take item from player and destroy it (requires npc_master priv)", -- 10 -- "take item from player and destroy it (requires yl_speak_up.npc_privs_priv priv)", -- 10
elseif(id_prefix == "r_" and (what_type == "give_item" or what_type == "take_item")) then elseif(id_prefix == "r_" and (what_type == "give_item" or what_type == "take_item")) then
if(not(data.inv_stack_name) or data.inv_stack_name == "") then if(not(data.inv_stack_name) or data.inv_stack_name == "") then
yl_speak_up.show_fs(player, "msg", { yl_speak_up.show_fs(player, "msg", {
@ -300,19 +317,15 @@ yl_speak_up.save_element_p_or_a_or_e = function(
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"}) "button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
return return
end end
if(not(minetest.check_player_privs(player, {npc_master=true}))) then local priv_list = {}
yl_speak_up.show_fs(player, "msg", { if(not(yl_speak_up.save_element_check_priv(player, yl_speak_up.npc_privs_priv,
input_to = "yl_speak_up:"..formspec_input_to, formspec_input_to, " in order to set this effect"))) then
formspec = "size[9,2]"..
"label[0.2,0.5;Error: You need the \"npc_master\" priv "..
" in order to set this effect.]"..
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
return return
end end
v[ "r_value" ] = data.inv_stack_name v[ "r_value" ] = data.inv_stack_name
-- "move the player to a given position (requires npc_master priv)", -- 11 -- "move the player to a given position (requires yl_speak_up.npc_privs_priv priv)", -- 11
elseif(what_type == "move" and id_prefix == "r_") then elseif(what_type == "move" and id_prefix == "r_") then
if(not(data.move_to_x) or not(data.move_to_y) or not(data.move_to_z)) then if(not(data.move_to_x) or not(data.move_to_y) or not(data.move_to_z)) then
yl_speak_up.show_fs(player, "msg", { yl_speak_up.show_fs(player, "msg", {
@ -323,13 +336,8 @@ yl_speak_up.save_element_p_or_a_or_e = function(
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"}) "button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
return return
end end
if(not(minetest.check_player_privs(player, {npc_master=true}))) then if(not(yl_speak_up.save_element_check_priv(player, yl_speak_up.npc_privs_priv,
yl_speak_up.show_fs(player, "msg", { formspec_input_to, " in order to set this effect"))) then
input_to = "yl_speak_up:"..formspec_input_to,
formspec = "size[9,2]"..
"label[0.2,0.5;Error: You need the \"npc_master\" priv "..
" in order to set this effect.]"..
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
return return
end end
v[ "r_value" ] = minetest.pos_to_string( v[ "r_value" ] = minetest.pos_to_string(
@ -347,13 +355,8 @@ yl_speak_up.save_element_p_or_a_or_e = function(
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"}) "button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
return return
end end
if(not(minetest.check_player_privs(player, {npc_master=true}))) then if(not(yl_speak_up.save_element_check_priv(player, "npc_master",
yl_speak_up.show_fs(player, "msg", { formspec_input_to, " in order to set this"))) then
input_to = "yl_speak_up:"..formspec_input_to,
formspec = "size[9,2]"..
"label[0.2,0.5;Error: You need the \"npc_master\" priv "..
" in order to set this.]"..
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
return return
end end
v[ id_prefix.."value" ] = data.lua_code v[ id_prefix.."value" ] = data.lua_code
@ -759,8 +762,8 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
and data and data.what and data and data.what
and ((id_prefix == "p_" and ((id_prefix == "p_"
and (what_type == "player_inv" or what_type == "npc_inv" or what_type == "block_inv")) and (what_type == "player_inv" or what_type == "npc_inv" or what_type == "block_inv"))
-- "give item (created out of thin air) to player (requires npc_master priv)", -- 9 -- "give item (created out of thin air) to player (requires yl_speak_up.npc_privs_priv priv)", -- 9
-- "take item from player and destroy it (requires npc_master priv)", -- 10 -- "take item from player and destroy it (requires yl_speak_up.npc_privs_priv priv)", -- 10
or (id_prefix == "r_" or (id_prefix == "r_"
and (what_type == "give_item" or what_type == "take_item" and (what_type == "give_item" or what_type == "take_item"
or what_type == "put_into_block_inv" or what_type == "take_from_block_inv")))) then or what_type == "put_into_block_inv" or what_type == "take_from_block_inv")))) then
@ -878,7 +881,7 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
was_changed = true was_changed = true
end end
-- "move the player to a given position (requires npc_master priv)", -- 11 -- "move the player to a given position (requires yl_speak_up.npc_privs_priv priv)", -- 11
if(fields.move_to_x or fields.move_to_y or fields.move_to_z) then if(fields.move_to_x or fields.move_to_y or fields.move_to_z) then
local dimension = {"x","y","z"} local dimension = {"x","y","z"}
for i, dim in ipairs(dimension) do for i, dim in ipairs(dimension) do
@ -1397,13 +1400,13 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
return yl_speak_up.get_fs_edit_option_effect_deal_with_offered_item( return yl_speak_up.get_fs_edit_option_effect_deal_with_offered_item(
pname, dialog, formspec, data, id_prefix, save_button, e) pname, dialog, formspec, data, id_prefix, save_button, e)
-- "give item (created out of thin air) to player (requires npc_master priv)", -- 9 -- "give item (created out of thin air) to player (requires yl_speak_up.npc_privs_priv priv)", -- 9
-- "take item from player and destroy it (requires npc_master priv)", -- 10 -- "take item from player and destroy it (requires yl_speak_up.npc_privs_priv priv)", -- 10
elseif(data.what and id_prefix == "r_" and (what_type == "give_item" or what_type=="take_item")) then elseif(data.what and id_prefix == "r_" and (what_type == "give_item" or what_type=="take_item")) then
return yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item( return yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item(
pname, dialog, formspec, data, id_prefix, save_button, e) pname, dialog, formspec, data, id_prefix, save_button, e)
-- "move the player to a given position (requires npc_master priv)", -- 11 -- "move the player to a given position (requires yl_speak_up.npc_privs_priv priv)", -- 11
elseif(data.what and id_prefix == "r_" and what_type == "move") then elseif(data.what and id_prefix == "r_" and what_type == "move") then
return yl_speak_up.get_fs_edit_option_effect_move( return yl_speak_up.get_fs_edit_option_effect_move(
pname, dialog, formspec, data, id_prefix, save_button, e) pname, dialog, formspec, data, id_prefix, save_button, e)
@ -1593,7 +1596,7 @@ yl_speak_up.get_fs_edit_option_p_and_e_property = function(
"<b>Note:</b> Properties are useful for NPC that have a generic ".. "<b>Note:</b> Properties are useful for NPC that have a generic "..
"behaviour and may vary their behaviour slightly.\n".. "behaviour and may vary their behaviour slightly.\n"..
"Properties starting with \"server\" can only be set or changed by ".. "Properties starting with \"server\" can only be set or changed by "..
"players with the \"npc_master\" privilege.".. "players with the \"npc_talk_admin\" privilege."..
"</normal>]" "</normal>]"
end end
@ -1947,8 +1950,8 @@ yl_speak_up.get_fs_edit_option_effect_deal_with_offered_item = function(
end end
-- "give item (created out of thin air) to player (requires npc_master priv)", -- 9 -- "give item (created out of thin air) to player (requires yl_speak_up.npc_privs_priv priv)", -- 9
-- "take item from player and destroy it (requires npc_master priv)", -- 10 -- "take item from player and destroy it (requires yl_speak_up.npc_privs_priv priv)", -- 10
yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item = function( yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item = function(
pname, dialog, formspec, data, id_prefix, save_button, e) pname, dialog, formspec, data, id_prefix, save_button, e)
if(e) then if(e) then
@ -1965,7 +1968,7 @@ yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item = function(
return formspec.. return formspec..
"label[0.2,3.0;"..text.."]".. "label[0.2,3.0;"..text.."]"..
"label[0.2,3.5;Note: You can *save* this effect only if you have the ".. "label[0.2,3.5;Note: You can *save* this effect only if you have the "..
"\"npc_master\" priv!]".. "\""..tostring(yl_speak_up.npc_privs_priv).."\" priv!]"..
"label[0.2,8.0;".. "label[0.2,8.0;"..
"And in order to be able to execute it, this NPC\n".. "And in order to be able to execute it, this NPC\n"..
"needs the \""..tostring(priv_name).."\" priv.\n\t".. "needs the \""..tostring(priv_name).."\" priv.\n\t"..
@ -1976,7 +1979,7 @@ yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item = function(
end end
-- "move the player to a given position (requires npc_master priv)", -- 11 -- "move the player to a given position (requires yl_speak_up.npc_privs_priv priv)", -- 11
yl_speak_up.get_fs_edit_option_effect_move = function( yl_speak_up.get_fs_edit_option_effect_move = function(
pname, dialog, formspec, data, id_prefix, save_button, e) pname, dialog, formspec, data, id_prefix, save_button, e)
if(e) then if(e) then
@ -1992,7 +1995,7 @@ yl_speak_up.get_fs_edit_option_effect_move = function(
return formspec.. return formspec..
"label[0.2,3.0;Move the player to this position:]".. "label[0.2,3.0;Move the player to this position:]"..
"label[0.2,3.5;Note: You can *save* this effect only if you have the ".. "label[0.2,3.5;Note: You can *save* this effect only if you have the "..
"\"npc_master\" priv!\n".. "\""..tostring(yl_speak_up.npc_privs_priv).."\" priv!\n"..
"And in order to be able to execute it, this NPC needs the \"".. "And in order to be able to execute it, this NPC needs the \""..
"effect_move_player\" priv.\n\t".. "effect_move_player\" priv.\n\t"..
"Type \"/npc_talk_privs grant "..tostring(yl_speak_up.speak_to[pname].n_id).. "Type \"/npc_talk_privs grant "..tostring(yl_speak_up.speak_to[pname].n_id)..

View File

@ -86,7 +86,7 @@ yl_speak_up.set_npc_property = function(pname, property_name, property_value, re
return "Properties of the type \"self.\" cannot be modified." return "Properties of the type \"self.\" cannot be modified."
end end
-- properites starting with "server" can only be changed or added manually by -- properites starting with "server" can only be changed or added manually by
-- players with the npc_master priv -- players with the npc_talk_admin priv
if(string.sub(property_name, 1, 6) == "server") then if(string.sub(property_name, 1, 6) == "server") then
if(not(reason) or reason ~= "manually" or not(pname) if(not(reason) or reason ~= "manually" or not(pname)
or not(minetest.check_player_privs(pname, {npc_talk_admin=true}))) then or not(minetest.check_player_privs(pname, {npc_talk_admin=true}))) then

View File

@ -108,7 +108,7 @@ yl_speak_up.input_talk = function(player, formname, fields)
if fields.button_start_edit_mode then if fields.button_start_edit_mode then
-- check if this particular NPC is really owned by this player or if the player has global privs -- check if this particular NPC is really owned by this player or if the player has global privs
if(not(yl_speak_up.may_edit_npc(player, n_id))) then if(not(yl_speak_up.may_edit_npc(player, n_id))) then
minetest.chat_send_player(pname, "Sorry. You do not have the npc_talk_owner or npc_master priv.") minetest.chat_send_player(pname, "Sorry. You do not have the npc_talk_owner or npc_talk_master priv.")
return return
end end
-- the staff allows to create multiple target dialogs as result; this makes no sense -- the staff allows to create multiple target dialogs as result; this makes no sense
@ -662,7 +662,7 @@ yl_speak_up.get_fs_talkdialog_add_edit_buttons = function(
text, text, text, text,
true, nil, nil, pname_for_old_fs) true, nil, nil, pname_for_old_fs)
-- Offer to enter edit mode if the player has the npc_talk_owner priv OR is allowed to edit the NPC. -- Offer to enter edit mode if the player has the npc_talk_owner priv OR is allowed to edit the NPC.
-- The npc_master priv allows to edit all NPC. -- The npc_talk_master priv allows to edit all NPC.
if(not(edit_mode)) then if(not(edit_mode)) then
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h, h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
"button_start_edit_mode", "button_start_edit_mode",

View File

@ -38,7 +38,7 @@ minetest.register_privilege("npc_talk_master", npc_talk_master_priv_definition)
local npc_talk_admin_priv_definition = { local npc_talk_admin_priv_definition = {
description="Can do maintenance of NPCs (adding generic, adding server_ properties)", description="Can do maintenance of NPCs (adding generic, adding server_ properties, managing NPC privs)",
give_to_singleplayer = false, give_to_singleplayer = false,
give_to_admin = true, give_to_admin = true,
} }