mirevall

doorlock

Apr 12th, 2017 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. -- 1.1.1
  2.  
  3. function yNt()
  4. local n=1
  5. while true do
  6. local x, y=term.getCursorPos()
  7. term.clearLine()
  8. if n==1 then write(">No< Yes") else write (" No >Yes<") end
  9. term.setCursorPos(x, y)
  10. a, b=os.pullEvent("key")
  11. if b==263 and n==2 then n=1 end
  12. if b==262 and n==1 then n=2 end
  13. if b==257 then
  14. print("")
  15. if n==1 then return false end
  16. if n==2 then return true end
  17. end
  18. end
  19. end
  20.  
  21. function Menu()
  22. term.clear()
  23. term.setCursorPos(1,1)
  24. term.setTextColour(colours.green)
  25. write("exit ")
  26. term.setTextColour(colours.white)
  27. print(" : Change nothing")
  28. term.setTextColour(colours.green)
  29. write("settings")
  30. term.setTextColour(colours.white)
  31. print(" : Change passwords and side")
  32. term.setTextColour(colours.green)
  33. write("unistall")
  34. term.setTextColour(colours.white)
  35. print(" : Unistall doorlock")
  36. print(" ")
  37. term.setTextColour(colours.yellow)
  38. write("@doorlock>")
  39. choise = read()
  40.  
  41. if choise ~= "exit" and choise ~= "unistall" and choise ~= "settings" then
  42. term.setTextColour(colours.red)
  43. print("unknown command")
  44. os.sleep(1.5)
  45. os.reboot()
  46. end
  47.  
  48. if choise == "unistall" then
  49. fs.delete("/CB/doorlock")
  50. os.reboot()
  51. end
  52.  
  53. if choise == "exit" then
  54. os.reboot()
  55. end
  56.  
  57. if choise == "settings" then
  58. Settings()
  59. os.sleep(1)
  60. os.reboot()
  61. end
  62. end
  63.  
  64. function Settings()
  65. term.setTextColour(colours.brown)
  66. write("Enter the user password : ")
  67. pass = read("*")
  68. write("Confirm : ")
  69. cpass = read("*")
  70.  
  71. if pass ~= cpass then
  72. term.setTextColour(colours.red)
  73. print("Passwords are not corresponding !")
  74. os.sleep(1.5)
  75. os.reboot()
  76. end
  77.  
  78. term.setTextColour(colours.brown)
  79. write("Enter the admin password : ")
  80. apass = read("*")
  81. write("Confirm : ")
  82. acpass = read("*")
  83.  
  84. if apass ~= acpass then
  85. term.setTextColour(colours.red)
  86. print("Passwords are not corresponding !")
  87. os.sleep(1.5)
  88. os.reboot()
  89. end
  90.  
  91. if apass == pass then
  92. term.setTextColour(colours.red)
  93. print("User and admin passwords are the same !")
  94. os.sleep(1.5)
  95. os.reboot()
  96. end
  97.  
  98. term.setTextColour(colours.white)
  99. write("Side of the door : ")
  100. side = read()
  101.  
  102. if side ~= "bottom" and side ~= "top" and side ~= "back" and side ~= "front" and side ~= "right" and side ~= "left" then
  103. term.setTextColour(colours.red)
  104. print("Side not exists.")
  105. os.sleep(1.5)
  106. os.reboot()
  107. end
  108.  
  109. term.setTextColour(colours.green)
  110. wr = fs.open("/CB/doorlock", "w")
  111. wr.writeLine(pass)
  112. wr.writeLine(apass)
  113. wr.writeLine(side)
  114. wr.close()
  115. pas = fs.open("/CB/password", "w")
  116. pas.write("none")
  117. pas.close()
  118. print("Password sucessfuly set")
  119. os.sleep(2)
  120. end
  121.  
  122. if not fs.exists("/CB/doorlock") then
  123. term.clear()
  124. term.setCursorPos(1,1)
  125. term.setTextColour(colours.red)
  126. print("Do you realy want to use DoorLock ?")
  127. print("This will set DoorLock as startup")
  128. if yNt() == false then
  129. os.reboot()
  130. end
  131. Settings()
  132. end
  133.  
  134.  
  135.  
  136. term.clear()
  137. term.setCursorPos(1,1)
  138. term.setTextColour(colours.blue)
  139. print("DoorLock V. 1.1.1")
  140. print(" ")
  141.  
  142. file = fs.open("/CB/doorlock", "r")
  143. word = file.readLine()
  144. aword = file.readLine()
  145. sid = file.readLine()
  146. file.close()
  147.  
  148. term.setTextColour(colours.brown)
  149. write("Password : ")
  150. passwd = read ("*")
  151.  
  152. if passwd ~= word then
  153. if passwd == aword then
  154. Menu()
  155. os.sleep(1)
  156. os.reboot()
  157. else
  158. term.setTextColour(colours.red)
  159. print("wrong password")
  160. os.sleep(1.5)
  161. os.reboot()
  162. end
  163. end
  164.  
  165. redstone.setOutput(sid, true)
  166. os.sleep(3)
  167. redstone.setOutput(sid, false)
  168. os.reboot()
Add Comment
Please, Sign In to add comment