Advertisement
Theshadow989

[Keycard] Door

Aug 23rd, 2021 (edited)
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.55 KB | None | 0 0
  1. --[[
  2. Security Card Access
  3. Written by TheShadow989
  4. ]]--
  5.  
  6. local _seclevel = 3 -- Card Level Allowed Access (1 - Lowest and 5 = highest)
  7. local sides = {"top", "bottom", "left", "right", "front", "back"}
  8. local _monitor, _drive= "", ""
  9. local mon = peripheral.wrap("monitor_0")
  10.  
  11. --[[
  12. Card Passwords
  13. Level 1: 5BCE0FE268FA6B4B801FB1082F185B90000AB1258202C653F64B4F037D172336
  14. Level 2: 9EA9B8889DE45FA608597CB52B79749E2E32C97EF6481CFE6B315655933331F8
  15. Level 3: 387B8E8247FE18FFFA39FA2DFCDFB555633A0585B6F7D781FFCDA8E82AA20232
  16. Level 4: 51B92A735030BDBF16100656E55D9F98D0CACA269266782E2F3E850894898BEE
  17. Level 5: 7B48A89633F05F625E007F3287CD3858584503B9972578791D321851C9D44E51
  18.  
  19. Insert a floppy disk into the computer and enter this command 'edit disk/password' and paste one the strings above inside the disk.
  20. ]]--
  21. local _passwords = {"5BCE0FE268FA6B4B801FB1082F185B90000AB1258202C653F64B4F037D172336", "9EA9B8889DE45FA608597CB52B79749E2E32C97EF6481CFE6B315655933331F8", "387B8E8247FE18FFFA39FA2DFCDFB555633A0585B6F7D781FFCDA8E82AA20232", "51B92A735030BDBF16100656E55D9F98D0CACA269266782E2F3E850894898BEE", "7B48A89633F05F625E007F3287CD3858584503B9972578791D321851C9D44E51"}
  22.  
  23. for i=1, #sides do
  24.     if peripheral.isPresent(sides[i]) then
  25.         if peripheral.getType(sides[i]) == "monitor" then
  26.             _monitor = sides[i]
  27.         end
  28.         if peripheral.getType(sides[i]) == "drive" then
  29.             _drive = sides[i]
  30.         end
  31.     end
  32. end
  33.  
  34. term.clear()
  35. term.setCursorPos(1,1)
  36.  
  37. mon.clear()
  38. mon.setBackgroundColor(colors.black)
  39. mon.setTextColor(colors.white)
  40. mon.setCursorPos(2,3)
  41. mon.write("Ready")
  42.  
  43. while true do
  44.     event, side = os.pullEvent()
  45.  
  46.     if event == "disk" then
  47.         local time = os.time()
  48.         local formattedTime = textutils.formatTime(time, false)
  49.         local data
  50.         local check = "blank"
  51.         local passwordMatch = -1
  52.         if fs.exists("disk/password") then            
  53.             local file = fs.open("disk/password","r")  
  54.             data = file.readLine()                  
  55.             file.close()
  56.             for i=1, #_passwords do
  57.                 if data == _passwords[i] then
  58.                     passwordMatch = i
  59.                 end
  60.             end
  61.  
  62.             if passwordMatch == -1 then
  63.                 mon.setBackgroundColor(colors.red)
  64.                 mon.setTextColor(colors.black)
  65.                 mon.clear()
  66.                 mon.setCursorPos(1,2)
  67.                 mon.write("Access")
  68.                 mon.setCursorPos(1,4)
  69.                 mon.write("Denied")
  70.  
  71.                 print("- Invalid Password. TIME:" .. formattedTime)
  72.  
  73.                 -- PASSWORD INVALID (DO STUFF HERE)
  74.                
  75.             elseif passwordMatch < _seclevel then
  76.                 mon.setBackgroundColor(colors.red)
  77.                 mon.setTextColor(colors.black)
  78.                 mon.clear()
  79.                 mon.setCursorPos(1,2)
  80.                 mon.write("Higher")
  81.                 mon.setCursorPos(1,3)
  82.                 mon.write("Access")
  83.                 mon.setCursorPos(1,4)
  84.                 mon.write("Required")
  85.  
  86.                 print("- Low Access. TIME:" .. formattedTime)
  87.  
  88.                 -- NEED HIGHER ACCESS CARD (DO STUFF HERE)
  89.  
  90.             elseif passwordMatch >= _seclevel then
  91.                 mon.setBackgroundColor(colors.green)
  92.                 mon.setTextColor(colors.black)
  93.                 mon.clear()
  94.                 mon.setCursorPos(1,2)
  95.                 mon.write("Access")
  96.                 mon.setCursorPos(1,4)
  97.                 mon.write("Granted")
  98.  
  99.                 print("- Access granted. Level " .. passwordMatch .. " card. TIME:" .. formattedTime)
  100.  
  101.                 -- ACCESS GRANTED (DO STUFF HERE)
  102.  
  103.     peripheral.call(_drive, "ejectDisk")
  104.    
  105.     sleep(2)
  106.  
  107.     redstone.setOutput("bottom", true)
  108.     sleep(8)
  109.     redstone.setOutput("bottom", false)
  110.  
  111.             end
  112.         else
  113.             mon.setBackgroundColor(colors.red)
  114.             mon.setTextColor(colors.black)
  115.             mon.clear()
  116.             mon.setCursorPos(1,2)
  117.             mon.write("Invalid")
  118.             mon.setCursorPos(1,3)
  119.             mon.write("Access")
  120.             mon.setCursorPos(1,4)
  121.             mon.write("Card")
  122.  
  123.             print("- Unformatted Card. TIME:" .. formattedTime)
  124.  
  125.             -- INVALID ACCESS CARD (DO STUFF HERE)
  126.         end
  127.  
  128.         peripheral.call(_drive, "ejectDisk")
  129.  
  130.         os.sleep(4)
  131.     end
  132.  
  133.     mon.setBackgroundColor(colors.black)
  134.     mon.setTextColor(colors.white)
  135.     mon.clear()
  136.     mon.setCursorPos(2,3)
  137.     mon.write("Ready")
  138.  
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement