From: Mario Date: Wed, 31 Jul 2024 12:53:10 +0000 (+0000) Subject: Add a mutator hook to handle flood control on client commands X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f169c6986221c536f9672d54fadb25f312c38f92;p=xonotic%2Fxonotic-data.pk3dir.git Add a mutator hook to handle flood control on client commands --- diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index 1e14def1d..ca028f12b 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -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) diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index 613392788..533484d0b 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -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) \