Advertisement
Oubi_Quimbleton

admin (Global)

Nov 28th, 2021 (edited)
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. --Variable initialization
  2. local srcId
  3. local cmd
  4. local tgtId
  5. local index
  6. local fnc
  7. local ids
  8. local access
  9. local result
  10.  
  11. --Check if srcId is valid
  12. local function checkAccess()
  13.     access = false
  14.     tools.clear()
  15.     print("Awaiting Broadcast...")
  16.     srcId, cmd = rednet.receive()
  17.     srcId, tgtId = rednet.receive()
  18.     if cmd == "open" or cmd == "close" then index = "door" end
  19.     fnc = (index..tgtId)
  20.     ids = getfenv()["idList"][fnc]() --Set Environment within APIs
  21.     for i = 1, ids[0], 1 do
  22.         if srcId == ids[i] then access = true end
  23.     end
  24. end
  25.  
  26. --NO DESCRIPTION
  27. local function sendResult()
  28.     if access == true then
  29.         rednet.send(tonumber(tgtId), cmd)
  30.         tgtId, result = rednet.receive()
  31.     else
  32.         result = "Access denied"
  33.     end
  34.     rednet.send(tonumber(srcId), result)
  35. end
  36.  
  37. rednet.open("left")
  38. --Run loop
  39. while true do
  40.     checkAccess()
  41.     sendResult()
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement