Advertisement
DOGGYWOOF

Card Data 2

Jun 16th, 2024 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. -- Path to the ID file
  2. local idPath = "/Disk/ID"
  3.  
  4. -- Function to check if ID matches
  5. local function checkID()
  6. -- Check if the ID file exists
  7. if fs.exists(idPath) then
  8. -- Read the ID from the file
  9. local file = fs.open(idPath, "r")
  10. local idFromFile = file.readAll()
  11. file.close()
  12.  
  13. -- Check if the ID on the bottom drive matches
  14. local bottomDrive = peripheral.wrap("bottom")
  15. local diskID = bottomDrive.getDiskID()
  16.  
  17. if diskID == idFromFile then
  18. -- ID is valid
  19. print("ID is valid")
  20. -- Open the door on the left
  21. peripheral.call("left", "open")
  22.  
  23. -- Display success message on the monitor on the right
  24. local monitor = peripheral.wrap("right")
  25. monitor.clear()
  26. monitor.setCursorPos(1, 1)
  27. monitor.write("Success!")
  28. monitor.setCursorPos(1, 2)
  29. monitor.write("Door opened.")
  30.  
  31. -- Wait for 3 seconds
  32. sleep(3)
  33.  
  34. -- Close the door
  35. peripheral.call("left", "close")
  36.  
  37. -- Eject the disk
  38. bottomDrive.ejectDisk()
  39. else
  40. -- ID is not valid
  41. print("ID is not valid")
  42.  
  43. -- Display error message on the monitor on the right
  44. local monitor = peripheral.wrap("right")
  45. monitor.clear()
  46. monitor.setCursorPos(1, 1)
  47. monitor.write("Error: Invalid ID")
  48. end
  49. else
  50. -- ID file not found
  51. print("ID file not found")
  52.  
  53. -- Display default message on the monitor on the right
  54. local monitor = peripheral.wrap("right")
  55. monitor.clear()
  56. monitor.setCursorPos(1, 1)
  57. monitor.write("DOGGY OS Enterprise Security")
  58. monitor.setCursorPos(1, 2)
  59. monitor.write("Insert valid ID Card")
  60. end
  61. end
  62.  
  63. -- Main loop
  64. while true do
  65. -- Check the ID
  66. checkID()
  67.  
  68. -- Wait for the disk to be inserted again
  69. while not peripheral.wrap("bottom").isDiskPresent() do
  70. sleep(1)
  71. end
  72. end
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement