Advertisement
sethxi

Door Auth Installer

Apr 11th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. local args = { ... }
  2.  
  3. if not args[1] or not args[2] then
  4.   print("Usage:\n"
  5.         .."install <pastebin id> <redstone side>")
  6.   return
  7. end
  8.  
  9. local f = fs.open(".auth", "w")
  10.   f.write([[
  11.     local get = "http://pastebin.com/raw.php?i=]] .. args[1] .. [["
  12.     local side = "]] .. args[2] .. [["
  13.  
  14.     os.pullEvent = os.pullEventRaw
  15.  
  16.     function table.contains(table, element)
  17.       for _, value in pairs(table) do
  18.         if value == element then
  19.           return true
  20.         end
  21.       end
  22.       return false
  23.     end
  24.  
  25.     local list = http.get(get).readAll()
  26.  
  27.     local f = fs.open(".authlist", "w")
  28.       f.write(list)
  29.     f.close()
  30.  
  31.     f = fs.open(".authlist", "r")
  32.       list = textutils.unserialize(f.readAll())
  33.     f.close()
  34.  
  35.     term.clear()
  36.     term.setCursorPos(1, 1)
  37.     if term.isColor() then term.setTextColor(colors.blue) end
  38.     print("Liquid Obsidian's Authenticator v1.0")
  39.  
  40.     while true do
  41.       local event, detector, username = os.pullEvent()
  42.       if event == "player" then
  43.         if table.contains(list, username) or username == "LiquidObsidian" then
  44.           if term.isColor() then term.setTextColor(colors.green) end
  45.             print("Access granted to " .. username .. ".")
  46.             rs.setOutput(side, true)
  47.             sleep(2)
  48.             rs.setOutput(side, false)
  49.           else
  50.             if term.isColor() then term.setTextColor(colors.red) end
  51.             print("Authentication denied for " .. username .. ".")
  52.           end
  53.         end
  54.       end
  55.   ]])
  56. f.close()
  57.  
  58. local f = fs.open("startup", "w")
  59.   f.write("shell.run('.auth')")
  60. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement