Exit with error if vports do not exist for any reason (#618)

Make sure node is registered before attempting to access the vports
This commit is contained in:
Oversword 2022-06-16 10:56:49 +01:00 committed by GitHub
parent 0a4a88b1b9
commit c4f9336a26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -470,7 +470,12 @@ local safe_globals = {
local function create_environment(pos, mem, event, itbl, send_warning)
-- Gather variables for the environment
local vports = minetest.registered_nodes[minetest.get_node(pos).name].virtual_portstates
local node_def = minetest.registered_nodes[minetest.get_node(pos).name]
if not node_def then return end
local vports = node_def.virtual_portstates
if not vports then return end
local vports_copy = {}
for k, v in pairs(vports) do vports_copy[k] = v end
local rports = get_real_port_states(pos)
@ -627,6 +632,7 @@ local function run_inner(pos, code, event)
-- Create environment
local itbl = {}
local env = create_environment(pos, mem, event, itbl, send_warning)
if not env then return false, "Env does not exist. Controller has been moved?" end
local success, msg
-- Create the sandbox and execute code