Microstar301

COMPUTERCRAFT / REDNET REPEATER

Mar 2nd, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 0 0
  1. -- Wireless Repeater for ComputerCraft
  2. --
  3. -- HOW TO USE
  4. -- ##########
  5. -- RUN AND TYPE IN THE SIDE OF THE MODEM
  6. -- THE SIDE WILL BE SAVED IN A FILE
  7. -- TO CHANGE THE SIDE AGAIN
  8. -- RUN AND PRESS S WHILE RUNNING
  9. --
  10. -- HOW TO SEND TO THE REPEATER
  11. -- ###########################
  12. -- FIRST SEND THE ADDRESS OF THE RECEIVING COMPUTER TO THE REPEATER
  13. -- THEN SEND THE MESSAGE TO THE REPEATER
  14. --
  15. -- 2014(c) by Microstar301
  16.  
  17. -- VERSION
  18. Vers = "0.46"
  19.  
  20. -- UPDATER
  21. term.clear()
  22. term.setCursorPos(1,1)
  23. write("DOWNLOADING CHECK FILE")
  24. textutils.slowWrite("...")
  25. local response = http.get("http://pastebin.com/raw/mrEBZSdc")
  26. if response then
  27.  print( "Success." )
  28.  local Resp = response.readAll()
  29.  response.close()
  30.  if Resp == Vers then
  31.   TERMA = 1
  32.  else
  33.   TERMA = 0
  34.  end
  35. else
  36.  print( "Failed." )
  37.  TERMA = 1
  38. end
  39.  
  40. if TERMA==0 then
  41.  print("RENEWED")
  42.  shell.run("rm",tostring(shell.getRunningProgram()))
  43.  shell.run("pastebin","get","A768VK2G",tostring(shell.getRunningProgram()))
  44.  os.reboot()
  45. else
  46.  print("UP TO DATE")
  47. end
  48.  
  49. sleep(2)
  50. term.setCursorPos(1,1)
  51. term.clear()
  52. textutils.slowPrint("*** INIZIALIZING REPEATER ***")
  53. print("ID: ",os.getComputerID())
  54. if fs.exists("REPCONF") == true then
  55.  fexists = "1"
  56.  local file = fs.open("REPCONF","r")
  57.  SSIDE = file.readAll()
  58.  file.close()
  59. else
  60.  fexists = "0"
  61.  print(" POSSIBLE SIDES:")
  62.  print(" top, bottom, left, right, back, front")
  63.  print("")
  64.  write(" SET MODEM SIDE : ")
  65.  USERINPUT = read()
  66. end
  67. if USERINPUT == "top" or USERINPUT == "bottom" or USERINPUT == "left" or USERINPUT == "right" or USERINPUT == "front" or USERINPUT == "back" or fexists=="1" then
  68.  if fexists == "0" then
  69.   SSIDE = USERINPUT
  70.   local file = fs.open("/REPCONF","w")
  71.   file.write(USERINPUT)
  72.   file.close()
  73.  end
  74.  rednet.open(SSIDE)
  75. else
  76.  error("SIDE DOES NOT EXIST")
  77. end
  78. local function REPEATER()
  79.  while true do
  80.   sender, address = rednet.receive()
  81.   address = tonumber(address)
  82.   sender, MSG = rednet.receive()
  83.   print("GOT MSG: ",MSG," FROM: ",sender)
  84.   rednet.send(address, MSG)
  85.   print("SENT MSG TO: ", address)
  86.  end
  87. end
  88. local function SETTINGS()
  89.  while true do
  90.   E , K = os.pullEvent("char")
  91.   if K == "s" then
  92.    SET = "1"
  93.    while SET == "1" do
  94.     print("SETUP:")
  95.     print("1. RESET SETTING 2. REBOOT 3. EXIT")
  96.     E, K = os.pullEvent("char")
  97.     if K == "1" then
  98.      if fs.delete("/REPCONF") == nil then
  99.       print("DONE")
  100.      end
  101.     end
  102.     if K == "2" then
  103.      os.reboot()
  104.     end
  105.     if K == "3" then
  106.      SET = "0"
  107.     end
  108.    end
  109.   else
  110.    print("PRESS S FOR SETUP")
  111.   end
  112.  end
  113. end
  114. parallel.waitForAll(SETTINGS,REPEATER)
Advertisement
Add Comment
Please, Sign In to add comment