Advertisement
gravitowl

GraviNet Setup

Mar 9th, 2021 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. local w, h = term.getSize()
  2.  
  3. function printCentered(text, y)
  4. term.setCursorPos(w/2 - #text/2, y)
  5. term.write(text)
  6. end
  7.  
  8. term.clear()
  9.  
  10. term.setCursorPos(1, 1)
  11. print(string.rep("-", w))
  12. printCentered("Welcome to the GraviNet Setup wizard.", 2)
  13. printCentered("This wizard will guide you", 3)
  14. printCentered("through connecting to GraviNet.", 4)
  15. print(string.rep("-", w))
  16. os.sleep(0.5)
  17. print("\n")
  18. print("Which side is your modem on?")
  19. print("[top, bottom, back, front, left, right]")
  20. local side = read()
  21. print("Modem at side: "..side)
  22. os.sleep(0.5)
  23. print("Attempting to connect to GraviNet, please wait.")
  24.  
  25. rednet.open(side)
  26. rednet.broadcast("$HELLO")
  27. local id, message
  28.  
  29. while true do
  30. id, message = rednet.receive(5)
  31. if not message then
  32. error("No network routers nearby, couldn't connect to GraviNet.")
  33. return
  34. end
  35.  
  36. if message == "$HELLO" then break end
  37. end
  38.  
  39. print("A network has been located!")
  40.  
  41. rednet.send(id, "$ADDME")
  42. while true do
  43. id, message = rednet.receive(5)
  44.  
  45. if not message then
  46. error("Connecting failed... Network did not accept your computer.")
  47. return
  48. end
  49. if message == "$ACK" then break end
  50. end
  51.  
  52. print("Succesfully connected to GraviNet. Updating your preferences...")
  53. local pref = fs.open("gravinet/client/pref", "w")
  54. pref.write(textutils.serialise({
  55. routerId = id,
  56. side = side
  57. }))
  58. pref.close()
  59.  
  60. os.sleep(0.5)
  61. term.clear()
  62. term.setCursorPos(1,1)
  63. print("A preference file has been created in the directory gravinet/pref . Do not delete this file!")
  64. os.sleep(0.5)
  65. print("Connection to network succesful, shutting down wizard...")
  66. os.sleep(1)
  67. rednet.close(side)
  68. term.clear()
  69. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement