Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- local auth_channel = 54321
- local reply_channel = 234
- local authCard = {}
- --debugging flag
- debug = 0
- modem = peripheral.find("modem")
- --Make sure there's an attached modem, else die
- if not modem then
- error("Modem not detected.")
- end
- --Open the reply channel for listening
- modem.open(reply_channel)
- while true do
- print("ProxReader v1.0")
- print("scs.mtweather.mil")
- print("Authorized Users Only")
- print("Access Attempts are Logged")
- print("Please insert and remove your Prox Card...")
- --Wait for a user to insert a disk into any attached drive
- diskHandle = os.pullEvent("disk")
- --Get a list of attached devices; take the drive, and find its side
- local sides = peripheral.getNames()
- for k,side in pairs(sides) do
- if peripheral.getType(side) == "drive" then
- rSide = side
- reader = peripheral.wrap(rSide)
- --Debug stuff
- if debug then
- print("Reader is on side "..rSide)
- end
- end
- end
- --Get the ID of the card and send it for authentication
- authCard = disk.getID(rSide)
- modem.transmit(auth_channel, reply_channel, authCard)
- --Debug stuff
- if debug then
- print("Sending authID: "..authCard)
- print("Sent on channel: "..auth_channel)
- print("Expect reply on channel: "..reply_channel)
- end
- --Wait for auth's reply on replyChan
- local event, modem_side, authChan, replyChan, message = os.pullEvent("modem_message")
- --Debug stuff
- if debug then
- print("Received event: "..event)
- print("I can reply on channel: "..replyChan)
- print("Message is: "..message)
- end
- if message == "valid" then
- disk.eject(rSide)
- term.clear()
- term.setCursorPos(1,1)
- print("Welcome!")
- --Get all sides, and toggle all redstone signals
- local redSides = { "left", "right", "top", "bottom", "back", "front" }
- --Debug stuff
- if debug then
- print("Enabling redstone on all sides")
- end
- for i=1, #redSides do
- redstone.setOutput(redSides[i], true)
- end
- sleep(3)
- --Debug stuff
- if debug then
- print("Disabling redstone on all sides")
- end
- for i=1, #redSides do
- redstone.setOutput(redSides[i], false)
- end
- else
- disk.eject(rSide)
- term.clear()
- term.setCursorPos(1,1)
- print("Not a valid prox card.")
- sleep(2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement