Fix privilege check when using the PC naming tool

This fix prevents malicious modified clients from using the PC tool
without the necessary privileges.
This commit is contained in:
gpcf 2024-08-11 23:22:36 +02:00
parent 9d7cec6151
commit 46fbf89acf
1 changed files with 10 additions and 5 deletions

View File

@ -22,6 +22,9 @@ function atlatc.pcnaming.resolve_pos(pos, func_name)
error("Invalid position supplied to " .. (func_name or "???")..": " .. dump(pos)) error("Invalid position supplied to " .. (func_name or "???")..": " .. dump(pos))
end end
local pcrename = {}
minetest.register_craftitem("advtrains_luaautomation:pcnaming",{ minetest.register_craftitem("advtrains_luaautomation:pcnaming",{
description = attrans("Passive Component Naming Tool\n\nRight-click to name a passive component."), description = attrans("Passive Component Naming Tool\n\nRight-click to name a passive component."),
groups = {cracky=1}, -- key=name, value=rating; rating=1..3. groups = {cracky=1}, -- key=name, value=rating; rating=1..3.
@ -43,6 +46,7 @@ minetest.register_craftitem("advtrains_luaautomation:pcnaming",{
minetest.record_protection_violation(pos, pname) minetest.record_protection_violation(pos, pname)
return return
end end
local node = advtrains.ndb.get_node(pos) local node = advtrains.ndb.get_node(pos)
local ndef = minetest.registered_nodes[node.name] local ndef = minetest.registered_nodes[node.name]
if node.name and ( if node.name and (
@ -57,16 +61,17 @@ minetest.register_craftitem("advtrains_luaautomation:pcnaming",{
pn=name pn=name
end end
end end
minetest.show_formspec(pname, "atlatc_naming_"..minetest.pos_to_string(pos), "field[pn;Set name of component (empty to clear);"..minetest.formspec_escape(pn).."]") pcrename[pname] = pos
minetest.show_formspec(pname, "atlatc_naming", "field[pn;Set name of component (empty to clear);"..minetest.formspec_escape(pn).."]")
end end
end end
end, end,
}) })
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)
local pts=string.match(formname, "^atlatc_naming_(.+)") if formname == "atlatc_naming" then
if pts then local pname = player:get_player_name()
local pos=minetest.string_to_pos(pts) local pos=pcrename[pname]
if fields.pn then if fields.pn and pos then
--first remove all occurences --first remove all occurences
for name, npos in pairs(atlatc.pcnaming.name_map) do for name, npos in pairs(atlatc.pcnaming.name_map) do
if vector.equals(npos, pos) then if vector.equals(npos, pos) then