From cf8ece355a7afaa32707ef259dde2e3d77a805d4 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Wed, 17 Jun 2020 16:55:23 +0000 Subject: [PATCH] Auto-register serverfromclient commands to forward to the server on the client git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12687 d7cf8633-e32d-0410-b094-e92efae38249 --- cmd.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/cmd.c b/cmd.c index ec638b19..2cb94d22 100644 --- a/cmd.c +++ b/cmd.c @@ -1512,7 +1512,7 @@ void Cmd_Init(void) // client console can see server cvars because the user may start a server cmd_client.cvars = &cvars_all; cmd_client.cvars_flagsmask = CVAR_CLIENT | CVAR_SERVER; - cmd_client.cmd_flags = CMD_CLIENT | CMD_CLIENT_FROM_SERVER; + cmd_client.cmd_flags = CMD_CLIENT | CMD_CLIENT_FROM_SERVER | CMD_SERVER_FROM_CLIENT; cmd_client.userdefined = &cmd_userdefined_all; // dedicated server console can only see server cvars, there is no client cmd_server.cvars = &cvars_all; @@ -1694,6 +1694,7 @@ void Cmd_AddCommand(int flags, const char *cmd_name, xcommand_t function, const cmd_function_t *func; cmd_function_t *prev, *current; cmd_state_t *cmd; + xcommand_t save = NULL; int i; for (i = 0; i < 3; i++) @@ -1701,6 +1702,11 @@ void Cmd_AddCommand(int flags, const char *cmd_name, xcommand_t function, const cmd = cmd_iter_all[i].cmd; if (flags & cmd->cmd_flags) { + if(cmd == &cmd_client && (flags & CMD_SERVER_FROM_CLIENT) && !(flags & CMD_CLIENT)) + { + save = function; + function = Cmd_ForwardToServer_f; + } // fail if the command is a variable name if (Cvar_FindVar(cmd->cvars, cmd_name, ~0)) { @@ -1715,14 +1721,8 @@ void Cmd_AddCommand(int flags, const char *cmd_name, xcommand_t function, const { if (!strcmp(cmd_name, func->name)) { - // Allow overriding forward to server - if(func->function == Cmd_ForwardToServer_f && (func->flags & 8)) - break; - else - { - Con_Printf("Cmd_AddCommand: %s already defined\n", cmd_name); - goto nested_continue; - } + Con_Printf("Cmd_AddCommand: %s already defined\n", cmd_name); + goto next; } } @@ -1775,8 +1775,10 @@ void Cmd_AddCommand(int flags, const char *cmd_name, xcommand_t function, const } func->next = current; } + if (save) + function = save; } -nested_continue: +next: continue; } } -- 2.39.2