]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add a mutator hook to handle flood control on client commands
authorMario <mario.mario@y7mail.com>
Wed, 31 Jul 2024 12:53:10 +0000 (12:53 +0000)
committerDr. Jaska <drjaska83@gmail.com>
Wed, 31 Jul 2024 12:53:10 +0000 (12:53 +0000)
qcsrc/server/command/cmd.qc
qcsrc/server/mutators/events.qh

index 1e14def1d7bb30f5470333488785886adef7c7fa..ca028f12b4395778a62c6b470b61727955fbccc1 100644 (file)
@@ -1054,6 +1054,8 @@ void SV_ParseClientCommand(entity this, string command)
                        LABEL(flood_control)
                        if (!timeout_status)  // not while paused
                        {
+                               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)
index 613392788616520b0f60cf5e2e17005e51c8d8cb..533484d0b0462d0e1e675d757c49de56b357b35b 100644 (file)
@@ -571,6 +571,18 @@ MUTATOR_HOOKABLE(PlayerUseKey, EV_PlayerUseKey);
     /**/
 MUTATOR_HOOKABLE(SV_ParseClientCommand, EV_SV_ParseClientCommand);
 
+/**
+ * please read EV_SV_ParseClientCommand description before using
+ * return true to skip flood control on the given command
+ */
+#define EV_ClientCommand_FloodControl(i, o) \
+    /** client sending the command */       i(entity, MUTATOR_ARGV_0_entity) \
+    /** command name */                     i(string, MUTATOR_ARGV_1_string) \
+    /** argc (also, argv() can be used) */  i(int, MUTATOR_ARGV_2_int) \
+    /** whole command, use only if you really have to */ i(string, MUTATOR_ARGV_3_string) \
+    /**/
+MUTATOR_HOOKABLE(ClientCommand_FloodControl, EV_ClientCommand_FloodControl);
+
 /** please read EV_SV_ParseClientCommand description before using */
 #define EV_SV_ParseServerCommand(i, o) \
    /** command name */ i(string, MUTATOR_ARGV_0_string) \