Advertisement
SirSheepe

Untitled

May 14th, 2023 (edited)
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. function isWired(_, o)
  2. return not o.isWireless()
  3. end
  4.  
  5. function isWireless(_, o)
  6. return o.isWireless()
  7. end
  8.  
  9. local remote = peripheral.find("modem", isWireless)
  10.  
  11. if not remote then
  12. print("Please connect a wireless modem to the network")
  13. while not peripheral.find("modem", isWireless) do
  14. os.sleep(1)
  15. end
  16. remote = peripheral.find("modem", isWireless)
  17. end
  18.  
  19. if not settings.get("cc") then
  20. local modem = peripheral.find("modem", isWired)
  21. local drive = peripheral.find("drive")
  22.  
  23. if not modem then
  24. print("Please connect the computer to the registration network")
  25. while not peripheral.find("modem", isWired) do
  26. os.sleep(1)
  27. end
  28. modem = peripheral.find("modem", isWired)
  29. end
  30.  
  31. if not drive then
  32. print("Please connect a drive to the network")
  33. while not peripheral.find("drive") do
  34. os.sleep(1)
  35. end
  36. drive = peripheral.find("drive")
  37. end
  38.  
  39. modem.open(42424)
  40.  
  41. local Scode = "SQTV3REG-S-" .. string.format("%04d", os.getComputerID())
  42. local Fcode = "SQTV3REG-F-" .. string.format("%04d", os.getComputerID())
  43.  
  44. print("waiting connection message")
  45.  
  46. while true do
  47. local msg = select(5, os.pullEvent("modem_message"))
  48.  
  49. if msg == Scode then
  50. modem.transmit(42424, os.getComputerID(), Scode)
  51. end
  52.  
  53. if msg == Fcode then
  54. modem.transmit(42424, os.getComputerID(), Fcode)
  55. settings.load("disk/uuid")
  56. settings.save()
  57. modem.close(42424)
  58. break
  59. end
  60. end
  61. end
  62.  
  63. local uuid = settings.get("uuid")
  64. local tchannel = settings.get("cc")
  65. local cid = settings.get("cid")
  66.  
  67. print("Turtle Loaded with ID " .. uuid)
  68. print("Attempting to connect to the server...")
  69.  
  70. remote.open(tchannel)
  71.  
  72. while not connected do
  73. os.startTimer(5)
  74. remote.transmit(tchannel, tchannel, string.format("SQTV3-%04d-CREQ-%s", cid, uuid))
  75.  
  76. local event, _, channel, reply, msg = os.pullEvent()
  77.  
  78. if event == "modem_message" and msg == string.format("SQTV3-%04d-CON", cid) then
  79. print("Connected")
  80. break
  81. end
  82. end
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement