Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. require("gatekeeper")
  2. require("pgsql")
  3.  
  4. local conn = pgsql.connect("hostaddr='10.6.6.1' port='5432' dbname='gmtest' user='gmtest' password='z0rteh' sslmode='disable'")
  5.  
  6. local verified = {}
  7. local adminonly = true
  8.  
  9. local function UpdateVerified(res)
  10.     if res:status() == pgsql.COMMAND.TUPLES_OK then
  11.         verified = {}
  12.        
  13.         for row in res() do
  14.             verified[row["steamid"]] = { admin = (row["admin"] == "t") }
  15.         end
  16.     else
  17.         ErrorNoHalt("Gatekeeper: Error updating authorized access list\n")
  18.     end
  19. end
  20.  
  21. local function RequestAuthList()
  22.     conn:query("SELECT * FROM gk_auth;", UpdateVerified)
  23. end
  24. conn:listen("gk_auth_change", RequestAuthList)
  25.  
  26. RequestAuthList()
  27.  
  28. local function PasswordCheck(name, pass, steam, ip)
  29.     local LogData = file.Read("gatekeeperlog.txt") or ""
  30.     local LogEntry = Format("User: '%s' Pass: '%s' SteamID: '%s' IP: '%s'", name, pass, steam, ip)
  31.    
  32.     LogData = LogData..Format("%s %s\n", os.date("[%m/%d/%y %H:%M:%S]"), LogEntry)
  33.    
  34.     file.Write("gatekeeperlog.txt", LogData)
  35.     print(LogEntry)
  36.    
  37.     local query = Format("INSERT INTO gk_connect ( name, password, steamid, ip ) VALUES ( \'%s\', \'%s\', \'%s\', \'%s\' );",
  38.         conn:escapeString(name), conn:escapeString(pass), conn:escapeString(steam), conn:escapeString(ip))
  39.    
  40.     conn:query(query)
  41.    
  42.     if steam == "STEAM_ID_UNKNOWN" then
  43.         return "Invalid Steam ticket provided."
  44.     end
  45.    
  46.     local entry = verified[steam]
  47.    
  48.     if entry then
  49.         if entry.admin or not adminonly then
  50.             return true
  51.         else
  52.             return Format("SteamID '%s' is verified but lacks admin access to join.", steam)
  53.         end
  54.        
  55.     end
  56.    
  57.     return Format("SteamID '%s' not verified. Talk to ComWalk.", steam)
  58. end
  59. hook.Add("PlayerPasswordAuth", "test", PasswordCheck)
  60.  
  61. local function ToggleMode(ply, cmd, args)
  62.     local entry = verified[ply:SteamID()]
  63.    
  64.     if entry and entry.admin then
  65.         adminonly = not adminonly
  66.        
  67.         ply:PrintMessage(HUD_PRINTCONSOLE, "Gatekeeper: admin only mode is now " .. (adminonly and "on" or "off"))
  68.        
  69.         return
  70.     end
  71.    
  72.     ply:PrintMessage(HUD_PRINTCONSOLE, "Gatekeeper: Permission denied.")
  73. end
  74. concommand.Add("gatekeeper_toggle", ToggleMode)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement