Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sandbox = {}
- local apilist = {"textutils", "pairs", "ipairs", "error", "sleep", "tostring"}
- --
- local target_ = ""
- local sender_ = ""
- local tmpout = ""
- local function echo(s)
- _G['irc_api.lua'].echo(s)
- end
- sandboxedprint = function(...)
- local outputs = {...}
- for _, v in ipairs(outputs) do
- if tmpout ~= "" then tmpout = tmpout..", " end
- tmpout = tmpout..tostring(v)
- end
- end
- function resetSandbox()
- sandbox = {}
- --Creating own os copy
- sandbox.os = {version = os.version, time = os.time}
- --Creating own fs copy
- sandbox.fs = {}
- sandbox.fs.list = function(path)
- return fs.list("/sandbox/"..path)
- end
- sandbox.fs.exists = function(path)
- return fs.exists("/sandbox/"..path)
- end
- sandbox.fs.isDir = function(path)
- return fs.isDir("/sandbox/"..path)
- end
- sandbox.fs.isReadOnly = function(path)
- return fs.isReadOnly("/sandbox/"..path)
- end
- sandbox.fs.getName = function(path)
- return fs.getName("/sandbox/"..path)
- end
- sandbox.fs.getDrive = function(path)
- return fs.getDrive("/sandbox/"..path)
- end
- sandbox.fs.getSize = function(path)
- return fs.getSize("/sandbox/"..path)
- end
- sandbox.fs.makeDir = function(path)
- return fs.makeDir("/sandbox/"..path)
- end
- sandbox.fs.move = function(from, tp)
- return fs.move("/sandbox/"..from, "/sandbox/"..to)
- end
- sandbox.fs.copy = function(from, tp)
- return fs.copy("/sandbox/"..from, "/sandbox/"..to)
- end
- sandbox.fs.delete = function(path)
- return fs.delete("/sandbox/"..path)
- end
- sandbox.fs.combine = function(from, tp)
- return fs.combine(from, to)
- end
- sandbox.fs.open = function(path, mode)
- return fs.open("/sandbox/"..path, mode)
- end
- --Creating own rednet copy
- --local rednet_ = {receiver = receive, open = open
- -- Actual reset
- for k, v in ipairs(apilist) do
- sandbox[v] = _G[v]
- end
- --echo(tostring(sandboxedprint))
- sandbox.print = sandboxedprint
- sandbox._G = sandbox
- end
- function runlua(code, target, sender)
- echo(code)
- echo(target)
- echo(sender)
- f, m = loadstring(code)
- target_ = target
- sender_ = sender
- if not f then
- sandboxedprint(m)
- else
- setfenv(f, sandbox)
- --local p = print
- --rawset(_G, "print", sandboxedprint)
- local s, m = pcall(function() parallel.waitForAny(f, function() sleep(5) error("Time limit exceeded") end) end)
- --rawset(_G, "print", p)
- if not s then tmpout = m end
- end
- local ret = tmpout
- tmpout = ""
- return ret
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement