Guest User

osmag.lua

a guest
Jan 11th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.87 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local os = require("os")
  4. local auth = require("auth")
  5.  
  6. local lb = component.light_board
  7. local door = component.os_door
  8. local char_space = string.byte(" ")
  9. local running = true
  10.  
  11. for i = 1,5 do
  12.   lb.setColor(i,0x00FF00)
  13. end
  14.  
  15. for i = 6,10 do
  16.   lb.setColor(i,0xFF0000)
  17. end
  18.  
  19.  
  20. function unknownEvent()
  21. end
  22.  
  23. local myEventHandlers = setmetatable({}, { __index = function() return unknownEvent end })
  24.  
  25. function myEventHandlers.key_up(adress, char, code, playerName)
  26.   if (char == char_space) then
  27.   running = false
  28.   end
  29.   end
  30.  
  31. local function openDoor()
  32.   door.toggle()
  33.   os.sleep(3)
  34.   door.toggle()
  35.   return
  36. end
  37.  
  38. local function setlb(state)
  39.   if state == true then
  40.     for lite = 1,5 do
  41.       lb.setActive(lite,true)
  42.     end
  43.     os.sleep(.2)
  44.     for lite = 1,5 do
  45.       lb.setActive(lite,false)
  46.     end
  47.   elseif state == false then
  48.     for lite = 6, 10 do
  49.       lb.setActive(lite,true)
  50.     end
  51.     os.sleep(.2)
  52.     for lite = 6,10 do
  53.       lb.setActive(lite,false)
  54.     end
  55.   end
  56. return end
  57.  
  58. local authorized = {}
  59.  
  60. for line in io.lines("/etc/auth.dat") do
  61. table.insert(authorized, line)
  62. end
  63.  
  64. function myEventHandlers.magData(addr, playerName, data, UUID, locked)
  65. for i = 1,#authorized do
  66. print("Checking index #" .. i .. " for a match against: " .. UUID)
  67. if UUID == authorized[i] then
  68. -- print("Match found. Door opening for " .. playerName .. ".")
  69. auth.userLog(playerName, "Office Doors - Accepted")
  70. setlb(true)
  71. openDoor()
  72. break
  73. elseif UUID ~= authorized[i] then
  74. -- print("Match not found! Card not authorized!")
  75. auth.userLog(playerName, "Office Doors - Denied")
  76. setlb(false)
  77. end
  78. end
  79. end
  80.  
  81. function handleEvent(eventID, ...)
  82.   if (eventID) then -- can be nil if no event was pulled for some time
  83.     myEventHandlers[eventID](...) -- call the appropriate event handler with all remaining arguments
  84.   end
  85. end
  86.  
  87. while running do
  88. handleEvent(event.pull())
  89. end
Advertisement
Add Comment
Please, Sign In to add comment