ULX

Author Topic: Working MySQL User Authentication with Global Ban support  (Read 12425 times)

0 Members and 2 Guests are viewing this topic.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Working MySQL User Authentication with Global Ban support
« Reply #15 on: February 25, 2011, 12:29:43 AM »
**Something fun I did with this module on my website.**

Just showcasing this.. this would be too much trouble to release as it would not work unless you had your website and groups set up exactly like mine.. which is unlikely

Also.. it's still VERY MUCH a work in progress...

**OLD LINK DEAD***




Kinda, btw thanks for helping me i know it can get annoying


So what your saying is, ill have those same variables but at the bottom ill add something like this

GCcash: ply.gccash


and lets say in a completely different folder like im making a derma menu what would that command be to take out a certain amount? And would i also need to connect to the database again? Its stuff like this that confuses me XD

Yeah, none of this is supported by my module. You'd have to write your own to start working with new tables and stuff. Mine only handles saving and loading player groups and bans. If you want save more info to the same database tables you can, but you'd have to either modify my script to read it or make your own to run along side of mine.
« Last Edit: March 27, 2012, 01:34:49 PM by MrPresident »

Offline gameguysz

  • Newbie
  • *
  • Posts: 10
  • Karma: -1
Re: Working MySQL User Authentication with Global Ban support
« Reply #16 on: February 25, 2011, 12:41:15 AM »
Well what im worried about is reading the database for groups. So if i just do that Group: ply.group thing it should work right?


like if ply:group == vip or something like that?

PS:Your site.. Awesome haha
I just started mine today XD

http://gamecrazedservers.ugs1.net/
« Last Edit: February 25, 2011, 12:44:10 AM by gameguysz »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Working MySQL User Authentication with Global Ban support
« Reply #17 on: February 25, 2011, 12:45:01 AM »
it auths them the same way that ULib does.

Using something like.. ply:GetUserGroup() == "vip" would work.


But yes..  ply:group == "vip" would work too.

Offline gameguysz

  • Newbie
  • *
  • Posts: 10
  • Karma: -1
Re: Working MySQL User Authentication with Global Ban support
« Reply #18 on: February 25, 2011, 12:47:37 AM »
it auths them the same way that ULib does.

Using something like.. ply:GetUserGroup() == "vip" would work.


But yes..  ply:group == "vip" would work too.

well not literally did i mean that XD but you answered my question! :D Thank  you!!!!!!

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: Working MySQL User Authentication with Global Ban support
« Reply #19 on: March 05, 2011, 09:37:59 PM »
Your link to the module is a bit screwed up.  May want to fix that.

Anyway, I may use this.  Could come in handy and saves me a lot of work.

Offline DJWolf

  • Newbie
  • *
  • Posts: 8
  • Karma: 3
Re: Working MySQL User Authentication with Global Ban support
« Reply #20 on: August 10, 2011, 04:08:15 PM »
I have the script loaded, but when someone connects, it says
Code: [Select]
No Results Found ... Creating Entry
Lua Error: ERROR: Hook 'SQL_Auth' Failed: [@lua\autorun\ugroup.lua:93] Invalid connection!
Lua Error: Removing Hook 'SQL_Auth'

this is what my edited version looks like
Code: [Select]
--------------------
--     Config     --
--------------------
local host = ""
local username = ""
local password = ""
local database = ""
local port = 3306
local table = "ugroup"

local persistent = false -- Use a persistent MySQL connection?

require( "mysql" )
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", "SQL", 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

-- Because we use this a lot
function Format( str )
if not str then return "NULL" end
return string.format( "%q", str )
end

function SQL_Auth( ply, sid, uid )
Connect()
local results = DoQuery( "SELECT * FROM " .. table .. " WHERE steamid = '" .. sid .. "'" )
Disconnect()

if not results[1] then
ServerLog("No Results Found ... Creating Entry")
--print("INSERT INTO " .. table .. " ( steamid, pname, pgroup, banned ) VALUES( " ..Format( Escape( sid ) ) .. ", " ..Format( Escape( ply:Nick() ) ) .. ", " ..Format( Escape( "user" ) ) .. ", " ..Format( Escape( "FALSE" ) ).. " )")
local result = DoQuery( "INSERT INTO " .. table .. " ( steamid, pname, pgroup, banned ) VALUES( " ..Format( Escape( sid ) ) .. ", " ..Format( Escape( ply:Nick() ) ) .. ", " ..Format( Escape( "user" ) ) .. ", " ..Format( Escape( "FALSE" ) ).. " )" )
else
ServerLog("Results Found ... Loading Results")
ply.steamid = results[1][1]
ply.name = results[1][2]
ply.group = results[1][3]
ply.banned = results[1][4]
ServerLog("Name: " .. ply.name)
ServerLog("SteamID: " .. ply.steamid)
ServerLog("Group: " .. ply.group)
ServerLog("Banned?: " .. ply.banned)

if ply.name != ply:Nick() then

ServerLog( "Updating name for player: " ..ply:Nick() )
--print("UPDATE " .. table .. " SET pname="..Format( Escape( ply:Nick() ) ) .. " WHERE sid=" ..Format( Escape( sid ) ) )
local result3 = DoQuery( "UPDATE " .. table .. " SET pname="..Format( Escape( ply:Nick() ) ) .. " WHERE steamid=" ..Format( Escape( sid ) ) )

end

ServerLog( "AUTHING PLAYER: " ..ply:Nick().. " in group (" ..ply.group..")." )
ULib.ucl.addUser( ply:SteamID(), _, _, ply.group )

if ply.banned == "TRUE" then
ULib.kick( ply, "BANNED! Visit our website at WEBSITE HERE to dispute this ban." )
end

end

end
hook.Add( "PlayerAuthed", "SQL_Auth", SQL_Auth )


function SQL_ChangeGroup( ply, cmd, args )
local sid = args[1]
local group = string.lower(args[2])


if !IsValid( ply ) or ply:IsAdmin() then


if #args != 2 then
if ply then
ULib.tsay(ply, "Not enough arguements!", true)
else
ServerLog("Not enough arguements!")
end
end

Connect()
local results = DoQuery( "SELECT * FROM " .. table .. " WHERE steamid = '" .. sid .. "'" )
Disconnect()

if not results[1] then
Connect()
local result = DoQuery( "INSERT INTO " .. table .. " ( steamid, pname, pgroup, banned ) VALUES( " ..Format( Escape( sid ) ) .. ", " ..Format( Escape( "SET BY CONSOLE" ) ) .. ", " ..Format( Escape( group ) ) .. ", " ..Format( Escape( "FALSE" ) ).. " )" )
Disconnect()
if ply then
ULib.tsay(ply, "created player: (" ..sid.. ") with group (" ..group.. ")", true)
ServerLog("created player: (" ..sid.. ") with group (" ..group.. ")")
else
ServerLog("created player: (" ..sid.. ") with group (" ..group.. ")")
end
else
Connect()
--print( "UPDATE " .. table .. " SET group="..Format( Escape( group ) ) .. " WHERE steamid=" ..Format( Escape( sid ) ) )
local result = DoQuery( "UPDATE " .. table .. " SET pgroup="..Format( Escape( group ) ) .. " WHERE steamid=" ..Format( Escape( sid ) ) )
Disconnect()
if ply then
ULib.tsay(ply, "set player: (" ..sid.. ") to group (" ..group.. ")", true)
ServerLog("set player: (" ..sid.. ") to group (" ..group.. ")")
else
ServerLog("set player: (" ..sid.. ") to group (" ..group.. ")")
end
end
ULib.ucl.addUser( sid, _, _, group )

else
ULib.tsay(ply, "This command is reserved for administrators only!", true)
end
end
concommand.Add( "setgroup", SQL_ChangeGroup)
i took out the ban and unban part mostly because i don't need it since i have uban running
In the event of an emergency, all power will be diverted away from security...  ^_^

Offline Mathew75

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: Working MySQL User Authentication with Global Ban support
« Reply #21 on: March 12, 2012, 01:11:12 PM »
Is there maybe a SQL for the tables? I'm not such a good MySQL guy.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Working MySQL User Authentication with Global Ban support
« Reply #22 on: March 15, 2012, 03:04:32 PM »
Mathew, do you have PHPMySQL? That's the easiest way to setup tables by hand.
Experiencing God's grace one day at a time.

Offline Digital Spit

  • Jr. Member
  • **
  • Posts: 79
  • Karma: 1
Re: Working MySQL User Authentication with Global Ban support
« Reply #23 on: March 27, 2012, 07:12:20 AM »
I know I'm bumping an old thread but for future users I would just like to say you can host a freemysql database here:http://www.freemysql.net/

I don't know how long they will have signing up open to the public.
It allows remote access so this is perfect for anyone who is wanting to use this mod.
You do get phpmyadmin as well

This is what I use for my servers!
Also the owner of the website is very good at responding to your emails or your support tickets!

Offline havejack

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Re: Working MySQL User Authentication with Global Ban support
« Reply #24 on: July 24, 2012, 09:44:52 AM »
sorry to bump this old thread, but could someone update the code to work with this

it would be really hand if someone could Because the module he trys to use no longer has a download link