From 86054f11c4d91b794fbeb2f93bdd7a46fbd58d81 Mon Sep 17 00:00:00 2001 From: terencehill Date: Sat, 10 Aug 2024 12:18:22 +0200 Subject: [PATCH] Reduce code duplication in chat anti spam system --- qcsrc/server/chat.qc | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/qcsrc/server/chat.qc b/qcsrc/server/chat.qc index 2aad1bcfd..b0f349233 100644 --- a/qcsrc/server/chat.qc +++ b/qcsrc/server/chat.qc @@ -189,16 +189,17 @@ int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodc flood_lmax = autocvar_g_chat_flood_lmax; flood_field = floodcontrol_chat; } + // to match cvar descriptions, a value of 3 must allow three-line bursts and not four! flood_burst = max(0, flood_burst - 1); - // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four! + int lines = -1; mod_time = gettime(GETTIME_FRAMESTART) + flood_burst * flood_spl; // do flood control for the default line size if(msgstr != "") { getWrappedLine_remaining = msgstr; msgstr = ""; - int lines = 0; + lines = 0; while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax)) { msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width @@ -211,23 +212,19 @@ int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodc msgstr = strcat(msgstr, "\n"); flood = 2; } + } - if (mod_time >= source.(flood_field)) - { - source.(flood_field) = max(gettime(GETTIME_FRAMESTART), source.(flood_field)) + lines * flood_spl; - } - else - { - flood = 1; - msgstr = fullmsgstr; - } + if (mod_time >= source.(flood_field)) + { + if (lines > 1) + flood_spl *= lines; + source.(flood_field) = max(gettime(GETTIME_FRAMESTART), source.(flood_field)) + flood_spl; } else { - if (mod_time >= source.(flood_field)) - source.(flood_field) = max(gettime(GETTIME_FRAMESTART), source.(flood_field)) + flood_spl; - else - flood = 1; + if (lines >= 0) // if true msgstr was modified + msgstr = fullmsgstr; + flood = 1; } } -- 2.39.2