• Print

Author Topic: ULib.HOOK_UCLAUTH firing twice and Player:query returns wrong  (Read 3917 times)

0 Members and 1 Guest are viewing this topic.

Offline dataviruset

  • Newbie
  • *
  • Posts: 3
  • Karma: 2
    • My personal homepage
ULib.HOOK_UCLAUTH firing twice and Player:query returns wrong
« on: January 02, 2014, 11:41:27 am »
Hi,

I can't get reserved slots in ULX to work, so I started debugging some in the GLua code (addons/ulx/lua/ulx/modules/slots.lua). I'm running reserved slots mode 3 (only have one slot open and kick players that doesn't have reserved slot access when the server is full).

The code now looks like this (I added some print()'s on line 10, 13 and 42):

Code: Lua
  1. local function playerAccess( ply )
  2.         local mode = GetConVarNumber( "ulx_rslotsMode" )
  3.         if mode == 0 then return end -- Off!
  4.  
  5.         local visible = util.tobool( GetConVarString( "ulx_rslotsVisible" ) )
  6.         local slots = calcSlots()
  7.         local cur = #player.GetAll()
  8.         local max = game.MaxPlayers()
  9.  
  10.         print("Checking player " .. ply:Name() .. "...")
  11.  
  12.         if ply:query( access ) then -- If they have access, handle this differently
  13.                 print("Player " .. ply:Name() .. " has reserved slot access")
  14.                 if not visible then -- Make sure our visible slots is up to date
  15.                         updateSlots()
  16.                 end
  17.  
  18.                 if mode == 3 and cur + slots > max then -- We've got some kicking to do!
  19.                         local shortestply
  20.                         local shortesttime = math.huge
  21.  
  22.                         local players = player.GetAll()
  23.                         for _, player in ipairs( players ) do
  24.                                 if not ULib.ucl.query( player, access ) then
  25.                                         if player:TimeConnected() < shortesttime then
  26.                                                 shortesttime = player:TimeConnected()
  27.                                                 shortestply = player
  28.                                         end
  29.                                 end
  30.                         end
  31.  
  32.                         if not shortestply then -- We've got a server filled to the brim with admins? Odd but okay
  33.                                 return
  34.                         end
  35.  
  36.                         ULib.kick( shortestply, "[ULX] Freeing slot. Sorry, you had the shortest connection time." )
  37.                 end
  38.  
  39.                 return
  40.         end
  41.  
  42.         print("Player " .. ply:Name() .. " doesn't have reserved slot access")
  43.  
  44.         if cur + slots > max then
  45.                 ULib.queueFunctionCall( ULib.kick, ply, "[ULX] Reserved slot, sorry!" ) -- Wait a frame so all access hooks can be called properly.
  46.         end
  47. end
  48. hook.Add( ULib.HOOK_UCLAUTH, "ULXReservedSlots", playerAccess, 20 ) -- Run at the end of auth

This is what happens when players without reserved slot access joins:
Code: [Select]
Checking player a shoe...
Player a shoe doesn't have reserved slot access
Checking player Cookie...
Player Cookie doesn't have reserved slot access
Checking player Chimera...
Player Chimera doesn't have reserved slot access

And this happens when players with access join:
Code: [Select]
Checking player YankingDeez...
Player YankingDeez doesn't have reserved slot access
Checking player YankingDeez...
Player YankingDeez has reserved slot access
Checking player | palsternacka...
Player | palsternacka doesn't have reserved slot access
Checking player | palsternacka...
Player | palsternacka has reserved slot access

Which means that the first time the ULib.HOOK_UCLAUTH hook runs, the reserved slot access players doesn't have access and therefore they get kicked if the server is full.
Should I file a bug report or did I do something wrong? Thanks in advance for any help!
Best regards
dataviruset a.k.a. Ozzzkar

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: ULib.HOOK_UCLAUTH firing twice and Player:query returns wrong
« Reply #1 on: January 03, 2014, 12:07:59 pm »
I tried it a few times and couldn't replicate the issue. Could you try removing all mods but ULX and ULib, run in sandbox, and see if it persists?
Experiencing God's grace one day at a time.

Offline dataviruset

  • Newbie
  • *
  • Posts: 3
  • Karma: 2
    • My personal homepage
Re: ULib.HOOK_UCLAUTH firing twice and Player:query returns wrong
« Reply #2 on: January 03, 2014, 04:11:14 pm »
I tried it a few times and couldn't replicate the issue. Could you try removing all mods but ULX and ULib, run in sandbox, and see if it persists?

Interesting. I didn't have time to make that test right now, maybe I can do it later. I changed the hook to use Garry's Mod's one instead and all issues disappeared (the hook only runs once):
Code: Lua
  1. -- Before
  2. hook.Add( ULib.HOOK_UCLAUTH, "ULXReservedSlots", playerAccess, 20 ) -- Run at the end of auth
  3.  
  4. -- After
  5. hook.Add( "PlayerAuthed", "ULXReservedSlots", playerAccess, 20 )

For reference until I have time to test (or somebody else tries it out), the only mods I ran was ULib + ULX + a slightly modified version of the SourceBans ULX integration module + MapVote. Running on TTT.
Best regards
dataviruset a.k.a. Ozzzkar

  • Print