Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------
- -- Config --
- --------------------
- local host = "192.168.1.160"
- local username = "lcaservers"
- local password = "3p1cl0lz"
- local database = "gamesv"
- local port = 3306
- --local prefix = "admin_" -- table prefix ##DEPRECIATED##
- local grants =
- {
- [0] = "user",
- [1] = "respected",
- [2] = "admin",
- [3] = "superadmin",
- --[4] = "user",
- }
- local persistent = true -- Use a persistent MySQL connection?
- --[[
- Table structure:
- gamesv.users
- id, name, steamid, group, password
- ( 1 halon STEAM_** 0 util.crc(passwd) )
- ## DEPRECIATED ##
- <prefix>themes
- ID_MEMBER, ID_THEME, variable, value (1, 1, steamid, STEAM_****)
- <prefix>members
- ID_MEMBER, memberName, ID_GROUP (1, halon, 1)
- [0] = "undefined",
- [1] = "superadmin",
- [2] = "admin",
- [3] = "respected",
- [4] = "user",
- ## DEPRECIATED ##
- ]]--
- require( "mysql" )
- module( "dbusers", package.seeall )
- local db
- --[[
- Execute the query
- ]]--
- function DoQuery( query, type )
- local result, isok, err = mysql.query( db, query, type or mysql.QUERY_NUMERIC )
- if not isok and err == "" then isok = true end -- False positive
- if not isok then
- error( tostring( err ), 2 )
- return nil
- end
- if result then
- -- DEBUGGING --
- -- print( query ) -- For debug
- -- PrintTable( result )
- end
- return result
- end
- --[[
- Connects to the database
- ]]--
- function Connect()
- if db then return db end -- Still connected
- db, err = mysql.connect( host, username, password, database, port )
- if db == 0 then
- db = nil
- error( tostring( err ), 1 )
- return
- end
- return db
- end
- --[[
- Disconnects from the database
- ]]--
- function Disconnect( force )
- if not db then return end -- Already disconnected
- if persistent and not force then return end -- Don't disconnect, persistent
- local succ, err = mysql.disconnect( db )
- if not succ then
- error( tostring( err ), 2 )
- end
- db = nil
- end
- hook.Add( "ShutDown", "DbUsersClose", function() Disconnect( true ) end ) -- Force closed on shutdown.
- --[[
- Unused function
- ]]--
- function Escape( str )
- if not db then
- Msg( "Not connected to DB.\n" )
- return
- end
- if not str then return end
- local esc, err = mysql.escape( db, str )
- if not esc then
- error( tostring( err ), 2 )
- return nil
- end
- -- DEBUGGING --
- --print( "esc=" .. esc ) -- For debug
- return esc
- end
- --[[
- Total rewrite of the old function
- ]]--
- function CheckUser( ply )
- Connect()
- ULib.ucl.authed[ ply ] = nil
- --ULib.ucl.awaitingauth[ ply ] = true
- local results = DoQuery("SELECT * FROM users WHERE steamid='" .. ply:SteamID() .. "'")
- if results[ 1 ] then
- local name = results[1][2]
- local group = grants[ tonumber(results[1][4]) ]
- ULib.ucl.addUser(ply:SteamID(),{},{},group)
- print(name .. " was added to " .. group)
- end
- ULib.ucl.probe( ply ) -- If they weren't added above add them now
- Disconnect()
- end
- hook.Add( "PlayerInitialSpawn", "DbUsersInitSpawn", CheckUser )
- hook.Remove( "PlayerInitialSpawn", "ucl_initialspawn" ) -- We'll handle calling ucl.probe ourself
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement