]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Refactor flood control code to work with .cmd_floodtime initialized to 0
authorterencehill <piuntn@gmail.com>
Fri, 2 Aug 2024 21:05:13 +0000 (23:05 +0200)
committerterencehill <piuntn@gmail.com>
Fri, 2 Aug 2024 21:05:13 +0000 (23:05 +0200)
qcsrc/server/client.qc
qcsrc/server/command/cmd.qc

index 854c1f0d07c193b3058b24fb752c637aea0b3762..575d6d971816ec8bfee5b7e0e2e779af92895db0 100644 (file)
@@ -1115,9 +1115,6 @@ void ClientConnect(entity this)
        TRANSMUTE(Client, this);
        CS(this).version_nagtime = time + 10 + random() * 10;
 
-       entity store = IS_CLIENT(this) ? CS(this) : this;
-       store.cmd_floodtime = -999999;
-
        Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_JOIN_CONNECT, this.netname);
 
        bot_clientconnect(this);
index ca028f12b4395778a62c6b470b61727955fbccc1..4606d2a41fc5905aeaf368b8cd4f7d63d6623de3 100644 (file)
@@ -1056,15 +1056,21 @@ void SV_ParseClientCommand(entity this, string command)
                        {
                                if(MUTATOR_CALLHOOK(ClientCommand_FloodControl, this, strtolower(argv(0)), argc, command))
                                        break; // a mutator has prevented flood control
-                               entity store = IS_CLIENT(this) ? CS(this) : this; // unfortunately, we need to store these on the client initially
+
                                // this is basically the same as the chat flood control
-                               if (time < store.cmd_floodtime)
+                               entity store = IS_CLIENT(this) ? CS(this) : this; // unfortunately, we need to store these on the client initially
+                               // NOTE: using mod_time instead of time here to avoid initializing both this.cmd_floodtime
+                               // and CS(this).cmd_floodtime to -(antispam_count * antispam_time) (or -999999)
+                               float mod_time = time + autocvar_sv_clientcommand_antispam_count * autocvar_sv_clientcommand_antispam_time;
+                               if (mod_time < store.cmd_floodtime)
                                {
-                                       sprint(this, strcat("^3CMD FLOOD CONTROL: wait ^1", ftos(store.cmd_floodtime - time), "^3 seconds, command was: ", command, "\n"));
+                                       sprint(this, strcat("^3CMD FLOOD CONTROL: wait ^1", ftos(store.cmd_floodtime - mod_time),
+                                               "^3 seconds, command was: ", command, "\n"));
                                        return;  // too much spam, halt
                                }
                                else
-                                       store.cmd_floodtime = max(time - autocvar_sv_clientcommand_antispam_count * autocvar_sv_clientcommand_antispam_time, store.cmd_floodtime) + autocvar_sv_clientcommand_antispam_time;
+                                       // micro-optimization: replaced mod_time - max_delay with time here as they are equal
+                                       store.cmd_floodtime = max(time, store.cmd_floodtime) + autocvar_sv_clientcommand_antispam_time;
                        }
                        break;  // continue, as we're not flooding yet
        }