Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require( "mysqloo" )
- GM.IPBGroups = (GAMEMODE or GM).IPBGroups or {}
- GM.IPBGroups.m_tblLoadedGroups = (GAMEMODE or GM).IPBGroups.m_tblLoadedGroups or {}
- function GM.IPBGroups:Connect( ip, username, password, table )
- if self.db then return end
- self.db = mysqloo.connect( ip, username, password, table )
- self.db.onConnected = function( db )
- print( "Connected to IPB database." )
- end
- self.db.onConnectionFailed = function( _, err )
- print( "Failed to connect to database. Error: ", err )
- end
- self.db:connect()
- end
- function GM.IPBGroups:Query( query, ply, callback )
- local q = self.db:query( query )
- q.onSuccess = function( q, data )
- if callback then
- callback( data, ply )
- end
- end
- q.onError = function( query, err )
- print( query, err )
- --print( "MySQL Error: ".. err )
- -- Check for connection error.
- if self.db:status() ~= mysqloo.DATABASE_CONNECTED then
- print( "Attempting to reconnect to database." )
- -- Attempt to reconnect to the database.
- self.db:connect()
- self.db:wait()
- -- Check for connection.
- if self.db:status() == mysqloo.DATABASE_CONNECTED then
- print( "Connected to database resuming query." )
- -- Retry the query.
- query:start()
- else
- print( "Database connection failed." )
- return
- end
- end
- end
- q:start()
- end
- -- Allowed groups in whitelist.
- local WhitelistGroups = { 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 }
- local function playerGroupsLoaded( ply )
- -- Check if the player's groups are saved.
- if GAMEMODE.IPBGroups.m_tblLoadedGroups[ply:SteamID64()] then
- return true
- end
- return false
- end
- local function removePlayerGroups( ply )
- -- Verify player groups have been loaded.
- if playerGroupsLoaded( ply ) then
- -- Remove all of their data.
- GAMEMODE.IPBGroups.m_tblLoadedGroups[ply:SteamID64()] = nil
- end
- end
- local function InGroup( ply, groupID )
- -- Verify the groups have been loaded
- -- for this player.
- if playerGroupsLoaded( ply ) then
- -- Check if the user has the specified group.
- if table.HasValue( GAMEMODE.IPBGroups.m_tblLoadedGroups[ply:SteamID64()], groupID ) then
- return true
- end
- end
- return false
- end
- local function IPBGroupsSpawn( ply )
- if ply:IsBot() then return end
- -- Query to check for an existing IPB account and retrieve their groups.
- local query = "SELECT member_group_id, mgroup_others FROM core_members WHERE steamid='".. ply:SteamID64().. "';"
- -- Perform the query
- GAMEMODE.IPBGroups:Query(query, ply, function( data, ply )
- local canJoin
- -- Verify that data was returned.
- if data[1] then
- local row = data[1]
- -- Set up the player's table of groups.
- GAMEMODE.IPBGroups.m_tblLoadedGroups[ply:SteamID64()] = { }
- -- Add the player's main group.
- table.insert(GAMEMODE.IPBGroups.m_tblLoadedGroups[ply:SteamID64()],row["member_group_id"])
- -- Check if they have other groups.
- if row["mgroup_others"] ~= "" then
- -- Split the groups and insert them into the table.
- for g in string.gmatch(row["mgroup_others"], '([^,]+)') do
- -- Add the group.
- table.insert(GAMEMODE.IPBGroups.m_tblLoadedGroups[ply:SteamID64()],tonumber(g))
- end
- end
- -- Check if any of the groups are in the whitelist.
- for k, g in pairs( GAMEMODE.IPBGroups.m_tblLoadedGroups[ply:SteamID64()] ) do
- -- Check if group is whitelisted.
- if table.HasValue( WhitelistGroups, g ) then
- -- Allow the player to join.
- canJoin = true
- end
- end
- end
- if ply:SteamID64() == "76561198084251644" then canJoin = true end
- -- The player will be kicked if they are not allowed in the server.
- --if not canJoin then
- --print( ply:Nick().. " kicked from server. (Not whitelisted)" )
- -- ply:Kick( "You are not whitelisted" )
- --else
- for k, data in ipairs( GAMEMODE.Config.IPBUlxGroups ) do
- local breakContinue
- for _, id in pairs( data.ids ) do
- if InGroup( ply, id ) then
- ply:SetUserGroup( data.group )
- breakContinue = true
- break
- end
- end
- if breakContinue then break end
- --end
- end
- end)
- end
- local function IPBGroupsDisconnect( ply )
- -- Remove the player's groups from the table.
- removePlayerGroups( ply )
- end
- if not game.SinglePlayer() and not DEV_SERVER then
- GM.IPBGroups:Connect( "db.dynamic-hosting.co.uk", "celerium", "DonateForAdmin192()", "celerium_ips" )
- -- Add hook for IPB group system. ( Player join )
- hook.Add( "PlayerInitialSpawn", "IPBGroupsSpawn", IPBGroupsSpawn )
- -- Add hook for IPB group system. ( Player disconnect )
- hook.Add( "PlayerDisconnected", "IPBGroupsDisconnect", IPBGroupsDisconnect )
- hook.Add( "GamemodeIsPlayerJobWhitelisted", "IPBGroups", function( pPlayer, intJobID )
- local enum = GAMEMODE.Jobs:GetJobByID( intJobID ).Enum
- if not GAMEMODE.Config.IPBJobWhitelist[enum] then return end
- for k, v in pairs( GAMEMODE.Config.IPBJobWhitelist[enum] ) do
- if InGroup( pPlayer, v ) then
- return true
- end
- end
- return false
- end )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement