Send SSCSMs in singleplayer and add more APIs to SSCSM sandbox (#72)
This commit is contained in:
parent
fdd2efbbbe
commit
17f710bfd5
@ -176,9 +176,10 @@ end
|
||||
local env = Env:new_empty()
|
||||
|
||||
-- Clone everything
|
||||
env:add_globals("assert", "dump", "dump2", "error", "ipairs", "math",
|
||||
env:add_globals("assert", "chacha", "dump", "dump2", "error", "ipairs", "math",
|
||||
"next", "pairs", "pcall", "select", "setmetatable", "string", "table",
|
||||
"tonumber", "tostring", "type", "vector", "xpcall", "_VERSION", "utf8")
|
||||
"tonumber", "tostring", "type", "vector", "xpcall", "_VERSION", "utf8",
|
||||
"PLATFORM")
|
||||
|
||||
env:set_copy("os", {clock = os.clock, difftime = os.difftime, time = os.time})
|
||||
|
||||
@ -219,6 +220,26 @@ do
|
||||
t[k] = safe_funcs[func] or func
|
||||
end
|
||||
|
||||
local core_settings = core.settings
|
||||
local sub = string.sub
|
||||
local function setting_safe(key)
|
||||
return type(key) == "string" and sub(key, 1, 7) ~= "secure." and
|
||||
key ~= "password"
|
||||
end
|
||||
|
||||
t.settings = {
|
||||
get = function(_, key)
|
||||
if setting_safe(key) then
|
||||
return core_settings:get(key)
|
||||
end
|
||||
end,
|
||||
get_bool = function(_, key, default)
|
||||
if setting_safe(key) then
|
||||
return core_settings:get_bool(key, default)
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
env:set_copy("minetest", t)
|
||||
end
|
||||
|
||||
|
@ -143,15 +143,13 @@ core.register_on_mods_loaded(recalc_csm_order)
|
||||
-- Handle players joining
|
||||
local has_sscsms = {}
|
||||
local mod_channel = core.mod_channel_join("sscsm:exec_pipe")
|
||||
if not core.is_singleplayer() then
|
||||
core.register_on_modchannel_message(function(channel_name, sender, message)
|
||||
core.register_on_modchannel_message(function(channel_name, sender, message)
|
||||
if channel_name ~= "sscsm:exec_pipe" or not sender or
|
||||
not mod_channel:is_writeable() or message ~= "0" or
|
||||
sender:find("\n") or has_sscsms[sender] then
|
||||
return
|
||||
end
|
||||
core.log("action", "[SSCSM] Sending CSMs on request for " .. sender
|
||||
.. "...")
|
||||
core.log("info", "[SSCSM] Sending CSMs on request for " .. sender .. "...")
|
||||
for _, name in ipairs(csm_order) do
|
||||
local def = sscsm.registered_csms[name]
|
||||
if not def.is_enabled_for or def.is_enabled_for(sender) then
|
||||
@ -159,8 +157,7 @@ if not core.is_singleplayer() then
|
||||
.. "\n" .. sscsm.registered_csms[name].code)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Register the SSCSM "builtins"
|
||||
sscsm.register({
|
||||
|
@ -256,6 +256,7 @@ void ScriptApiSecurity::initializeSecurityClient()
|
||||
"_VERSION",
|
||||
"xpcall",
|
||||
// Completely safe libraries
|
||||
"chacha",
|
||||
"coroutine",
|
||||
"string",
|
||||
"table",
|
||||
|
Loading…
x
Reference in New Issue
Block a user