]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Reduce code duplication in chat anti spam system
authorterencehill <piuntn@gmail.com>
Sat, 10 Aug 2024 10:18:22 +0000 (12:18 +0200)
committerterencehill <piuntn@gmail.com>
Sat, 10 Aug 2024 10:31:30 +0000 (12:31 +0200)
qcsrc/server/chat.qc

index 2aad1bcfd94005ff0ee8629f373a39995b62f02d..b0f3492331de7203a2ba0d301a009881cbb14c3c 100644 (file)
@@ -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;
                }
        }