Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("client")
- local component = require("component")
- local computer = require("computer")
- local event = require("event")
- local m = component.modem
- local spaceing = "}|}!"
- local spaceing2 = "!?!?db?!?}{w"
- local self_address
- local connectedToRouter = false
- local router_address = ""
- local test_passed = false
- local prefix = "remote_robots"
- local robots_string
- local isConnected = false
- m.open(5)
- computer.beep()
- function split(s, delimiter)
- result = {};
- for match in (s..delimiter):gmatch("(.-)"..delimiter) do
- table.insert(result, match);
- end
- return result;
- end
- function sendMessage(to, message)
- m.send(router_address, 5, "send" .. spaceing .. to .. spaceing .. message)
- end
- function sendBroadcast(message)
- m.send(router_address, 5, "broadcast" .. spaceing .. message)
- end
- function listenToRouter()
- local _, _, from, port, _, message = event.pull("modem_message")
- if port == 5 then
- command = split(message, spaceing)
- if command[1] == "transmit" then
- if command[2] == "send" then
- if command[4] == "connectionTest" then
- test_passed = true
- end
- end
- if command[2] == "broadcast" then
- end
- end
- if command[1] == "connect" then
- if command[2] == "2" then
- connectToRouter()
- end
- end
- end
- end
- function connectToRouter()
- m.broadcast(5, "connect" .. spaceing)
- local _, _, from, port, _, message = event.pull("modem_message")
- if port == 5 then
- command = split(message, spaceing)
- if command[1] == "connect" then
- if command[2] == "1" then
- router_address = from
- self_address = command[3]
- connectedToRouter = true
- end
- end
- end
- end
- function start()
- print("searching for router...")
- connectToRouter()
- connectToRouter()
- print("Done...")
- print("test connection...")
- sendMessage(self_address, "connectionTest")
- listenToRouter()
- if test_passed == true then
- print("Done... Connection works...")
- print("searching for robots...")
- sendBroadcast(prefix .. spaceing2 .. "searching_for_robot")
- local run = true
- while true do
- local _, _, from, port, _, message = event.pull(10, "modem_message")
- if from == nil then
- run = false
- break
- else
- if port == 5 then
- command = split(message, spaceing)
- if command[3] == self_address then
- else
- print(message)
- end
- end
- end
- end
- print("")
- else
- print("test failed, try again...")
- start()
- end
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement