Advertisement
Guest User

ulock

a guest
Nov 25th, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.65 KB | None | 0 0
  1. -- Simple Door Lock
  2. -- Created by DannySMc
  3. -- Version 1.2
  4. -- Platform: Lua Virtual Machine
  5.  
  6. -- Security Method
  7. oldEvent = os.pullEvent
  8. os.pullEvent = os.pullEventRaw
  9.  
  10. -- Check for API
  11. os.loadAPI("uapi")
  12. rednet.open("bottom")
  13.  
  14. -- Installer for Configuration File
  15. if fs.exists(".uLockConf") == false then
  16.   uapi.cs()
  17.   print("Running Installer...")
  18.   sleep(0.5)
  19.   term.setCursorPos(1,3)
  20.   term.write("Redstone output side: ")
  21.   strSide = read()
  22.   term.setCursorPos(1,5)
  23.   term.write("Redstone pulse time: ")
  24.   strPulse = tonumber(read())
  25.   term.setCursorPos(1,7)
  26.   term.write("Terminal Label: ")
  27.   strName = read()
  28.   term.setCursorPos(1,9)
  29.   term.write("Password for unlock: ")
  30.   strPassword = read("*")
  31.   term.setCursorPos(1,11)
  32.   print("What is the name this program is saved as?")
  33.   term.setCursorPos(1,12)
  34.   term.write("Program Name: ")
  35.   strProgName = read()
  36.  
  37.   strPassword = uapi.checksum(strPassword, 1000)
  38.  
  39.   -- Create Configuration File
  40.   uapi.saveConfig({['progName']=strProgName, ['terminalName']=strName, ['redSide']=strSide, ['redPulse']=strPulse, ['lockPassword']=strPassword}, ".uLockConf")
  41.  
  42.   -- Startup File
  43.   term.setCursorPos(1,14)
  44.   print("Do you wish to create a startup file?")
  45.   term.setCursorPos(1,15)
  46.   repeat
  47.   term.write("YES/NO: ")
  48.   startupAnswer = read()
  49.   until ((startupAnswer == "YES") or (startupAnswer == "NO"))
  50.  
  51.   if startupAnswer == "YES" then
  52.     startFile = fs.open("startup", "w")
  53.     startFile.writeLine('os.loadAPI("uapi")')
  54.     startFile.writeLine('config = uapi.loadConfig(".uLockConf")')
  55.     startFile.writeLine("shell.run(config.progName)")
  56.     startFile.close()
  57.     print("Install Complete!")
  58.     sleep(0.5)
  59.   else
  60.     print("Install Complete!")
  61.     sleep(0.5)
  62.   end
  63.  
  64.   print("Rebooting the terminal...")
  65.   sleep(1)
  66.   os.reboot()
  67. end
  68.  
  69. -- Load Configuration File
  70. config = uapi.loadConfig(".uLockConf")
  71.  
  72. -- Password Lock Program
  73. uapi.cs()
  74. uapi.drawBox(1, 51, 1, 5, " ", "white", "cyan")
  75. uapi.drawBox(2, 51, 2, 3, " ", "white", "cyan")
  76. uapi.drawBox(3, 51, 3, 1, " ", "white", "cyan")
  77. uapi.printC(config.terminalName, 3, false, "white", "cyan")
  78. uapi.drawBox(1, 51, 19, 1, " ", "white", "cyan")
  79. uapi.printC("Password Lock (Ver 1.2) -> Created By DannySMc", 19, false, "white", "cyan")
  80. uapi.resetCol()
  81. term.setCursorPos(1, 10)
  82. term.write(">     Password: ")
  83. password = read("*")
  84. password = uapi.checksum(password, 1000)
  85. if password == config.lockPassword then
  86.   term.setCursorPos(1,11)
  87.   print(">     Password Correct!")
  88.   rednet.send(16, "OPEN")
  89.   sleep(0.5)
  90.   os.reboot()
  91. else
  92.   term.setCursorPos(1,11)
  93.   print(">     Password Incorrect!")
  94.   sleep(1.5)
  95.   os.reboot()
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement