Advertisement
AnonGaming

Untitled

Mar 8th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. -- packet
  2. -- {"dest" = serverID, "route" = {1,1,1,1}, "msg" = "Message"}
  3.  
  4.  
  5. local route = {}
  6. local nextServ = 0
  7. local hops = 9999
  8.  
  9. rednet.open("right")
  10.  
  11.  
  12. function findroute()
  13.  
  14. local routeMsg = {}
  15. routeMsg["requestRoute"] = true
  16. routeMsg["server"] = true
  17.  
  18. local msg = textutils.seriaslise(routeMsg)
  19.  
  20. rednet.broadcast(msg)
  21. --Resp
  22. -- {"hops" = 1,"server" = true/false, "route" = {}}
  23. for i=1,10 do
  24.  
  25. senderID,message = rednet.receive()
  26.  
  27. if message then
  28.  
  29. local resp = textutils.unseralise(message)
  30.  
  31. if resp then
  32.  
  33. if resp["hops"] and resp["server"] and resp["relay"] and resp["route"] then
  34. print("network Response")
  35. if resp["serer"] == true then
  36. if resp["hops"] < hops then
  37. print("new route detected")
  38. route = resp["route"]
  39. table.insert(route,os.getComputerID())
  40. hops = resp["hops"]
  41. nextServ = senderID
  42. end
  43. end
  44. end
  45. end
  46. end
  47. end
  48. print("Route: ")
  49. print("Hops: "..hops)
  50.  
  51. end
  52.  
  53. findroute()
  54.  
  55.  
  56.  
  57. while true do
  58.  
  59.  
  60. senderID,message = rednet.receive()
  61.  
  62.  
  63. if message then
  64. local messageArr = textutils.unseralise(message)
  65.  
  66. if messageArr then
  67. --Check message formats for cmd
  68. if messageArr["requestRoute"] then
  69. local resp = {}
  70. resp["hops"] = hops
  71. resp["route"] = route
  72. resp["relay"] = true
  73. resp["sever"] = false
  74. local ms = textutils.seriaslise(resp)
  75. rednet.send(senderID,ms)
  76. end
  77.  
  78. end
  79. end
  80.  
  81.  
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement