Repository navigation
Conversation
A player was known by its avatar's entity network ID, drawn from the counter every replicated entity shares, so a server that spawns thousands of entities at startup gave its first player an ID in the thousands. PlayerIdAllocator numbers joined connections the way FiveM numbers server IDs: 1 for the first join after startup, one higher for each join after. A disconnected player's ID is not handed out again until the counter wraps, and then IDs still held are skipped. NetworkServer holds one per connection and releases it with the rest of the connection's state. Entity network IDs are unchanged.
The ID is taken when the join is accepted, before the game builds the avatar, so a request that is refused or abandoned never uses a number up. PlayerConnectionData carries it to OnPlayerConnect, the join is logged with it, and the status command lists joined players by it.
Server-only, beside ping and ip, so every game's Player subclass inherits it. Player.id stays the entity network ID that TextLabel targets and handle transfer rely on.
KickPlayer cleared the connection's identity, and now its player ID, as soon as it asked MafiaNet to close the connection. MafiaNet reports that close a tick or more later, as an ID_DISCONNECTION_NOTIFICATION, and the disconnect handlers that run then (the game's OnPlayerDisconnect, the scripts' playerDisconnect) found a kicked player with no player ID, Steam ID or name. A live connection now keeps that state until its notification is handled; only the build gate closes at the kick. A guid with no live connection gets no notification, so it is still cleared at once.
It is 0 whenever it is unavailable, not only once a player has left, and an ID is reused after the counter wraps. PlayerConnectionData also notes that OnPlayerDisconnect follows only for a player who reached OnPlayerReady, so state keyed on the ID must not rely on it alone.
|
No actionable comments were generated in the recent review. WalkthroughThe server now assigns player IDs to joined connections. It retains connection identity and IDs through disconnect callbacks, exposes the ID through the scripting ChangesConnection player ID flow
Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant ClientJoin
participant NetworkServer
participant PlayerIdAllocator
participant ScriptingPlayer
ClientJoin->>NetworkServer: AssignPlayerId(guid)
NetworkServer->>PlayerIdAllocator: Assign(guid)
PlayerIdAllocator-->>NetworkServer: playerId
ScriptingPlayer->>NetworkServer: GetPlayerId(guid)
NetworkServer-->>ScriptingPlayer: playerId
Suggested reviewers: Merge Risk:
|
|
@coderabbitai review |
Action not completed
|
Player IDs now sit under _clientsMutex with the rest of the per-connection state, and the kick's build-gate erase takes it too.
A player was known to scripts and admins by its avatar's entity network ID. Every replicated entity draws from that one counter, so a server that spawns thousands of entities at startup hands its first player an ID in the thousands. With HogwartsMP's 4,005 loot spots under server authority, the first player after a fresh start got an ID around 4009.
Players now get a player ID of their own, numbered the way FiveM numbers server IDs. The first join after startup is 1 and each join takes the next number. A disconnected player's ID is not handed out again, so a reconnect gets a new one; only after 2^32 - 1 joins does the counter start over at 1, and then it skips IDs still held. Entity network IDs are unchanged.
NetworkServerAssignPlayerId,GetPlayerId(also onNetworkPeer, where it returns 0) andFindPlayerById, which gives the connection; its avatar isGetViewer(guid)PlayerConnectionDataplayerId, assigned when the join is accepted, beforeOnPlayerConnectplayer.playerId, server-only, besidepingandip.player.idstays the entity network ID that TextLabel targets and handle transfer rely onstatuslists joined players as[playerId] name (ping ms), and each join logs<name> joined as player NThe ID is given at join, not at admission, so a request that is refused or abandoned, or a client that leaves mid-download, never uses a number up. A
PendingConnectionhas none yet, whichconnection_admission.mdnow says.The fourth commit fixes a gap the review turned up, already in develop for identity.
KickPlayercleared the connection's state as soon as it asked MafiaNet to close it, but MafiaNet 0.24 reports that close a tick or more later, so a kicked player's disconnect handlers saw no player ID, Steam ID or name. A live connection now keeps its state until the close notification is handled; only the build gate closes at the kick.This is a scripting-layer addition (MINOR): no RPC or wire format changes, and clients do not see player IDs. HogwartsMP already uses
playerIdas a parameter name for entity network IDs in a few APIs (pvp.getStats(playerId),relation.playerId); those want renaming when it adopts this, so the two cannot be mixed up.player_idscovers numbering, no reuse, the wrap, the lookups and the 4,005-entity startup. Over loopback, it also checks that the ID and identity are still readable in the server's disconnect handler after a kick and after a client disconnect. Ajs_featurescase readsplayer.playerIdfrom script. All 835 FrameworkTests and 3 client scripting tests pass with MSVC; it has not been run on a live HogwartsMP server yet.Summary by CodeRabbit
player.playerId; it is distinct from the entity network ID and is0when unavailable.