Advertisement
Rolcam

Computercraft Keycard Reader System V1 [Part 2 - Validator]

Oct 30th, 2020 (edited)
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.02 KB | None | 0 0
  1. --[[ Info
  2.  
  3. Requires an advanced computer to run
  4.  
  5. This program is designed as the validator for my keycard reader system. Since this computer SHOULDN'T have any openly accessible
  6. floppy disk drives connected to it, this program should be safe from hijacking attempts. This is the program that can be used
  7. to unlock doors, access a disk drive server, dispense stuff, etc.
  8.  
  9. IMPORTANT: I put delays in the program to keep this program synced to my card reader program. If you plan on using a custom reader,
  10. feel free to remove them. Otherwise, keep them in.
  11.  
  12. ]]--
  13. os.pullEvent = os.pullEventRaw
  14. term.clear()
  15. term.setCursorPos(1,1)
  16. term.setTextColor(colors.orange)
  17. print("Keycard Validation System V1")
  18. sleep(0.5)
  19. print("Please Wait...")
  20. -- Change to the side the reader will be connected to
  21. rednet.open("right")
  22. term.setTextColor(colors.green)
  23. print("Rednet Communications Opened!")
  24. sleep(1)
  25.  
  26. -- Main Program (loops indefinitely)
  27. while true do
  28.     term.clear()
  29.     term.setCursorPos(1,1)
  30.     term.setTextColor(colors.orange)
  31.     -- You can change the text to say whatever
  32.     print("Keycard Validation System")
  33.     print("Waiting for keycard data...")
  34.     id,IDdata = rednet.receive()
  35.     term.setTextColor(colors.blue)
  36.     print("Data Received...")
  37.         -- ID checker - Checks ID number received from the card reader
  38.         -- Change ### to ID number for the maintenance mode disk
  39.         if IDdata == ### then
  40.             term.setTextColor(colors.orange)
  41.             print("Maintenance Card Detected!")
  42.             sleep(1)
  43.             rednet.broadcast("Break")
  44.             print("Exiting to Terminal...")
  45.             sleep(2)
  46.             break;
  47.         -- Add elseif statements for each ID you want validated (change the ### to the ID number of the disk)
  48.         -- Copy this elseif statment to add more valid IDs
  49.         elseif IDdata == ### then
  50.             -- Delay is here for communications. Removing it may cause desync between systems
  51.             term.setTextColor(colors.green)
  52.             print("User Authorized!")
  53.             name = "name goes here"
  54.             valid = 1
  55.             sleep(1)
  56.             rednet.broadcast("Granted")
  57.         else
  58.             term.setTextColor(colors.red)
  59.             -- Delay is here for communications. Removing it may cause desync between systems.
  60.             sleep(1)
  61.             rednet.broadcast("Denied")
  62.             print("Invalid ID Detected!")
  63.             print("Access Denied!")
  64.             sleep(3)
  65.             os.reboot()
  66.         end
  67.     -- If the ID was validated this will run
  68.     if valid == 1 then
  69.         term.setTextColor(colors.blue)
  70.         print("Awaiting a response from the reader...")
  71.         id,data = rednet.receive()
  72.         if data == "resume" then
  73.             rednet.broadcast(name)
  74.             sleep(2)
  75.             print("Response Received")
  76.             -- Insert desired behavior here (e.g. break to terminal, unlock a door, or whatever)
  77.             -- Demo Behavior, remove when editing
  78.             rs.setOutput("left", true)
  79.             sleep(2)
  80.             rs.setOutput("left", false)
  81.         else
  82.             term.setTextColor(colors.red)
  83.             print("Invalid Response")
  84.             sleep(3)
  85.         end
  86.     end        
  87. end        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement