]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
cmd: reinstate execution of aliases with the same name as a command
authorbones_was_here <bones_was_here@xonotic.au>
Mon, 11 Dec 2023 12:02:55 +0000 (22:02 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Tue, 12 Dec 2023 06:45:04 +0000 (16:45 +1000)
Fixes https://gitlab.com/xonotic/darkplaces/-/issues/397

Based on the div0-stable version of Cmd_ExecuteString().

Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
cmd.c

diff --git a/cmd.c b/cmd.c
index 1f2609569ef42e31dc189f03afa6512b6629dc5d..b4bb9a58e8fb6be85006f67b84ef1217241ac8fa 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -2201,21 +2201,25 @@ void Cmd_ExecuteString (cmd_state_t *cmd, const char *text, cmd_source_t src, qb
        for (func = cmd->userdefined->qc_functions; func; func = func->next)
                if (!strcasecmp(cmd->argv[0], func->name))
                        if(cmd->Handle(cmd, func, text, src))
-                               goto done;
+                               goto functions_done;
 
        for (func = cmd->engine_functions; func; func=func->next)
                if (!strcasecmp (cmd->argv[0], func->name))
                        if(cmd->Handle(cmd, func, text, src))
-                               goto done;
+                               goto functions_done;
 
-       // if it's a client command and no command was found, say so.
+functions_done:
+       // If it's a client command and wasn't found and handled, say so.
+       // Also don't let clients call server aliases.
        if (cmd->source == src_client)
        {
-               Con_Printf("Client \"%s\" tried to execute \"%s\"\n", host_client->name, text);
+               if (!func)
+                       Con_Printf("Client \"%s\" tried to execute \"%s\"\n", host_client->name, text);
                goto done;
        }
 
 // check alias
+       // Execute any alias with the same name as a command after the command.
        for (a=cmd->userdefined->alias ; a ; a=a->next)
        {
                if (!strcasecmp (cmd->argv[0], a->name))
@@ -2225,6 +2229,10 @@ void Cmd_ExecuteString (cmd_state_t *cmd, const char *text, cmd_source_t src, qb
                }
        }
 
+       // If the command was found and handled don't try to handle it as a cvar.
+       if (func)
+               goto done;
+
 // check cvars
        if (!Cvar_Command(cmd) && host.framecount > 0)
                Con_Printf(CON_WARN "Unknown command \"%s\"\n", Cmd_Argv(cmd, 0));