Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require("gatekeeper")
- require("pgsql")
- local conn = pgsql.connect("hostaddr='10.6.6.1' port='5432' dbname='gmtest' user='gmtest' password='z0rteh' sslmode='disable'")
- local verified = {}
- local adminonly = true
- local function UpdateVerified(res)
- if res:status() == pgsql.COMMAND.TUPLES_OK then
- verified = {}
- for row in res() do
- verified[row["steamid"]] = { admin = (row["admin"] == "t") }
- end
- else
- ErrorNoHalt("Gatekeeper: Error updating authorized access list\n")
- end
- end
- local function RequestAuthList()
- conn:query("SELECT * FROM gk_auth;", UpdateVerified)
- end
- conn:listen("gk_auth_change", RequestAuthList)
- RequestAuthList()
- local function PasswordCheck(name, pass, steam, ip)
- local LogData = file.Read("gatekeeperlog.txt") or ""
- local LogEntry = Format("User: '%s' Pass: '%s' SteamID: '%s' IP: '%s'", name, pass, steam, ip)
- LogData = LogData..Format("%s %s\n", os.date("[%m/%d/%y %H:%M:%S]"), LogEntry)
- file.Write("gatekeeperlog.txt", LogData)
- print(LogEntry)
- local query = Format("INSERT INTO gk_connect ( name, password, steamid, ip ) VALUES ( \'%s\', \'%s\', \'%s\', \'%s\' );",
- conn:escapeString(name), conn:escapeString(pass), conn:escapeString(steam), conn:escapeString(ip))
- conn:query(query)
- if steam == "STEAM_ID_UNKNOWN" then
- return "Invalid Steam ticket provided."
- end
- local entry = verified[steam]
- if entry then
- if entry.admin or not adminonly then
- return true
- else
- return Format("SteamID '%s' is verified but lacks admin access to join.", steam)
- end
- end
- return Format("SteamID '%s' not verified. Talk to ComWalk.", steam)
- end
- hook.Add("PlayerPasswordAuth", "test", PasswordCheck)
- local function ToggleMode(ply, cmd, args)
- local entry = verified[ply:SteamID()]
- if entry and entry.admin then
- adminonly = not adminonly
- ply:PrintMessage(HUD_PRINTCONSOLE, "Gatekeeper: admin only mode is now " .. (adminonly and "on" or "off"))
- return
- end
- ply:PrintMessage(HUD_PRINTCONSOLE, "Gatekeeper: Permission denied.")
- end
- concommand.Add("gatekeeper_toggle", ToggleMode)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement