Author Topic: ULX User mysql  (Read 7586 times)

0 Members and 1 Guest are viewing this topic.

Offline CheesyViking

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
ULX User mysql
« on: January 18, 2013, 02:05:51 AM »
Hey I'm making a auto donation system with PayPal IPN system and I was wondering how to give permissions to the users automatically is there a way I can get a mysql table for them or something like that?

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: ULX User mysql
« Reply #1 on: January 18, 2013, 06:13:32 AM »
check around in the Developer's Corner forum and releases. I know there are a few examples of MySQL authentication floating around out there. (I put them there)

Offline CheesyViking

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: ULX User mysql
« Reply #2 on: January 18, 2013, 05:56:17 PM »
Hey, thanks for the fast reply sorry I wasn't on but is this the thing?
http://forums.ulyssesmod.net/index.php/topic,5188.0.html

Offline CheesyViking

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: ULX User mysql
« Reply #3 on: January 18, 2013, 06:07:17 PM »
The module download links don't work what do I do?

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: ULX User mysql
« Reply #4 on: January 19, 2013, 04:17:49 AM »
How versed are you with lua?

Offline CheesyViking

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: ULX User mysql
« Reply #5 on: January 19, 2013, 04:00:41 PM »
Not very fond...

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: ULX User mysql
« Reply #6 on: January 19, 2013, 05:03:51 PM »
The reason I asked is because I have a working version:

Code: [Select]
require("mysqloo")
G4PSQL = {}
 
local DATABASE_HOST = "127.0.0.1"
local DATABASE_PORT = 3306
local DATABASE_NAME = "g4padmin"
local DATABASE_USERNAME = "root"
local DATABASE_PASSWORD = ""
local DATABSE_TABLE = "userauth"

function G4PSQL_Init()

G4PSQL_ConnectToDatabase()
timer.Simple(60, G4PSQL_Init )

end
hook.Add( "Initialize", "G4PSQL_Init", G4PSQL_Init )

function G4PSQL_Format( str )
if not str then return "NULL" end
return string.format( "%q", str )
end

function Escape( str )
if not G4PSQL.db then
Msg( "Not connected to DB.\n" )
return
end

if not str then return end

local esc = G4PSQL.db:escape( str )
if not esc then
return nil
end
return esc
end


function G4PSQL_ConnectToDatabase()
G4PSQL.db = mysqloo.connect( "127.0.0.1", "root", "", "g4padmin", 3306 )
G4PSQL.db:connect()
end

function G4PSQL_PlayerAuthDB( ply )

if G4PSQL.db == nil then
G4PSQL_ConnectToDatabase()
end

if G4PSQL.db:status() == 0 then
local sid = ply:SteamID()
print("Checking for: " .. Escape( sid ) )
local q1 = G4PSQL.db:query("SELECT * FROM " ..DATABSE_TABLE.. " WHERE steamid = "..G4PSQL_Format( Escape( sid ) ).."")
function q1:onSuccess( data )
if data[1] then
--PrintTable(data)
ply.steamid = data[1]["steamid"]
ply.name = data[1]["pname"]
ply.group = data[1]["pgroup"]
ply.banned = data[1]["banned"]
ply.lastplayed = data[1]["lastplayed"]
--ServerLog("/////PLAYER DATA FOUND/////" .. "\n")
--ServerLog("Name: " .. ply.name .. "\n")
--ServerLog("SteamID: " .. ply.steamid .. "\n")
--ServerLog("Group: " .. ply.group .. "\n")
--ServerLog("Last Played: " .. ply.lastplayed .. "\n")
--ServerLog("Banned?: " .. ply.banned .. "\n")
--ServerLog("///////////////////////////" .. "\n")

