Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local shell = require("shell")
- local fs = require("filesystem")
- local args, ops = shell.parse(...)
- local m = component.modem -- get primary modem component
- m.open(1110)
- function split(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- if (args[1] == "find") then
- m.broadcast(1110, "0;0;FINDPARENT;find")
- local _, _, from, _, _, msg = event.pull("modem_message")
- if (msg == "FINDROUTER:ME") then
- m.send(from, 1110, "0;0;FINDPARENT;" .. from)
- local _, _, fr, _, _, msg = event.pull("modem_message")
- if (from == fr) then
- local f = fs.open("/home/qclient.conf", "w")
- f:write(from .. ";" .. msg)
- f:close()
- print("Found and registered at " .. from .. " as " .. msg)
- end
- end
- elseif (ops['p']) then
- local f = fs.open("/home/qclient.conf", "r")
- local fc = f:read(fs.size("/home/qclient.conf"))
- conf = {}
- conf = split(fc, ";")
- m.send(conf[1], 1110, conf[2] .. ";" .. ops['r'] .. ";" .. ops['d'])
- f:close()
- if (ops['l']) then
- local _, _, from, port, _, message = event.pull("modem_message")
- print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement