SHARE
TWEET

Router.lua

a guest Oct 21st, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local c = require("component")
  2. local event = require("event")
  3. local term = require("term")
  4. local computer = c.computer
  5.  
  6. -- Client settings.
  7. local Log = true
  8. local beep = true
  9. local port = 123
  10.  
  11. if c.isAvailable("modem") then
  12.   m = c.modem
  13.   if m.isWireless() then
  14.     print("wireless modem detected!")
  15.     m.open(port)
  16.   else
  17.     print("Modem is not wireless.. aborting.")
  18.   end
  19. end
  20.  
  21. if c.isAvailable("tunnel") then
  22.   tunnel = c.tunnel
  23.   print("Linked card detected!")
  24. end
  25.  
  26. os.sleep(0.5)
  27.  
  28. term.clear()
  29. local continue = true
  30.  
  31.  
  32. function handler(adr, msg)
  33.  
  34.   if msg == "EXIT 1337" then
  35.     m.send(adr, port, "Router succesfully terminated.")
  36.     m.broadcast(port, "Uh oh! The server has gone offline. please wait and reboot...")
  37.     m.close(123)
  38.     computer.beep(1000,0.1)
  39.     os.sleep(0.1)
  40.     computer.beep(1000,0.1)
  41.     os.sleep(0.1)
  42.     computer.beep(1000,0.1)
  43.     os.sleep(0.1)
  44.     computer.beep(1000,2)
  45.     event.ignore("modem_message")
  46.     os.exit()
  47.   end
  48.  
  49.   if msg == "reactor_off" then
  50.     m.send("0974be2b-4665-48d0-bafe-8424718c701a", port, "off")
  51.     m.send(adr, port, "Reactor toggled off.")
  52.   elseif msg == "reactor on" then
  53.     m.send("0974be2b-4665-58d0-bafe-8424718c701a", port, "on")
  54.     m.send(adr, port, "Reactor toggled on.")
  55.   end
  56. end
  57.  
  58. while true do
  59.  
  60.   _, lAddress, rAddress, _, dist, cmd = event.pull("modem_message")
  61.   if Log then
  62.     print(rAddress:match("...").." | "..cmd)
  63.   end
  64.  
  65.   if beep then
  66.     computer.beep(1750,0.1)
  67.   end
  68.  
  69.   handler(rAddress, cmd)
  70.  
  71.   os.sleep(1)
  72.  
  73. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top