if ply.name != ply:Nick() then
--ServerLog( "Updating name for player: " ..ply:Nick() .. "\n" )
local q2 = G4PSQL.db:query("UPDATE " ..DATABSE_TABLE.. " SET pname="..G4PSQL_Format( Escape( ply:Nick() ) ) .. " WHERE steamid=" ..G4PSQL_Format( Escape( sid ) ) )
function q2:onSuccess( data2 )
--ServerLog( "Name updated sucessfully!\n" )
end
function q2:onError( Q, E )
ServerLog( "ERROR!!! " .. Q .. "\n" )
ServerLog( "ERROR!!! " .. E .. "\n" )
end
q2:start()
end

--ServerLog( "AUTHING PLAYER: " ..ply:Nick().. " in group (" ..ply.group..")." .. "\n" )
ULib.ucl.addUser( ply:SteamID(), _, _, ply.group )
SGS_SetUpTeams(ply)
local q4 = G4PSQL.db:query("UPDATE " ..DATABSE_TABLE.. " SET lastplayed="..G4PSQL_Format( Escape( tostring(os.date("%y/%m/%d")) ) ) .. " WHERE steamid=" ..G4PSQL_Format( Escape( sid ) ) )
function q4:onSuccess( data4 )
--ServerLog( "User Data (lastplayed) updated sucessfully!\n" )
end
function q4:onError( Q, E )
ServerLog( "ERROR!!! " .. Q .. "\n" )
ServerLog( "ERROR!!! " .. E .. "\n" )
end
q4:start()

if string.upper(ply.banned) == "TRUE" then
ULib.kick( ply, "BANNED! Visit our website at www.g4p.org to dispute this ban." )
end
ULib.tsay(ply, "Welcome back " ..ply:Nick().. ", you have been authenticated as: " ..ply.group..".", true)
ply:Spawn()
else
--print("No Entry Found")
--ServerLog("No Results Found ... Creating Entry\n")
local q3 = G4PSQL.db:query( "INSERT INTO " ..DATABSE_TABLE.. " ( steamid, pname, pgroup, lastplayed, banned ) VALUES( " ..G4PSQL_Format( Escape( sid ) ) .. ", " ..G4PSQL_Format( Escape( ply:Nick() ) ) .. ", " ..G4PSQL_Format( Escape( "user" ) ) .. ", " ..G4PSQL_Format( Escape( tostring(os.date("%y/%m/%d")) ) ) .. ", " ..G4PSQL_Format( Escape( "FALSE" ) ).. " )" )
function q3:onSuccess( data3 )
--ServerLog( "Entry added sucessfully!\n" )
end
function q3:onError( Q, E )
ServerLog( "ERROR!!! " .. Q .. "\n" )
ServerLog( "ERROR!!! " .. E .. "\n" )
end
q3:start()
ply:Spawn()
end
end
q1:start()
else
G4PSQL_RetryAuth( ply )
return
end
end
hook.Add( "PlayerAuthed", "G4PSQL_PlayerAuthDB", G4PSQL_PlayerAuthDB )

function G4PSQL_RetryAuth( ply )
if not ply.retries then ply.retries = 3 end

if ply.retries > 0 then
ply.retries = ply.retries - 1
--ServerLog("DATABASE NOT CONNECTED - RETRYING (" .. tostring(ply.retries) .. " retries left)" .. "\n")
G4PSQL_ConnectToDatabase()
timer.Simple(2, function() G4PSQL_PlayerAuthDB( ply ) end)
else
ServerLog( "FALLBACK AUTHENTICATION... DATABASE CAN NOT BE CONNECTED TO\n" )
--ServerLog( "AUTHING PLAYER: " ..ply:Nick().. " in group (user)." .. "\n" )
ULib.ucl.addUser( ply:SteamID(), _, _, "user" )
SGS_SetUpTeams(ply)
ply:Spawn()
end
end

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


if !IsValid( ply ) or ply:IsUserGroup("superadmin") then


if #args != 2 then
SGS_SendMessage(ply, "Wrong number of arguements!")
return
end

if (string.sub(sid, 1, 5) == "STEAM") then
sid = sid
qtype = 1
else
if IsValid(ULib.getUser(sid)) then
sid = ULib.getUser(sid)
qtype = 2
if not sid then
SGS_SendMessage(ply, "User not found!")
return
end
else
SGS_SendMessage(ply, "User not found!")
return
end
end

