forked from minetest-mods/mesecons
Audit code for possible nil value indexing with unregistered nodes.
This commit is contained in:
parent
ec63bd3abf
commit
96011bc718
@ -241,8 +241,7 @@ function mesecon:update_autoconnect(pos, secondcall, replace_old)
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.registered_nodes["default:stone_with_mese"] == nil then
|
||||
|
||||
if not minetest.registered_nodes["default:stone_with_mese"] then --before MESE update, use old recipes
|
||||
minetest.register_craft({
|
||||
output = "mesecons:wire_00000000_off 18",
|
||||
recipe = {
|
||||
|
@ -1 +1,2 @@
|
||||
default
|
||||
mesecons
|
||||
|
@ -34,31 +34,23 @@ local brules =
|
||||
|
||||
local vertical_updatepos = function (pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
if minetest.registered_nodes[node.name].is_vertical_conductor then
|
||||
if minetest.registered_nodes[node.name]
|
||||
and minetest.registered_nodes[node.name].is_vertical_conductor then
|
||||
local node_above = minetest.env:get_node(mesecon:addPosRule(pos, vrules[1]))
|
||||
local node_below = minetest.env:get_node(mesecon:addPosRule(pos, vrules[2]))
|
||||
local namestate = minetest.registered_nodes[node.name].vertical_conductor_state
|
||||
|
||||
-- above and below: vertical mesecon
|
||||
if minetest.registered_nodes[node_above.name].is_vertical_conductor
|
||||
and minetest.registered_nodes[node_below.name].is_vertical_conductor then
|
||||
minetest.env:add_node (pos,
|
||||
{name = "mesecons_extrawires:vertical_"..namestate})
|
||||
local above = minetest.registered_nodes[node_above.name] and minetest.registered_nodes[node_above.name].is_vertical_conductor
|
||||
local below = minetest.registered_nodes[node_below.name] and minetest.registered_nodes[node_below.name].is_vertical_conductor
|
||||
|
||||
-- above only: bottom
|
||||
elseif minetest.registered_nodes[node_above.name].is_vertical_conductor
|
||||
and not minetest.registered_nodes[node_below.name].is_vertical_conductor then
|
||||
minetest.env:add_node (pos,
|
||||
{name = "mesecons_extrawires:vertical_bottom_"..namestate})
|
||||
|
||||
-- below only: top
|
||||
elseif not minetest.registered_nodes[node_above.name].is_vertical_conductor
|
||||
and minetest.registered_nodes[node_below.name].is_vertical_conductor then
|
||||
minetest.env:add_node (pos,
|
||||
{name = "mesecons_extrawires:vertical_top_"..namestate})
|
||||
if above and below then -- above and below: vertical mesecon
|
||||
minetest.env:add_node(pos, {name = "mesecons_extrawires:vertical_"..namestate})
|
||||
elseif above and not below then -- above only: bottom
|
||||
minetest.env:add_node(pos, {name = "mesecons_extrawires:vertical_bottom_"..namestate})
|
||||
elseif not above and below then -- below only: top
|
||||
minetest.env:add_node(pos, {name = "mesecons_extrawires:vertical_top_"..namestate})
|
||||
else -- no vertical wire above, no vertical wire below: use default wire
|
||||
minetest.env:add_node (pos,
|
||||
{name = "mesecons_extrawires:vertical_"..namestate})
|
||||
minetest.env:add_node (pos, {name = "mesecons_extrawires:vertical_"..namestate})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -92,9 +92,11 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
|
||||
local direction = mesecon:get_movestone_direction(pos)
|
||||
|
||||
if not direction then -- no mesecon power
|
||||
--push only solid nodes
|
||||
local name = minetest.env:get_node(pos).name
|
||||
if name ~= "air" and name ~= "ignore"
|
||||
and minetest.registered_nodes[name].liquidtype == "none" then
|
||||
and ((not minetest.registered_nodes[name])
|
||||
or minetest.registered_nodes[name].liquidtype == "none") then
|
||||
mesecon:mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH)
|
||||
end
|
||||
minetest.env:add_node(pos, {name="mesecons_movestones:movestone"})
|
||||
@ -176,9 +178,11 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
|
||||
local direction = mesecon:get_movestone_direction(pos)
|
||||
|
||||
if not direction then -- no mesecon power
|
||||
--push only solid nodes
|
||||
local name = minetest.env:get_node(pos).name
|
||||
if name ~= "air" and name ~= "ignore"
|
||||
and minetest.registered_nodes[name].liquidtype == "none" then
|
||||
and ((not minetest.registered_nodes[name])
|
||||
or minetest.registered_nodes[name].liquidtype == "none") then
|
||||
mesecon:mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH)
|
||||
--STICKY
|
||||
mesecon:mvps_pull_all(pos, self.lastdir)
|
||||
|
@ -48,7 +48,8 @@ function mesecon:mvps_get_stack(pos, dir, maximum)
|
||||
end
|
||||
|
||||
if nn.name == "air"
|
||||
or minetest.registered_nodes[nn.name].liquidtype ~= "none" then --is liquid
|
||||
or (minetest.registered_nodes[nn.name]
|
||||
and minetest.registered_nodes[nn.name].liquidtype ~= "none") then --is liquid
|
||||
break
|
||||
end
|
||||
|
||||
@ -106,8 +107,9 @@ function mesecon:mvps_pull_single(pos, dir) -- pos: pos of mvps; direction: dire
|
||||
np = mesecon:addPosRule(pos, dir)
|
||||
nn = minetest.env:get_node(np)
|
||||
|
||||
if minetest.registered_nodes[nn.name].liquidtype == "none"
|
||||
and not mesecon:is_mvps_stopper(nn, {x = -dir.x, y = -dir.y, z = -dir.z}, {{pos = np, node = nn}}, 1) then
|
||||
if ((not minetest.registered_nodes[nn.name]) --unregistered node
|
||||
or minetest.registered_nodes[nn.name].liquidtype == "none") --non-liquid node
|
||||
and not mesecon:is_mvps_stopper(nn, {x = -dir.x, y = -dir.y, z = -dir.z}, {{pos = np, node = nn}}, 1) then --non-stopper node
|
||||
local meta = minetest.env:get_meta(np):to_table()
|
||||
minetest.env:remove_node(np)
|
||||
minetest.env:add_node(pos, nn)
|
||||
@ -129,10 +131,23 @@ function mesecon:mvps_pull_all(pos, direction) -- pos: pos of mvps; direction: d
|
||||
local lpos2 = {x=pos.x-direction.x*2, y=pos.y-direction.y*2, z=pos.z-direction.z*2} -- 2 away
|
||||
local lnode2 = minetest.env:get_node(lpos2)
|
||||
|
||||
if lnode.name ~= "ignore" and lnode.name ~= "air" and minetest.registered_nodes[lnode.name].liquidtype == "none" then return end
|
||||
if lnode2.name == "ignore" or lnode2.name == "air" or not(minetest.registered_nodes[lnode2.name].liquidtype == "none") then return end
|
||||
--avoid pulling solid nodes
|
||||
if lnode.name ~= "ignore"
|
||||
and lnode.name ~= "air"
|
||||
and ((not minetest.registered_nodes[lnode.name])
|
||||
or minetest.registered_nodes[lnode.name].liquidtype == "none") then
|
||||
return
|
||||
end
|
||||
|
||||
local oldpos = {x=lpos2.x+direction.x, y=lpos2.y+direction.y, z=lpos2.z+direction.z}
|
||||
--avoid pulling empty or liquid nodes
|
||||
if lnode2.name == "ignore"
|
||||
or lnode2.name == "air"
|
||||
or (minetest.registered_nodes[lnode2.name]
|
||||
and minetest.registered_nodes[lnode2.name].liquidtype ~= "none") then
|
||||
return
|
||||
end
|
||||
|
||||
local oldpos = {x=lpos2.x + direction.x, y=lpos2.y + direction.y, z=lpos2.z + direction.z}
|
||||
repeat
|
||||
lnode2 = minetest.env:get_node(lpos2)
|
||||
minetest.env:add_node(oldpos, {name=lnode2.name})
|
||||
@ -142,7 +157,10 @@ function mesecon:mvps_pull_all(pos, direction) -- pos: pos of mvps; direction: d
|
||||
lpos2.y = lpos2.y-direction.y
|
||||
lpos2.z = lpos2.z-direction.z
|
||||
lnode = minetest.env:get_node(lpos2)
|
||||
until lnode.name=="air" or lnode.name=="ignore" or not(minetest.registered_nodes[lnode2.name].liquidtype == "none")
|
||||
until lnode.name == "air"
|
||||
or lnode.name == "ignore"
|
||||
or (minetest.registered_nodes[lnode2.name]
|
||||
and minetest.registered_nodes[lnode2.name].liquidtype ~= "none")
|
||||
minetest.env:remove_node(oldpos)
|
||||
end
|
||||
|
||||
@ -151,9 +169,9 @@ function mesecon:mvps_move_objects(pos, dir, nodestack)
|
||||
|
||||
-- Move object at tip of stack
|
||||
local pushpos = mesecon:addPosRule(pos, -- get pos at tip of stack
|
||||
{x = dir.x * (#nodestack),
|
||||
y = dir.y * (#nodestack),
|
||||
z = dir.z * (#nodestack)})
|
||||
{x = dir.x * #nodestack,
|
||||
y = dir.y * #nodestack,
|
||||
z = dir.z * #nodestack})
|
||||
|
||||
|
||||
local objects = minetest.env:get_objects_inside_radius(pushpos, 1)
|
||||
@ -177,8 +195,11 @@ function mesecon:mvps_move_objects(pos, dir, nodestack)
|
||||
local entity = obj:get_luaentity()
|
||||
if not entity or not mesecon:is_mvps_unmov(entity.name) then
|
||||
local np = mesecon:addPosRule(obj:getpos(), dir)
|
||||
|
||||
--move only if destination is not solid
|
||||
local nn = minetest.env:get_node(np)
|
||||
if not minetest.registered_nodes[nn.name].walkable then
|
||||
if not ((not minetest.registered_nodes[nn.name])
|
||||
or minetest.registered_nodes[nn.name].walkable) then
|
||||
obj:setpos(np)
|
||||
end
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ piston_facedir_direction = function (node)
|
||||
return rules[1]
|
||||
end
|
||||
|
||||
piston_get_direction = function (dir, node)
|
||||
piston_get_direction = function(dir, node)
|
||||
if type(dir) == "function" then
|
||||
return dir(node)
|
||||
else
|
||||
@ -54,14 +54,16 @@ piston_get_direction = function (dir, node)
|
||||
end
|
||||
end
|
||||
|
||||
local piston_remove_pusher = function (pos, node)
|
||||
local piston_remove_pusher = function(pos, node)
|
||||
pistonspec = minetest.registered_nodes[node.name].mesecons_piston
|
||||
if pushername == pistonspec.pusher then --make sure there actually is a pusher (for compatibility reasons mainly)
|
||||
return
|
||||
end
|
||||
|
||||
dir = piston_get_direction(pistonspec.dir, node)
|
||||
local pusherpos = mesecon:addPosRule(pos, dir)
|
||||
local pushername = minetest.env:get_node(pusherpos).name
|
||||
|
||||
if pushername == pistonspec.pusher then --make sure there actually is a pusher (for compatibility reasons mainly)
|
||||
minetest.env:remove_node(pusherpos)
|
||||
minetest.sound_play("piston_retract", {
|
||||
pos = pos,
|
||||
@ -69,10 +71,9 @@ local piston_remove_pusher = function (pos, node)
|
||||
gain = 0.3,
|
||||
})
|
||||
nodeupdate(pusherpos)
|
||||
end
|
||||
end
|
||||
|
||||
local piston_on = function (pos, node)
|
||||
local piston_on = function(pos, node)
|
||||
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
|
||||
|
||||
local dir = piston_get_direction(pistonspec.dir, node)
|
||||
@ -91,10 +92,10 @@ local piston_on = function (pos, node)
|
||||
end
|
||||
end
|
||||
|
||||
local piston_off = function (pos, node)
|
||||
local piston_off = function(pos, node)
|
||||
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
|
||||
minetest.env:add_node(pos, {param2 = node.param2, name = pistonspec.offname})
|
||||
piston_remove_pusher (pos, node)
|
||||
piston_remove_pusher(pos, node)
|
||||
|
||||
if pistonspec.sticky then
|
||||
dir = piston_get_direction(pistonspec.dir, node)
|
||||
@ -104,7 +105,7 @@ local piston_off = function (pos, node)
|
||||
end
|
||||
end
|
||||
|
||||
local piston_orientate = function (pos, placer)
|
||||
local piston_orientate = function(pos, placer)
|
||||
-- not placed by player
|
||||
if not placer then return end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user