Skip to content

Commit

Permalink
Escape formspec content of boards and steles
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklp09 committed Jul 27, 2023
1 parent 1f8e99c commit bd59f7f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
6 changes: 5 additions & 1 deletion boards/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ dofile(boards.path.."/font_tinycurs.lua")

local function set_formspec(pos)
local meta = minetest.get_meta(pos)
local display_text = minetest.formspec_escape(meta:get_string("display_text"))
meta:set_string("formspec",
"size[6,4]"..default.gui_bg..default.gui_bg_img..default.gui_slots..
"textarea[0.5,0.7;5.5,3;display_text;"..FS("Text")..";${display_text}]"..
"textarea[0.5,0.7;5.5,3;display_text;"..FS("Text")..";" .. display_text .. "]"..
"button_exit[3,3.5;2,1;ok;"..FS("Write").."]"..
"button_exit[1,3.5;2,1;wipe;"..FS("Wipe").."]")
end
Expand Down Expand Up @@ -83,6 +84,9 @@ local models = {
set_formspec(pos)
display_api.update_entities(pos)
end,
on_rightclick = function(pos)
set_formspec(pos)
end,
on_receive_fields = on_receive_fields,
},
},
Expand Down
27 changes: 18 additions & 9 deletions steles/nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ for i, material in ipairs(steles.materials) do
local parts = material:split(":")
groups.display_api = 1

local function set_formspec(pos)
local meta = minetest.get_meta(pos)
local display_text = minetest.formspec_escape(meta:get_string("display_text"))
meta:set_string("formspec", string.format([=[
size[6,4]%s%s%s
textarea[0.5,0.7;5.5,2;display_text;%s;%s]
button[1,3;2,1;font;%s]
button_exit[3,3;2,1;ok;%s]]=],
default.gui_bg, default.gui_bg_img, default.gui_slots,
FS("Displayed text (3 lines max)"),
display_text,
FS("Font"), FS("Write")))
end

minetest.register_node("steles:"..parts[2].."_stele", {
description = steles.materials_desc[i],
sunlight_propagates = true,
Expand Down Expand Up @@ -62,17 +76,12 @@ for i, material in ipairs(steles.materials) do
return display_api.on_place(itemstack, placer, pointed_thing)
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", string.format([=[
size[6,4]%s%s%s
textarea[0.5,0.7;5.5,2;display_text;%s;${display_text}]
button[1,3;2,1;font;%s]
button_exit[3,3;2,1;ok;%s]]=],
default.gui_bg, default.gui_bg_img, default.gui_slots,
FS("Displayed text (3 lines max)"),
FS("Font"), FS("Write")))
set_formspec(pos)
display_api.on_construct(pos)
end,
on_rightclick = function(pos)
set_formspec(pos)
end,
on_destruct = display_api.on_destruct,
on_rotate = display_api.on_rotate,
on_receive_fields = function(pos, formname, fields, player)
Expand Down

0 comments on commit bd59f7f

Please sign in to comment.