Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local log = print
- local function serializeImpl( t, tTracking )
- local sType = type(t)
- if sType == "table" then
- if tTracking[t] ~= nil then
- error( "Cannot serialize table with recursive entries" )
- end
- tTracking[t] = true
- local result = "{"
- for k,v in pairs(t) do
- result = result..("["..serializeImpl(k, tTracking).."]="..serializeImpl(v, tTracking)..",")
- end
- result = result.."}"
- return result
- elseif sType == "string" then
- return string.format( "%q", t )
- elseif sType == "number" or sType == "boolean" or sType == "nil" then
- return tostring(t)
- elseif sType == "function" then
- log("Warning: Serializer is giving a dummy function")
- return "function() end"
- else
- error( "Cannot serialize type "..sType )
- end
- end
- local function serialize( t )
- local tTracking = {}
- return serializeImpl( t, tTracking )
- end
- local function unserialize( s )
- local func, e = loadstring( "return "..s, "serialize" )
- if not func then
- return s
- else
- setfenv( func, {} )
- return func()
- end
- end
- local function getclientinfo(...)
- local args = {...}
- log("Sending: " .. serialize(args))
- client:send(serialize({...}).."\n")
- local reply,err = client:receive()
- if err then
- log("Error: " .. reply)
- else
- log("Received: " .. reply)
- return unpack(unserialize(reply))
- end
- end
- log("ccemu starting up")
- log("Loading socket")
- local socket = require("socket")
- log("Listening on port 2840")
- local server = assert(socket.bind("*",2840))
- log("Waiting for client")
- client = server:accept()
- log("Client connected")
- function print(...) return getclientinfo("print",...) end
- function write(...) return getclientinfo("write",...) end
- function read(...) return getclientinfo("read",...) end
- function os.execute() print("No fuck you") end
- print("Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio")
- while true do
- write("> ")
- local input = read()
- local funct,err = loadstring(input)
- if type(funct or nil) ~= "function" then
- getclientinfo("term.setTextColor",16384)
- print(err)
- getclientinfo("term.setTextColor",1)
- else
- local data = {pcall(funct)}
- if data[1] == true then
- for i = 2,#data do
- print(data[i])
- end
- else
- getclientinfo("term.setTextColor",16384)
- print(data[2])
- getclientinfo("term.setTextColor",1)
- end
- end
- end
- log("Closing client")
- client:close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement