Advertisement
1lann

MAI FIRST EVAR PUBLIC PROGRAM

Jun 18th, 2013
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.18 KB | None | 0 0
  1. -- 1lann's First Ever Publically Available Program
  2. -- Published on Janurary 5 2012
  3. -- Unmodified, Original from: http://www.minecraftforum.net/topic/895297-computercraft-program-library/page__st__60#entry11702697
  4. --[[ Setup instructions:
  5. Setting Up:
  6. 1. Make sure you set the program as the startup program
  7. 2. The current configuration is that the right of the computer will control the vault/safe lock, while the back will control what will happen if a person runs out of login attempts. Guide: When the left side is on, it will open the vault. When the back is on, it will activate the what will happen if a person runs out of login attempts.
  8.  
  9. Setting up the lock:
  10. 1. Run startup
  11. 2. Set a password at prompt
  12. 3. Put stuff in your vault, then lock it]]
  13.  
  14. function readyToLock(n)
  15. write("Ready? ")
  16.  command = read()
  17.  if command == "lock" then
  18.   print "Ok, locking your safe!"
  19.   redstone.setOutput("right", false)
  20. lockSafe()
  21.  end
  22.  print "Sorry I don't understand what you said, try again"
  23.  readyToLock()
  24. end
  25.  
  26. function doLock(n)
  27. num = 0
  28. file = io.open("attempts.dat", "w")
  29. file:write(num)
  30. file:close()
  31. redstone.setOutput("right", false)
  32. redstone.setOutput("back", true)
  33. print "[SYSTEM LOCKDOWN]"
  34. nothing = read()
  35. doLock()
  36. end
  37.  
  38. function lockSafe(n)
  39. term.clear()
  40. file = io.open("password.dat", "w")
  41. file:write(password)
  42. file:close()
  43. file = io.open("attemptset.dat", "w")
  44. file:write(numset)
  45. file:close()
  46. file = io.open("attempts.dat", "w")
  47. file:write(num)
  48. file:close()
  49. if attemptEnabled == true then aten = "true"
  50. end
  51. if attemptEnabled == false then aten = "false"
  52. end
  53. file = io.open("attempten.dat", "w")
  54. file:write(aten)
  55. file:close()
  56. redstone.setOutput("right", false)
  57. print "   [SAFE LOCKED]"
  58. print " [PRESS ENTER TO UNLOCK]"
  59. print "         SCAL v.1"
  60. enter = read()
  61. passwordAuth()
  62. end
  63.  
  64. function passwordAuth(n)
  65. if num < 0.1 then
  66. doLock()
  67. end
  68. print "Enter your password to unlock your safe"
  69. if attemptEnabled == true then
  70. print ("You have " .. num .. " attempts remaining")
  71. end
  72. write "Password: "
  73. entry = read("*")
  74. if entry == password then
  75. print "Password Accepted!"
  76. sleep(2)
  77. num = numset
  78. file = io.open("attempts.dat", "w")
  79. file:write(num)
  80. file:close()
  81. redstone.setOutput("right", true)
  82. launchMenu()
  83. end
  84. print "Password Incorrect!"
  85. sleep(2)
  86. if attemptEnabled == true then
  87. numb = num
  88. num = numb - 1
  89. if num < 0.1 then
  90. doLock()
  91. end
  92. end
  93. lockSafe()
  94. end
  95.  
  96. function changePassword(n)
  97. term.clear()
  98. print "Please enter you current password"
  99. print "Or type back to go back"
  100. write "Current Password: "
  101. cpassword = read("*")
  102. if cpassword == password then
  103. term.clear()
  104. write "New password: "
  105. password = read()
  106. print "New password set!"
  107. file = io.open("password.dat", "w")
  108. file:write(password)
  109. file:close()
  110. sleep(2)
  111. launchMenu()
  112. end
  113. if cpassword == "back" then
  114. launchMenu()
  115. end
  116. print "Password Incorrect! Locking safe"
  117. sleep(3)
  118. lockSafe()
  119. end
  120.  
  121. function changeAttempts(n)
  122. term.clear()
  123. if attemptEnabled == true then
  124. result = "enabled"
  125. end
  126. if attemptEnabled == false then
  127. result = "disabled"
  128. end
  129. print ("Currently, attempts are " .. result)
  130. print ("and you can do " .. numset .. " login attempts")
  131. print "\nType toggle to enable/disable attempts."
  132. print "\nType set to set the number of login attempts one can do"
  133. print "\nType back to go back"
  134. cattempts = read()
  135. if cattempts == "toggle" then
  136. if attemptEnabled == true then
  137. attemptEnabled = false
  138. print "Attempts are now disabled!"
  139. if attemptEnabled == true then aten = "true"
  140. end
  141. if attemptEnabled == false then aten = "false"
  142. end
  143. file = io.open("attempten.dat", "w")
  144. file:write(aten)
  145. file:close()
  146. sleep(3)
  147. launchMenu()
  148. end
  149. if attemptEnabled == false then
  150. attemptEnabled = true
  151. print "Attempts are now enabled!"
  152. if attemptEnabled == true then aten = "true"
  153. end
  154. if attemptEnabled == false then aten = "false"
  155. end
  156. file = io.open("attempten.dat", "w")
  157. file:write(aten)
  158. file:close()
  159. sleep(3)
  160. launchMenu()
  161. end
  162. end
  163. if cattempts == "back" then
  164. launchMenu()
  165. end
  166. if cattempts == "set" then
  167. setAttempts()
  168. end
  169. print "Not a valid option!"
  170. sleep(3)
  171. changeAttempts()
  172. end
  173.  
  174. function setAttempts(n)
  175. term.clear()
  176. print "Enter a number above 0 to set the number of login attempts"
  177. print "Type anything else to go back"
  178. nmbr = read()
  179. entern = tonumber(nmbr)
  180. if entern == nil then
  181. changeAttempts()
  182. end
  183. if entern > 0 then
  184. numset = entern
  185. num = entern
  186. print ("You can now only do " .. numset .. " attempts")
  187. file = io.open("attemptset.dat", "w")
  188. file:write(numset)
  189. file:close()
  190. file = io.open("attempts.dat", "w")
  191. file:write(num)
  192. file:close()
  193. sleep(4)
  194. launchMenu()
  195. end
  196. print "The number must be above 0"
  197. sleep(3)
  198. changeAttempts()
  199. end
  200.  
  201.  
  202. function lockdown(n)
  203. term.clear()
  204. print "This will lockdown your safe and you will have"
  205. print "to break it down. This would also stop the"
  206. print "computer from operating, if you are sure,"
  207. print "enter your password"
  208. print "or type back to go back"
  209. write "Password: "
  210. cpassword = read("*")
  211. if cpassword == password then
  212. term.clear()
  213. doLock()
  214. end
  215. if cpassword == "back" then
  216. launchMenu()
  217. end
  218. print "Password Incorrect! Locking safe"
  219. sleep(3)
  220. lockSafe()
  221. end
  222.  
  223. function launchMenu(n)
  224. term.clear()
  225. file = io.open("password.dat", "w")
  226. file:write(password)
  227. file:close()
  228. file = io.open("attemptset.dat", "w")
  229. file:write(numset)
  230. file:close()
  231. file = io.open("attempts.dat", "w")
  232. file:write(num)
  233. file:close()
  234. if attemptEnabled == true then aten = "true"
  235. end
  236. if attemptEnabled == false then aten = "false"
  237. end
  238. file = io.open("attempten.dat", "w")
  239. file:write(aten)
  240. file:close()
  241. print "Welcome! The actions you can do are:"
  242. print "changepassword - Change your current password"
  243. print "changeattempts - Change the number of login"
  244. print "attempts you can do"
  245. print "lockdown - WARNING: Does a system lockdown"
  246. print "lock - locks your safe"
  247. write "Action: "
  248. action = read()
  249. if action == "lock" then
  250. print "Locking safe..."
  251. sleep(2)
  252. lockSafe()
  253. end
  254. if action == "changepassword" then
  255. changePassword()
  256. end
  257. if action == "changeattempts" then
  258. changeAttempts()
  259. end
  260. if action == "lockdown" then
  261. lockdown()
  262. end
  263. print "Not a valid option!"
  264. sleep(3)
  265. launchMenu()
  266. end
  267.  
  268. passwordexist = false
  269. if fs.exists("password.dat") then
  270. passwordexist = true
  271. file = io.open("password.dat", "r")
  272. password = file:read()
  273. file:close()
  274. file = io.open("attemptset.dat", "r")
  275. numsetz = file:read()
  276. file:close()
  277. numset = tonumber(numsetz)
  278. file = io.open("attempts.dat", "r")
  279. numz = file:read()
  280. file:close()
  281. num = tonumber(numz)
  282. file = io.open("attempten.dat", "r")
  283. aten = file:read()
  284. file:close()
  285. if aten == "true" then attemptEnabled = true
  286. end
  287. if aten == "false" then attemptEnabled = false
  288. end
  289. end
  290. if passwordexist == false then
  291. attemptEnabled = true
  292. num = 4
  293. numset = 4
  294. redstone.setOutput("right", true)
  295. redstone.setOutput("back", false)
  296. print "Oh hey there, I'm SCAL, which means"
  297. print "Secure Computer Authorized Lock"
  298. print "I see you're new here, go ahead and set a new"
  299. write "Password: "
  300. password = read ()
  301. term.clear()
  302. print "Ok you better remember that!"
  303. print "Go ahead and type in \"lock\" when you're ready"
  304. print "to lock your safe"
  305. readyToLock()
  306. end
  307. redstone.setOutput("right", false)
  308. redstone.setOutput("back", false)
  309. passwordAuth()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement