Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --RSP Client
- side = peripheral.find("modem")
- rednet.open(side)
- local cn = tostring(os.getComputerID())
- local oldPull = os.pullEvent
- rednet.host("rsp",cn)
- local idlist = {rednet.lookup("rspserv")}
- if #idlist == 0 then
- error("No RSP servers found.",0)
- elseif #idlist == 1 then
- idzz = idlist[1]
- else
- print("Computer ID List")
- for i,v in ipairs(idlist) do
- rednet.send(v,{"label"})
- local id, msg = rednet.receive(0.5)
- if type(msg) == "table" then
- if #msg == 1 then
- idlist[i] = tostring(idlist[i]).." ("..msg[1]..")"
- end
- end
- print(idlist[i])
- end
- write("Connect to: ")
- idzz = tonumber(read())
- end
- rednet.send(idzz,{"init",unpack({term.getSize()})})
- function os.pullEvent(f)
- local e = {os.pullEventRaw(f)}
- if e[1] == "terminate" then
- rednet.unhost("rsp",cn)
- rednet.send(idzz,{"dc"})
- rednet.close(side)
- os.pullEvent = oldPull
- error("Terminated",0)
- else
- return unpack(e)
- end
- end
- function loop()
- local id = "msg"
- while true do
- local event, ids, msg = os.pullEvent()
- if event == "rednet_message" and ids == idzz then
- if type(msg) == "table" then
- idz = true
- if msg[1] == "write" then
- term.write(msg[2])
- elseif msg[1] == "pos" then
- term.setCursorPos(msg[2],msg[3])
- elseif msg[1] == "clear" then
- term.clear()
- elseif msg[1] == "tc" then
- term.setTextColor(msg[2])
- elseif msg[1] == "bc" then
- term.setBackgroundColor(msg[3])
- elseif msg[1] == "cl" then
- term.clearLine()
- elseif msg[1] == "bl" then
- term.setCursorBlink(msg[2])
- elseif msg[1] == "scroll" then
- term.scroll(msg[2])
- else
- idz = false
- end
- if idz then
- id = ids
- end
- end
- elseif event == "key" and id ~= "msg" then
- rednet.send(id,{"key",ids})
- elseif event == "char" and id ~= "msg" then
- rednet.send(id,{"char",ids})
- end
- end
- end
- loop()
Advertisement
Add Comment
Please, Sign In to add comment