Guest User

lock

a guest
Jul 9th, 2016
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. --Title: Dark lock 1.4
  2. --Version: Ver. 1.4
  3. --Author: Darkrising (minecraft alias djhannz)
  4. --Platform: ComputerCraft LUA Virtual Machine
  5. --Notes: lock program with lockout period
  6. --config
  7. --numbers are in seconds
  8. dofile("lock/attempt")
  9. dofile("lock/conf")
  10. counter=0
  11. attemptcounter=0
  12. i=0
  13. yes=0
  14.  
  15. function timercheck()
  16. if (istimergoing == 1) then
  17. term.clear() term.setCursorPos(1,1)
  18. print("You attempted to restart the computer!")
  19. print("")
  20. print("Restarting Countdown.")
  21. pcall(sleep,3)
  22. countdown()
  23. end
  24. end
  25. function beforelock()
  26. timercheck()
  27. if counter==numberofattempts then
  28. pcall(countdown)
  29. end
  30. if not (counter == numberofattempts) then
  31. lock()
  32. end
  33. end
  34. function lock()
  35. repeat
  36. status, user=pcall(read,"*")
  37. if user == pass then
  38. term.clear() term.setCursorPos(1,1)
  39. screenwrite("Password Correct",1)
  40. pcall(sleep,1)
  41. term.clear() term.setCursorPos(1,1)
  42. shell.run("shell")
  43. yes=1
  44. end
  45.  
  46. if not (user == pass) then
  47. term.clear() term.setCursorPos(1,1)
  48. attemptcounter=attemptcounter+1
  49. counter=counter+1
  50. screenwrite("Incorrect Attempts: "..attemptcounter,1)
  51. lineacross("-",2)
  52. screenwrite("Wrong Password",3)
  53. print("")
  54. write("Password: ")
  55. i=i+1
  56. beforelock()
  57. end
  58. until yes==1
  59. end
  60. function countdown()
  61. cou=lockoutperiod
  62. repeat
  63. pcall(sleep,1)
  64. term.clear() term.setCursorPos(1,1)
  65. cou=cou-1
  66. screenwrite("Too many wrong attempts",1)
  67. screenwrite("Please wait "..cou.." Seconds before trying again",2)
  68. file = io.open("lock/attempt","w")
  69. file:write("istimergoing = ".. 1)
  70. file:close()
  71. until cou==0
  72. attemptcounter=0
  73. file = io.open("lock/attempt","w")
  74. file:write("istimergoing = ".. 0)
  75. file:close()
  76. istimergoing = 0
  77. counter=0
  78. cou=lockoutperiod
  79. term.clear() term.setCursorPos(1,1)
  80. screenwrite("Incorrect Attempts: "..attemptcounter,1)
  81. lineacross("-",2)
  82. screenwrite("Wrong Password",3)
  83. print("")
  84. write("Password: ")
  85. beforelock()
  86. end
  87. function screenwrite(text, line)
  88. x,y = term.getSize()
  89. l = string.len(text)
  90.  
  91. x = (x/2 - l/2)
  92. term.setCursorPos(x,line)
  93. term.write(text)
  94.  
  95. cx, cy = term.getCursorPos()
  96. term.setCursorPos(1, cy+1)
  97. end
  98. function lineacross(text, line)
  99. x,y = term.getSize()
  100. term.setCursorPos(x,line)
  101.  
  102. for i=1,x do
  103. term.setCursorPos(i,line)
  104. term.write(text)
  105. end
  106. cx, cy = term.getCursorPos()
  107. term.setCursorPos(1, cy+1)
  108. end
  109.  
  110. term.clear() term.setCursorPos(1,1)
  111. lineacross("-",1)
  112. screenwrite("Welcome!",2)
  113. screenwrite("This computer is running Dark lock 1.4",3)
  114. lineacross("-",4)
  115. write("Password: ")
  116. beforelock()
Add Comment
Please, Sign In to add comment