Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local s
- local host = {}
- local original = {}
- local buffer = {}
- local function loadTermLib()
- for k,v in pairs(term.native()) do
- original[k] = v
- end
- for k,v in pairs(original) do
- if k == "current" or k == "redirect" then
- host[k] = original[k]
- else
- host[k] = function(...)
- local args = {...}
- table.insert(args, 1, k)
- local copy = {}
- for k,v in pairs(args) do
- copy[k] = v
- end
- table.insert(buffer, copy)
- table.remove(args, 1)
- return original[k](unpack(args))
- end
- end
- end
- host["native"] = function() return host end
- end
- local function connect()
- s = Socket.new("http://chuie.io:9000/", Socket.randomId())
- loadTermLib()
- s:on("event", function(msg)
- os.queueEvent(unpack(textutils.unserialize(msg:gsub("\\u003c", "<"):gsub("\\u003e", ">"):gsub("\\u0026", "&"))))
- end)
- term.redirect(host)
- end
- local function flushTerm()
- if #buffer > 0 then
- s:write("term", textutils.serialize(buffer):gsub("\n", ""))
- buffer = {}
- end
- end
- local function errorMonitor()
- while true do
- local e, p1, p2, p3, p4 = os.pullEvent()
- if e == "socket_failure" then
- local f = io.open("/errors", "a")
- f:write("socket_failure: " .. p1 .. "\n")
- f:close()
- end
- flushTerm()
- end
- end
- connect()
- parallel.waitForAny(Socket.run, errorMonitor, function() shell.run("shell") end)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- print("Exited screen share")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement