systox

router...

Oct 9th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. -- Router
  2.  
  3. local timeout = 0.5
  4.  
  5. function start()
  6. rednet.open("top")
  7. local password = 55631
  8.  
  9. local id, message = rednet.receive()
  10.     if (message) ~= nil then
  11.         if message == "SD" then
  12.             if fs.exists("network/"..id) then
  13.                 rednet.send(id,"data")
  14.                 local iid,sid = rednet.receive()
  15.                 local iid,smessage = rednet.receive()
  16.                 rednet.send(tonumber(sid),smessage)
  17.                 local rid,check = rednet.receive(timeout)
  18.                 if not check then
  19.                     print("false")
  20.                     rednet.send(id,"0")
  21.                     start()
  22.                 else
  23.                     print("true")
  24.                     rednet.send(id,"1")
  25.                     start()
  26.                 end
  27.             end
  28.         elseif tonumber(message) == tonumber(password) then
  29.             if fs.exists("network/"..id) then
  30.                 rednet.send(tonumber(id),"connected!")
  31.                 print("Client "..id.." connected!")
  32.                 start()
  33.             else
  34.                 rednet.send(tonumber(id),"Type!")
  35.                 local id, tp = rednet.receive()
  36.                 print(tp)
  37.                 local file = fs.open("network/"..id,"w")
  38.                 file.writeLine(id)
  39.                 file.writeLine(tp)
  40.                 file.close()
  41.                 rednet.send(id,"connected!")
  42.                 print("Client "..id.." connected!")
  43.                 sleep(.2)
  44.                 os.reboot()
  45.             end
  46.         else
  47.             print(message)
  48.             rednet.send(id,"!")
  49.             sleep(5)
  50.             os.reboot()
  51.         end
  52.     end
  53. end
  54.  
  55. start()
Add Comment
Please, Sign In to add comment