Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local a=http.get"https://raw.githubusercontent.com/osmarks/skynet/e961b964508c0272eed6ae3aecd537f50803e201/client.lua"local b=fs.open("skynet","w")b.write(a.readAll())a.close()b.close()
- local m = peripheral.find "modem"
- local o = peripheral.find "monitor"
- local skynet = require "./skynet"
- o.setTextScale(0.5)
- m.open(31415)
- term.redirect(o)
- local function ignore(c, rc, ms)
- return c == 666 or c == 999 or rc == 999 or rc == 0x736b or (type(m) == "table" and ms.sProtocol == "zi" or ms.type == "PING" or ms.type == "ACK") or c == "monday"
- end
- local function compact_serialize(x)
- local t = type(x)
- if t == "number" then
- return tostring(x)
- elseif t == "string" then
- return textutils.serialise(x)
- elseif t == "table" then
- local out = "{ "
- for k, v in pairs(x) do
- out = out .. string.format("[%s]=%s, ", compact_serialize(k), compact_serialize(v))
- end
- return out .. "}"
- elseif t == "boolean" then
- return tostring(x)
- else
- error("Unsupported type " .. t)
- end
- end
- local function safe_serialize(m)
- local ok, res = pcall(compact_serialize, m)
- if ok then return res
- else return ("[UNSERIALIZABLE %s: %s]"):format(tostring(m), res) end
- end
- local function tostring_with_default(x)
- if not x then return "[UNKNOWN]"
- else return tostring(x) end
- end
- local function listen_modem()
- while true do
- local e = {os.pullEvent "modem_message"}
- local msg = e[5]
- if type(msg) == "table" then
- if msg.type == "position fix" and not ignore(msg.channel, msg.replyChannel) then
- local p = msg.position
- print("@", p.x, p.y, p.z)
- elseif msg.origin == "VLA by Anavrins" and not ignore(msg.senderChannel, msg.replyChannel, msg.message) then
- print(("%s \16 %s | %s"):format(tostring_with_default(msg.senderChannel), tostring_with_default(msg.replyChannel), tostring_with_default(msg.distance or msg.senderDistance)))
- print(safe_serialize(msg.message))
- end
- end
- end
- end
- local function listen_skynet()
- skynet.open "*"
- while true do
- local channel, message, meta = skynet.receive()
- if not meta.relay and not ignore(channel, nil, message) then
- print(("\187 %s"):format(tostring(channel)))
- print(safe_serialize(message))
- end
- end
- end
- parallel.waitForAll(listen_modem, listen_skynet)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement