Advertisement
DOGGYWOOF

Untitled

Jun 17th, 2024 (edited)
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. local cardDriveSide = "bottom" -- side where the card reader is connected
  2. local monitorSide = "right" -- side where the monitor is connected
  3. local doorSide = "left" -- side where the door is connected
  4.  
  5. -- Wrap peripherals
  6. local cardDrive = peripheral.wrap(cardDriveSide)
  7. local monitor = peripheral.wrap(monitorSide)
  8.  
  9. -- Lock status
  10. local deviceLocked = fs.exists("Block.txt")
  11.  
  12. -- Function to display a message on the monitor
  13. local function displayMessage(line, message)
  14. monitor.setCursorPos(1, line)
  15. monitor.clearLine()
  16. monitor.write(message)
  17. end
  18.  
  19. -- Function to display a detailed message about the access card status
  20. local function displayAccessCardMessage(status)
  21. monitor.clear()
  22. if status == "insert" then
  23. displayMessage(1, "Doggy OS Enterprise Security")
  24. displayMessage(2, "============================")
  25. displayMessage(4, "Welcome to Doggy OS Enterprise Security System.")
  26. displayMessage(6, "Please insert your access card to proceed.")
  27. elseif status == "valid" then
  28. displayMessage(1, "Access Granted")
  29. displayMessage(2, "============================")
  30. displayMessage(4, "Welcome, authorized user!")
  31. displayMessage(6, "Access has been granted.")
  32. sleep(3) -- Display message for 3 seconds
  33. elseif status == "invalid" then
  34. displayMessage(1, "Access Denied")
  35. displayMessage(2, "============================")
  36. displayMessage(4, "Invalid or unauthorized card.")
  37. displayMessage(6, "Access denied. Please contact")
  38. displayMessage(7, "security for assistance.")
  39. sleep(3) -- Display message for 3 seconds
  40. elseif status == "locked" then
  41. displayMessage(1, "Device Disabled")
  42. displayMessage(2, "============================")
  43. displayMessage(4, "Suspicious activity detected.")
  44. displayMessage(6, "Device is locked. Please")
  45. displayMessage(7, "contact security for assistance.")
  46. elseif status == "override" then
  47. displayMessage(1, "Override Disk Detected")
  48. displayMessage(2, "============================")
  49. displayMessage(4, "Admin access granted.")
  50. displayMessage(6, "Device will reset now.")
  51. sleep(3) -- Display message for 3 seconds
  52. end
  53. end
  54.  
  55. -- Function to lock the device after suspicious activity
  56. local function lockDevice()
  57. deviceLocked = true
  58. displayAccessCardMessage("locked")
  59. -- Create a lock file to persist the lock state
  60. local file = fs.open("Block.txt", "w")
  61. file.write("Device is locked due to suspicious activity.")
  62. file.close()
  63. end
  64.  
  65. -- Function to handle the override disk
  66. local function handleOverrideDisk()
  67. fs.delete("Block.txt")
  68. displayAccessCardMessage("override")
  69. sleep(2)
  70. os.reboot()
  71. end
  72.  
  73. -- Function to show "Device Disabled" message and check for override disk
  74. local function showDeviceDisabledMessage()
  75. displayAccessCardMessage("locked")
  76. while deviceLocked do
  77. if cardDrive.isDiskPresent() then
  78. local diskID = cardDrive.getDiskID()
  79. local diskMountPath = "/disk"
  80.  
  81. if fs.exists(diskMountPath .. "/Overide/" .. diskID .. ".ID") then
  82. handleOverrideDisk()
  83. break
  84. end
  85. end
  86. sleep(1) -- Wait briefly before checking again
  87. end
  88. end
  89.  
  90. -- Function to check the inserted card and control the door
  91. function checkCard()
  92. if deviceLocked then
  93. showDeviceDisabledMessage() -- Show static lock message if locked
  94. return
  95. end
  96.  
  97. displayAccessCardMessage("insert") -- Initial message to insert card
  98.  
  99. while true do
  100. if cardDrive.isDiskPresent() then
  101. local diskID = cardDrive.getDiskID()
  102. local diskMountPath = "/disk"
  103.  
  104. -- Check for startup files
  105. if fs.exists(diskMountPath .. "/startup") or fs.exists(diskMountPath .. "/startup.lua") then
  106. if not fs.exists("Block.txt") then
  107. -- Create Block.txt and reboot the device
  108. local file = fs.open("Block.txt", "w")
  109. file.write("Device is locked due to suspicious activity.")
  110. file.close()
  111. os.reboot()
  112. break
  113. end
  114. end
  115.  
  116. if fs.exists(diskMountPath .. "/Overide/" .. diskID .. ".ID") then
  117. handleOverrideDisk()
  118. break
  119. elseif fs.exists(diskMountPath .. "/Cards/" .. diskID .. ".ID") then
  120. displayAccessCardMessage("valid")
  121. redstone.setOutput(doorSide, true) -- Open door
  122. sleep(1) -- Ensure door is fully open before ejecting
  123.  
  124. -- Eject the card
  125. cardDrive.ejectDisk()
  126. sleep(2) -- Keep door open for 2 seconds after ejecting
  127. redstone.setOutput(doorSide, false) -- Close door
  128.  
  129. break -- Exit loop after valid card action
  130. else
  131. displayAccessCardMessage("invalid")
  132. lockDevice()
  133. break -- Exit loop after invalid card action
  134. end
  135. else
  136. -- No card inserted, continue checking
  137. sleep(1) -- Wait briefly before checking again
  138. end
  139. end
  140. end
  141.  
  142. -- Main loop to continuously check for the card
  143. while true do
  144. checkCard()
  145. end
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement