Obviously this only works for SMF forums, but maybe it will help you. The grants is based off the group IDs assigned by the forums. This is more than my previously stated few lines of code because of the MySQL wrapper, which was grabbed from UBan (and not really entirely necessary). The only function of substance is CheckUser().
--------------------
-- Config --
--------------------
local host = "localhost"
local username = "secretuser"
local password = "secretpass"
local database = "ulyssesmod_forums"
local port = 3306
local prefix = "smf2_" -- table prefix
local grants =
{
[9] = "superadmin",
[10] = "donator",
[2] = "superadmin",
[11] = "donatoradmin",
[13] = "admin",
}
local persistent = false -- Use a persistent MySQL connection?
--[[
Table structure:
<prefix>themes
ID_MEMBER, ID_THEME, variable, value (1, 1, steamid, STEAM_****)
<prefix>members
ID_MEMBER, memberName, ID_GROUP (1, megiddo, 9)
9 = developer
10 = donator
2 = global mod
]]--
require( "mysql" )
module( "forumusers", package.seeall )
local db
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
-- print( query ) -- For debug
-- PrintTable( result )
end
return result
end
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
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", "ForumUsersClose", function() Disconnect( true ) end ) -- Force closed on shutdown.
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
-- print( "esc=" .. esc ) -- For debug
return esc
end
-- Check a user
function CheckUser( ply )
Connect()
ULib.ucl.authed[ ply ] = nil
ULib.ucl.awaitingauth[ ply ] = nil
local results = DoQuery( "SELECT ID_MEMBER FROM " .. prefix .. "themes WHERE value=\"" .. ply:SteamID() .. "\"" ) -- Get memberids with this steamid
if results[ 1 ] then -- Get into the row. I realize we're not handling cases where multiple users have the same steamid but meh. Should never happen, right?
local uid = results[ 1 ][ 1 ] -- Member ID
local results = DoQuery( "SELECT memberName, ID_GROUP FROM " .. prefix .. "members WHERE ID_MEMBER=" .. uid ) -- Get name and group
if results[ 1 ] and grants[ tonumber( results[ 1 ][ 2 ] ) ] then -- Should always exist but might as always make sure. Also make sure they have a permission
local name = results[ 1 ][ 1 ]
local group = grants[ tonumber( results[ 1 ][ 2 ] ) ]
ULib.ucl.addUser( name, "steamid", ply:SteamID(), { group } )
end
end
ULib.ucl.probe( ply ) -- If they weren't added above add them now
Disconnect()
end
hook.Add( "PlayerInitialSpawn", "ForumUsersInitSpawn", CheckUser )
hook.Remove( "PlayerInitialSpawn", "ucl_initialspawn" ) -- We'll handle calling ucl.probe ourself