• Print

Author Topic: How does the ULX ban time work?  (Read 8122 times)

0 Members and 1 Guest are viewing this topic.

Offline Jet

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
How does the ULX ban time work?
« on: October 06, 2014, 07:58:57 pm »
I looked through the code and found where it records the ban and figures out when to unban them etc but I'm just wondering how ULX checks/knows if it's time to unban them. I've done some googling and haven't found anything but please let me know if I've missed something. Thanks.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: How does the ULX ban time work?
« Reply #1 on: October 06, 2014, 08:27:22 pm »
If I recall, and quick review of ULib.addBan, all we do is allow the server to update after it starts, then start tracking it's own temporary bans.
That is, Source/Gmod doesn't track temp bans across sessions (at least, it didn't used to, perhaps it does now, it's been years since I last researched)
So, you temp ban someone for 20 minutes, server crashes, restarts 10 minutes later (not a map change, I think it tracks across that), without ULib or other admin mod tracking it, the banned user could then join.
All we do is write additional ban info, including the expiration time, to /data/ulib/bans.
The server does it's own time tracking.
If the server restarts, while execing the normal permanent banned_user.cfg and banned_ip.cfg, we then load our bans.txt and 'reban' those that have not expired.
The normal source engine then does the tracking from there.

Then again, my recollection may be off.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jakej78b

  • Newbie
  • *
  • Posts: 26
  • Karma: 4
Re: How does the ULX ban time work?
« Reply #2 on: October 30, 2014, 11:04:44 am »
I've recently started using the global ban feature, which seemed to not have any automatic unbanning or maybe I just missed it. This might be something that the ulysses team should do to their bans as well. In the CheckPassword hook, I simply added a function to check if the expired time was less than or equal to the current time, and if it was just remove the ban by calling ULib.unban.

Code: Lua
  1. hook.Add('CheckPassword','CheckTheBanned', function(steamid64, ip, sv_password, cl_password, cl_name)
  2.         if( string.len( sv_password ) > 0 and sv_password ~= cl_password )then
  3.                 return false, "Bad Password."
  4.         end
  5.  
  6.         local steamid = util.SteamIDFrom64( steamid64 )
  7.         local curTime = os.time()
  8.         local c_ban = ULib.bans[ steamid ]
  9.                
  10.         if( c_ban ~= nil )then
  11.                 if c_ban.unban <= curTime then
  12.                         ULib.unban( steamid )
  13.                         print("Unbanning "..cl_name.." ("..steamid..") for expired ban.")
  14.                         return true
  15.                 else
  16.                         return false, "You've been banned from this server."
  17.                 end
  18.         end
  19. end)
  20.  
I'm using this to leave source banning completely out of it however, since I used a database rather than a text file. This would however be splitting ULib/ULX bans completely apart from source banning, which you may not want. At first I was thinking that you were using some sort of timer, but then I realized that source does all that work for you behind the scenes, just kinda a recommendation/change that might be wanted. Seems like ULib/ULX is still built upon concepts that were only required in previous versions, and it should be updated to use newer concepts for more efficiency.
« Last Edit: October 30, 2014, 11:14:42 am by jakej78b »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: How does the ULX ban time work?
« Reply #3 on: October 30, 2014, 03:28:45 pm »
So let me verify what you're saying;
You check the ban time on each join using lua code (and ULib ban table parts).
We load all the temp ban times at start up, and let the server maintain it's internal bans.

