Advertisement
djshadowxm81

ccProxCardTesting

Mar 5th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.pullEvent = os.pullEventRaw
  2. local auth_channel = 54321
  3. local reply_channel = 234
  4. local authCard = {}
  5.  
  6. --debugging flag
  7. debug = 0
  8.  
  9. modem = peripheral.find("modem")
  10.  
  11. --Make sure there's an attached modem, else die
  12. if not modem then
  13.     error("Modem not detected.")
  14. end
  15.  
  16. --Open the reply channel for listening
  17. modem.open(reply_channel)
  18.  
  19. while true do
  20.  
  21.     print("ProxReader v1.0")
  22.     print("scs.mtweather.mil")
  23.     print("Authorized Users Only")
  24.     print("Access Attempts are Logged")
  25.     print("Please insert and remove your Prox Card...")
  26.  
  27.     --Wait for a user to insert a disk into any attached drive
  28.     diskHandle = os.pullEvent("disk")
  29.  
  30.     --Get a list of attached devices; take the drive, and find its side
  31.     local sides = peripheral.getNames()
  32.     for k,side in pairs(sides) do
  33.         if peripheral.getType(side) == "drive" then
  34.             rSide = side
  35.             reader = peripheral.wrap(rSide)
  36.  
  37.             --Debug stuff
  38.             if debug then
  39.             print("Reader is on side "..rSide)
  40.             end
  41.        
  42.         end
  43.     end
  44.  
  45.     --Get the ID of the card and send it for authentication
  46.     authCard = disk.getID(rSide)
  47.     modem.transmit(auth_channel, reply_channel, authCard)
  48.  
  49.     --Debug stuff
  50.     if debug then
  51.     print("Sending authID: "..authCard)
  52.     print("Sent on channel: "..auth_channel)
  53.     print("Expect reply on channel: "..reply_channel)
  54.     end
  55.  
  56.     --Wait for auth's reply on replyChan
  57.     local event, modem_side, authChan, replyChan, message = os.pullEvent("modem_message")
  58.  
  59.     --Debug stuff
  60.     if debug then
  61.     print("Received event: "..event)
  62.     print("I can reply on channel: "..replyChan)
  63.     print("Message is: "..message)
  64.     end
  65.  
  66.     if message == "valid" then
  67.         disk.eject(rSide)
  68.         term.clear()
  69.         term.setCursorPos(1,1)
  70.         print("Welcome!")
  71.  
  72.         --Get all sides, and toggle all redstone signals
  73.         local redSides = { "left", "right", "top", "bottom", "back", "front" }
  74.  
  75.         --Debug stuff
  76.         if debug then
  77.         print("Enabling redstone on all sides")
  78.         end
  79.  
  80.         for i=1, #redSides do
  81.             redstone.setOutput(redSides[i], true)
  82.         end
  83.  
  84.         sleep(3)
  85.  
  86.         --Debug stuff
  87.         if debug then
  88.         print("Disabling redstone on all sides")
  89.         end
  90.  
  91.         for i=1, #redSides do          
  92.             redstone.setOutput(redSides[i], false)
  93.         end
  94.     else
  95.         disk.eject(rSide)
  96.         term.clear()
  97.         term.setCursorPos(1,1)
  98.         print("Not a valid prox card.")
  99.         sleep(2)
  100.     end
  101. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement