Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function string:split(s, delimiter)
- local result = {};
- for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
- table.insert(result, match);
- end
- return result;
- end
- function getMsgData(msg)
- local i, j = string.find(msg, ":")
- local tag = string.sub(msg, 1, i - 1)
- local pts = string:split(string.sub(msg, i + 1, -1), ",")
- return tag, pts
- end
- --syslib end
- rednet.open("back")
- function identify()
- local label = os.getComputerLabel()
- if label == nil then
- label="<unnamed>"
- end
- rednet.broadcast("@root:identify," .. label)
- end
- identify()
- local rootId
- while true do
- local id, msg = rednet.receive()
- local tag, pts = getMsgData(msg)
- if tag == "root" then
- if pts[1] == "initialise" then
- rootId = id
- identify()
- elseif pts[1] == "reboot" then os.reboot()
- else print("unknown msg>root-msg: ", msg)
- end
- elseif tag == "action" then
- if pts[1] == "executePastebin" then
- shell.run("delete", "temp")
- shell.run("pastebin", "get", pts[2], "temp")
- shell.run("temp", "" .. id)
- rednet.send(id, "answer:executePastebinFinished," .. pts[2])
- elseif pts[1] == "setStartup" then
- shell.run("delete", "startup")
- local f = fs.open("startup", "w")
- f.write("shell.run(\"delete\",\"unitHandler\")\n")
- f.write("shell.run(\"pastebin\",\"get\",\"" .. pts[2] .. "\",\"unitHandler\")\n")
- f.write("shell.run(\"unitHandler\")\n")
- f.close()
- else print("unknown msg>action-msg: ", msg)
- end
- elseif tag ~= "@root" then
- print("unknown msg-tag: ", msg)
- end
- end
Add Comment
Please, Sign In to add comment