added function yl_speak_up.may_edit_npc for checking players privs

This commit is contained in:
Sokomine 2021-05-10 19:00:45 +02:00
parent ab1c8de031
commit 052b6ab73f

View File

@ -1056,9 +1056,7 @@ local function get_fs_initial_config(player, n_id, d_id, is_initial_config)
local pname = player:get_player_name()
-- is the player allowed to edit this npc?
if(not(yl_speak_up.npc_owner[ n_id ] == pname
and minetest.check_player_privs(player, {npc_talk_owner=true}))
and not(minetest.check_player_privs(player, {npc_master=true}))) then
if(not(yl_speak_up.may_edit_npc(player, n_id))) then
return get_error_message()
end
@ -1517,9 +1515,7 @@ local function get_fs_talkdialog(player, n_id, d_id)
-- Offer to enter edit mode if the player has the npc_talk_owner priv AND owns the npc.
-- The npc_master priv allows to edit all NPC.
elseif((yl_speak_up.npc_owner[ n_id ] == pname
and minetest.check_player_privs(player, {npc_talk_owner=true}))
or (minetest.check_player_privs(player, {npc_master=true}))) then
elseif(yl_speak_up.may_edit_npc(player, n_id)) then
-- chat option: "I am your owner. I have new orders for you.
h = h + 1
table.insert(formspec, "button_exit[0.5," .. h .. ";53.8,0.9;button_start_edit_mode;]")
@ -2606,9 +2602,7 @@ minetest.register_on_player_receive_fields(
-- the player is trying to save the initial configuration
if(fields.save_initial_config) then
-- is the player allowed to initialize this npc?
if(not(yl_speak_up.npc_owner[ n_id ] == pname
and minetest.check_player_privs(player, {npc_talk_owner=true}))
and not(minetest.check_player_privs(player, {npc_master=true}))) then
if(not(yl_speak_up.may_edit_npc(player, n_id))) then
return
end
if(not(fields.n_npc) or string.len(fields.n_npc) < 2) then
@ -2693,9 +2687,7 @@ minetest.register_on_player_receive_fields(
-- start edit mode (requires npc_talk_owner)
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
if(not(yl_speak_up.npc_owner[ yl_speak_up.speak_to[pname].n_id ] == pname
and minetest.check_player_privs(player, {npc_talk_owner=true}))
and not(minetest.check_player_privs(player, {npc_master=true}))) 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.")
return
end
@ -3424,6 +3416,7 @@ function yl_speak_up.fashion(player, obj)
end
yl_speak_up.update_nametag = function(self)
if self.yl_speak_up.npc_name then
-- the nametag is normal (green)
@ -3473,3 +3466,15 @@ yl_speak_up.set_muted = function(p_name, obj, set_muted)
" on command of "..p_name)
end
end
-- has the player the right privs?
yl_speak_up.may_edit_npc = function(player, n_id)
if(not(player)) then
return false
end
local pname = player:get_player_name()
-- is the player allowed to edit this npc?
return (yl_speak_up.npc_owner[ n_id ] == pname
and minetest.check_player_privs(player, {npc_talk_owner=true})
or minetest.check_player_privs(player, {npc_master=true}))
end