Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- packet
- -- {"dest" = serverID, "route" = {1,1,1,1}, "msg" = "Message"}
- local route = {}
- local nextServ = 0
- local hops = 9999
- rednet.open("right")
- function findroute()
- local routeMsg = {}
- routeMsg["requestRoute"] = true
- routeMsg["server"] = true
- local msg = textutils.seriaslise(routeMsg)
- rednet.broadcast(msg)
- --Resp
- -- {"hops" = 1,"server" = true/false, "route" = {}}
- for i=1,10 do
- senderID,message = rednet.receive()
- if message then
- local resp = textutils.unseralise(message)
- if resp then
- if resp["hops"] and resp["server"] and resp["relay"] and resp["route"] then
- print("network Response")
- if resp["serer"] == true then
- if resp["hops"] < hops then
- print("new route detected")
- route = resp["route"]
- table.insert(route,os.getComputerID())
- hops = resp["hops"]
- nextServ = senderID
- end
- end
- end
- end
- end
- end
- print("Route: ")
- print("Hops: "..hops)
- end
- findroute()
- while true do
- senderID,message = rednet.receive()
- if message then
- local messageArr = textutils.unseralise(message)
- if messageArr then
- --Check message formats for cmd
- if messageArr["requestRoute"] then
- local resp = {}
- resp["hops"] = hops
- resp["route"] = route
- resp["relay"] = true
- resp["sever"] = false
- local ms = textutils.seriaslise(resp)
- rednet.send(senderID,ms)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement