GetPlayerEndpoint and others not null w/ temporary IDs

Expected Result: On artifact 4162 and before, when a player had disconnected or left server, getting the value of GetPlayerEndpoint or similar natives would return nil.

Actual Result: On artifact 4394 and 4445 (the two I tested), even after disconnection GetPlayerEndpoint and GetPlayerGuid would return valid values instead of nil for temporary IDs only. This is contrary to actual server IDs that will return nil after player disconnection.

More Info: This only happens to temporary IDs after a player has completely connected to the server. If the player is dropped by deferrals in playerConnecting then this does not occur and it returns nil as expected.

Reproduction

local sources = {}

AddEventHandler('playerConnecting', function(name, setKickReason, deferrals)
    table.insert(sources, source)
    local player = source

    Citizen.Wait(5000)
    DropPlayer(player, 'aloha')
end)
AddEventHandler('playerDropped', function(reason)
    print('playerDropped', source, reason)
    local player = source

    -- show a delayed version for the actual server id (not temporary)
    Citizen.Wait(1000)
    print(player, GetPlayerEndpoint(player), GetPlayerGuid(player))
end)

Citizen.CreateThread(function()
    while true do
        for _, s in ipairs(sources) do
            print(s, GetPlayerEndpoint(s), GetPlayerGuid(s))
        end
        Citizen.Wait(1000)
    end
end)

Additional Information
Confirmed included fxserver artifacts: 4394,4445
Confirmed excluded fxserver artifacts: 4162 (and before)
Client version: canary @ 4445
Computer: Win 10 Pro

This is a bit odd, since there never was any code to remove the TempID from m_clientsByNetID. What I rather suspect as being the issue here is there somehow being a dangling reference to the client in some cases so the weak_ptr doesn’t get invalidated.

Found the dangling reference cycle. Of course it’s in that component:

PR’d a fix: fix(server/gui): client reference cycle in OnDrop by blattersturm · Pull Request #938 · citizenfx/fivem · GitHu

2 Likes

I appreciate the quick fix :grinning_face_with_smiling_eyes: