Advertisement
Kodos

[OC] OpenSecurity MagReader Program

Oct 16th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local os = require("os")
  4.  
  5. local door = component.os_door
  6. local char_space = string.byte(" ")
  7. local running = true
  8.  
  9. function unknownEvent()
  10. end
  11.  
  12. local myEventHandlers = setmetatable({}, { __index = function() return unknownEvent end })
  13.  
  14. function myEventHandlers.key_up(adress, char, code, playerName)
  15.   if (char == char_space) then
  16.   running = false
  17.   end
  18.   end
  19.  
  20. local function openDoor()
  21.   door.toggle()
  22.   os.sleep(3)
  23.   door.toggle()
  24.   return
  25. end
  26.  
  27. local authorized = { "7aa03fe4-b3e7-496e-a6e4-abedcd11f50b","Herpderp" }
  28.  
  29. function myEventHandlers.magData(addr, playerName, data, UUID, locked)
  30. for i = 1,#authorized do
  31. print("Checking index #" .. i .. " for a match against: " .. UUID)
  32. if UUID == authorized[i] then
  33. print("Door opening for " .. playerName .. ".")
  34. openDoor()
  35. break
  36. elseif UUID ~= authorized[i] then
  37. print("Card not authorized!")
  38. end
  39. end
  40. end
  41.  
  42. function handleEvent(eventID, ...)
  43.   if (eventID) then -- can be nil if no event was pulled for some time
  44.     myEventHandlers[eventID](...) -- call the appropriate event handler with all remaining arguments
  45.   end
  46. end
  47.  
  48. while running do
  49. handleEvent(event.pull())
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement