RandomShovel

[CC] Startup Lock v1.2

Aug 5th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.32 KB | None | 0 0
  1. --[[  The Magic Config  ]]--
  2.  
  3. local password = "password"
  4. --  Place your password here
  5.  
  6. local master_password = "master password"
  7. --  Place your master password here
  8.  
  9. local lock_door = false
  10. --  This locks doors... dunno what else you could say about that...
  11.  
  12. local max_attempts = 3
  13. --  Set the max number of "guesses" a player can make before it locks
  14. --  Set this to -1 for infinite guesses
  15.  
  16. local case_sensitive = false
  17. --  Set this to true if you want exact passwords
  18. --  If password is "password", "PasSwOrd" will be denied.
  19.  
  20.  
  21. --[[  The Magical Lock  ]]--
  22.  
  23. os.pullEvent = os.pullEventRaw
  24.  
  25.  
  26. --[[  Tables ]]--
  27.  
  28. local tArgs = { ... }
  29.  
  30.  
  31. --[[  Functions  ]]--
  32.  
  33. function cs()
  34.  term.clear()
  35.  term.setCursorPos(1, 1)
  36. end
  37.  
  38. function screen()
  39.  cs()
  40.  local mx, my = term.getSize()
  41.  if term.isColor() then
  42.   term.setTextColor(colors.cyan)
  43.  end
  44.  for a=1, 3 do
  45.   for b=1, mx do
  46.    write("+")
  47.   end
  48.   if a == 1 then
  49.    term.setCursorPos(1, 3)
  50.   elseif a == 2 then
  51.    term.setCursorPos(1, my)
  52.   end
  53.  end
  54.  term.setCursorPos(1, my-1)
  55.  if term.isColor() then
  56.   term.setTextColor(colors.lime)
  57.  end
  58.  write("Attempts Left: ")
  59.  if term.isColor() then
  60.   term.setTextColor(colors.red)
  61.  end
  62.  if attempts then
  63.   if attempts == -1 then
  64.    write("Infinite")
  65.   else
  66.    write(attempts)
  67.   end
  68.  else
  69.   attempts = max_attempts
  70.   write(attempts)
  71.  end
  72.  term.setCursorPos(1, 2)
  73.  if term.isColor() then
  74.   term.setTextColor(colors.lime)
  75.  end
  76.  centerT("RandomSecurity")
  77. end
  78.  
  79. function centerT(text)
  80.  mx, my = term.getSize()
  81.  cx, cy = term.getCursorPos()
  82.  term.setCursorPos(math.floor((mx-string.len(text))/2), cy)
  83.  write(text)
  84. end
  85.  
  86. function split(s,re)
  87.  local i1 = 1
  88.  local ls = {}
  89.  local append = table.insert
  90.  if not re then
  91.   re = '%s+'
  92.  end
  93.  if re == '' then
  94.   return {s}
  95.  end
  96.  while true do
  97.   local i2,i3 = s:find(re,i1)
  98.   if not i2 then
  99.   local last = s:sub(i1)
  100.    if last ~= '' then
  101.     append(ls,last)
  102.    end
  103.    if #ls == 1 and ls[1] == '' then
  104.     return {}
  105.    else
  106.     return ls
  107.    end
  108.   end
  109.   append(ls,s:sub(i1,i2-1))
  110.   i1 = i3+1
  111.  end
  112. end
  113.  
  114. function centerST(text)
  115.  mx, my = term.getSize()
  116.  if not pocket then
  117.   term.setCursorPos(math.ceil((mx-string.len(text))/2), my/2+0.5)
  118.   write(text)
  119.  else
  120.   nString = split(text)
  121.   strHalf = math.floor(#nString / 2)
  122.   local pocketUPos = 0
  123.   for i=1, strHalf do
  124.    pocketUPos = pocketUPos + string.len(nString[i])
  125.   end
  126.   term.setCursorPos(math.floor((mx-pocketUPos)/2), my/2-1)
  127.   for i=1, strHalf do
  128.    write(nString[i].." ")
  129.   end
  130.   local pocketDPos = 1
  131.   for i=strHalf+1, #nString do
  132.    pocketDPos = pocketDPos + string.len(nString[i])
  133.   end
  134.   term.setCursorPos(math.floor((mx-pocketDPos)/2), my/2+1)
  135.   for i=strHalf+1, #nString do
  136.    write(nString[i].." ")
  137.   end
  138.  end
  139. end
  140.  
  141. --[[  Main  ]]--
  142.  
  143. if #tArgs > 0 then
  144.  if string.lower(tArgs[1]) == "save" or "disk" then
  145.   cs()
  146.   textutils.slowPrint("Saving to disk...")
  147.   local sides = rs.getSides()
  148.   for i=1, #sides do
  149.    if disk.isPresent(sides[i]) then
  150.     cs()
  151.     print("Saving file to "..sides[i].." drive")
  152.     fs.copy(shell.getRunningProgram(), "disk/startup")
  153.    end
  154.   end
  155.  end
  156.  sleep(1.5)
  157.  os.reboot()
  158. end
  159.  
  160. screen()
  161. centerST("Press ENTER to continue")
  162. local event, key = os.pullEvent("key")
  163.  
  164. if key then
  165.  while true do
  166.   cs()
  167.   screen()
  168.   term.setCursorPos(1, 5)
  169.   centerT("Enter Password")
  170.   term.setCursorPos(3, 7)
  171.   input = read("*")
  172.   if not case_sensitive then
  173.    input = string.lower(input)
  174.    password = string.lower(password)
  175.    master_password = string.lower(master_password)
  176.   end
  177.   if input == password then
  178.    sleep(1)
  179.    cs()
  180.    screen()
  181.    centerST("Password Accepted!")
  182.    sleep(2)
  183.    if not lock_door then
  184.     cs()
  185.     break
  186.    else
  187.     centerST("Opening door...")
  188.     local sides = rs.getSides()
  189.     for i=1, #sides do
  190.      rs.setOutput(sides[i], true)
  191.      sleep(4)
  192.      rs.setOutput(sides[i], false)
  193.     end
  194.     cs()
  195.    end
  196.   elseif input == master_password and lock_door then
  197.    sleep(1)
  198.    cs()
  199.    screen()
  200.    centerST("Door lock terminated")
  201.    sleep(2)
  202.    cs()
  203.    break
  204.   else
  205.    attempts = attempts - 1
  206.    cs()
  207.    screen()
  208.    term.setCursorPos(1, 5)
  209.    centerT("Password Incorrect!")
  210.    if attempts == 0 then
  211.     cs()
  212.     centerST("You have no attempts left!")
  213.     sleep(10)
  214.     os.reboot()
  215.    end
  216.   end
  217.  end
  218. end
Advertisement
Add Comment
Please, Sign In to add comment