From a780a70d97c92d8c74d2130fd0dbb20ccccebcb0 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sat, 8 May 2021 14:35:57 +0200 Subject: [PATCH] used formspec_escape wherever necessary --- functions.lua | 71 +++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/functions.lua b/functions.lua index 6fa5859..bd9e1b3 100644 --- a/functions.lua +++ b/functions.lua @@ -10,7 +10,6 @@ yl_sokomine["q_apple_explorer"] = {} -- chat option: "That was all. I'm finished with giving you new orders. Remember them!" -- -> ends edit mode -- --- TODO: check if security is ok (minetest.formspec_escape etc) -- TODO: allow owner to mute/unmute npc (would be bad if players can already see what is going -- to happen while the owner creates a long quest) @@ -1239,7 +1238,7 @@ local function get_fs_talkdialog(player, n_id, d_id) -- the first entry will be "New dialog" local n = 1 for k, v in pairs(dialog.n_dialogs) do - dialog_list = dialog_list .. "," .. v.d_id + dialog_list = dialog_list .. "," .. minetest.formspec_escape(v.d_id) -- which one is the current dialog? n = n + 1 d_id_to_dropdown_index[v.d_id] = n @@ -1253,14 +1252,15 @@ local function get_fs_talkdialog(player, n_id, d_id) -- add previous/next buttons for previous/next dialog (sorted as in the dropdown menu); -- this is just an alternate way of walking through the dialogs for k,v in pairs(d_id_to_dropdown_index) do + local ke = minetest.formspec_escape(k) if( v == i-1) then - table.insert(formspec, "button[8.5,4.0;2,0.9;prev_dialog_"..k..";<]") + table.insert(formspec, "button[8.5,4.0;2,0.9;prev_dialog_"..ke..";<]") -- add a tooltip - table.insert(formspec, "tooltip[prev_dialog_" .. k .. ";Go to previous dialog "..k..".]") + table.insert(formspec, "tooltip[prev_dialog_" .. ke .. ";Go to previous dialog "..ke..".]") elseif(v == i+1) then - table.insert(formspec, "button[11,4.0;2,0.9;next_dialog_"..k..";>]") + table.insert(formspec, "button[11,4.0;2,0.9;next_dialog_"..ke..";>]") -- add a tooltip - table.insert(formspec, "tooltip[next_dialog_" .. k .. ";Go to next dialog "..k..".]") + table.insert(formspec, "tooltip[next_dialog_" .. ke .. ";Go to next dialog "..ke..".]") end end -- add a "+" button for creating a new dialog @@ -1292,13 +1292,14 @@ local function get_fs_talkdialog(player, n_id, d_id) end for _, sb_v in pairs(sorted_buttons) do + local oid = minetest.formspec_escape(sb_v.o_id) -- in edit_mode: show all options if edit_mode then h = h + 1 -- add a button "o_:" that leads to an edit formspec for this option - table.insert(formspec, "button[1.8," .. h .. ";2,0.9;edit_option_" .. sb_v.o_id .. ";"..sb_v.o_id..":]") + table.insert(formspec, "button[1.8," .. h .. ";2,0.9;edit_option_" .. oid .. ";"..oid..":]") -- add a tooltip "Edit target dialog, pre(C)onditions and (Ef)fects for option o_" - table.insert(formspec, "tooltip[edit_option_" .. sb_v.o_id .. ";Edit target dialog, pre(C)onditions and (Ef)fects for option "..sb_v.o_id..".]") + table.insert(formspec, "tooltip[edit_option_" .. oid .. ";Edit target dialog, pre(C)onditions and (Ef)fects for option "..oid..".]") -- find the right target dialog for this option (if it exists): local target_dialog = nil @@ -1317,45 +1318,46 @@ local function get_fs_talkdialog(player, n_id, d_id) end if(target_dialog) then -- add a button "-> d_" that leads to the target dialog (if one is set) - table.insert(formspec, "button[8.5," .. h .. ";1,0.9;button_" .. sb_v.o_id .. ";->]") + table.insert(formspec, "button[8.5," .. h .. ";1,0.9;button_" .. oid .. ";->]") -- add a tooltip "Go to target dialog d_" - table.insert(formspec, "tooltip[button_" .. sb_v.o_id .. ";Go to target dialog "..target_dialog.." that will be shown when this option ("..sb_v.o_id..") is selected.]") + table.insert(formspec, "tooltip[button_" .. oid .. ";Go to target dialog "..minetest.formspec_escape(target_dialog).." that will be shown when this option ("..oid..") is selected.]") -- selecting an option this way MUST NOT execute the pre(C)onditions or (Ef)fects! end -- allow to set a new target dialog - table.insert(formspec, "dropdown[3.9,"..h..";4.7,1;d_id_"..sb_v.o_id..";"..dialog_list..";"..(d_id_to_dropdown_index[target_dialog] or "0")..",]") + table.insert(formspec, "dropdown[3.9,"..h..";4.7,1;d_id_"..oid..";"..dialog_list..";"..minetest.formspec_escape(d_id_to_dropdown_index[target_dialog] or "0")..",]") -- add a tooltip "Change target dialog" - table.insert(formspec, "tooltip[3.9,"..h..";4.7,1;Change target dialog for option "..sb_v.o_id..".;#FFFFFF;#000000]") + table.insert(formspec, "tooltip[3.9,"..h..";4.7,1;Change target dialog for option "..oid..".;#FFFFFF;#000000]") -- are there any prerequirements? local prereq = active_dialog.d_options[sb_v.o_id].o_prerequisites if(prereq) then - table.insert(formspec, "button[0.5," .. h .. ";0.5,0.9;conditions_"..sb_v.o_id..";C]") + table.insert(formspec, "button[0.5," .. h .. ";0.5,0.9;conditions_"..oid..";C]") -- label: "There are pre(C)onditions required for showing this option. Display them." - table.insert(formspec, "tooltip[conditions_" .. sb_v.o_id .. ";There are pre(C)onditions required for showing this option. Display them.]") + table.insert(formspec, "tooltip[conditions_" .. oid .. ";There are pre(C)onditions required for showing this option. Display them.]") end if(has_other_results) then - table.insert(formspec, "button[1.1," .. h .. ";0.6,0.9;effects_"..sb_v.o_id..";Ef]") + table.insert(formspec, "button[1.1," .. h .. ";0.6,0.9;effects_"..oid..";Ef]") -- label: "There are further (Ef)fects (apart from switching to a new dialog) set for this option. Display them." - table.insert(formspec, "tooltip[effects_" .. sb_v.o_id .. ";There are further (Ef)fects (apart from switching to a new dialog) set for this option. Display them.]") + table.insert(formspec, "tooltip[effects_" .. oid .. ";There are further (Ef)fects (apart from switching to a new dialog) set for this option. Display them.]") end -- show the actual text for the option - table.insert(formspec, "field[9.4," .. h .. ";44.9,0.9;text_option_" .. sb_v.o_id .. ";;"..sb_v.o_text_when_prerequisites_met.."]") + table.insert(formspec, "field[9.4," .. h .. ";44.9,0.9;text_option_" .. oid .. ";;".. + minetest.formspec_escape(sb_v.o_text_when_prerequisites_met).."]") -- add a tooltip "Edit the text that is displayed on button o_." - table.insert(formspec, "tooltip[text_option_" .. sb_v.o_id .. ";Edit the text that is displayed on button "..sb_v.o_id..".]") + table.insert(formspec, "tooltip[text_option_" .. oid .. ";Edit the text that is displayed on button "..oid..".]") -- normal mode: show an option if the prerequirements (if any are defined) are met elseif allowed[sb_v.o_id] == true then h = h + 1 - table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;button_" .. sb_v.o_id .. ";]") + table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;button_" .. oid .. ";]") table.insert( formspec, - "tooltip[button_" .. sb_v.o_id .. ";" .. sb_v.o_text_when_prerequisites_met .. "]" + "tooltip[button_" .. oid .. ";" .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_met) .. "]" ) local l = h + 0.45 - table.insert(formspec, "label[0.7," .. l .. ";" .. sb_v.o_text_when_prerequisites_met .. "]") + table.insert(formspec, "label[0.7," .. l .. ";" .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_met) .. "]") else if sb_v.o_hide_when_prerequisites_not_met == "true" then else @@ -1364,11 +1366,11 @@ local function get_fs_talkdialog(player, n_id, d_id) sb_v.o_text_when_prerequisites_not_met == "" then h = h + 1 - table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;button_" .. sb_v.o_id .. ";]") + table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;button_" .. oid .. ";]") table.insert( formspec, "tooltip[button_" .. - sb_v.o_id .. + oid .. ";" .. yl_speak_up.message_button_option_prerequisites_not_met_default .. "]" ) local l = h + 0.45 @@ -1384,15 +1386,15 @@ local function get_fs_talkdialog(player, n_id, d_id) sb_v.o_text_when_prerequisites_not_met ~= "" then h = h + 1 - table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;button_" .. sb_v.o_id .. ";]") + table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;button_" .. oid .. ";]") table.insert( formspec, - "tooltip[button_" .. sb_v.o_id .. ";" .. sb_v.o_text_when_prerequisites_not_met .. "]" + "tooltip[button_" .. oid .. ";" .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_not_met) .. "]" ) local l = h + 0.45 table.insert( formspec, - "label[0.7," .. l .. ";" .. sb_v.o_text_when_prerequisites_not_met .. "]" + "label[0.7," .. l .. ";" .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_not_met) .. "]" ) table.insert(formspec, "box[0.5," .. h .. ";53.8,0.9;#BBBBBB]") end @@ -1408,15 +1410,15 @@ local function get_fs_talkdialog(player, n_id, d_id) then -- no grey, but text h = h + 1 - table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;button_" .. sb_v.o_id .. ";]") + table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;button_" .. oid .. ";]") table.insert( formspec, - "tooltip[button_" .. sb_v.o_id .. ";" .. sb_v.o_text_when_prerequisites_not_met .. "]" + "tooltip[button_" .. oid .. ";" .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_not_met) .. "]" ) local l = h + 0.45 table.insert( formspec, - "label[0.7," .. l .. ";" .. sb_v.o_text_when_prerequisites_not_met .. "]" + "label[0.7," .. l .. ";" .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_not_met) .. "]" ) end end @@ -1551,16 +1553,17 @@ local function get_fs_talkdialog(player, n_id, d_id) for _, sb_v in pairs(sorted_buttons) do local end_index = start_index + max_number_of_buttons if counter >= start_index and counter < end_index then + local oid = minetest.formspec_escape(sb_v.o_id) if allowed[sb_v.o_id] == true then h = h + 1 table.insert( formspec, "button[1," .. - h .. ";44,0.9;button_" .. sb_v.o_id .. ";" .. sb_v.o_text_when_prerequisites_met .. "]" + h .. ";44,0.9;button_" .. oid .. ";" .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_met) .. "]" ) table.insert( formspec, - "tooltip[button_" .. sb_v.o_id .. ";" .. sb_v.o_text_when_prerequisites_met .. "]" + "tooltip[button_" .. oid .. ";" .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_met) .. "]" ) else if sb_v.o_hide_when_prerequisites_not_met == "true" then @@ -1594,7 +1597,7 @@ local function get_fs_talkdialog(player, n_id, d_id) h .. ";" .. yl_speak_up.message_button_option_prerequisites_not_met_default .. - " : " .. sb_v.o_text_when_prerequisites_not_met .. "]" + " : " .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_not_met) .. "]" ) end if @@ -1613,12 +1616,12 @@ local function get_fs_talkdialog(player, n_id, d_id) "button[1," .. h .. ";44,0.9;button_" .. - sb_v.o_id .. ";" .. sb_v.o_text_when_prerequisites_not_met .. "]" + oid .. ";" .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_not_met) .. "]" ) table.insert( formspec, "tooltip[button_" .. - sb_v.o_id .. ";" .. sb_v.o_text_when_prerequisites_not_met .. "]" + oid .. ";" .. minetest.formspec_escape(sb_v.o_text_when_prerequisites_not_met) .. "]" ) end end