From cc081ddee442b7375cf26d330a9be192b0f65560 Mon Sep 17 00:00:00 2001 From: serge_shubin Date: Mon, 23 Mar 2026 05:55:19 +0800 Subject: [PATCH] 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) --- code/server/sv_game.c | 11 +++-------- code/server/sv_netdemo.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/code/server/sv_game.c b/code/server/sv_game.c index 4063fc7..b227f3c 100644 --- a/code/server/sv_game.c +++ b/code/server/sv_game.c @@ -83,16 +83,11 @@ Sends a command string to a client =============== */ void SV_GameSendServerCommand( int clientNum, const char *text ) { - // capture for demo recording (deduplicate: only capture broadcasts - // and first per-client send of chat/print commands) + // capture for demo recording: broadcasts and per-client chat/tchat if ( clientNum == -1 ) { SVD_CaptureServerCommand( text ); - } else if ( clientNum == 0 ) { - // per-client commands sent to client 0 first — capture "chat" and - // "tchat" once (they'll be sent to all clients in a loop) - if ( !strncmp( text, "chat", 4 ) || !strncmp( text, "tchat", 5 ) ) { - SVD_CaptureServerCommand( text ); - } + } else if ( !strncmp( text, "chat", 4 ) || !strncmp( text, "tchat", 5 ) ) { + SVD_CaptureServerCommand( text ); } if ( clientNum == -1 ) { diff --git a/code/server/sv_netdemo.c b/code/server/sv_netdemo.c index bb2b6de..fc14425 100644 --- a/code/server/sv_netdemo.c +++ b/code/server/sv_netdemo.c @@ -509,12 +509,23 @@ Capture a broadcast server command for the current frame. Called from SV_SendServerCommand when cl == NULL (broadcast). */ void SVD_CaptureServerCommand( const char *cmd ) { + int i; + if ( !demo.recording ) { return; } if ( demo.numServerCmds >= SVD_MAX_SERVERCMDS ) { 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 ); demo.numServerCmds++; }