local gcheck = false
for k, v in pairs(ULib.ucl.groups) do
if group == k then
SGS_SendMessage(ply, "Checking " ..group.. " against " .. k)
gcheck = true
break
end
end
if gcheck == false then
SGS_SendMessage(ply, "Group doesn't exist!")
return
end

if G4PSQL.db:status() == 0 then
if qtype == 1 then
local q1 = G4PSQL.db:query("SELECT * FROM " ..DATABSE_TABLE.. " WHERE steamid = "..G4PSQL_Format( Escape( sid ) ).."")
function q1:onSuccess( data )
if data[1] then
SGS_SendMessage(ply, "Updating group for steamID: (" ..sid .. ")")
local q2 = G4PSQL.db:query("UPDATE " ..DATABSE_TABLE.. " SET pgroup="..G4PSQL_Format( Escape( group ) ) .. " WHERE steamid=" ..G4PSQL_Format( Escape( sid ) ) )
function q2:onSuccess( data2 )
SGS_SendMessage(ply, "Player (" .. sid .. ") Group Changed!")
end
function q2:onError( Q, E )
ServerLog( "ERROR!!! " .. Q .. "\n" )
ServerLog( "ERROR!!! " .. E .. "\n" )
end
q2:start()
else
SGS_SendMessage(ply, "No Entry Found")
SGS_SendMessage(ply, "No Results Found ... Creating Entry")
local q3 = G4PSQL.db:query( "INSERT INTO " ..DATABSE_TABLE.. " ( steamid, pname, pgroup, lastplayed, banned ) VALUES( " ..G4PSQL_Format( Escape( sid ) ) .. ", " ..G4PSQL_Format( Escape( "ADMIN ENTERED" ) ) .. ", " .. G4PSQL_Format( Escape( group ) ) .. ", " ..G4PSQL_Format( Escape( tostring("NEVER") ) ) .. ", " ..G4PSQL_Format( Escape( "FALSE" ) ).. " )" )
function q3:onSuccess( data3 )
SGS_SendMessage(ply, "Entry added sucessfully!")
end
function q3:onError( Q, E )
ServerLog( "ERROR!!! " .. Q .. "\n" )
ServerLog( "ERROR!!! " .. E .. "\n" )
end
q3:start()
end
end
q1:start()
else
local q1 = G4PSQL.db:query("SELECT * FROM " ..DATABSE_TABLE.. " WHERE steamid = "..G4PSQL_Format( Escape( sid:SteamID() ) ).."")
function q1:onSuccess( data )
if data[1] then
SGS_SendMessage(ply, "Updating group for player: " ..sid:Nick())
local q2 = G4PSQL.db:query("UPDATE " ..DATABSE_TABLE.. " SET pgroup="..G4PSQL_Format( Escape( group ) ) .. " WHERE steamid=" ..G4PSQL_Format( Escape( sid:SteamID() ) ) )
function q2:onSuccess( data2 )
SGS_SendMessage(ply, "Player Group Changed!")
ULib.ucl.addUser( sid:SteamID(), _, _, group )
SGS_SetUpTeams(sid)
end
function q2:onError( Q, E )
ServerLog( "ERROR!!! " .. Q .. "\n" )
ServerLog( "ERROR!!! " .. E .. "\n" )
end
q2:start()
else
SGS_SendMessage(ply, "No Entry Found")
SGS_SendMessage(ply, "No Results Found ... Creating Entry")
local q3 = G4PSQL.db:query( "INSERT INTO " ..DATABSE_TABLE.. " ( steamid, pname, pgroup, lastplayed, banned ) VALUES( " ..G4PSQL_Format( Escape( sid:SteamID() ) ) .. ", " ..G4PSQL_Format( Escape( "ADMIN ENTERED" ) ) .. ", " .. G4PSQL_Format( Escape( group ) ) .. ", " ..G4PSQL_Format( Escape( tostring("NEVER") ) ) .. ", " ..G4PSQL_Format( Escape( "FALSE" ) ).. " )" )
function q3:onSuccess( data3 )
SGS_SendMessage(ply, "Entry added sucessfully!")
end
function q3:onError( Q, E )
ServerLog( "ERROR!!! " .. Q .. "\n" )
ServerLog( "ERROR!!! " .. E .. "\n" )
end
q3:start()
end
end
q1:start()
end
else
SGS_SendMessage(ply, "DATABASE NOT CONNECTED PLEASE TRY AGAIN!")
G4PSQL_ConnectToDatabase()
end
else
SGS_SendMessage(ply, "This command is reserved for administrators only!")
end
end
concommand.Add( "g4p_setgroup", G4PSQL_ChangeGroup)

function G4PSQL_Ban( ply, cmd, args )
local sid = args[1]
local reason = args[2]
local badmin = "NONE"
local baid = "NONE"

if !IsValid( ply ) or ply:IsAdmin() then
if IsValid(ply) then
badmin = ply:Nick()
bacolor = team.GetColor(ply:Team())
baid = ply:SteamID()
else
badmin = "(Console)"
bacolor = Color(80,80,80,255)
baid = "(Console)"
end

if #args != 2 then
SGS_SendMessage(ply, "Wrong number of arguements! Be sure to include the name/steamID and a reason. Also be sure the reason is in QUOTES.")
return
end

if (string.sub(sid, 1, 5) == "STEAM") then
sid = sid
qtype = 1
else
if IsValid(ULib.getUser(sid)) then
sid = ULib.getUser(sid)
qtype = 2
if not sid then
SGS_SendMessage(ply, "User not found!")
return
end
else
SGS_SendMessage(ply, "User not found!")
return
end
end

if G4PSQL.db:status() == 0 then
if qtype == 2 then
local q1 = G4PSQL.db:query("SELECT * FROM " ..DATABSE_TABLE.. " WHERE steamid = "..G4PSQL_Format( Escape( sid:SteamID() ) ).."")
function q1:onSuccess( data )
if data[1] then
SGS_SendMessage(ply, "Banning player: " ..sid:Nick())
local q2 = G4PSQL.db:query("UPDATE " ..DATABSE_TABLE.. " SET banned=" .. G4PSQL_Format( Escape( "TRUE" ) ) .. ", badmin=" .. G4PSQL_Format( Escape( baid ) ) .. ", breason=" .. G4PSQL_Format( Escape( reason ) ) .. " WHERE steamid=" ..G4PSQL_Format( Escape( sid:SteamID() ) ) )
function q2:onSuccess( data2 )
SGS_SendMessage(ply, "Player Banned for " ..reason.."!")
ULib.tsayColor(_, 1, Color(0,0,0,255), "(", Color(255,0,0,255), sid:Nick(), Color(0,0,0,255), ") ", Color(255,255,255,255), "was globally banned by ", bacolor, badmin, Color(255,255,255,255), " for ", Color(0,0,0,255), reason, Color(255,255,255,255), ".")
ULib.kick( sid, "BANNED! Visit our website at www.g4p.org to dispute this ban."  )
end
function q2:onError( Q, E )
ServerLog( "ERROR!!! " .. Q .. "\n" )
ServerLog( "ERROR!!! " .. E .. "\n" )
end
q2:start()
else
SGS_SendMessage(ply, "No Entry Found")
SGS_SendMessage(ply, "No Results Found ... Creating Entry")
local q3 = G4PSQL.db:query( "INSERT INTO " ..DATABSE_TABLE.. " ( steamid, pname, pgroup, lastplayed, banned, badmin, breason ) VALUES( " ..G4PSQL_Format( Escape( sid:SteamID() ) ) .. ", " ..G4PSQL_Format( Escape( "ADMIN ENTERED" ) ) .. ", " .. G4PSQL_Format( Escape( "user" ) ) .. ", " ..G4PSQL_Format( Escape( tostring("NEVER") ) ) .. ", " ..G4PSQL_Format( Escape( "TRUE" ) ).. ", " ..G4PSQL_Format( Escape( "NONE" ) ).. ", " ..G4PSQL_Format( Escape( reason ) ).." )" )
function q3:onSuccess( data3 )
SGS_SendMessage(ply, "Player Banned for " ..reason.."!")
ULib.tsayColor(_, 1, Color(0,0,0,255), "(", Color(255,0,0,255), sid:Nick(), Color(0,0,0,255), ") ", Color(255,255,255,255), "was globally banned by ", bacolor, badmin, Color(255,255,255,255), " for ", Color(0,0,0,255), reason, Color(255,255,255,255), ".")
ULib.kick( sid:SteamID(), "BANNED! Visit our website at www.g4p.org to dispute this ban."  )
end
function q3:onError( Q, E )
ServerLog( "ERROR!!! " .. Q .. "\n" )
ServerLog( "ERROR!!! " .. E .. "\n" )
end
q3:start()
end
end
q1:start()
else
local q1 = G4PSQL.db:query("SELECT * FROM " ..DATABSE_TABLE.. " WHERE steamid = "..G4PSQL_Format( Escape( sid ) ).."")
function q1:onSuccess( data )
if data[1] then
SGS_SendMessage(ply, "Banning SteamID: " ..sid)
local q2 = G4PSQL.db:query("UPDATE " ..DATABSE_TABLE.. " SET banned=" .. G4PSQL_Format( Escape( "TRUE" ) ) .. ", badmin=" .. G4PSQL_Format( Escape( baid ) ) .. ", breason=" .. G4PSQL_Format( Escape( reason ) ) .. " WHERE steamid=" ..G4PSQL_Format( Escape( sid ) ) )
function q2:onSuccess( data2 )
SGS_SendMessage(ply, "SteamID (" .. sid .. ") Banned for " ..reason.."!")
ULib.tsayColor(_, 1, Color(0,0,0,255), "(", Color(255,0,0,255), sid, Color(0,0,0,255), ") ", Color(255,255,255,255), "was globally banned by ", bacolor, badmin, Color(255,255,255,255), " for ", Color(0,0,0,255), reason, Color(255,255,255,255), ".")
end
function q2:onError( Q, E )
ServerLog( "ERROR!!! " .. Q .. "\n" )
ServerLog( "ERROR!!! " .. E .. "\n" )
end
q2:start()
else
SGS_SendMessage(ply, "No Entry Found")
SGS_SendMessage(ply, "No Results Found ... Creating Entry")
local q3 = G4PSQL.db:query( "INSERT INTO " ..DATABSE_TABLE.. " ( steamid, pname, pgroup, lastplayed, banned, badmin, breason ) VALUES( " ..G4PSQL_Format( Escape( sid ) ) .. ", " ..G4PSQL_Format( Escape( "ADMIN ENTERED" ) ) .. ", " .. G4PSQL_Format( Escape( "user" ) ) .. ", " ..G4PSQL_Format( Escape( tostring("NEVER") ) ) .. ", " ..G4PSQL_Format( Escape( "TRUE" ) ).. ", " ..G4PSQL_Format( Escape( "NONE" ) ).. ", " ..G4PSQL_Format( Escape( reason ) ).. " )" )
function q3:onSuccess( data3 )
SGS_SendMessage(ply, "SteamID (" .. sid .. ") Banned for " ..reason.."!")
ULib.tsayColor(_, 1, Color(0,0,0,255), "(", Color(255,0,0,255), sid, Color(0,0,0,255), ") ", Color(255,255,255,255), "was globally banned by ", bacolor, badmin, Color(255,255,255,255), " for ", Color(0,0,0,255), reason, Color(255,255,255,255), ".")
end
function q3:onError( Q, E )
ServerLog( "ERROR!!! " .. Q .. "\n" )
ServerLog( "ERROR!!! " .. E .. "\n" )
end
q3:start()
end
end
q1:start()
end
else
SGS_SendMessage(ply, "DATABASE NOT CONNECTED PLEASE TRY AGAIN!")
G4PSQL_ConnectToDatabase()
end
else
SGS_SendMessage(ply, "This command is reserved for administrators only!")
end
end
concommand.Add( "g4p_ban", G4PSQL_Ban)


function G4PSQL_UnBan( ply, cmd, args )
local sid = args[1]
banmin = "NONE"
bacolor = Color(255,255,255,255)

if !IsValid( ply ) or ply:IsAdmin() then
if IsValid(ply) then
badmin = ply:Nick()
bacolor = team.GetColor(ply:Team())
else
badmin = "(Console)"
bacolor = Color(80,80,80,255)
end

if #args != 1 then
SGS_SendMessage(ply, "Wrong number of arguements!")
end

if G4PSQL.db:status() == 0 then
local q1 = G4PSQL.db:query("SELECT * FROM " ..DATABSE_TABLE.. " WHERE steamid = "..G4PSQL_Format( Escape( sid ) ).."")
function q1:onSuccess( data )
if data[1] then
if data[1]["banned"] == "TRUE" then
SGS_SendMessage(ply, "UnBanning SteamID: (" ..sid .. ")")
local q2 = G4PSQL.db:query("UPDATE " ..DATABSE_TABLE.. " SET banned="..G4PSQL_Format( Escape( "FALSE" ) ) .. " WHERE steamid=" ..G4PSQL_Format( Escape( sid ) ) )
function q2:onSuccess( data2 )
ULib.tsayColor(_, 1, Color(0,0,0,255), "(", Color(255,0,0,255), sid, Color(0,0,0,255), ") ", Color(255,255,255,255), "was unbanned by ", bacolor, badmin, Color(255,255,255,255), ".")
SGS_SendMessage(ply, "SteamID (" .. sid .. ") Unbanned!")
end
function q2:onError( Q, E )
ServerLog( "ERROR!!! " .. Q .. "\n" )
ServerLog( "ERROR!!! " .. E .. "\n" )
end
q2:start()
else
SGS_SendMessage(ply, "Player Found... but player isn't currently banned...")
end
else
SGS_SendMessage(ply, "No Entry Found")
SGS_SendMessage(ply, "Couldn't find SteamID: " .. sid)
end
end
q1:start()
else
SGS_SendMessage(ply, "DATABASE NOT CONNECTED PLEASE TRY AGAIN!")
G4PSQL_ConnectToDatabase()
end
else
SGS_SendMessage(ply, "This command is reserved for administrators only!")
end
end
concommand.Add( "g4p_unban", G4PSQL_UnBan)

But you will need to do some modifications to make it work for you. There it is if you want to try your hand at it.

It uses MySQLOO, you can find it on Facepunch.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX User mysql
« Reply #7 on: January 19, 2013, 07:40:31 PM »

Code: [Select]
local DATABASE_PASSWORD = ""


I've been looking for a nice new database server to store my stolen important data.
Thanks for the code!

:P
(Yes, I know...I'm joking)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: ULX User mysql
« Reply #8 on: January 20, 2013, 09:25:35 AM »
Wow thanks a lot Mr President, that can be handy for so much!
Just by glancing over it, it looks like it's a lot bigger than just moving a person to a group. It actually handles and manages groups, bans, etc. Very cool!
My TTT server. Join the fun!

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: ULX User mysql
« Reply #9 on: January 20, 2013, 12:17:49 PM »

I've been looking for a nice new database server to store my stolen important data.
Thanks for the code!

:P
(Yes, I know...I'm joking)

Good luck trying to access it from off the local machine though. :P

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: ULX User mysql
« Reply #10 on: March 03, 2013, 10:56:14 PM »
Alright, so I've been working on my first major project, creating a donation system from scratch. It's pretty much done, and I used your code above to connect to my DB, and retrieve the donation amount for a connecting player. But now I need to know, what would be the best practice for retaining that amount on each connected player server-side, and retrieving it from different scripts? Do I need to set up a table or a variable, or do I save it to their pdata? I really struggle to understand this part of gmod lua.

I don't need help with how to do these things, I just need help with how to properly store and retrieve the information. I'd like to do things like build in donor perks, and display donation status on my scoreboard, etc. So I would be calling this information from multiple scripts.

Thanks!
My TTT server. Join the fun!

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: ULX User mysql
« Reply #11 on: March 04, 2013, 06:11:31 PM »
Ok, so I've found that this data is being stored locally (thanks stickly for the tips), but only server-side.
I'm having trouble sending the data gathered from the db to client side of things.

Anyone care to show how it's done? Thanks
My TTT server. Join the fun!

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: ULX User mysql
« Reply #12 on: March 05, 2013, 07:37:59 AM »
Stickly pointed me toward
Code: [Select]
function ULib.clientRPC( plys,
fn,
... )
But the documentation lacks any examples, and it's hard for me to grasp exactly how to use it, and what it actually does.

Could anyone write a quick and dirty example of this in use, both on the client and server side? Doesn't even have to be relevant to my original question.
Or better yet, point me to where this is used in an existing script.

Other people have told me to use net but that is also confusing with insufficient documentation (for me).

Basically I have a working script, but have hit a brick wall in transferring data between client and server.
« Last Edit: March 05, 2013, 07:39:47 AM by krooks »
My TTT server. Join the fun!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX User mysql
« Reply #13 on: March 05, 2013, 02:27:56 PM »
Stickly uses the heck out of it for XGUI menu info updates.
But, more simple examples within ULX.
lua/ulx/modules/sh/user.lua
Code: [Select]
function ulx.usermanagementhelp( calling_ply )
if calling_ply:IsValid() then
ULib.clientRPC( calling_ply, "ulx.showUserHelp" )
else
ulx.showUserHelp()
end
end
local usermanagementhelp = ulx.command( CATEGORY_NAME, "ulx usermanagementhelp", ulx.usermanagementhelp )
usermanagementhelp:defaultAccess( ULib.ACCESS_ALL )
usermanagementhelp:help( "See the user management help." )

Or
/lua/ulx/base.lua
Code: [Select]
local function sendAutocompletes( ply )
if ply:query( "ulx map" ) or ply:query( "ulx votemap2" ) then -- Only send if they have access to this.
ULib.clientRPC( ply, "ulx.populateClMaps", ulx.maps )
ULib.clientRPC( ply, "ulx.populateClGamemodes", ulx.gamemodes )
end

ULib.clientRPC( ply, "ulx.populateClVotemaps", ulx.votemaps )
ULib.clientRPC( ply, "ulx.populateKickReasons", ulx.common_kick_reasons )
end
hook.Add( ULib.HOOK_UCLAUTH, "sendAutoCompletes", sendAutocompletes )
hook.Add( "PlayerInitialSpawn", "sendAutoCompletes", sendAutocompletes )

-- This will load ULX client side
local function playerInit( ply )
local _, v, r = ulx.getVersion()
ULib.clientRPC( ply, "ulx.clInit", v, r )
end
hook.Add( "PlayerInitialSpawn", "ULXInitPlayer", playerInit )

Our ULib docs seems, to me, to explain it pretty well.
Treat any function as though it's run on client. Parameters passed get used.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline krooks

  • Sr. Member
  • ****
  • Posts: 382
  • Karma: 32
  • I don't like video games.
    • Diamond Krooks
Re: ULX User mysql
« Reply #14 on: March 06, 2013, 01:14:43 AM »
Thank you JamminR for those snippets.
I spent about 2 hours messing with my code, trying to mimic those, but came up with nothing.
I wrote a long frustrated post, about how I don't think I'm cut out for this type of code, gave it a break, and started to mess with some other code, when I ran across a good SetNWInt / GetNWInt example.

And this is what I came up with:

Code: [Select]
server:
ply.donation = data[1]["donation"]
        ply:SetNWInt("donation", ply.donation )

client:
draw.SimpleText('Total donations: $' ..LocalPlayer():GetNWInt("donation"), 'PS_Heading3', self:GetWide() - 10, 0, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_BOTTOM)
and it worked! (and now it is WAY too late for a week night)
My TTT server. Join the fun!