Ulysses Stuff > Suggestions

Mysql

(1/5) > >>

ben build:
This is quite a big request but would it be possible to have a mysql option which makes it use mysql for users, groups and bans instead of txt

I run multiple servers and i don't want to have to write my own admins system to accommodate this, I know there is the uban system but it doesn't seem to integrate very well.

spbogie:
There is no need to write an entirely new admin mod just to get your users through SQL. You can just write a module for ULib and call ULib.ucl.addUser and ULib.ucl.addGroup. Full documentation of the ULib developer library can be found at http://www.ulyssesmod.net/docs.
One small note on making it a module however, you should only put a small init script in lua/ULib/modules/ as it will be run on both client and server. Put all the functionality and configuration in (a) separate file(s) located elsewhere.

I do not personally have the time right now to create this myself (finals and such), and I know Megiddo and JamminR have been quite busy lately as well, but we encourage you, or anyone else, to attempt. We wrote ULib for everyone, not just us, to use. If you take up this project, we would greatly appreciate it if you would release it here. If you can't/don't want to try this, and no one else picks it up, you will have to wait until we have time.

Megiddo:
We're pulling the users for all our servers from these forums with just a few lines of code. :)

JamminR:
I personally don't know SQL, but as spbogie said, don't have time to learn either.
Megiddo, mind sharing those few lines of code for pulling from our db, minus PW and servernames/etc. Or would that open us to risk?
I've always been curious what it looks like. Might help Ben on his way.

Ben,
As for UBan, Other than it using different commands, why would it be more difficult than what you wish now?

Megiddo:
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().


--- Code: -----------------------
--     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
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version