// 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_SERVER_FROM_CLIENT;
+ cmd_client.cmd_flags = CMD_CLIENT | CMD_CLIENT_FROM_SERVER;
+ cmd_client.auto_flags = CMD_SERVER_FROM_CLIENT;
+ cmd_client.auto_function = CL_ForwardToServer_f; // FIXME: Move this to the client.
cmd_client.userdefined = &cmd_userdefined_all;
cmd_client.text_mutex = Thread_CreateMutex();
// dedicated server console can only see server cvars, there is no client
cmd_server.cvars = &cvars_all;
cmd_server.cvars_flagsmask = CVAR_SERVER;
cmd_server.cmd_flags = CMD_SERVER;
+ cmd_server.auto_flags = 0;
+ cmd_server.auto_function = NULL;
cmd_server.userdefined = &cmd_userdefined_all;
cmd_server.text_mutex = Thread_CreateMutex();
// server commands received from clients have no reason to access cvars, cvar expansion seems perilous.
cmd_serverfromclient.cvars = &cvars_null;
cmd_serverfromclient.cvars_flagsmask = 0;
cmd_serverfromclient.cmd_flags = CMD_SERVER_FROM_CLIENT | CMD_USERINFO;
+ cmd_serverfromclient.auto_flags = 0;
+ cmd_serverfromclient.auto_function = NULL;
cmd_serverfromclient.userdefined = &cmd_userdefined_null;
cmd_serverfromclient.text_mutex = Thread_CreateMutex();
return cmd->args;
}
-
/*
============
Cmd_TokenizeString
cmd_function_t *prev, *current;
cmd_state_t *cmd;
xcommand_t save = NULL;
+ qboolean auto_add = false;
int i;
for (i = 0; i < 3; i++)
{
cmd = cmd_iter_all[i].cmd;
- if (flags & cmd->cmd_flags)
+ if ((flags & cmd->cmd_flags) || (flags & cmd->auto_flags))
{
- if(cmd == &cmd_client && (flags & CMD_SERVER_FROM_CLIENT) && !(flags & CMD_CLIENT))
+ if((flags & cmd->auto_flags) && cmd->auto_function)
{
save = function;
- function = CL_ForwardToServer_f;
+ function = cmd->auto_function;
+ auto_add = true;
}
+
// fail if the command is a variable name
if (Cvar_FindVar(cmd->cvars, cmd_name, ~0))
{
{
if (!strcmp(cmd_name, func->name))
{
+ if(func->autofunc && !auto_add)
+ break;
Con_Printf("Cmd_AddCommand: %s already defined\n", cmd_name);
goto next;
}
func->function = function;
func->description = description;
func->next = cmd->engine_functions;
+ func->autofunc = auto_add;
// insert it at the right alphanumeric position
for (prev = NULL, current = cmd->engine_functions; current && strcmp(current->name, func->name) < 0; prev = current, current = current->next)
func->description = description;
func->csqcfunc = true; //[515]: csqc
func->next = cmd->userdefined->csqc_functions;
+ func->autofunc = false;
// insert it at the right alphanumeric position
for (prev = NULL, current = cmd->userdefined->csqc_functions; current && strcmp(current->name, func->name) < 0; prev = current, current = current->next)
function = save;
}
next:
+ auto_add = false;
continue;
}
}
const char *description;
xcommand_t function;
qboolean csqcfunc;
+ qboolean autofunc;
qboolean initstate; // indicates this command existed at init
} cmd_function_t;
int cvars_flagsmask; // which CVAR_* flags should be visible to this interpreter? (CVAR_CLIENT | CVAR_SERVER, or just CVAR_SERVER)
int cmd_flags; // cmd flags that identify this interpreter
+
+ /*
+ * If a requested flag matches auto_flags, a command will be
+ * added to a given interpreter with auto_function. For example,
+ * a CMD_SERVER_FROM_CLIENT command should be automatically added
+ * to the client interpreter as CL_ForwardToServer_f. It can be
+ * overridden at any time.
+ */
+ int auto_flags;
+ xcommand_t auto_function;
}
cmd_state_t;
int Cmd_Argc (cmd_state_t *cmd);
const char *Cmd_Argv (cmd_state_t *cmd, int arg);
const char *Cmd_Args (cmd_state_t *cmd);
+const char *Cmd_Args_After(cmd_state_t *cmd, int arg);
// The functions that execute commands get their parameters with these
// functions. Cmd_Argv(cmd, ) will return an empty string, not a NULL
// if arg > argc, so string operations are always safe.