Fix chat capture: capture any target, deduplicate in buffer

Per-client chat is sent to every connected client in a loop.
Capture chat/tchat commands regardless of target clientNum, and
deduplicate by checking if the exact string is already buffered
for the current frame.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
serge_shubin 2026-03-23 05:55:19 +08:00
parent 90b26dc2a1
commit cc081ddee4
2 changed files with 14 additions and 8 deletions

View file

@ -83,16 +83,11 @@ Sends a command string to a client
=============== ===============
*/ */
void SV_GameSendServerCommand( int clientNum, const char *text ) { void SV_GameSendServerCommand( int clientNum, const char *text ) {
// capture for demo recording (deduplicate: only capture broadcasts // capture for demo recording: broadcasts and per-client chat/tchat
// and first per-client send of chat/print commands)
if ( clientNum == -1 ) { if ( clientNum == -1 ) {
SVD_CaptureServerCommand( text ); SVD_CaptureServerCommand( text );
} else if ( clientNum == 0 ) { } else if ( !strncmp( text, "chat", 4 ) || !strncmp( text, "tchat", 5 ) ) {
// per-client commands sent to client 0 first — capture "chat" and SVD_CaptureServerCommand( text );
// "tchat" once (they'll be sent to all clients in a loop)
if ( !strncmp( text, "chat", 4 ) || !strncmp( text, "tchat", 5 ) ) {
SVD_CaptureServerCommand( text );
}
} }
if ( clientNum == -1 ) { if ( clientNum == -1 ) {

View file

@ -509,12 +509,23 @@ Capture a broadcast server command for the current frame.
Called from SV_SendServerCommand when cl == NULL (broadcast). Called from SV_SendServerCommand when cl == NULL (broadcast).
*/ */
void SVD_CaptureServerCommand( const char *cmd ) { void SVD_CaptureServerCommand( const char *cmd ) {
int i;
if ( !demo.recording ) { if ( !demo.recording ) {
return; return;
} }
if ( demo.numServerCmds >= SVD_MAX_SERVERCMDS ) { if ( demo.numServerCmds >= SVD_MAX_SERVERCMDS ) {
return; // overflow, drop command return; // overflow, drop command
} }
// deduplicate: per-client chat is sent N times (once per client),
// only store the first occurrence
for ( i = 0; i < demo.numServerCmds; i++ ) {
if ( !strcmp( demo.serverCmds[i], cmd ) ) {
return;
}
}
Q_strncpyz( demo.serverCmds[demo.numServerCmds], cmd, SVD_MAX_SERVERCMD_LEN ); Q_strncpyz( demo.serverCmds[demo.numServerCmds], cmd, SVD_MAX_SERVERCMD_LEN );
demo.numServerCmds++; demo.numServerCmds++;
} }