XoXFaby

doors

Nov 1st, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.09 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1,1)
  3. password = ""
  4. passwordC = ""
  5. passwordR = ""
  6. doorSide = ""
  7. doorT = 0
  8. ret = ""
  9.  
  10. if fs.exists("doorconfig") then
  11.     conffile = fs.open("doorconfig", "r")
  12.     password = conffile.readLine() or "123"
  13.     passwordC = conffile.readLine() or "1234"
  14.     passwordR = conffile.readLine() or "12345"
  15.     doorSide = conffile.readLine() or "left"
  16.     doorT = conffile.readLine()
  17.     conffile.close()
  18. else
  19.     conffile = fs.open("doorconfig", "w")
  20.     print("What would you like your password to be?")
  21.     while password == "" do
  22.         password = read()
  23.         if password == "" then print("Your password must not be empty.") end
  24.     end
  25.     term.clear()
  26.     term.setCursorPos(1,1)
  27.     print("What would you like your password to return to XoXOS to be?")
  28.     while passwordC == "" do
  29.         passwordC = read()
  30.         if passwordC == "" then print("Your password must not be empty.") end
  31.         if passwordC == password then print("Can not be the same as door password."); passwordC = "" end
  32.     end
  33.     term.clear()
  34.     term.setCursorPos(1,1)
  35.     print("What would you like your password to reset your config to be?")
  36.     while passwordR == "" do
  37.         passwordR = read()
  38.         if passwordR == "" then print("Your password must not be empty.") end
  39.         if passwordR == password or passwordR == passwordC then print("Can not be the same as the other passwords."); passwordR = "" end
  40.     end
  41.     term.clear()
  42.     term.setCursorPos(1,1)
  43.     print("Which side is the door at? (Options: top, bottom, left, right, front, back")
  44.     while doorSide == "" do
  45.         doorSide = string.lower(read())
  46.         if not (doorSide == "top" or doorSide == "bottom" or doorSide == "left" or doorSide == "right" or doorSide == "front" or doorSide == "back" ) then print("Invalid Side.");doorSide = "" end
  47.     end
  48.     term.clear()
  49.     term.setCursorPos(1,1)
  50.     print("How long should the door stay open? (seconds)")
  51.     while doorT == 0 do
  52.         doorT = read()
  53.         if tonumber(doorT) == nil then print("Not a number");doorT = 0
  54.         elseif tonumber(doorT) <= 0 then print("Number must be bigger than 0.") ; doorT = 0
  55.         else doorT = tonumber(doorT) end
  56.     end
  57.     conffile.writeLine(password)
  58.     conffile.writeLine(passwordC)
  59.     conffile.writeLine(passwordR)
  60.     conffile.writeLine(doorSide)
  61.     conffile.writeLine(doorT)
  62.     conffile.close()
  63. end
  64.  
  65. oldpull = os.pullEvent
  66. os.pullEvent = os.pullEventRaw
  67. rs.setOutput(string.lower(doorSide), false)
  68.  
  69. while true do
  70.     function pwd()
  71.         while true do
  72.             term.clear()
  73.             term.setCursorPos(1,1)
  74.             print("Please enter password:")
  75.             pass = read("*")
  76.             if pass == password then
  77.                 rs.setOutput(string.lower(doorSide), true)
  78.                 print("Password Correct.")
  79.                 sleep(doorT)
  80.                 rs.setOutput(string.lower(doorSide), false)
  81.             elseif pass == passwordC then
  82.                 ret = "st"
  83.                 return
  84.             elseif pass == passwordR then
  85.                 fs.delete("doorconfig")
  86.                 ret = "rs"
  87.                 return
  88.             else
  89.                 print("Password Incorrect.")
  90.                 sleep(5) -- Prevent / slower bruteforcing
  91.             end
  92.         end
  93.     end
  94.     function prot()
  95.         while true do
  96.             if fs.exists("disk/startup") then
  97.                 fs.move("disk/startup", "disk/nicetry")
  98.             end
  99.             sleep(0.1)
  100.         end
  101.     end
  102.     if parallel.waitForAny(pwd, prot) then
  103.         term.clear()
  104.         term.setCursorPos(1,1)
  105.         if ret == "st" then
  106.         return true
  107.         elseif ret == "rs" then
  108.         return false
  109.         end
  110.     end
  111. end
Advertisement
Add Comment
Please, Sign In to add comment