From c9294a4d8a32c430adc0a87d8707fdfc9f6ad8c2 Mon Sep 17 00:00:00 2001 From: kay27 Date: Fri, 22 Jan 2021 21:42:37 +0400 Subject: [PATCH] Fix https://git.minetest.land/Wuzzy/MineClone2/issues/996 Coordinate exploit in signs and chests, sent by @cora --- mods/ITEMS/mcl_chests/init.lua | 34 ++++++++++++++++------------------ mods/ITEMS/mcl_signs/init.lua | 4 +++- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index 492abf787..c3b3df780 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -360,6 +360,15 @@ minetest.register_node("mcl_chests:"..basename, { end, }) +local function close_forms(canonical_basename, pos) + local players = minetest.get_connected_players() + for p=1, #players do + if vector.distance(players[p]:get_pos(), pos) <= 30 then + minetest.close_formspec(players[p]:get_player_name(), "mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z) + end + end +end + minetest.register_node(small_name, { description = desc, _tt_help = tt_help, @@ -483,10 +492,7 @@ minetest.register_node(small_name, { end, on_destruct = function(pos) - local players = minetest.get_connected_players() - for p=1, #players do - minetest.close_formspec(players[p]:get_player_name(), "mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z) - end + close_forms(canonical_basename, pos) end, mesecons = mesecons, on_rotate = simple_rotate, @@ -527,19 +533,15 @@ minetest.register_node(left_name, { return end - local players = minetest.get_connected_players() - for p=1, #players do - minetest.close_formspec(players[p]:get_player_name(), "mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z) - end + close_forms(canonical_basename, pos) local param2 = n.param2 local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "left") if not p or minetest.get_node(p).name ~= "mcl_chests:"..basename.."_right" then return end - for pl=1, #players do - minetest.close_formspec(players[pl]:get_player_name(), "mcl_chests:"..canonical_basename.."_"..p.x.."_"..p.y.."_"..p.z) - end + close_forms(canonical_basename, p) + minetest.swap_node(p, { name = small_name, param2 = param2 }) create_entity(p, small_name, small_textures, param2, false, "default_chest", "mcl_chests_chest") end, @@ -678,19 +680,15 @@ minetest.register_node("mcl_chests:"..basename.."_right", { return end - local players = minetest.get_connected_players() - for p=1, #players do - minetest.close_formspec(players[p]:get_player_name(), "mcl_chests:"..canonical_basename.."_"..pos.x.."_"..pos.y.."_"..pos.z) - end + close_forms(canonical_basename, pos) local param2 = n.param2 local p = mcl_util.get_double_container_neighbor_pos(pos, param2, "right") if not p or minetest.get_node(p).name ~= "mcl_chests:"..basename.."_left" then return end - for pl=1, #players do - minetest.close_formspec(players[pl]:get_player_name(), "mcl_chests:"..canonical_basename.."_"..p.x.."_"..p.y.."_"..p.z) - end + close_forms(canonical_basename, p) + minetest.swap_node(p, { name = small_name, param2 = param2 }) create_entity(p, small_name, small_textures, param2, false, "default_chest", "mcl_chests_chest") local meta = minetest.get_meta(pos) diff --git a/mods/ITEMS/mcl_signs/init.lua b/mods/ITEMS/mcl_signs/init.lua index 441fcbb4c..d21b58242 100644 --- a/mods/ITEMS/mcl_signs/init.lua +++ b/mods/ITEMS/mcl_signs/init.lua @@ -197,7 +197,9 @@ local destruct_sign = function(pos) end local players = minetest.get_connected_players() for p=1, #players do - minetest.close_formspec(players[p]:get_player_name(), "mcl_signs:set_text_"..pos.x.."_"..pos.y.."_"..pos.z) + if vector.distance(players[p]:get_pos(), pos) <= 30 then + minetest.close_formspec(players[p]:get_player_name(), "mcl_signs:set_text_"..pos.x.."_"..pos.y.."_"..pos.z) + end end end