Guest User

startup

a guest
Oct 22nd, 2017
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. local user = "Door"
  2. local pass = "test"
  3. local userAPIl = "/userAPI"
  4. local StringUtilsl = "/StringUtils"
  5. local biolock = "top"
  6. local token = ""
  7. local neededlevel = 2
  8. local speaker = peripheral.find("speaker")
  9. local doorname = "main"
  10. ---------------------------------------------------
  11. print("Door Controller with userAPI")
  12. os.loadAPI(StringUtilsl)
  13. os.loadAPI(userAPIl)
  14. os.loadAPI("HalfLifeAPI")
  15.  
  16. token = userAPI.getToken(user,pass)
  17.  
  18. if token == "Unknown user" then print(token) end
  19. if token == "Bad password" then print(token) end
  20.  
  21. local function open()
  22.   speaker.speak(HalfLifeAPI.say("granted"),10)
  23.   print("opened")
  24.   rs.setOutput("left", true)
  25.   sleep(3)
  26.   rs.setOutput("left", false)
  27. end
  28.  
  29. local function receive()
  30.   modem = peripheral.find("modem")
  31.   modem.open(3323)
  32.   print("Starting wireless..")
  33.   while true do
  34.     local event, mS, sC,rC,content = os.pullEvent("modem_message")
  35.     if sC ~= 3323 then return nil end
  36.     if type(content) ~= "string" then return nil end
  37.     if content == doorname then open() print("openning wireless") end
  38.   end
  39. end
  40. local function biolockk()
  41. while true do
  42.   local useless, id = os.pullEvent("biolock")
  43.   local ac = userAPI.findBiolock(id, user, token)
  44.   if ac >= neededlevel then open() else
  45.     speaker.speak(HalfLifeAPI.say("denied"),10)
  46.   end  
  47. end
  48. end
  49. parallel.waitForAll(biolockk, receive)
Add Comment
Please, Sign In to add comment