Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local os = require("os")
- local auth = require("auth")
- local lb = component.light_board
- local door = component.os_door
- local char_space = string.byte(" ")
- local running = true
- for i = 1,5 do
- lb.setColor(i,0x00FF00)
- end
- for i = 6,10 do
- lb.setColor(i,0xFF0000)
- end
- function unknownEvent()
- end
- local myEventHandlers = setmetatable({}, { __index = function() return unknownEvent end })
- function myEventHandlers.key_up(adress, char, code, playerName)
- if (char == char_space) then
- running = false
- end
- end
- local function openDoor()
- door.toggle()
- os.sleep(3)
- door.toggle()
- return
- end
- local function setlb(state)
- if state == true then
- for lite = 1,5 do
- lb.setActive(lite,true)
- end
- os.sleep(.2)
- for lite = 1,5 do
- lb.setActive(lite,false)
- end
- elseif state == false then
- for lite = 6, 10 do
- lb.setActive(lite,true)
- end
- os.sleep(.2)
- for lite = 6,10 do
- lb.setActive(lite,false)
- end
- end
- return end
- local authorized = {}
- for line in io.lines("/etc/auth.dat") do
- table.insert(authorized, line)
- end
- function myEventHandlers.magData(addr, playerName, data, UUID, locked)
- for i = 1,#authorized do
- print("Checking index #" .. i .. " for a match against: " .. UUID)
- if UUID == authorized[i] then
- -- print("Match found. Door opening for " .. playerName .. ".")
- auth.userLog(playerName, "Office Doors - Accepted")
- setlb(true)
- openDoor()
- break
- elseif UUID ~= authorized[i] then
- -- print("Match not found! Card not authorized!")
- auth.userLog(playerName, "Office Doors - Denied")
- setlb(false)
- end
- end
- end
- function handleEvent(eventID, ...)
- if (eventID) then -- can be nil if no event was pulled for some time
- myEventHandlers[eventID](...) -- call the appropriate event handler with all remaining arguments
- end
- end
- while running do
- handleEvent(event.pull())
- end
Advertisement
Add Comment
Please, Sign In to add comment