Ulysses
Ulysses Stuff => Suggestions => Topic started by: ben build on February 15, 2008, 05:12:59 PM
-
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.
-
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 (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.
-
We're pulling the users for all our servers from these forums with just a few lines of code. :)
-
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?
-
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
-
I am actually working on making ulx mostly sql for my friends server. I will make it so it is easy to integrate with new version.
*wishes for ulx callbacks*
-
*wishes for ulx callbacks*
Callbacks for what?
-
Callbacks for what?
like
ulx.AddBanFunction(func_here)
function func_here()
//called when a person is banned.
end
so other mods can be integrated into ulx really easy and hook its bannings.
-
Why do you not just add them yourself?
-
For your purpose you would want to overried the functionality anyways. If you want everything to be over on SQL then it is probably best to override the underlying ULib functions instead, directing all bans done through ulib to your SQL server, and leaving ULX unmodified.
-
ok well I will try to get this done soon as possible. Problem is though that mysql broke for the latest gmod. So either I have to wait or attempt to rebuild it myself... Never was good with gmod dlls.
-
dlls will no longer work from the addons directory, other than that, the sql module should work fine. You just need to move it out of addons and put it in the main /lua/includes/modules.
-
ok well I am trying to figure out whats wrong with it, hopefully i get it working soon. :D.
-
*wishes for ulx callbacks*
Incidentally, after two years, this request got filled! See here (http://ulyssesmod.net/docs/files/lua/ULib/shared/defines-lua.html#ULibCommandCalled).
-
You bumped a two year old thread?
-
/me considers a "why reply" ban... then realizes this isn't facepunch.
-
You bumped a two year old thread?
It's a perk of being an admin, I can bump threads with impunity. :)
-
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().
<JamminR-Edited out re-paste of code block>
Hmm I used a SMF forum already, and already set usergroups for admins in SMF.
Does this code still work? would be kinda intresting to use :)
-
Pantho, both gmod and SMF have changed since we used the code.
Theoretically, yes it should still work, most likely needing some tweaking.
Requires sql plugins for gmod, and an SMF plugin for custom fields (which store a SMF user's steamid)
-
Pantho, both gmod and SMF have changed since we used the code.
Theoretically, yes it should still work, most likely needing some tweaking.
Requires sql plugins for gmod, and an SMF plugin for custom fields (which store a SMF user's steamid)
I've already got custom tables in my SMF Database I used for my CSS versions.
I can edit the file enough to correct for changes SQL databases etc, plus I used SMF 2 RCx (I forget which). I completely suck at LUA but I will check into it tomorrow :)
-
I completely suck at LUA but I will check into it tomorrow :)
I don't know SQL, but Lua is one of the easiest scripting languages I've ever tinkered with.
I forget that the code also uses ULib queries, which have been, not just changed, overhauled.
If/As you find/get errors, post the code (minus your login info(and server info if you don't want to even share that) and the errors you get in Developers corner. Between all the geeks around here, we should be able to help.
(Geek ~= bad)