Skip to content

Translate ##P<n> chat tokens to player names from configstrings#145

Open
ozy24 wants to merge 3 commits intoParil:rerelease-gamefrom
ozy24:fix-chat-player-tokens
Open

Translate ##P<n> chat tokens to player names from configstrings#145
ozy24 wants to merge 3 commits intoParil:rerelease-gamefrom
ozy24:fix-chat-player-tokens

Conversation

@ozy24
Copy link

@ozy24 ozy24 commented Feb 18, 2026

Problem

Rerelease/KEX servers encode player names in chat and broadcast messages as ##P<n> tokens, expecting the client to resolve them. Without client-side handling, these tokens are shown as raw strings (e.g., ##P0 instead of the real player name). This is most noticeable when connected to a dedicated server.

Solution

Added client-side CL_TranslatePlayerNameTokens and called it from CL_HandlePrint to:

  • Resolve tokens: Look up player names using cl.csr.playerskins.
  • Parse Format: Extract the netname from the playerskins configstring format (name\skin\dogtag).
  • State Safety: Exit early if cls.state < ca_loading to ensure cl.csr is valid (set by svc_serverdata).

Verification

  • cl.csr.playerskins matches CS_PLAYERSKINS in shared.c.
  • cl.csr is set correctly for PROTOCOL_VERSION_RERELEASE and PROTOCOL_VERSION_KEX in parse.c.
  • Verified the logic successfully translates tokens on Windows (MSVC 2022).

Q_strlcpy(s, out, size);
}

static void CL_HandlePrint(int level, char *s)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can placeholders occur in any "print" from the server, or just localized prints?

If it's the latter, the translation should only be called from CL_ParseLocPrint().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the server code, ##P tokens occur in broadcast prints, which are sent as regular svc_print messages (not localized prints). So keeping the translation in CL_HandlePrint is necessary to catch them — moving it to CL_ParseLocPrint only would miss them.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking the server should probably not generate "standard" prints in PF_Loc_Print, but that's a different discussion.

@res2k
Copy link
Collaborator

res2k commented Mar 14, 2026

LGTM so far.
@Paril Any notes from your side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants