]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
cmd: always register server-only commands, don't register client-only commands on...
authorbones_was_here <bones_was_here@xonotic.au>
Tue, 12 Dec 2023 04:33:48 +0000 (14:33 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Tue, 12 Dec 2023 06:45:07 +0000 (16:45 +1000)
Fixes the lack of the `heartbeat` command on dedicated and listen, and
the presence of commands like `toggleconsole` on dedicated.

Similar to 3a58ad52e63635c93e95955f984fd6052156e56b this might reveal a
few commands that aren't flagged correctly.

Changes the bitmask vars to the correct type.
Renames cmd_flags to cmd_flagsmask for consistency.

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

diff --git a/cmd.c b/cmd.c
index b4bb9a58e8fb6be85006f67b84ef1217241ac8fa..b1294c3c11f3f48882eda24881464d41427171b8 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -1593,7 +1593,7 @@ static void Cmd_Apropos_f(cmd_state_t *cmd)
        Con_Printf("%i result%s\n\n", count, (count > 1) ? "s" : "");
 }
 
-static cmd_state_t *Cmd_AddInterpreter(cmd_buf_t *cbuf, cvar_state_t *cvars, int cvars_flagsmask, int cmds_flagsmask, cmd_userdefined_t *userdefined)
+static cmd_state_t *Cmd_AddInterpreter(cmd_buf_t *cbuf, cvar_state_t *cvars, unsigned cvars_flagsmask, unsigned cmds_flagsmask, cmd_userdefined_t *userdefined)
 {
        cmd_state_t *cmd = (cmd_state_t *)Mem_Alloc(tempmempool, sizeof(cmd_state_t));
        
@@ -1604,7 +1604,7 @@ static cmd_state_t *Cmd_AddInterpreter(cmd_buf_t *cbuf, cvar_state_t *cvars, int
 
        cmd->cvars = cvars;
        cmd->cvars_flagsmask = cvars_flagsmask;
-       cmd->cmd_flags = cmds_flagsmask;
+       cmd->cmd_flagsmask = cmds_flagsmask;
        cmd->userdefined = userdefined;
 
        return cmd;
@@ -1618,6 +1618,8 @@ Cmd_Init
 void Cmd_Init(void)
 {
        cmd_buf_t *cbuf;
+       unsigned cvars_flagsmask, cmds_flagsmask;
+
        cbuf_mempool = Mem_AllocPool("Command buffer", 0, NULL);
        cbuf = (cmd_buf_t *)Mem_Alloc(cbuf_mempool, sizeof(cmd_buf_t));
        cbuf->maxsize = CMDBUFSIZE;
@@ -1633,7 +1635,17 @@ void Cmd_Init(void)
        cmd_iter_all = (cmd_iter_t *)Mem_Alloc(tempmempool, sizeof(cmd_iter_t) * 3);
 
        // local console
-       cmd_iter_all[0].cmd = cmd_local = Cmd_AddInterpreter(cbuf, &cvars_all, CF_CLIENT | CF_SERVER, CF_CLIENT | CF_CLIENT_FROM_SERVER | CF_SERVER_FROM_CLIENT, &cmd_userdefined_all);
+       if (cls.state == ca_dedicated)
+       {
+               cvars_flagsmask = CF_SERVER;
+               cmds_flagsmask = CF_SERVER | CF_SERVER_FROM_CLIENT;
+       }
+       else
+       {
+               cvars_flagsmask = CF_CLIENT | CF_SERVER;
+               cmds_flagsmask = CF_CLIENT | CF_SERVER | CF_CLIENT_FROM_SERVER | CF_SERVER_FROM_CLIENT;
+       }
+       cmd_iter_all[0].cmd = cmd_local = Cmd_AddInterpreter(cbuf, &cvars_all, cvars_flagsmask, cmds_flagsmask, &cmd_userdefined_all);
        cmd_local->Handle = Cmd_CL_Callback;
 
        // server commands received from clients have no reason to access cvars, cvar expansion seems perilous.
@@ -1773,7 +1785,7 @@ static void Cmd_TokenizeString (cmd_state_t *cmd, const char *text)
 Cmd_AddCommand
 ============
 */
-void Cmd_AddCommand(int flags, const char *cmd_name, xcommand_t function, const char *description)
+void Cmd_AddCommand(unsigned flags, const char *cmd_name, xcommand_t function, const char *description)
 {
        cmd_function_t *func;
        cmd_function_t *prev, *current;
@@ -1783,7 +1795,7 @@ void Cmd_AddCommand(int flags, const char *cmd_name, xcommand_t function, const
        for (i = 0; i < 2; i++)
        {
                cmd = cmd_iter_all[i].cmd;
-               if (flags & cmd->cmd_flags)
+               if (flags & cmd->cmd_flagsmask)
                {
                        // fail if the command is a variable name
                        if (Cvar_FindVar(cmd->cvars, cmd_name, ~0))
diff --git a/cmd.h b/cmd.h
index fef1f11feeab9f30c6821fa7339bb0283f34fdda..30b3abd05d732ce6d05b75d4d85f3c94a17e66eb 100644 (file)
--- a/cmd.h
+++ b/cmd.h
@@ -85,7 +85,7 @@ typedef struct cmd_alias_s
 
 typedef struct cmd_function_s
 {
-       int flags;
+       unsigned flags;
        struct cmd_function_s *next;
        const char *name;
        const char *description;
@@ -140,9 +140,8 @@ typedef struct cmd_state_s
        cmd_function_t *engine_functions;
 
        struct cvar_state_s *cvars; // which cvar system is this cmd state able to access? (&cvars_all or &cvars_null)
-       int cvars_flagsmask; // which CVAR_* flags should be visible to this interpreter? (CF_CLIENT | CF_SERVER, or just CF_SERVER)
-
-       int cmd_flags; // cmd flags that identify this interpreter
+       unsigned cvars_flagsmask; // which CVAR_* flags should be visible to this interpreter? (CF_CLIENT | CF_SERVER, or just CF_SERVER)
+       unsigned cmd_flagsmask; // cmd flags that identify this interpreter
 
        qbool (*Handle)(struct cmd_state_s *, struct cmd_function_s *, const char *, enum cmd_source_s);
 }
@@ -221,7 +220,7 @@ void Cmd_SaveInitState(void);
 // called by FS_GameDir_f, this restores cvars, commands and aliases to init values
 void Cmd_RestoreInitState(void);
 
-void Cmd_AddCommand(int flags, const char *cmd_name, xcommand_t function, const char *description);
+void Cmd_AddCommand(unsigned flags, const char *cmd_name, xcommand_t function, const char *description);
 // called by the init functions of other parts of the program to
 // register commands and functions to call for them.
 // The cmd_name is referenced later, so it should not be in temp memory