ULX

Author Topic: Sourcebans and ULX  (Read 317 times)

0 Members and 1 Guest are viewing this topic.

Offline LeviN

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Sourcebans and ULX
« on: March 27, 2020, 10:23:13 AM »
Hey guys. Was not sure if this was the place to post this but could use some help with the latest sourcebans ++ and a sourcebans lua script.

I currently use: https://github.com/blastehh/AnotherULXSBanModule
Using the latest mysqloo and have the script in place from tmpsql to convert everything to mysqloo following some threads.

I currently have been reproducing these errors every day, at the start of map change only.

Errors presented : https://pastebin.com/GWSsRMLn
Now it bans users and goes into the database without any issue. It does not pick up the bans from the webhost/database and show them in the menu that the script creates. Could anyone be able to help out? Completely new to this and its a learning process for me.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 795
  • Karma: 57
Re: Sourcebans and ULX
« Reply #1 on: March 27, 2020, 02:00:57 PM »
Replied on Discord but will post here too for anyone else:

https://github.com/blastehh/AnotherULXSBanModule/blob/master/garrysmod/addons/anotherulxsbanmodule/lua/ulx/modules/sban.lua#L308

This is the root of the first error. Looking at the source, SBAN_SQL_Query doesn't always return a value, but when it does it returns a function: https://github.com/blastehh/AnotherULXSBanModule/blob/master/garrysmod/addons/anotherulxsbanmodule/lua/ulx/modules/sban.lua#L150

The function SBAN_canunban (which is the function where the error is thrown at line 308) returns #SBAN_SQL_Query(query, qTab) > 0, but since SBAN_SQL_Query either returns nil or a function, the length operator (#) throws an error.
So, I think, if I understand the code right, if you change line 308 from return #SBAN_SQL_Query(query, qTab) > 0 to return #(SBAN_SQL_Query(query, qTab)(query)) > 0. Notice the extra parameter call to the function return.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Discord

Online JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8073
  • Karma: 388
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Sourcebans and ULX
« Reply #2 on: March 27, 2020, 03:42:21 PM »
Also - in issue tracker of project, dev explains what is expected to be returned.
https://github.com/blastehh/AnotherULXSBanModule/issues/16#issuecomment-245778459
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 795
  • Karma: 57
Re: Sourcebans and ULX
« Reply #3 on: March 29, 2020, 03:06:47 AM »
Also - in issue tracker of project, dev explains what is expected to be returned.
https://github.com/blastehh/AnotherULXSBanModule/issues/16#issuecomment-245778459

Thanks :)

I'm currently trying to understand the script and I'm beginning to understand how it functions. I've worked through how the SQL data is returned (it's returned as a table of tables of tables, very convoluted IMO) but I'm figuring it out.

I'll post back here once everything is fixed! There were more bugs than just the one stated here.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Discord

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 795
  • Karma: 57
Re: Sourcebans and ULX
« Reply #4 on: March 29, 2020, 07:27:55 PM »
We found the solution!

If you don't care how to do it and just want the solution, here you go: https://github.com/iViscosity/AnotherULXSBanModule

Turns out the return type for the implementation of pmysql is very convoluted (the query returns a table of tables of tables:
Code: [Select]
result = {
1:
{
data = {
1:
{
field_name = field_value
}
}
}
}

so to access field_name you need to call:

Code: [Select]
result[1].data[1].field_name
Once I figured that out, it was relatively simple to track down how everything was being called. The first error, shown in the pastebin in OP's post, was solved by replacing

Code: Lua
  1. #SBAN_SQL_Query(query, qTab) > 0
  2.  
on line 308 with:

Code: Lua
  1. SBAN_SQL_Query(query, qTab) ~= nil
  2.  
while also replacing the return type of SBAN_SQL_Query(sql, qTab) from:

Code: Lua
  1. return function(sql)
  2.         local results = database_sban:query_sync(sql)
  3.         return results[1].data
  4. end
  5.  
on lines 154-157 with:

Code: Lua
  1. return function(sql)
  2.         local results = database_sban:query_sync(sql)
  3.         return results[1]
  4. end
  5.  
because the return type of query_sync will ALWAYS be a table, but it MAY be an empty table.

I also removed the function

Code: Lua
  1. local function SBAN_SQL_Query_Callback(results, qTab)
  2.         qTab.cb(results, qTab)
  3. end
  4.  

because I could simply call SBAN_SQL_Query like:
Code: Lua
  1. SBAN_SQL_Query(sql, qTab.cb, qTab)
  2.  
I'm iViscosity. I like gaming and programming. Need some help? Shoot me a PM or Join my Discord!.
--==[ Links ]==--
Steam
YouTube
Steam Group (feel free to join!)
Discord

Offline LeviN

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: Sourcebans and ULX
« Reply #5 on: March 29, 2020, 07:37:33 PM »
Yup, solved! Appreciate the time and effort taken to fix this!

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 251
  • Karma: 167
  • Code monkey
    • ULX Unofficial Documentation
Re: Sourcebans and ULX
« Reply #6 on: March 31, 2020, 05:16:02 AM »
Great job, iViscosity! ;D