forked from minetest-mods/mesecons
		
	Audit code for possible nil value indexing with unregistered nodes.
This commit is contained in:
		| @@ -241,8 +241,7 @@ function mesecon:update_autoconnect(pos, secondcall, replace_old) | |||||||
| 	end | 	end | ||||||
| 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({ | 	minetest.register_craft({ | ||||||
| 		output = "mesecons:wire_00000000_off 18", | 		output = "mesecons:wire_00000000_off 18", | ||||||
| 		recipe = { | 		recipe = { | ||||||
|   | |||||||
| @@ -1 +1,2 @@ | |||||||
|  | default | ||||||
| mesecons | mesecons | ||||||
|   | |||||||
| @@ -34,31 +34,23 @@ local brules = | |||||||
|  |  | ||||||
| local vertical_updatepos = function (pos) | local vertical_updatepos = function (pos) | ||||||
| 	local node = minetest.env:get_node(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_above = minetest.env:get_node(mesecon:addPosRule(pos, vrules[1])) | ||||||
| 		local node_below = minetest.env:get_node(mesecon:addPosRule(pos, vrules[2])) | 		local node_below = minetest.env:get_node(mesecon:addPosRule(pos, vrules[2])) | ||||||
| 		local namestate = minetest.registered_nodes[node.name].vertical_conductor_state | 		local namestate = minetest.registered_nodes[node.name].vertical_conductor_state | ||||||
|  |  | ||||||
| 		-- above and below: vertical mesecon | 		local above = minetest.registered_nodes[node_above.name] and minetest.registered_nodes[node_above.name].is_vertical_conductor | ||||||
| 		if 	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 | ||||||
| 		and	minetest.registered_nodes[node_below.name].is_vertical_conductor then |  | ||||||
| 			minetest.env:add_node (pos,  |  | ||||||
| 			{name = "mesecons_extrawires:vertical_"..namestate}) |  | ||||||
|  |  | ||||||
| 		-- above only: bottom | 		if above and below then -- above and below: vertical mesecon | ||||||
| 		elseif 		minetest.registered_nodes[node_above.name].is_vertical_conductor | 			minetest.env:add_node(pos, {name = "mesecons_extrawires:vertical_"..namestate}) | ||||||
| 		and 	not 	minetest.registered_nodes[node_below.name].is_vertical_conductor then | 		elseif above and not below then -- above only: bottom | ||||||
| 			minetest.env:add_node (pos,  | 			minetest.env:add_node(pos, {name = "mesecons_extrawires:vertical_bottom_"..namestate}) | ||||||
| 			{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}) | ||||||
| 		-- 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}) |  | ||||||
| 		else -- no vertical wire above, no vertical wire below: use default wire | 		else -- no vertical wire above, no vertical wire below: use default wire | ||||||
| 			minetest.env:add_node (pos,  | 			minetest.env:add_node (pos, {name = "mesecons_extrawires:vertical_"..namestate}) | ||||||
| 			{name = "mesecons_extrawires:vertical_"..namestate}) |  | ||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
| end | end | ||||||
|   | |||||||
| @@ -92,9 +92,11 @@ minetest.register_entity("mesecons_movestones:movestone_entity", { | |||||||
| 		local direction = mesecon:get_movestone_direction(pos) | 		local direction = mesecon:get_movestone_direction(pos) | ||||||
|  |  | ||||||
| 		if not direction then -- no mesecon power | 		if not direction then -- no mesecon power | ||||||
|  | 			--push only solid nodes | ||||||
| 			local name = minetest.env:get_node(pos).name | 			local name = minetest.env:get_node(pos).name | ||||||
| 			if  name ~= "air" and name ~= "ignore" | 			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) | 				mesecon:mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH) | ||||||
| 			end | 			end | ||||||
| 			minetest.env:add_node(pos, {name="mesecons_movestones:movestone"}) | 			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) | 		local direction = mesecon:get_movestone_direction(pos) | ||||||
|  |  | ||||||
| 		if not direction then -- no mesecon power | 		if not direction then -- no mesecon power | ||||||
|  | 			--push only solid nodes | ||||||
| 			local name = minetest.env:get_node(pos).name | 			local name = minetest.env:get_node(pos).name | ||||||
| 			if  name ~= "air" and name ~= "ignore" | 			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) | 				mesecon:mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH) | ||||||
| 				--STICKY | 				--STICKY | ||||||
| 				mesecon:mvps_pull_all(pos, self.lastdir) | 				mesecon:mvps_pull_all(pos, self.lastdir) | ||||||
|   | |||||||
| @@ -48,7 +48,8 @@ function mesecon:mvps_get_stack(pos, dir, maximum) | |||||||
| 		end | 		end | ||||||
|  |  | ||||||
| 		if nn.name == "air" | 		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 | 			break | ||||||
| 		end | 		end | ||||||
|  |  | ||||||
| @@ -106,8 +107,9 @@ function mesecon:mvps_pull_single(pos, dir) -- pos: pos of mvps; direction: dire | |||||||
| 	np = mesecon:addPosRule(pos, dir) | 	np = mesecon:addPosRule(pos, dir) | ||||||
| 	nn = minetest.env:get_node(np) | 	nn = minetest.env:get_node(np) | ||||||
|  |  | ||||||
| 	if minetest.registered_nodes[nn.name].liquidtype == "none" | 	if ((not minetest.registered_nodes[nn.name]) --unregistered node | ||||||
| 	and not mesecon:is_mvps_stopper(nn, {x = -dir.x, y = -dir.y, z = -dir.z}, {{pos = np, node = nn}}, 1) then | 	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() | 		local meta = minetest.env:get_meta(np):to_table() | ||||||
| 		minetest.env:remove_node(np) | 		minetest.env:remove_node(np) | ||||||
| 		minetest.env:add_node(pos, nn) | 		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 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) | 	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 | 	--avoid pulling solid nodes | ||||||
| 	if lnode2.name == "ignore" or lnode2.name == "air" or not(minetest.registered_nodes[lnode2.name].liquidtype == "none") then return end | 	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 | 	repeat | ||||||
| 		lnode2 = minetest.env:get_node(lpos2) | 		lnode2 = minetest.env:get_node(lpos2) | ||||||
| 		minetest.env:add_node(oldpos, {name=lnode2.name}) | 		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.y = lpos2.y-direction.y | ||||||
| 		lpos2.z = lpos2.z-direction.z | 		lpos2.z = lpos2.z-direction.z | ||||||
| 		lnode = minetest.env:get_node(lpos2) | 		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) | 	minetest.env:remove_node(oldpos) | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -151,9 +169,9 @@ function mesecon:mvps_move_objects(pos, dir, nodestack) | |||||||
|  |  | ||||||
| 	-- Move object at tip of stack | 	-- Move object at tip of stack | ||||||
| 	local pushpos = mesecon:addPosRule(pos, -- get pos at tip of stack | 	local pushpos = mesecon:addPosRule(pos, -- get pos at tip of stack | ||||||
| 		{x = dir.x * (#nodestack), | 		{x = dir.x * #nodestack, | ||||||
| 		 y = dir.y * (#nodestack), | 		 y = dir.y * #nodestack, | ||||||
| 		 z = dir.z * (#nodestack)}) | 		 z = dir.z * #nodestack}) | ||||||
|  |  | ||||||
|  |  | ||||||
| 	local objects = minetest.env:get_objects_inside_radius(pushpos, 1) | 	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() | 		local entity = obj:get_luaentity() | ||||||
| 		if not entity or not mesecon:is_mvps_unmov(entity.name) then | 		if not entity or not mesecon:is_mvps_unmov(entity.name) then | ||||||
| 			local np = mesecon:addPosRule(obj:getpos(), dir) | 			local np = mesecon:addPosRule(obj:getpos(), dir) | ||||||
|  |  | ||||||
|  | 			--move only if destination is not solid | ||||||
| 			local nn = minetest.env:get_node(np) | 			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) | 				obj:setpos(np) | ||||||
| 			end | 			end | ||||||
| 		end | 		end | ||||||
|   | |||||||
| @@ -46,7 +46,7 @@ piston_facedir_direction = function (node) | |||||||
| 	return rules[1] | 	return rules[1] | ||||||
| end | end | ||||||
|  |  | ||||||
| piston_get_direction = function (dir, node) | piston_get_direction = function(dir, node) | ||||||
| 	if type(dir) == "function" then | 	if type(dir) == "function" then | ||||||
| 		return dir(node) | 		return dir(node) | ||||||
| 	else | 	else | ||||||
| @@ -54,25 +54,26 @@ piston_get_direction = function (dir, node) | |||||||
| 	end | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| local piston_remove_pusher = function (pos, node) | local piston_remove_pusher = function(pos, node) | ||||||
| 	pistonspec = minetest.registered_nodes[node.name].mesecons_piston | 	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) | 	dir = piston_get_direction(pistonspec.dir, node) | ||||||
| 	local pusherpos = mesecon:addPosRule(pos, dir) | 	local pusherpos = mesecon:addPosRule(pos, dir) | ||||||
| 	local pushername = minetest.env:get_node(pusherpos).name | 	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.env:remove_node(pusherpos) | 	minetest.sound_play("piston_retract", { | ||||||
| 		minetest.sound_play("piston_retract", { | 		pos = pos, | ||||||
| 			pos = pos, | 		max_hear_distance = 20, | ||||||
| 			max_hear_distance = 20, | 		gain = 0.3, | ||||||
| 			gain = 0.3, | 	}) | ||||||
| 		}) | 	nodeupdate(pusherpos) | ||||||
| 		nodeupdate(pusherpos) |  | ||||||
| 	end |  | ||||||
| end | end | ||||||
|  |  | ||||||
| local piston_on = function (pos, node) | local piston_on = function(pos, node) | ||||||
| 	local pistonspec = minetest.registered_nodes[node.name].mesecons_piston | 	local pistonspec = minetest.registered_nodes[node.name].mesecons_piston | ||||||
|  |  | ||||||
| 	local dir = piston_get_direction(pistonspec.dir, node) | 	local dir = piston_get_direction(pistonspec.dir, node) | ||||||
| @@ -91,10 +92,10 @@ local piston_on = function (pos, node) | |||||||
| 	end | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| local piston_off = function (pos, node) | local piston_off = function(pos, node) | ||||||
| 	local pistonspec = minetest.registered_nodes[node.name].mesecons_piston | 	local pistonspec = minetest.registered_nodes[node.name].mesecons_piston | ||||||
| 	minetest.env:add_node(pos, {param2 = node.param2, name = pistonspec.offname}) | 	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 | 	if pistonspec.sticky then | ||||||
| 		dir = piston_get_direction(pistonspec.dir, node) | 		dir = piston_get_direction(pistonspec.dir, node) | ||||||
| @@ -104,7 +105,7 @@ local piston_off = function (pos, node) | |||||||
| 	end | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| local piston_orientate = function (pos, placer) | local piston_orientate = function(pos, placer) | ||||||
| 	-- not placed by player | 	-- not placed by player | ||||||
| 	if not placer then return end | 	if not placer then return end | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user