Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---@class command
- ---@field key string
- ---@field arguments rednet.transmittable[]
- local COMMAND_PROTOCOL = "controller.command"
- local REQUEST_PROTOCOL = "controller.request"
- local RESPONSE_PROTOCOL = "controller.response"
- local connectedTurtles = {}
- local function split(str, sep)
- sep = sep or "%s"
- local t = {}
- for s in string.gmatch(str, "[^" .. sep .. "]+") do
- table.insert(t, s)
- end
- return t
- end
- local function receiver()
- while true do
- local id, message = rednet.receive(REQUEST_PROTOCOL)
- if message == "connect" then
- rednet.send(id, true, RESPONSE_PROTOCOL)
- table.insert(connectedTurtles, id)
- end
- end
- end
- local function main()
- term.clear()
- term.setCursorPos(1, 1)
- peripheral.find("modem", rednet.open)
- while true do
- term.setTextColor(colors.yellow)
- write("$ ")
- term.setTextColor(colors.white)
- local input = read()
- local args = split(input)
- rednet.broadcast({ key = table.remove(args, 1), arguments = args }, COMMAND_PROTOCOL)
- end
- end
- parallel.waitForAll(main, receiver)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement