Advertisement
programcreator

Door Server

Jan 27th, 2015
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. function monReset()
  2.     mon = peripheral.wrap("monitor_0")
  3.     mon.clear()
  4.     mon.setCursorPos(1,1)
  5.     mon.setTextScale(5)
  6. end
  7.  
  8. function rs(state)
  9.     if state == true then
  10.         redstone.setOutput("right",true)
  11.         redstone.setOutput("back",true)
  12.         redstone.setOutput("left",true)
  13.         redstone.setOutput("front",true)
  14.         redstone.setOutput("top",true)
  15.         redstone.setOutput("bottom",true)
  16.     elseif state == false then
  17.         redstone.setOutput("right",false)
  18.         redstone.setOutput("back",false)
  19.         redstone.setOutput("left",false)
  20.         redstone.setOutput("front",false)
  21.         redstone.setOutput("top",false)
  22.         redstone.setOutput("bottom",false)
  23.     end
  24. end
  25.  
  26. thisDoor = "mainDoor"
  27. monReset()
  28. --mon.setTextColor(colors.red)
  29. mon.write("Closed")
  30. permissionOP = "do"
  31. mod = peripheral.wrap("bottom")
  32. modem = peripheral.wrap("left")
  33. modem.open(17)
  34. mod.open(3721)
  35. term.clear()
  36. term.setCursorPos(1,1)
  37. if fs.exists("disk/"..thisDoor) then
  38.     local h = fs.open("disk/"..thisDoor, "r")
  39.     pass = h.readAll()
  40.     h.close()
  41.     print("The passkey is: "..pass)
  42. else
  43.     print("No such file!")
  44. end
  45.  
  46. print("Listening to requests...")
  47. event , side , ch1 , ch2 , msg = os.pullEvent("modem_message")
  48. if side == "left" and msg == pass and ch1 == 17 then
  49.     if permissionOP == "do" then
  50.         rs(true)
  51.         monReset()
  52.         --mon.setTextColor(colours.green)
  53.         mon.write("Open")
  54.         sleep(5)
  55.         monReset()
  56.         --mon.setTextColor(colours.red)
  57.         mon.write("Closed")
  58.         rs(false)
  59.     end
  60. elseif side == "bottom" and msg == "reboot" and ch1 == 3721 then
  61.     shell.run("reboot")
  62. elseif side == "bottom" and msg == "lock" and ch1 == 3721 then
  63.     permissionOP = "g"
  64.     rs(false)
  65. elseif side == "bottom" and msg == "open" and ch1 == 3721 then
  66.     permissionOP = "g"
  67.     rs(true)
  68. elseif side == "bottom" and msg == "reset" and ch1 == 3721 then
  69.     permissionOP = "do"
  70.     rs(false)
  71. else
  72.     print("fail")
  73. end
  74. shell.run("startup")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement