Author Topic: Ulib/ULX function overriding (and now Hooks too) - MySQL  (Read 13894 times)

0 Members and 1 Guest are viewing this topic.

Offline EraYaN

  • Newbie
  • *
  • Posts: 10
  • Karma: 1
  • -EraYaN-
    • EraYaN
Ulib/ULX function overriding (and now Hooks too) - MySQL
« on: March 13, 2011, 05:28:09 AM »
HI,

I want to do the following thing:
Create full mySQL bindings for ULib/ULX, mySQL is not the problem. but how would I go and overriding ulib/ulx functions like ban/kick basicly only the file writing functions need overriding, right?
I would love to override in separate files so ULib updates wont ruin my functions. But I couldn't find anything helpful on the internet.
And if anyone wants to help, svn is up.

EraYaN
« Last Edit: March 13, 2011, 02:42:11 PM by EraYaN »
-EraYaN-

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Ulib/ULX function overriding
« Reply #1 on: March 13, 2011, 09:54:12 AM »
The knee-jerk response would be that you should use a hook like this one, but I think you'd be better off simply redefining the kick and ban functions listed here.
Experiencing God's grace one day at a time.

Offline EraYaN

  • Newbie
  • *
  • Posts: 10
  • Karma: 1
  • -EraYaN-
    • EraYaN
Re: Ulib/ULX function overriding
« Reply #2 on: March 13, 2011, 02:18:23 PM »
Thanks for the response!

Hooks seems fine to use, they tend to work like C#/Java/C++ events right?

Ok I still need your help, I just started Lua after a long time other languages like C++, C# and PHP
(I hate the not be able to test immediately, anything?)
I copied your way of getting the code run
so in autorun folder there is and file the includes init.lua and that one includes my file I put some examples in:
Code: [Select]
function ULib.slap( ent, damage, power, nosound )
Msg('Slap override')
end
-- way of overriding?

-- ban hook function
function banHook(ply, commandName, translated_args)

end
hook.Add("ULibPostTranslatedCommand", "EraYaNBanHook", banHook) -- or is there a ulib/ulx alternative


-- player join (add to mysql database)
function playerJoinDB(ply)
-- check if player in db otherwise add him/her
end
hook.Add("UCLAuthed", "HookName", playerJoinDB) -- or is there a ulib/ulx alternative

I tested it but not a very good result
Code: [Select]
Registering gamemode 'sandbox' derived from 'base'
Sending 270 'User Info' ConVars to server (cl_spewuserinfoconvars to see)
Scanning for downloaded fonts..
Reloading Particles..
Client "[BB] EraYaN" spawned in server (192.168.1.54:27006)<STEAM_0:1:2700xxxx>.
Welcome to Garry's Mod dedicated server! We're playing gm_construct.
Redownloading all lightmaps
ULX version <SVN> unknown revision loaded.
Player [1][unconnected] authed <-- shouldn't my player auth hook thing show after this line
test true

///////////////////////////////////////
//  ULX GUI -- Made by Stickly Man!  //
///////////////////////////////////////
// Loading GUI Modules...            //
-snip-
// Modules Loaded!                   //
///////////////////////////////////////

] ulx slap "[BB] EraYaN"
You slapped Yourself with 0 damage <-- and the other hook overhere

I probably missed something but i just so new  to gmod lua and the hook/ulx system

EraYaN

EDIT: I looked at the log files, it seems that by changing the function ulx.logWriteln( str ) (preferably not in the log.lua but in an external file) or maybe hooking on to it(best way i guess) that I can send all the logs to a MySQL database right? or anywhere else.
« Last Edit: March 13, 2011, 02:23:28 PM by EraYaN »
-EraYaN-

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Ulib/ULX function overriding
« Reply #3 on: March 13, 2011, 02:44:29 PM »
My guess would be that you're not overriding ULib.slap (the function) because you're setting up the function before ULib does (and thus, ULib is actually overwriting yours).

As far as the hooks, there's no ULib alternative to hook.Add (except that we just make the hook system in general more awesome). You didn't show any print messages in those two hooks, so I don't see why you should expect them to print?
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Ulib/ULX function overriding (and now Hooks too) - MySQL
« Reply #4 on: March 13, 2011, 03:08:21 PM »
EraYan, you can (almost) always guarantee your code/functions run after ULib initializes if you put them in Gmod's addons and ULX/ULib's modules format.
gmod root/addons/Your_SQL_addon_name/lua/<ulib | ulx>/modules/<your lua files>
Make sure to use an info.txt within your addon_name folder. (See all other addons for an example, or the gmod wiki)
As ulib or ulx initialize (depending on which modules folder you used), the code you place there will load.

As for immediate testing, lua_run is your friend. as is lua_run_cl
My other team members will be able to help you more with that.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline EraYaN

  • Newbie
  • *
  • Posts: 10
  • Karma: 1
  • -EraYaN-
    • EraYaN
Re: Ulib/ULX function overriding (and now Hooks too) - MySQL
« Reply #5 on: March 14, 2011, 01:22:21 PM »
i'm getting futher now

i was trying to get the logsystem working, but dont you guy have something like and OnLog hook?
-EraYaN-

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Ulib/ULX function overriding (and now Hooks too) - MySQL
« Reply #6 on: March 14, 2011, 03:27:18 PM »
Not in ULib directly, no.
http://ulyssesmod.net/docs/index/General.html - functions
http://ulyssesmod.net/docs/index/Hooks.html - hooks

Unfortunately, ULX isn't as well documented <externally> like ULib is.
I'm reasonably sure that it doesn't have a hook in it for logging only.

You may find ULib's ULibCommandCalled hook useful, but, its been so long since I've looked at ULX's logging, I don't remember if it calls any ULib functions, or just uses it's own.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline EraYaN

  • Newbie
  • *
  • Posts: 10
  • Karma: 1
  • -EraYaN-
    • EraYaN
Re: Ulib/ULX function overriding (and now Hooks too) - MySQL
« Reply #7 on: March 21, 2011, 12:05:57 PM »
It uses it's own :(

ok I'm making progress. Next thing to do is design the UCL queries. Logging is working, User tracking is working (tracks deaths/frags).
I was thinking where does ulx save things like teams? ads? gimp messages? and all stuff like that.

-EraYaN-
-EraYaN-

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Ulib/ULX function overriding (and now Hooks too) - MySQL
« Reply #8 on: March 21, 2011, 12:23:09 PM »
It saves it wherever it's most convenient. If it's something to do with groups, it's saved inside groups.txt. If you want to save user-specific data, you'd want to save it to users.txt (there's ULib functions to save the file). Otherwise, create your own file or use SQLite or MySQL.
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Ulib/ULX function overriding (and now Hooks too) - MySQL
« Reply #9 on: March 21, 2011, 03:22:12 PM »
I was thinking where does ulx save things like teams? ads? gimp messages? and all stuff like that.
gmod root/data/ulib for users/groups
gmod root/data/ulx/<various> for settings/permap settings/ads/etc

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline EraYaN

  • Newbie
  • *
  • Posts: 10
  • Karma: 1
  • -EraYaN-
    • EraYaN
Re: Ulib/ULX function overriding (and now Hooks too) - MySQL
« Reply #10 on: March 30, 2011, 10:52:22 AM »
Thanks for the help but maybe you could help me with some lua.

Code: [Select]
function erayan.doCheckGroup(name, inherit_from, displayname, can_target)
if not erayan.database.state == 0 then
notifyerror( 'SQL Connection not open.' )
return false
else
if inherit_from == nil then
inherit_from = ''
end
if can_target == nil then
can_target = ''
end
local queryText = erayan.queries['select_group']:format(name,erayan.config.server)
print( 'EraYaN: ','Query',queryText)
local query = erayan.database:query(queryText)
if (query) then
query.onFailure = erayan.checkGroupOnFailure
query.onSuccess = erayan.checkGroupOnSuccess
query.onData = erayan.checkGroupOnData
query.name = name
query.inherit_from = inherit_from
query.displayname = displayname
query.can_target = can_target
query:start()
print( 'EraYaN: ','-----------------------Checking Group-----------------------')
else
table.insert(erayan.database.pending, {queryText})
CheckStatus()
print( 'EraYaN: ','-----------------------Check Group Query Pending-----------------------')
end

end
end

function erayan.checkGroupOnFailure(self, err)
notifyerror( 'SQL Check Group Fail ', err )
end

function erayan.checkGroupOnSuccess()
print( 'EraYaN: ', '-----------------------Checked Group----------------------- ')
end

function erayan.checkGroupOnData(self, datarow)
print( 'EraYaN: ','-----------------------Recieved Group Data----------------------- ')
print( 'EraYaN: ','DataRow', datarow['Hits'])
print( 'EraYaN: ',type(datarow['Hits']),datarow['Hits'])
if datarow['Hits']  == "0" then
print( 'EraYaN: ','-----------------------Adding group...----------------------- ')
erayan.doAddGroup( self.name, self.inherit_from, self.displayname, self.can_target )
else
print( 'EraYaN: ','-----------------------Updating group...----------------------- ')
erayan.doUpdateGroup( datarow['ulibGroupID'], self.inherit_from, self.displayname, self.can_target )
end
end

it runs the first function (as it should) and prints

Code: [Select]
EraYaN:         Query  <query here>
EraYaN:         -----------------------Checking Group-----------------------

it works on my users so I dont get why it doesn't call the callbacks

EDIT: the queries are ok they run fine in MySQL workbench
EDIT2: checked again, queries run but callbacks aren't called
« Last Edit: March 31, 2011, 08:31:29 AM by EraYaN »
-EraYaN-

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Ulib/ULX function overriding (and now Hooks too) - MySQL
« Reply #11 on: April 01, 2011, 08:26:56 PM »
You'll have to share how you're hooking those functions.
Experiencing God's grace one day at a time.

Offline EraYaN

  • Newbie
  • *
  • Posts: 10
  • Karma: 1
  • -EraYaN-
    • EraYaN
Re: Ulib/ULX function overriding (and now Hooks too) - MySQL
« Reply #12 on: August 27, 2011, 02:58:56 PM »
So i'm digging my old topic to the top again because of the following:

I want to load bans from mysql.

But what function is actually used to load the bans uLib.refreshBans()? I've overridden that one but no avail.

EDIT: I fixed it for now by just rerunning the function not as nice tho. and still not making the bans in effect.
EDIT2: the server doesn't seem to execute callback when no one's connected, thats a problem because what is the first player to join is banned?
EDIT3: I tried to hook a console command (bot) to Initialize but it returns: "Error, bad server command bot"
Code:
Code: [Select]
function wakeUpWithBot()
game.ConsoleCommand( "bot" ) -- Execute after done loading bans
timer.Create("EraYaNRemoveBot", 10, 1, function() for k, v in pairs(player.GetBots()) do  Msg( ULib.queueFunctionCall( game.ConsoleCommand, ("kickid %i"):format(v:UserID()) ) ) end end)
end
hook.Add("Initialize", "EraYaNWakeUpWithBot", wakeUpWithBot)--InitPostEntity gives same error
some where here.. Any hook called then?
http://erayan.eu/jing/right_there.png
« Last Edit: August 28, 2011, 01:30:14 PM by EraYaN »
-EraYaN-