SHOW:
|
|
- or go back to the newest paste.
| 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 | - | local sides = peripheral.getNames() |
| 11 | + | --Make sure there's an attached modem, else die |
| 12 | - | for k,side in pairs(sides) do |
| 12 | + | |
| 13 | - | if peripheral.getType(side) == "drive" then |
| 13 | + | |
| 14 | - | rSide = side |
| 14 | + | |
| 15 | - | reader = peripheral.wrap(rSide) |
| 15 | + | |
| 16 | --Open the reply channel for listening | |
| 17 | modem.open(reply_channel) | |
| 18 | ||
| 19 | - | if not reader then |
| 19 | + | |
| 20 | - | error("Card reader not detected.")
|
| 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 | - | term.clear() |
| 26 | + | |
| 27 | - | term.setCursorPos(1,1) |
| 27 | + | --Wait for a user to insert a disk into any attached drive |
| 28 | - | term.setTextColor(colors.blue) |
| 28 | + | |
| 29 | - | print("ProxyReader v1.5")
|
| 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 | - | print("Please insert your Proxy Card...")
|
| 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 | - | term.setTextColor(colors.lime) |
| 41 | + | |
| 42 | end | |
| 43 | - | print("Take your Proxy Card and enter.")
|
| 43 | + | |
| 44 | - | local redSides = {"left", "right", "top", "bottom", "back", "front"}
|
| 44 | + | |
| 45 | - | for i = 1, #redSides do |
| 45 | + | --Get the ID of the card and send it for authentication |
| 46 | - | redstone.setOutput(redSides[i], true) |
| 46 | + | |
| 47 | modem.transmit(auth_channel, reply_channel, authCard) | |
| 48 | ||
| 49 | - | for i = 1, #redSides do |
| 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 | - | term.setTextColor(colors.red) |
| 54 | + | |
| 55 | - | print("Not a valid proxy card.")
|
| 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 |