Though I can imagine our method causing some strain during server start up for large ban files, how is using lua to check bans every join more efficient than the Source server running it's own checks before Lua is even initiated for the player?
(Please understand I'm not intending to be argumentative/sarcastic, I find the idea and discussion potential here interesting and perhaps educational).
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jakej78b

  • Newbie
  • *
  • Posts: 26
  • Karma: 4
Re: How does the ULX ban time work?
« Reply #4 on: October 31, 2014, 07:39:19 pm »
I'm not sure if I could argue with that, since the source method does get called before lua is initialized. However, I thought hooking CheckPassword completely overrode the source check for a bad password, which is the first thing that is called when you attempt to join a server to my knowledge. Using CheckPassword may not be as efficient, but it would be more informative to the user that was banned by displaying information about the ban. I guess when I wrote that I was thinking that you were using lua to catch users who joined, I wasn't thinking about the built in source banning at all. Source automatically unbans people when their time is up, how does ULib notice that and remove the ban from the table (ULib.bans) and file (data/ulib/bans.txt)?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: How does the ULX ban time work?
« Reply #5 on: November 01, 2014, 07:31:41 am »
-thought hooking CheckPassword completely overrode the source check for a bad password
-would be more informative to the user that was banned by displaying information about the ban
Not sure fully how CheckPassword works, but, yes, Garry may have written to do just that on the server side. Server lua would be running before the player's lua init would of course, so I could see it could basically overwrite.
I agree with your "more information" idea and like it. My only concern would be that of ban spam.
When minges constantly bang against the locked door of a ban, and the server constantly notifies the other players "idiot tried connecting, but is banned" 20-30 times, though annoying, it's not too much info. If using Lua to send reasons/admin who did it, time expired, whatever info, you then add to the server's workload to send to the ban minge.
Not sure how much more, but, just a slight concern I'd wonder about.

Source automatically unbans people when their time is up, how does ULib notice that and remove the ban from the table (ULib.bans) and file (data/ulib/bans.txt)?
Honestly, after looking, I'm not 100% sure.
ULib has ULib.refreshBans(), but I can't see that we ever call it in ULX.
Nor in my reasonably quick (10 minutes of) searching our repo, I only see that we update the ban table on Ulib.unban and at server startup*. (* = read on, see educated guess)

As for the bans.txt file, hate to admit this, but I'm somewhat lost.
ULX checks the banned users time within the file at server startup (and a ban, if another admin rebans after the first); but I can't find the code relating to when exactly when, if it does, that it's removed when
If that time has past, the ban is not added to the table.
Here's my educated guess - I think we just use attrition.
Temp ban expires mid-game. Player joins. ULib (and ULX) doesn't care. (Remember, we let Source server do the checking).
However, at server startup (and somewhere else I forgot), we re-write the bans.txt file after updating/verifying the time within it.
Those 'temp' bans from bans.txt aren't added to the server's clock, and, I think they're not written back into bans.txt
Either that, or, we just keep the info in bans.txt for historical purposes. I don't have a test server right now to test, but you've gotten my "Wish I had time to install Gmod server to test" juices flowing.

Megiddo/Stickly Man would best know questions to you and could confirm deny any of my theories.
Not sure how much MrPresident has dug into our ban/unban code, but he could probably assist too.
Maybe they'll stop by
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: How does the ULX ban time work?
« Reply #6 on: November 01, 2014, 03:04:30 pm »
Ah, this is likely XGUI's doing- I've added code to create timers every hour for unbanning users. It definitely isn't the best way (or place) to handle it, but I think I added back when XGUI was not a part of standard ULX.

You can see the code here: https://github.com/Nayruden/Ulysses/blob/master/ulx/lua/ulx/xgui/server/sv_bans.lua#L258-268
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline jakej78b

  • Newbie
  • *
  • Posts: 26
  • Karma: 4
Re: How does the ULX ban time work?
« Reply #7 on: November 01, 2014, 05:42:46 pm »
Ah, this is likely XGUI's doing- I've added code to create timers every hour for unbanning users. It definitely isn't the best way (or place) to handle it, but I think I added back when XGUI was not a part of standard ULX.

This is a good example of code that should be updated and moved. You'd think unbanning and updating files would be part of ULib, not part of a gui addon for ulx. Wouldn't you say unbanning would be better handled within CheckPassword than it would br in a timer?

I could understand how continually requesting information about the ban could be resource intensive, but you could easily add a flood filter or just leave the information out completely. Even if you still allow source to handle the bans, CheckPassword seems like the best hook for ULib to perform it's table and file updating.

  • Print