Check that a node is in fact a travelnet or elevator before parsing input data (#40)

* Check that a node is in fact a travelnet or elevator before parsing input data

* Update functions.lua

Check that node_def and node_def.groups exist before using them

Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com>

Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com>
Co-authored-by: Buckaroo Banzai <39065740+BuckarooBanzay@users.noreply.github.com>
This commit is contained in:
Oversword 2022-02-01 18:08:29 +00:00 committed by GitHub
parent d0b8e43254
commit b4b8f12852
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

View File

@ -46,6 +46,9 @@ function travelnet.form_input_handler(player, formname, fields)
if not pos then
return
end
if not travelnet.is_travelnet_or_elevator(pos) then
return
end
-- back button leads back to the main menu
if fields.back and fields.back ~= "" then

View File

@ -80,6 +80,12 @@ function travelnet.is_elevator(node_name)
return node_name == "travelnet:elevator"
end
function travelnet.is_travelnet_or_elevator(pos)
local node = minetest.get_node(pos)
local node_def = minetest.registered_nodes[node.name]
return node_def and node_def.groups and (node_def.groups.travelnet or node_def.groups.elevator)
end
function travelnet.door_is_open(node, opposite_direction)
return string.sub(node.name, -5) == "_open"
-- handle doors that change their facedir

View File

@ -226,9 +226,7 @@ function travelnet.on_receive_fields(pos, _, fields, player)
minetest.load_area(target_pos)
-- check if the box has at the other end has been removed.
local target_node = minetest.get_node(target_pos)
local target_node_def = minetest.registered_nodes[target_node.name]
local has_travelnet_group = target_node_def.groups.travelnet or target_node_def.groups.elevator
local has_travelnet_group = travelnet.is_travelnet_or_elevator(target_pos)
if not has_travelnet_group then
-- provide information necessary to identify the removed box