summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2022-01-01 23:12:36 -0600
committercheapie <no-email-for-you@example.com>2022-01-01 23:14:11 -0600
commit4f6673a3e39c3dcd7677c4a271531e863cb46975 (patch)
tree582e751e796578423fcf9d596c90d53a4b1a23a0
parentf6f8e8aac5cadb16199aad2489c8bc37be03a8ca (diff)
downloadmesecons-4f6673a3e39c3dcd7677c4a271531e863cb46975.tar
mesecons-4f6673a3e39c3dcd7677c4a271531e863cb46975.tar.gz
mesecons-4f6673a3e39c3dcd7677c4a271531e863cb46975.tar.bz2
mesecons-4f6673a3e39c3dcd7677c4a271531e863cb46975.tar.xz
mesecons-4f6673a3e39c3dcd7677c4a271531e863cb46975.zip
Allow LuaC programs to opt into lightweight interrupts even if the server isn't using them
This adds a third parameter to interrupt(time,iid,lightweight) - if "lightweight" is true, then the interrupt will be lightweight even if the server's configuration doesn't force it to be.
-rw-r--r--mesecons_luacontroller/init.lua19
1 files changed, 15 insertions, 4 deletions
diff --git a/mesecons_luacontroller/init.lua b/mesecons_luacontroller/init.lua
index 0d9753f..90374b4 100644
--- a/mesecons_luacontroller/init.lua
+++ b/mesecons_luacontroller/init.lua
@@ -366,7 +366,8 @@ local get_interrupt
if mesecon.setting("luacontroller_lightweight_interrupts", false) then
-- use node timer
get_interrupt = function(pos, itbl, send_warning)
- return (function(time, iid)
+ return (function(time, iid, lightweight)
+ if lightweight == false then send_warning("Interrupts are always lightweight on this server") end
if type(time) ~= "nil" and type(time) ~= "number" then error("Delay must be a number to set or nil to cancel") end
if type(time) == "number" and time < 1 then send_warning("Delays of less than 1 second are not allowed on this server") end
local ok, warn = validate_iid(iid)
@@ -379,15 +380,25 @@ else
-- itbl: Flat table of functions to run after sandbox cleanup, used to prevent various security hazards
get_interrupt = function(pos, itbl, send_warning)
-- iid = interrupt id
- return function (time, iid)
+ return function (time, iid, lightweight)
-- NOTE: This runs within string metatable sandbox, so don't *rely* on anything of the form (""):y
-- Hence the values get moved out. Should take less time than original, so totally compatible
- if type(time) ~= "number" then error("Delay must be a number") end
+ if lightweight then
+ if type(time) ~= "nil" and type(time) ~= "number" then error("Delay must be a number to set or nil to cancel") end
+ else
+ if type(time) ~= "number" then error("Delay must be a number") end
+ end
table.insert(itbl, function ()
-- Outside string metatable sandbox, can safely run this now
local luac_id = minetest.get_meta(pos):get_int("luac_id")
local ok, warn = validate_iid(iid)
- if ok then mesecon.queue:add_action(pos, "lc_interrupt", {luac_id, iid}, time, iid, 1) end
+ if ok then
+ if lightweight then
+ set_nodetimer_interrupt(pos,time,iid)
+ else
+ mesecon.queue:add_action(pos, "lc_interrupt", {luac_id, iid}, time, iid, 1)
+ end
+ end
if warn then send_warning(warn) end
end)
end