]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Auto-register serverfromclient commands to forward to the server on the client
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 17 Jun 2020 16:55:23 +0000 (16:55 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 17 Jun 2020 16:55:23 +0000 (16:55 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12687 d7cf8633-e32d-0410-b094-e92efae38249

cmd.c

diff --git a/cmd.c b/cmd.c
index ec638b19c1bc8ca8822025a5215ffd1a8dbf5f97..2cb94d2209fa7c584b7e023b2b1f2380ab66a878 100644 (file)
--- 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;
        }
 }