DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
cmd.h File Reference
#include "qtypes.h"
#include "qdefs.h"
#include "com_list.h"
+ Include dependency graph for cmd.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cmd_alias_t
 
struct  cmd_buf_t
 
struct  cmd_function_t
 
struct  cmd_input_t
 
struct  cmd_state_t
 command interpreter state - the tokenizing and execution of commands, as well as pointers to which cvars and aliases they can access More...
 
struct  cmd_userdefined_t
 container for user-defined QC functions and aliases, shared between different command interpreters More...
 

Macros

#define CF_ALLOCATED   (1u<<31)
 created by Cvar_Get() (console or QC)
 
#define CF_ARCHIVE   (1u<<5)
 cvar should have its set value saved to config.cfg and persist across sessions
 
#define CF_CHEAT   (1u<<4)
 command or cvar that gives an unfair advantage over other players and is blocked unless sv_cheats is 1
 
#define CF_CLIENT   (1u<<0)
 cvar/command that only the client can change/execute
 
#define CF_CLIENT_FROM_SERVER   (1u<<2)
 command that the server is allowed to execute on the client
 
#define CF_DEFAULTSET   (1u<<30)
 
#define CF_MAXFLAGSVAL   ((1u<<12) - 1)
 used to determine if flags is valid
 
#define CF_NONE   0u
 
#define CF_NOTIFY   (1u<<7)
 cvar should trigger a chat notification to all connected clients when changed
 
#define CF_PERSISTENT   (1u<<10)
 cvar must not be reset on gametype switch (such as scr_screenshot_name, which otherwise isn't set to the mod name properly)
 
#define CF_PRIVATE   (1u<<11)
 cvar should not be $ expanded or sent to the server under any circumstances (rcon_password, etc)
 
#define CF_READONLY   (1u<<6)
 cvar cannot be changed from the console or the command buffer, and is considered CF_PERSISTENT
 
#define CF_REGISTERED   (1u<<29)
 created by Cvar_RegisterVariable()
 
#define CF_SERVER   (1u<<1)
 cvar/command that only the server can change/execute
 
#define CF_SERVER_FROM_CLIENT   (1u<<3)
 command the client is allowed to execute on the server as a stringcmd
 
#define CF_SERVERINFO   (1u<<8)
 command or cvar relevant to serverinfo string handling
 
#define CF_SHARED   (CF_CLIENT | CF_SERVER)
 
#define CF_USERINFO   (1u<<9)
 command or cvar used to communicate userinfo to the server
 

Typedefs

typedef void(* xcommand_t) (struct cmd_state_s *cmd)
 

Enumerations

enum  cmd_source_t { src_client , src_local }
 

Functions

void Cbuf_AddText (cmd_state_t *cmd, const char *text)
 
void Cbuf_Clear (cmd_buf_t *cbuf)
 Clears all command buffers.
 
void Cbuf_Execute (cmd_buf_t *cbuf)
 
void Cbuf_Frame (cmd_buf_t *cbuf)
 
void Cbuf_InsertText (cmd_state_t *cmd, const char *text)
 
void Cbuf_Lock (cmd_buf_t *cbuf)
 
void Cbuf_Unlock (cmd_buf_t *cbuf)
 
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.
 
static int Cmd_Argc (cmd_state_t *cmd)
 
static const char * Cmd_Args (cmd_state_t *cmd)
 
static const char * Cmd_Argv (cmd_state_t *cmd, int arg)
 Cmd_Argv(cmd, ) will return an empty string (not a NULL) if arg > argc, so string operations are always safe.
 
qbool Cmd_Callback (cmd_state_t *cmd, cmd_function_t *func)
 
int Cmd_CheckParm (cmd_state_t *cmd, const char *parm)
 Returns the position (1 to argc-1) in the command's argument list where the given parameter apears, or 0 if not present.
 
qbool Cmd_CL_Callback (cmd_state_t *cmd, cmd_function_t *func, const char *text, size_t textlen, cmd_source_t src)
 
void Cmd_ClearCSQCCommands (cmd_state_t *cmd)
 
const char * Cmd_CompleteAlias (cmd_state_t *cmd, const char *partial)
 
const char ** Cmd_CompleteAliasBuildList (cmd_state_t *cmd, const char *partial)
 
int Cmd_CompleteAliasCountPossible (cmd_state_t *cmd, const char *partial)
 
void Cmd_CompleteAliasPrint (cmd_state_t *cmd, const char *partial)
 
const char ** Cmd_CompleteBuildList (cmd_state_t *cmd, const char *partial)
 
const char * Cmd_CompleteCommand (cmd_state_t *cmd, const char *partial)
 attempts to match a partial command for automatic command line completion returns NULL if nothing fits
 
void Cmd_CompleteCommandPrint (cmd_state_t *cmd, const char *partial)
 
int Cmd_CompleteCountPossible (cmd_state_t *cmd, const char *partial)
 
void Cmd_ExecuteString (cmd_state_t *cmd, const char *text, size_t textlen, cmd_source_t src, qbool lockmutex)
 Parses a single line of text into arguments and tries to execute it.
 
qbool Cmd_Exists (cmd_state_t *cmd, const char *cmd_name)
 used by the cvar code to check for cvar / command name overlap
 
void Cmd_Init (void)
 Command execution takes a null terminated string, breaks it into tokens, then searches for a command or variable that matches the first token.
 
void Cmd_NoOperation_f (cmd_state_t *cmd)
 
void Cmd_PreprocessAndExecuteString (cmd_state_t *cmd, const char *text, size_t textlen, cmd_source_t src, qbool lockmutex)
 Like Cmd_ExecuteString, but with variable expansion.
 
qbool Cmd_QuoteString (char *out, size_t outlen, const char *in, const char *quoteset, qbool putquotes)
 quotes a string so that it can be used as a command argument again; quoteset is a string that contains one or more of ", \, $ and specifies the characters to be quoted (you usually want to either pass ""\" or ""\$").
 
void Cmd_RestoreInitState (void)
 Restores cvars, commands and aliases to their init values and deletes any that were added since init.
 
void Cmd_SaveInitState (void)
 called by Host_Init, this marks cvars, commands and aliases with their init values
 
void Cmd_Shutdown (void)
 
qbool Cmd_SV_Callback (cmd_state_t *cmd, cmd_function_t *func, const char *text, size_t textlen, cmd_source_t src)
 

Variables

cmd_state_tcmd_local
 command interpreter for local commands injected by SVQC, CSQC, MQC, server or client engine code uses cmddefs_all
 
cmd_state_tcmd_serverfromclient
 command interpreter for server commands received over network from clients uses cmddefs_null
 
cmd_userdefined_t cmd_userdefined_all
 aliases and csqc functions
 
cmd_userdefined_t cmd_userdefined_null
 intentionally empty
 
qbool host_stuffcmdsrun
 

Macro Definition Documentation

◆ CF_ALLOCATED

#define CF_ALLOCATED   (1u<<31)

created by Cvar_Get() (console or QC)

Definition at line 64 of file cmd.h.

Referenced by Cvar_Delete(), Cvar_Get(), Cvar_RegisterVariable(), Cvar_SetQuick(), Cvar_WriteVariables(), and VM_cvar_type().

◆ CF_ARCHIVE

#define CF_ARCHIVE   (1u<<5)

cvar should have its set value saved to config.cfg and persist across sessions

Definition at line 53 of file cmd.h.

Referenced by Cvar_ResetToDefaults_NoSaveOnly_f(), Cvar_ResetToDefaults_SaveOnly_f(), Cvar_SetA_f(), Cvar_WriteVariables(), and VM_cvar_type().

◆ CF_CHEAT

#define CF_CHEAT   (1u<<4)

command or cvar that gives an unfair advantage over other players and is blocked unless sv_cheats is 1

Definition at line 52 of file cmd.h.

Referenced by Cmd_SV_Callback(), and SV_InitOperatorCommands().

◆ CF_CLIENT

◆ CF_CLIENT_FROM_SERVER

#define CF_CLIENT_FROM_SERVER   (1u<<2)

command that the server is allowed to execute on the client

Definition at line 50 of file cmd.h.

Referenced by CDAudio_Init(), CL_Init(), CL_InitCommands(), CL_Parse_Init(), Cmd_Init(), Curl_Init_Commands(), and V_Init().

◆ CF_DEFAULTSET

#define CF_DEFAULTSET   (1u<<30)

Definition at line 63 of file cmd.h.

Referenced by Cvar_LockDefaults_f(), and Cvar_WriteVariables().

◆ CF_MAXFLAGSVAL

#define CF_MAXFLAGSVAL   ((1u<<12) - 1)

used to determine if flags is valid

Definition at line 60 of file cmd.h.

Referenced by VM_registercvar().

◆ CF_NONE

#define CF_NONE   0u

Definition at line 47 of file cmd.h.

◆ CF_NOTIFY

#define CF_NOTIFY   (1u<<7)

cvar should trigger a chat notification to all connected clients when changed

Definition at line 55 of file cmd.h.

Referenced by Cvar_SetQuick_Internal(), and NetConn_ServerParsePacket().

◆ CF_PERSISTENT

#define CF_PERSISTENT   (1u<<10)

cvar must not be reset on gametype switch (such as scr_screenshot_name, which otherwise isn't set to the mod name properly)

Definition at line 58 of file cmd.h.

Referenced by Cvar_ResetToDefaults_All_f(), Cvar_ResetToDefaults_NoSaveOnly_f(), Cvar_ResetToDefaults_SaveOnly_f(), Cvar_RestoreInitState(), and Cvar_SaveInitState().

◆ CF_PRIVATE

#define CF_PRIVATE   (1u<<11)

cvar should not be $ expanded or sent to the server under any circumstances (rcon_password, etc)

Definition at line 59 of file cmd.h.

Referenced by CL_SendCvar_f(), Cmd_GetDirectCvarValue(), Cvar_PrintHelp(), PRVM_Cvar_ReadOk(), PRVM_Prog_Load(), and VM_cvar_type().

◆ CF_READONLY

#define CF_READONLY   (1u<<6)

cvar cannot be changed from the console or the command buffer, and is considered CF_PERSISTENT

Definition at line 54 of file cmd.h.

Referenced by Cvar_Readonly(), Cvar_ResetToDefaults_All_f(), Cvar_ResetToDefaults_NoSaveOnly_f(), Cvar_ResetToDefaults_SaveOnly_f(), Cvar_RestoreInitState(), Cvar_SaveInitState(), GL_Setup(), VM_cvar_set(), and VM_cvar_type().

◆ CF_REGISTERED

#define CF_REGISTERED   (1u<<29)

created by Cvar_RegisterVariable()

Definition at line 62 of file cmd.h.

Referenced by Cvar_RegisterVariable(), and Cvar_SetQuick().

◆ CF_SERVER

#define CF_SERVER   (1u<<1)

◆ CF_SERVER_FROM_CLIENT

#define CF_SERVER_FROM_CLIENT   (1u<<3)

command the client is allowed to execute on the server as a stringcmd

Definition at line 51 of file cmd.h.

Referenced by Cmd_CL_Callback(), Cmd_Init(), SV_Init(), and SV_InitOperatorCommands().

◆ CF_SERVERINFO

#define CF_SERVERINFO   (1u<<8)

command or cvar relevant to serverinfo string handling

Definition at line 56 of file cmd.h.

Referenced by Cvar_SetQuick_Internal().

◆ CF_SHARED

◆ CF_USERINFO

#define CF_USERINFO   (1u<<9)

command or cvar used to communicate userinfo to the server

Definition at line 57 of file cmd.h.

Referenced by Cmd_Init(), Cvar_SetQuick_Internal(), and SV_InitOperatorCommands().

Typedef Documentation

◆ xcommand_t

typedef void(* xcommand_t) (struct cmd_state_s *cmd)

Definition at line 69 of file cmd.h.

Enumeration Type Documentation

◆ cmd_source_t

Enumerator
src_client 

came in over a net connection as a clc_stringcmd host_client will be valid during this state.

src_local 

from the command buffer

Definition at line 71 of file cmd.h.

72{
cmd_source_t
Definition cmd.h:72
@ src_client
came in over a net connection as a clc_stringcmd host_client will be valid during this state.
Definition cmd.h:73
@ src_local
from the command buffer
Definition cmd.h:75

Function Documentation

◆ Cbuf_AddText()

void Cbuf_AddText ( cmd_state_t * cmd,
const char * text )

as new commands are generated from the console or keybindings, the text is added to the end of the command buffer.

Definition at line 264 of file cmd.c.

265{
266 size_t l = strlen(text);
267 cmd_buf_t *cbuf = cmd->cbuf;
268 llist_t llist = {&llist, &llist};
269
270 if (cbuf->size + l > cbuf->maxsize)
271 {
272 Con_Printf(CON_WARN "Cbuf_AddText: input too large, %luKB ought to be enough for anybody.\n", (unsigned long)(cbuf->maxsize / 1024));
273 return;
274 }
275
276 Cbuf_Lock(cbuf);
277
278 // If the string terminates but the (last) line doesn't, the node will be left in the pending state (to be continued).
279 Cbuf_ParseText(cmd, &llist, (List_Is_Empty(&cbuf->start) ? NULL : List_Entry(cbuf->start.prev, cmd_input_t, list)), text, true);
280 List_Splice_Tail(&llist, &cbuf->start);
281
282 Cbuf_Unlock(cbuf);
283}
void Cbuf_Unlock(cmd_buf_t *cbuf)
Definition cmd.c:50
static void Cbuf_ParseText(cmd_state_t *cmd, llist_t *head, cmd_input_t *existing, const char *text, qbool allowpending)
Definition cmd.c:210
void Cbuf_Lock(cmd_buf_t *cbuf)
Definition cmd.c:45
static void List_Splice_Tail(const llist_t *list, llist_t *head)
Definition com_list.h:409
#define List_Entry(ptr, type, member)
Definition com_list.h:44
static qbool List_Is_Empty(const llist_t *list)
Definition com_list.h:211
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
#define CON_WARN
Definition console.h:101
float strlen(string s)
void cmd(string command,...)
#define NULL
Definition qtypes.h:12
size_t maxsize
Definition cmd.h:117
llist_t start
Definition cmd.h:113
size_t size
Definition cmd.h:118
struct llist_s * prev
Definition com_list.h:32

References Cbuf_Lock(), Cbuf_ParseText(), Cbuf_Unlock(), cmd(), Con_Printf(), CON_WARN, List_Entry, List_Is_Empty(), List_Splice_Tail(), cmd_buf_t::maxsize, NULL, llist_t::prev, cmd_buf_t::size, cmd_buf_t::start, and strlen().

Referenced by Cbuf_Execute_Deferred(), CL_FinishTimeDemo(), CL_SignonReply(), CL_VM_Parse_StuffCmd(), Curl_CheckCommandWhenDone(), Host_Init(), Key_Console(), Key_Event(), M_Demo_Key(), M_GameOptions_Key(), M_LanConfig_Key(), M_Load_Key(), M_Main_Key(), M_Menu_Options_Graphics_AdjustSliders(), M_Options_Key(), M_Reset_Key(), M_Save_Key(), M_ServerList_Key(), M_Setup_Key(), M_SinglePlayer_Key(), M_Transfusion_Episode_Key(), M_Transfusion_Skill_Key(), M_Video_Key(), VM_changelevel(), VM_coredump(), and VM_localcmd().

◆ Cbuf_Clear()

void Cbuf_Clear ( cmd_buf_t * cbuf)

Clears all command buffers.

Definition at line 436 of file cmd.c.

437{
438 while (!List_Is_Empty(&cbuf->start))
439 List_Move_Tail(cbuf->start.next, &cbuf->free);
440 while (!List_Is_Empty(&cbuf->deferred))
441 List_Move_Tail(cbuf->deferred.next, &cbuf->free);
442 cbuf->size = 0;
443}
static void List_Move_Tail(llist_t *list, llist_t *head)
Definition com_list.h:336
llist_t deferred
Definition cmd.h:114
llist_t free
Definition cmd.h:115
struct llist_s * next
Definition com_list.h:33

References cmd_buf_t::deferred, cmd_buf_t::free, List_Is_Empty(), List_Move_Tail(), llist_t::next, cmd_buf_t::size, and cmd_buf_t::start.

Referenced by Cbuf_Execute(), Host_Error(), and MVM_error_cmd().

◆ Cbuf_Execute()

void Cbuf_Execute ( cmd_buf_t * cbuf)

Pulls off terminated lines of text from the command buffer and sends them through Cmd_ExecuteString. Stops when the buffer is empty. Normally called once per frame, but may be explicitly invoked.

Note
Do not call inside a command function!

Definition at line 351 of file cmd.c.

352{
353 cmd_input_t *current;
354 unsigned int i = 0;
355
356 // LadyHavoc: making sure the tokenizebuffer doesn't get filled up by repeated crashes
357 cbuf->tokenizebufferpos = 0;
358
359 while (!List_Is_Empty(&cbuf->start))
360 {
361 /*
362 * Delete the text from the command buffer and move remaining
363 * commands down. This is necessary because commands (exec, alias)
364 * can insert data at the beginning of the text buffer
365 */
366 current = List_Entry(cbuf->start.next, cmd_input_t, list);
367
368 /*
369 * Assume we're rolling with the current command-line and
370 * always set this false because alias expansion or cbuf insertion
371 * without a newline may set this true, and cause weirdness.
372 */
373 current->pending = false;
374
375 Cmd_PreprocessAndExecuteString(current->source, current->text, current->length, src_local, false);
376 cbuf->size -= current->length;
377 // Recycle memory so using WASD doesn't cause a malloc and free
378 List_Move_Tail(&current->list, &cbuf->free);
379
380 if (cbuf->wait)
381 {
382 /*
383 * Skip out while text still remains in
384 * buffer, leaving it for next frame
385 */
386 cbuf->wait = false;
387 break;
388 }
389
390 if (++i == 1000000 && prvm_runawaycheck)
391 {
392 Con_Printf(CON_WARN "Cbuf_Execute: runaway loop counter hit limit of %d commands, clearing command buffers!\n", i);
393 Cbuf_Clear(cbuf);
394 }
395 }
396}
void Cbuf_Clear(cmd_buf_t *cbuf)
Clears all command buffers.
Definition cmd.c:436
qbool prvm_runawaycheck
Definition prvm_edict.c:60
void Cmd_PreprocessAndExecuteString(cmd_state_t *cmd, const char *text, size_t textlen, cmd_source_t src, qbool lockmutex)
Like Cmd_ExecuteString, but with variable expansion.
Definition cmd.c:1323
int i
qbool wait
Definition cmd.h:116
int tokenizebufferpos
Definition cmd.h:120
char * text
Definition cmd.h:162
size_t length
excludes \0 terminator
Definition cmd.h:161
qbool pending
Definition cmd.h:163
cmd_state_t * source
Definition cmd.h:158
llist_t list
Definition cmd.h:157

References Cbuf_Clear(), Cmd_PreprocessAndExecuteString(), Con_Printf(), CON_WARN, cmd_buf_t::free, i, cmd_input_t::length, cmd_input_t::list, List_Entry, List_Is_Empty(), List_Move_Tail(), llist_t::next, cmd_input_t::pending, prvm_runawaycheck, cmd_buf_t::size, cmd_input_t::source, src_local, cmd_buf_t::start, cmd_input_t::text, cmd_buf_t::tokenizebufferpos, and cmd_buf_t::wait.

Referenced by Cbuf_Frame(), CL_ReadDemoMessage(), and Host_Init().

◆ Cbuf_Frame()

void Cbuf_Frame ( cmd_buf_t * cbuf)

Performs deferred commands and runs Cbuf_Execute, called by Host_Frame

Definition at line 417 of file cmd.c.

418{
419 // check for commands typed to the host
421
422// R_TimeReport("preconsole");
423
424 // execute commands queued with the defer command
426 if (cbuf->size)
427 {
429 Cbuf_Execute(cbuf);
431 }
432
433// R_TimeReport("console");
434}
static void Cbuf_Frame_Input(void)
Definition cmd.c:405
static void Cbuf_Execute_Deferred(cmd_buf_t *cbuf)
Definition cmd.c:320
void Cbuf_Execute(cmd_buf_t *cbuf)
Definition cmd.c:351
#define SV_LockThreadMutex()
Definition server.h:606
#define SV_UnlockThreadMutex()
Definition server.h:607

References Cbuf_Execute(), Cbuf_Execute_Deferred(), Cbuf_Frame_Input(), cmd_buf_t::size, SV_LockThreadMutex, and SV_UnlockThreadMutex.

Referenced by Host_Frame().

◆ Cbuf_InsertText()

void Cbuf_InsertText ( cmd_state_t * cmd,
const char * text )

when a command wants to issue other commands immediately, the text is inserted at the beginning of the buffer, before any remaining unexecuted commands.

Definition at line 292 of file cmd.c.

293{
294 cmd_buf_t *cbuf = cmd->cbuf;
295 llist_t llist = {&llist, &llist};
296 size_t l = strlen(text);
297
298 if (cbuf->size + l > cbuf->maxsize)
299 {
300 Con_Printf(CON_WARN "Cbuf_InsertText: input too large, %luKB ought to be enough for anybody.\n", (unsigned long)(cbuf->maxsize / 1024));
301 return;
302 }
303
304 Cbuf_Lock(cbuf);
305
306 // bones_was_here assertion: when prepending to the buffer it never makes sense to leave node(s) in the `pending` state,
307 // it would have been impossible to append to such text later in the old raw text buffer,
308 // and allowing it causes bugs when .cfg files lack \n at EOF (see: https://gitlab.com/xonotic/darkplaces/-/issues/378).
309 Cbuf_ParseText(cmd, &llist, (List_Is_Empty(&cbuf->start) ? NULL : List_Entry(cbuf->start.next, cmd_input_t, list)), text, false);
310 List_Splice(&llist, &cbuf->start);
311
312 Cbuf_Unlock(cbuf);
313}
static void List_Splice(const llist_t *list, llist_t *head)
Definition com_list.h:400

References Cbuf_Lock(), Cbuf_ParseText(), Cbuf_Unlock(), cmd(), Con_Printf(), CON_WARN, List_Entry, List_Is_Empty(), List_Splice(), cmd_buf_t::maxsize, llist_t::next, NULL, cmd_buf_t::size, cmd_buf_t::start, and strlen().

Referenced by Cbuf_Frame_Input(), CL_NextDemo(), Cmd_Exec(), Cmd_ExecuteAlias(), Cmd_StuffCmds_f(), FS_ChangeGameDirs(), Host_AddConfigText(), Key_Console(), Key_Event(), and M_Keys_Key().

◆ Cbuf_Lock()

void Cbuf_Lock ( cmd_buf_t * cbuf)

Definition at line 45 of file cmd.c.

46{
48}
void * lock
Definition cmd.h:122
#define Thread_LockMutex(m)
Definition thread.h:17

References cmd_buf_t::lock, and Thread_LockMutex.

Referenced by Cbuf_AddText(), Cbuf_InsertText(), Cmd_Defer_f(), and Cmd_ExecuteString().

◆ Cbuf_Unlock()

void Cbuf_Unlock ( cmd_buf_t * cbuf)

Definition at line 50 of file cmd.c.

51{
53}
#define Thread_UnlockMutex(m)
Definition thread.h:18

References cmd_buf_t::lock, and Thread_UnlockMutex.

Referenced by Cbuf_AddText(), Cbuf_InsertText(), Cmd_Defer_f(), Cmd_ExecuteString(), and Cmd_Shutdown().

◆ Cmd_AddCommand()

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

Definition at line 1661 of file cmd.c.

1662{
1663 cmd_function_t *func;
1664 cmd_function_t *prev, *current;
1666 int i;
1667
1668 for (i = 0; i < 2; i++)
1669 {
1670 cmd = cmd_iter_all[i].cmd;
1671 if (flags & cmd->cmd_flagsmask)
1672 {
1673 // fail if the command is a variable name
1674 if (Cvar_FindVar(cmd->cvars, cmd_name, ~0))
1675 {
1676 Con_Printf(CON_WARN "Cmd_AddCommand: %s already defined as a var\n", cmd_name);
1677 return;
1678 }
1679
1680 if (function)
1681 {
1682 // fail if the command already exists in this interpreter
1683 for (func = cmd->engine_functions; func; func = func->next)
1684 {
1685 if (!strcmp(cmd_name, func->name))
1686 {
1687 Con_Printf(CON_WARN "Cmd_AddCommand: %s already defined\n", cmd_name);
1688 continue;
1689 }
1690 }
1691
1692 func = (cmd_function_t *)Mem_Alloc(cmd->mempool, sizeof(cmd_function_t));
1693 func->flags = flags;
1694 func->name = cmd_name;
1695 func->function = function;
1696 func->description = description;
1697 func->next = cmd->engine_functions;
1698
1699 // insert it at the right alphanumeric position
1700 for (prev = NULL, current = cmd->engine_functions; current && strcmp(current->name, func->name) < 0; prev = current, current = current->next)
1701 ;
1702 if (prev) {
1703 prev->next = func;
1704 }
1705 else {
1706 cmd->engine_functions = func;
1707 }
1708 func->next = current;
1709 }
1710 else
1711 {
1712 // mark qcfunc if the function already exists in the qc_functions list
1713 for (func = cmd->userdefined->qc_functions; func; func = func->next)
1714 {
1715 if (!strcmp(cmd_name, func->name))
1716 {
1717 func->qcfunc = true; //[515]: csqc
1718 continue;
1719 }
1720 }
1721
1722 func = (cmd_function_t *)Mem_Alloc(cmd->mempool, sizeof(cmd_function_t));
1723 func->flags = flags;
1724 func->name = cmd_name;
1725 func->function = function;
1726 func->description = description;
1727 func->qcfunc = true; //[515]: csqc
1728 func->next = cmd->userdefined->qc_functions;
1729
1730 // bones_was_here: if this QC command overrides an engine command, store its pointer
1731 // to avoid doing this search at invocation if QC declines to handle this command.
1732 for (cmd_function_t *f = cmd->engine_functions; f; f = f->next)
1733 {
1734 if (!strcmp(cmd_name, f->name))
1735 {
1736 Con_DPrintf("Adding QC override of engine command %s\n", cmd_name);
1737 func->overridden = f;
1738 break;
1739 }
1740 }
1741
1742 // insert it at the right alphanumeric position
1743 for (prev = NULL, current = cmd->userdefined->qc_functions; current && strcmp(current->name, func->name) < 0; prev = current, current = current->next)
1744 ;
1745 if (prev) {
1746 prev->next = func;
1747 }
1748 else {
1749 cmd->userdefined->qc_functions = func;
1750 }
1751 func->next = current;
1752 }
1753 }
1754 }
1755}
static cmd_iter_t * cmd_iter_all
Definition cmd.c:36
void Con_DPrintf(const char *fmt,...)
A Con_Printf that only shows up if the "developer" cvar is set.
Definition console.c:1544
float flags
cvar_t * Cvar_FindVar(cvar_state_t *cvars, const char *var_name, unsigned neededflags)
Definition cvar.c:36
float f
struct cmd_function_s * overridden
the engine cmd overriden by this QC cmd, if applicable
Definition cmd.h:95
const char * name
Definition cmd.h:91
struct cmd_function_s * next
Definition cmd.h:90
qbool qcfunc
Definition cmd.h:94
unsigned flags
Definition cmd.h:89
const char * description
Definition cmd.h:92
xcommand_t function
Definition cmd.h:93
cmd_state_t * cmd
Definition cmd.c:32
command interpreter state - the tokenizing and execution of commands, as well as pointers to which cv...
Definition cmd.h:127
#define Mem_Alloc(pool, size)
Definition zone.h:92

References cmd(), cmd_iter_t::cmd, cmd_iter_all, Con_DPrintf(), Con_Printf(), CON_WARN, Cvar_FindVar(), cmd_function_t::description, f, cmd_function_t::flags, flags, cmd_function_t::function, i, Mem_Alloc, cmd_function_t::name, cmd_function_t::next, NULL, cmd_function_t::overridden, and cmd_function_t::qcfunc.

Referenced by CDAudio_Init(), CL_Demo_Init(), CL_Init(), CL_InitCommands(), CL_InitInput(), CL_Parse_Init(), CL_Particles_Init(), CL_Screen_Init(), CL_Video_Init(), Cmd_Init(), Con_Init(), Crypto_Init_Commands(), Curl_Init_Commands(), FS_Init_Commands(), gl_backend_init(), GL_Draw_Init(), GL_Main_Init(), GL_Surf_Init(), Host_InitLocal(), Key_Init(), M_Init(), Memory_Init_Commands(), Mod_Init(), MR_Init_Commands(), NetConn_Init(), PRVM_Init(), R_Modules_Init(), R_Shadow_EditLights_Init(), R_Sky_Init(), R_Textures_Init(), S_Init(), Sbar_Init(), SV_Init(), SV_InitOperatorCommands(), Sys_EM_Register_Commands(), V_Init(), VID_Shared_Init(), VM_CL_registercmd(), VM_M_registercommand(), and VM_SV_registercommand().

◆ Cmd_Argc()

static int Cmd_Argc ( cmd_state_t * cmd)
inlinestatic

Definition at line 249 of file cmd.h.

250{
251 return cmd->argc;
252}

References cmd().

Referenced by Call_MR_ToggleMenu_f(), CD_f(), CL_Color_f(), CL_Connect_f(), CL_Disconnect_f(), CL_DownloadBegin_f(), CL_DownloadFinished_f(), CL_EstablishConnection(), CL_Fog_f(), CL_Fog_HeightTexture_f(), CL_ForwardToServer_f(), CL_FullInfo_f(), CL_FullServerinfo_f(), CL_IPLog_List_f(), CL_Locs_Add_f(), CL_Name_f(), CL_Packet_f(), CL_Particles_LoadEffectInfo_f(), CL_PingPLReport_f(), CL_PlayDemo_f(), CL_PlayVideo_f(), CL_PQRcon_f(), CL_Rcon_f(), CL_Reconnect_f(), CL_Record_f(), CL_SendCvar_f(), CL_SetInfo_f(), CL_Startdemos_f(), CL_TimeDemo_f(), CL_User_f(), Cmd_Alias_f(), Cmd_Apropos_f(), Cmd_CheckParm(), Cmd_Defer_f(), Cmd_Echo_f(), Cmd_Exec_f(), Cmd_ExecuteString(), Cmd_GetDirectCvarValue(), Cmd_List_f(), Cmd_StuffCmds_f(), Cmd_Toggle_f(), Cmd_UnAlias_f(), Con_ConDump_f(), Con_Maps_f(), Con_MsgCmdMode(), Crypto_HostKey_Clear_f(), Crypto_KeyGen_f(), Curl_Curl_f(), Cvar_Command(), Cvar_Del_f(), Cvar_List_f(), Cvar_Set_f(), Cvar_SetA_f(), Download_CheckExtensions(), FS_GameDir_f(), FS_ListDirectoryCmd(), FS_Which_f(), GL_TextureMode_f(), Host_SaveConfig_f(), Image_FixTransparentPixels_f(), IN_BestWeapon_f(), IN_BestWeapon_Register_f(), Key_Bind_f(), Key_History_f(), Key_In_Bind_f(), Key_In_BindList_f(), Key_In_Bindmap_f(), Key_In_Unbind_f(), Key_Unbind_f(), LoadFont_f(), LoadSky_f(), MemList_f(), Mod_Decompile_f(), Mod_GenerateLightmaps_f(), Mod_Precache_f(), PRVM_Breakpoint_f(), PRVM_CallProfile_f(), PRVM_ChildProfile_f(), PRVM_ED_Count_f(), PRVM_ED_EdictGet_f(), PRVM_ED_EdictSet_f(), PRVM_ED_GlobalGet_f(), PRVM_ED_PrintEdict_f(), PRVM_ED_PrintEdicts_f(), PRVM_EdictWatchpoint_f(), PRVM_Fields_f(), PRVM_GameCommand(), PRVM_Global_f(), PRVM_Globals_f(), PRVM_GlobalSet_f(), PRVM_GlobalWatchpoint_f(), PRVM_PrintFunction_f(), PRVM_Profile_f(), R_Envmap_f(), R_ReplaceWorldTexture_f(), R_Shadow_EditLights_Edit_f(), R_Shadow_EditLights_Spawn_f(), S_PauseSound_f(), S_Play_Common(), SCR_Centerprint_f(), SCR_InfoBar_f(), SCR_ScreenShot_f(), SV_Changelevel_f(), SV_Download_f(), SV_Ent_Create_f(), SV_Ent_Remove_f(), SV_Kick_f(), SV_Loadgame_f(), SV_Map_f(), SV_MaxPlayers_f(), SV_Name_f(), SV_Playermodel_f(), SV_Playerskin_f(), SV_PModel_f(), SV_Rate_BurstSize_f(), SV_Restart_f(), SV_Savegame_f(), SV_Say(), SV_SendCvar_f(), SV_Status_f(), SV_Tell_f(), and V_BonusFlash_f().

◆ Cmd_Args()

static const char * Cmd_Args ( cmd_state_t * cmd)
inlinestatic

◆ Cmd_Argv()

static const char * Cmd_Argv ( cmd_state_t * cmd,
int arg )
inlinestatic

Cmd_Argv(cmd, ) will return an empty string (not a NULL) if arg > argc, so string operations are always safe.

Definition at line 254 of file cmd.h.

255{
256 if (arg >= cmd->argc )
257 return cmd->null_string;
258 return cmd->argv[arg];
259}

References cmd().

Referenced by Call_MR_ToggleMenu_f(), CD_f(), CL_Color_f(), CL_Connect_f(), CL_Disconnect_f(), CL_DownloadBegin_f(), CL_DownloadFinished_f(), CL_EstablishConnection(), CL_Fog_f(), CL_Fog_HeightTexture_f(), CL_ForwardToServer_f(), CL_FullInfo_f(), CL_FullServerinfo_f(), CL_IPLog_List_f(), CL_Locs_Add_f(), CL_Name_f(), CL_Packet_f(), CL_Particles_LoadEffectInfo_f(), CL_PingPLReport_f(), CL_PlayDemo_f(), CL_PlayVideo_f(), CL_PQRcon_f(), CL_Rcon_f(), CL_Record_f(), CL_SendCvar_f(), CL_SetInfo_f(), CL_Startdemos_f(), CL_TimeDemo_f(), CL_User_f(), Cmd_Alias_f(), Cmd_Apropos_f(), Cmd_Callback(), Cmd_CheckParm(), Cmd_Defer_f(), Cmd_Echo_f(), Cmd_Exec_f(), Cmd_ExecuteString(), Cmd_GetDirectCvarValue(), Cmd_List_f(), Cmd_Toggle_f(), Cmd_UnAlias_f(), Con_ConDump_f(), Con_Maps_f(), Crypto_HostKey_Clear_f(), Crypto_KeyGen_f(), Curl_Curl_f(), Cvar_Command(), Cvar_Del_f(), Cvar_List_f(), Cvar_Set_f(), Cvar_SetA_f(), Download_CheckExtensions(), FS_GameDir_f(), FS_ListDirectoryCmd(), FS_Which_f(), GL_TextureMode_f(), Host_SaveConfig_f(), Image_FixTransparentPixels_f(), IN_BestWeapon_f(), IN_BestWeapon_Register_f(), IN_Impulse(), Key_Bind_f(), Key_History_f(), Key_In_Bind_f(), Key_In_BindList_f(), Key_In_Bindmap_f(), Key_In_Unbind_f(), Key_Unbind_f(), KeyDown(), KeyUp(), LoadFont_f(), LoadSky_f(), MemList_f(), Mod_Decompile_f(), Mod_Precache_f(), PRVM_Breakpoint_f(), PRVM_CallProfile_f(), PRVM_ChildProfile_f(), PRVM_ED_Count_f(), PRVM_ED_EdictGet_f(), PRVM_ED_EdictSet_f(), PRVM_ED_GlobalGet_f(), PRVM_ED_PrintEdict_f(), PRVM_ED_PrintEdicts_f(), PRVM_EdictWatchpoint_f(), PRVM_Fields_f(), PRVM_Global_f(), PRVM_Globals_f(), PRVM_GlobalSet_f(), PRVM_GlobalWatchpoint_f(), PRVM_PrintFunction_f(), PRVM_Profile_f(), R_Envmap_f(), R_ReplaceWorldTexture_f(), R_Shadow_EditLights_Edit_f(), S_PauseSound_f(), S_Play_Common(), SCR_Centerprint_f(), SCR_InfoBar_f(), SCR_ScreenShot_f(), SV_Changelevel_f(), SV_Color_f(), SV_Download_f(), SV_Ent_Create_f(), SV_Ent_Remove_All_f(), SV_Ent_Remove_f(), SV_Give_f(), SV_Kick_f(), SV_Loadgame_f(), SV_Map_f(), SV_MaxPlayers_f(), SV_Name_f(), SV_Playermodel_f(), SV_Playerskin_f(), SV_PModel_f(), SV_Rate_BurstSize_f(), SV_Rate_f(), SV_Savegame_f(), SV_SendCvar_f(), SV_Status_f(), SV_Viewframe_f(), SV_Viewmodel_f(), V_BonusFlash_f(), and V_cshift_f().

◆ Cmd_Callback()

qbool Cmd_Callback ( cmd_state_t * cmd,
cmd_function_t * func )

Definition at line 2008 of file cmd.c.

2009{
2010 if (func->function)
2011 func->function(cmd);
2012 else
2013 Con_Printf(CON_WARN "Command \"%s\" can not be executed\n", Cmd_Argv(cmd, 0));
2014 return true;
2015}
static const char * Cmd_Argv(cmd_state_t *cmd, int arg)
Cmd_Argv(cmd, ) will return an empty string (not a NULL) if arg > argc, so string operations are alwa...
Definition cmd.h:254

References cmd(), Cmd_Argv(), Con_Printf(), CON_WARN, and cmd_function_t::function.

Referenced by Cmd_CL_Callback().

◆ Cmd_CheckParm()

int Cmd_CheckParm ( cmd_state_t * cmd,
const char * parm )

Returns the position (1 to argc-1) in the command's argument list where the given parameter apears, or 0 if not present.

Definition at line 2140 of file cmd.c.

2141{
2142 int i;
2143
2144 if (!parm)
2145 {
2146 Con_Printf(CON_WARN "Cmd_CheckParm: NULL");
2147 return 0;
2148 }
2149
2150 for (i = 1; i < Cmd_Argc (cmd); i++)
2151 if (!strcasecmp (parm, Cmd_Argv(cmd, i)))
2152 return i;
2153
2154 return 0;
2155}
static int Cmd_Argc(cmd_state_t *cmd)
Definition cmd.h:249

References cmd(), Cmd_Argc(), Cmd_Argv(), Con_Printf(), CON_WARN, and i.

◆ Cmd_CL_Callback()

qbool Cmd_CL_Callback ( cmd_state_t * cmd,
cmd_function_t * func,
const char * text,
size_t textlen,
cmd_source_t src )

Definition at line 2017 of file cmd.c.

2018{
2019 // TODO: Assign these functions to QC commands directly?
2020 if(func->qcfunc)
2021 {
2022 if(((func->flags & CF_CLIENT) && CL_VM_ConsoleCommand(text, textlen)) ||
2023 ((func->flags & CF_SERVER) && SV_VM_ConsoleCommand(text, textlen)))
2024 return true;
2025
2026 if (func->overridden) // If this QC command overrides an engine command,
2027 func = func->overridden; // fall back to that command.
2028 }
2029 if (func->flags & CF_SERVER_FROM_CLIENT)
2030 {
2032 {
2034 return true;
2035 }
2036 else if(!(func->flags & CF_SERVER))
2037 {
2038 Con_Printf(CON_WARN "Cannot execute client commands from a dedicated server console.\n");
2039 return true;
2040 }
2041 }
2042 return Cmd_Callback(cmd, func);
2043}
void CL_ForwardToServer_f(cmd_state_t *cmd)
adds the current command line as a clc_stringcmd to the client message.
Definition cl_cmd.c:174
qbool Cmd_Callback(cmd_state_t *cmd, cmd_function_t *func)
Definition cmd.c:2008
#define CF_SERVER
cvar/command that only the server can change/execute
Definition cmd.h:49
#define CF_SERVER_FROM_CLIENT
command the client is allowed to execute on the server as a stringcmd
Definition cmd.h:51
#define CF_CLIENT
cvar/command that only the client can change/execute
Definition cmd.h:48
qbool CL_VM_ConsoleCommand(const char *text, size_t textlen)
Definition csprogs.c:573
cvar_t host_isclient
Definition host.c:61
qbool SV_VM_ConsoleCommand(const char *text, size_t textlen)
Definition svvm_cmds.c:2927
int integer
Definition cvar.h:73

References CF_CLIENT, CF_SERVER, CF_SERVER_FROM_CLIENT, CL_ForwardToServer_f(), CL_VM_ConsoleCommand(), cmd(), Cmd_Callback(), Con_Printf(), CON_WARN, cmd_function_t::flags, host_isclient, cvar_t::integer, cmd_function_t::overridden, cmd_function_t::qcfunc, and SV_VM_ConsoleCommand().

Referenced by Cmd_Init().

◆ Cmd_ClearCSQCCommands()

void Cmd_ClearCSQCCommands ( cmd_state_t * cmd)

Definition at line 1981 of file cmd.c.

1982{
1983 cmd_function_t *func;
1984 cmd_function_t **next = &cmd->userdefined->qc_functions;
1985
1986 while(*next)
1987 {
1988 func = *next;
1989 *next = func->next;
1990 Z_Free(func);
1991 }
1992}
#define Z_Free(data)
Definition zone.h:164

References cmd(), cmd_function_t::next, and Z_Free.

Referenced by CL_VM_ShutDown().

◆ Cmd_CompleteAlias()

const char * Cmd_CompleteAlias ( cmd_state_t * cmd,
const char * partial )

Definition at line 1892 of file cmd.c.

1893{
1894 cmd_alias_t *alias;
1895 size_t len;
1896
1897 len = strlen(partial);
1898
1899 if (!len)
1900 return NULL;
1901
1902 // Check functions
1903 for (alias = cmd->userdefined->alias; alias; alias = alias->next)
1904 if (!strncasecmp(partial, alias->name, len))
1905 return alias->name;
1906
1907 return NULL;
1908}
struct cmd_alias_s * next
Definition cmd.h:80
char name[MAX_ALIAS_NAME]
Definition cmd.h:81

References cmd(), cmd_alias_t::name, cmd_alias_t::next, NULL, and strlen().

◆ Cmd_CompleteAliasBuildList()

const char ** Cmd_CompleteAliasBuildList ( cmd_state_t * cmd,
const char * partial )

Definition at line 1961 of file cmd.c.

1962{
1963 cmd_alias_t *alias;
1964 size_t len = 0;
1965 size_t bpos = 0;
1966 size_t sizeofbuf = (Cmd_CompleteAliasCountPossible (cmd, partial) + 1) * sizeof (const char *);
1967 const char **buf;
1968
1969 len = strlen(partial);
1970 buf = (const char **)Mem_Alloc(tempmempool, sizeofbuf + sizeof (const char *));
1971 // Loop through the alias list and print all matches
1972 for (alias = cmd->userdefined->alias; alias; alias = alias->next)
1973 if (!strncasecmp(partial, alias->name, len))
1974 buf[bpos++] = alias->name;
1975
1976 buf[bpos] = NULL;
1977 return buf;
1978}
int Cmd_CompleteAliasCountPossible(cmd_state_t *cmd, const char *partial)
Definition cmd.c:1931
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition glquake.h:657
mempool_t * tempmempool
Definition zone.c:794

References buf, cmd(), Cmd_CompleteAliasCountPossible(), Mem_Alloc, cmd_alias_t::name, cmd_alias_t::next, NULL, strlen(), and tempmempool.

Referenced by Con_CompleteCommandLine().

◆ Cmd_CompleteAliasCountPossible()

int Cmd_CompleteAliasCountPossible ( cmd_state_t * cmd,
const char * partial )

Definition at line 1931 of file cmd.c.

1932{
1933 cmd_alias_t *alias;
1934 size_t len;
1935 int h;
1936
1937 h = 0;
1938
1939 len = strlen(partial);
1940
1941 if (!len)
1942 return 0;
1943
1944 // Loop through the command list and count all partial matches
1945 for (alias = cmd->userdefined->alias; alias; alias = alias->next)
1946 if (!strncasecmp(partial, alias->name, len))
1947 h++;
1948
1949 return h;
1950}

References cmd(), cmd_alias_t::name, cmd_alias_t::next, and strlen().

Referenced by Cmd_CompleteAliasBuildList(), and Con_CompleteCommandLine().

◆ Cmd_CompleteAliasPrint()

void Cmd_CompleteAliasPrint ( cmd_state_t * cmd,
const char * partial )

Definition at line 1911 of file cmd.c.

1912{
1913 cmd_alias_t *alias;
1914 size_t len = strlen(partial);
1915 // Loop through the alias list and print all matches
1916 for (alias = cmd->userdefined->alias; alias; alias = alias->next)
1917 if (!strncasecmp(partial, alias->name, len))
1918 Con_Printf("^5%s^7: %s", alias->name, alias->value);
1919}
char * value
Definition cmd.h:82

References cmd(), Con_Printf(), cmd_alias_t::name, cmd_alias_t::next, strlen(), and cmd_alias_t::value.

Referenced by Con_CompleteCommandLine().

◆ Cmd_CompleteBuildList()

const char ** Cmd_CompleteBuildList ( cmd_state_t * cmd,
const char * partial )

Definition at line 1847 of file cmd.c.

1848{
1849 cmd_function_t *func;
1850 size_t len = 0;
1851 size_t bpos = 0;
1852 size_t sizeofbuf = (Cmd_CompleteCountPossible (cmd, partial) + 1) * sizeof (const char *);
1853 const char **buf;
1854
1855 len = strlen(partial);
1856 buf = (const char **)Mem_Alloc(tempmempool, sizeofbuf + sizeof (const char *));
1857 // Loop through the functions lists and print all matches
1858 for (func = cmd->userdefined->qc_functions; func; func = func->next)
1859 if (!strncasecmp(partial, func->name, len))
1860 buf[bpos++] = func->name;
1861 for (func = cmd->engine_functions; func; func = func->next)
1862 if (!strncasecmp(partial, func->name, len))
1863 buf[bpos++] = func->name;
1864
1865 buf[bpos] = NULL;
1866 return buf;
1867}
int Cmd_CompleteCountPossible(cmd_state_t *cmd, const char *partial)
Definition cmd.c:1814

References buf, cmd(), Cmd_CompleteCountPossible(), Mem_Alloc, cmd_function_t::name, cmd_function_t::next, NULL, strlen(), and tempmempool.

Referenced by Con_CompleteCommandLine().

◆ Cmd_CompleteCommand()

const char * Cmd_CompleteCommand ( cmd_state_t * cmd,
const char * partial )

attempts to match a partial command for automatic command line completion returns NULL if nothing fits

Definition at line 1783 of file cmd.c.

1784{
1785 cmd_function_t *func;
1786 size_t len;
1787
1788 len = strlen(partial);
1789
1790 if (!len)
1791 return NULL;
1792
1793// check functions
1794 for (func = cmd->userdefined->qc_functions; func; func = func->next)
1795 if (!strncasecmp(partial, func->name, len))
1796 return func->name;
1797
1798 for (func = cmd->engine_functions; func; func = func->next)
1799 if (!strncasecmp(partial, func->name, len))
1800 return func->name;
1801
1802 return NULL;
1803}

References cmd(), cmd_function_t::name, cmd_function_t::next, NULL, and strlen().

◆ Cmd_CompleteCommandPrint()

void Cmd_CompleteCommandPrint ( cmd_state_t * cmd,
const char * partial )

Definition at line 1870 of file cmd.c.

1871{
1872 cmd_function_t *func;
1873 size_t len = strlen(partial);
1874 // Loop through the command list and print all matches
1875 for (func = cmd->userdefined->qc_functions; func; func = func->next)
1876 if (!strncasecmp(partial, func->name, len))
1877 Con_Printf("^2%s^7: %s\n", func->name, func->description);
1878 for (func = cmd->engine_functions; func; func = func->next)
1879 if (!strncasecmp(partial, func->name, len))
1880 Con_Printf("^2%s^7: %s\n", func->name, func->description);
1881}

References cmd(), Con_Printf(), cmd_function_t::description, cmd_function_t::name, cmd_function_t::next, and strlen().

Referenced by Con_CompleteCommandLine().

◆ Cmd_CompleteCountPossible()

int Cmd_CompleteCountPossible ( cmd_state_t * cmd,
const char * partial )

Definition at line 1814 of file cmd.c.

1815{
1816 cmd_function_t *func;
1817 size_t len;
1818 int h;
1819
1820 h = 0;
1821 len = strlen(partial);
1822
1823 if (!len)
1824 return 0;
1825
1826 // Loop through the command list and count all partial matches
1827 for (func = cmd->userdefined->qc_functions; func; func = func->next)
1828 if (!strncasecmp(partial, func->name, len))
1829 h++;
1830
1831 for (func = cmd->engine_functions; func; func = func->next)
1832 if (!strncasecmp(partial, func->name, len))
1833 h++;
1834
1835 return h;
1836}

References cmd(), cmd_function_t::name, cmd_function_t::next, and strlen().

Referenced by Cmd_CompleteBuildList(), and Con_CompleteCommandLine().

◆ Cmd_ExecuteString()

void Cmd_ExecuteString ( cmd_state_t * cmd,
const char * text,
size_t textlen,
cmd_source_t src,
qbool lockmutex )

Parses a single line of text into arguments and tries to execute it.

The text can come from the command buffer, a remote client, or stdin.

Definition at line 2068 of file cmd.c.

2069{
2070 int oldpos;
2071 cmd_function_t *func;
2072 cmd_alias_t *a;
2073
2074 if (lockmutex)
2075 Cbuf_Lock(cmd->cbuf);
2076 oldpos = cmd->cbuf->tokenizebufferpos;
2077 cmd->source = src;
2078
2079 Cmd_TokenizeString (cmd, text);
2080
2081// execute the command line
2082 if (!Cmd_Argc(cmd))
2083 goto done; // no tokens
2084
2085// check functions
2086 for (func = cmd->userdefined->qc_functions; func; func = func->next)
2087 if (!strcasecmp(cmd->argv[0], func->name))
2088 if(cmd->Handle(cmd, func, text, textlen, src))
2089 goto functions_done;
2090
2091 for (func = cmd->engine_functions; func; func=func->next)
2092 if (!strcasecmp (cmd->argv[0], func->name))
2093 if(cmd->Handle(cmd, func, text, textlen, src))
2094 goto functions_done;
2095
2096functions_done:
2097 // If it's a client command and wasn't found and handled, say so.
2098 // Also don't let clients call server aliases.
2099 if (cmd->source == src_client)
2100 {
2101 if (!func)
2102 Con_Printf("Client \"%s\" tried to execute \"%s\"\n", host_client->name, text);
2103 goto done;
2104 }
2105
2106// check alias
2107 // Execute any alias with the same name as a command after the command.
2108 for (a=cmd->userdefined->alias ; a ; a=a->next)
2109 {
2110 if (!strcasecmp (cmd->argv[0], a->name))
2111 {
2113 goto done;
2114 }
2115 }
2116
2117 // If the command was found and handled don't try to handle it as a cvar.
2118 if (func)
2119 goto done;
2120
2121// check cvars
2122 // Xonotic is still maintained so we don't want to hide problems from getting fixed
2123 if (!Cvar_Command(cmd) && (host.framecount > 0 || gamemode == GAME_XONOTIC))
2124 Con_Printf(CON_WARN "Unknown command \"%s\"\n", Cmd_Argv(cmd, 0));
2125done:
2126 cmd->cbuf->tokenizebufferpos = oldpos;
2127 if (lockmutex)
2128 Cbuf_Unlock(cmd->cbuf);
2129}
static void Cmd_TokenizeString(cmd_state_t *cmd, const char *text)
Definition cmd.c:1601
static void Cmd_ExecuteAlias(cmd_state_t *cmd, cmd_alias_t *alias)
Definition cmd.c:1306
gamemode_t gamemode
Definition com_game.c:26
@ GAME_XONOTIC
Definition com_game.h:34
qbool Cvar_Command(cmd_state_t *cmd)
Definition cvar.c:833
host_static_t host
Definition host.c:41
prvm_eval_t * src
client_t * host_client
Definition sv_main.c:29
ret a
char name[MAX_SCOREBOARDNAME]
Definition server.h:235
unsigned int framecount
incremented every frame, never reset, >0 means Host_AbortCurrentFrame() is possible
Definition host.h:45

References a, Cbuf_Lock(), Cbuf_Unlock(), cmd(), Cmd_Argc(), Cmd_Argv(), Cmd_ExecuteAlias(), Cmd_TokenizeString(), Con_Printf(), CON_WARN, Cvar_Command(), host_static_t::framecount, GAME_XONOTIC, gamemode, host, host_client, client_t::name, cmd_function_t::name, cmd_function_t::next, src, and src_client.

Referenced by CL_ParseServerMessage(), CL_Record_f(), CL_VM_Parse_StuffCmd(), Cmd_PreprocessAndExecuteString(), Key_Message(), SV_ReadClientMessage(), and VM_SV_clientcommand().

◆ Cmd_Exists()

qbool Cmd_Exists ( cmd_state_t * cmd,
const char * cmd_name )

used by the cvar code to check for cvar / command name overlap

Definition at line 1762 of file cmd.c.

1763{
1764 cmd_function_t *func;
1765
1766 for (func = cmd->userdefined->qc_functions; func; func = func->next)
1767 if (!strcmp(cmd_name, func->name))
1768 return true;
1769
1770 for (func=cmd->engine_functions ; func ; func=func->next)
1771 if (!strcmp (cmd_name,func->name))
1772 return true;
1773
1774 return false;
1775}

References cmd(), cmd_function_t::name, and cmd_function_t::next.

Referenced by Cvar_Get(), Cvar_RegisterVariable(), Cvar_RegisterVirtual(), and VM_registercvar().

◆ Cmd_Init()

void Cmd_Init ( void )

Command execution takes a null terminated string, breaks it into tokens, then searches for a command or variable that matches the first token.

Commands can come from three sources, but the handler functions may choose to dissallow the action or forward it to a remote server if the source is not apropriate.

Definition at line 1492 of file cmd.c.

1493{
1494 cmd_buf_t *cbuf;
1495 unsigned cvars_flagsmask, cmds_flagsmask;
1496
1497 cbuf_mempool = Mem_AllocPool("Command buffer", 0, NULL);
1498 cbuf = (cmd_buf_t *)Mem_Alloc(cbuf_mempool, sizeof(cmd_buf_t));
1499 cbuf->maxsize = CMDBUFSIZE;
1500 cbuf->lock = Thread_CreateMutex();
1501 cbuf->wait = false;
1502 host.cbuf = cbuf;
1503
1504 cbuf->start.prev = cbuf->start.next = &(cbuf->start);
1505 cbuf->deferred.prev = cbuf->deferred.next = &(cbuf->deferred);
1506 cbuf->free.prev = cbuf->free.next = &(cbuf->free);
1507
1508 // FIXME: Get rid of cmd_iter_all eventually. This is just a hack to reduce the amount of work to make the interpreters dynamic.
1510
1511 // local console
1512 if (cls.state == ca_dedicated)
1513 {
1514 cvars_flagsmask = CF_SERVER;
1515 cmds_flagsmask = CF_SERVER | CF_SERVER_FROM_CLIENT;
1516 }
1517 else
1518 {
1519 cvars_flagsmask = CF_CLIENT | CF_SERVER;
1521 }
1522 cmd_iter_all[0].cmd = cmd_local = Cmd_AddInterpreter(cbuf, &cvars_all, cvars_flagsmask, cmds_flagsmask, &cmd_userdefined_all);
1524
1525 // server commands received from clients have no reason to access cvars, cvar expansion seems perilous.
1528
1529 cmd_iter_all[2].cmd = NULL;
1530//
1531// register our commands
1532//
1533 // client-only commands
1534 Cmd_AddCommand(CF_SHARED, "wait", Cmd_Wait_f, "make script execution wait for next rendered frame");
1535
1536 // maintenance commands used for upkeep of cvars and saved configs
1537 Cmd_AddCommand(CF_SHARED, "stuffcmds", Cmd_StuffCmds_f, "execute commandline parameters (must be present in quake.rc script)");
1538 Cmd_AddCommand(CF_SHARED, "cvar_lockdefaults", Cvar_LockDefaults_f, "stores the current values of all cvars into their default values, only used once during startup after parsing default.cfg");
1539 Cmd_AddCommand(CF_SHARED, "cvar_resettodefaults_all", Cvar_ResetToDefaults_All_f, "sets all cvars to their locked default values");
1540 Cmd_AddCommand(CF_SHARED, "cvar_resettodefaults_nosaveonly", Cvar_ResetToDefaults_NoSaveOnly_f, "sets all non-saved cvars to their locked default values (variables that will not be saved to config.cfg)");
1541 Cmd_AddCommand(CF_SHARED, "cvar_resettodefaults_saveonly", Cvar_ResetToDefaults_SaveOnly_f, "sets all saved cvars to their locked default values (variables that will be saved to config.cfg)");
1542
1543 // general console commands used in multiple environments
1544 Cmd_AddCommand(CF_SHARED, "exec", Cmd_Exec_f, "execute a script file");
1545 Cmd_AddCommand(CF_SHARED, "echo",Cmd_Echo_f, "print a message to the console (useful in scripts)");
1546 Cmd_AddCommand(CF_SHARED, "alias",Cmd_Alias_f, "create a script function (parameters are passed in as $X (being X a number), $* for all parameters, $X- for all parameters starting from $X). Without arguments show the list of all alias");
1547 Cmd_AddCommand(CF_SHARED, "unalias",Cmd_UnAlias_f, "remove an alias");
1548 Cmd_AddCommand(CF_SHARED, "set", Cvar_Set_f, "create or change the value of a console variable");
1549 Cmd_AddCommand(CF_SHARED, "seta", Cvar_SetA_f, "create or change the value of a console variable that will be saved to config.cfg");
1550 Cmd_AddCommand(CF_SHARED, "unset", Cvar_Del_f, "delete a cvar (does not work for static ones like _cl_name, or read-only ones)");
1551
1552#ifdef FILLALLCVARSWITHRUBBISH
1553 Cmd_AddCommand(CF_SHARED, "fillallcvarswithrubbish", Cvar_FillAll_f, "fill all cvars with a specified number of characters to provoke buffer overruns");
1554#endif /* FILLALLCVARSWITHRUBBISH */
1555
1556 // 2000-01-09 CmdList, CvarList commands By Matthias "Maddes" Buecher
1557 // Added/Modified by EvilTypeGuy eviltypeguy@qeradiant.com
1558 Cmd_AddCommand(CF_SHARED, "cmdlist", Cmd_List_f, "lists all console commands beginning with the specified prefix or matching the specified wildcard pattern");
1559 Cmd_AddCommand(CF_SHARED, "cvarlist", Cvar_List_f, "lists all console variables beginning with the specified prefix or matching the specified wildcard pattern");
1560 Cmd_AddCommand(CF_SHARED, "apropos", Cmd_Apropos_f, "lists all console variables/commands/aliases containing the specified string in the name or description");
1561 Cmd_AddCommand(CF_SHARED, "find", Cmd_Apropos_f, "lists all console variables/commands/aliases containing the specified string in the name or description");
1562
1563 Cmd_AddCommand(CF_SHARED, "defer", Cmd_Defer_f, "execute a command in the future");
1564
1565 // DRESK - 5/14/06
1566 // Support Doom3-style Toggle Command
1567 Cmd_AddCommand(CF_SHARED | CF_CLIENT_FROM_SERVER, "toggle", Cmd_Toggle_f, "toggles a console variable's values (use for more info)");
1568}
client_static_t cls
Definition cl_main.c:116
@ ca_dedicated
Definition client.h:530
static void Cmd_Wait_f(cmd_state_t *cmd)
Definition cmd.c:65
static void Cmd_Apropos_f(cmd_state_t *cmd)
Definition cmd.c:1400
static void Cmd_Defer_f(cmd_state_t *cmd)
Definition cmd.c:79
mempool_t * cbuf_mempool
Definition cmd.c:38
static void Cmd_List_f(cmd_state_t *cmd)
Definition cmd.c:1352
qbool Cmd_SV_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, size_t textlen, cmd_source_t src)
Definition cmd.c:2045
static void Cmd_StuffCmds_f(cmd_state_t *cmd)
Definition cmd.c:463
cmd_userdefined_t cmd_userdefined_all
aliases and csqc functions
Definition cmd.c:28
static void Cmd_Echo_f(cmd_state_t *cmd)
Definition cmd.c:717
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...
Definition cmd.c:1661
static cmd_state_t * Cmd_AddInterpreter(cmd_buf_t *cbuf, cvar_state_t *cvars, unsigned cvars_flagsmask, unsigned cmds_flagsmask, cmd_userdefined_t *userdefined)
Definition cmd.c:1470
static void Cmd_UnAlias_f(cmd_state_t *cmd)
Definition cmd.c:889
qbool Cmd_CL_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, size_t textlen, cmd_source_t src)
Definition cmd.c:2017
cmd_state_t * cmd_local
command interpreter for local commands injected by SVQC, CSQC, MQC, server or client engine code uses...
Definition cmd.c:25
static void Cmd_Toggle_f(cmd_state_t *cmd)
Definition cmd.c:735
cmd_state_t * cmd_serverfromclient
command interpreter for server commands received over network from clients uses cmddefs_null
Definition cmd.c:26
static void Cmd_Exec_f(cmd_state_t *cmd)
Definition cmd.c:685
static void Cmd_Alias_f(cmd_state_t *cmd)
Definition cmd.c:813
cmd_userdefined_t cmd_userdefined_null
intentionally empty
Definition cmd.c:29
#define CF_SHARED
Definition cmd.h:67
#define CF_USERINFO
command or cvar used to communicate userinfo to the server
Definition cmd.h:57
#define CF_CLIENT_FROM_SERVER
command that the server is allowed to execute on the client
Definition cmd.h:50
void Cvar_Del_f(cmd_state_t *cmd)
Definition cvar.c:1110
void Cvar_ResetToDefaults_NoSaveOnly_f(cmd_state_t *cmd)
Definition cvar.c:952
void Cvar_ResetToDefaults_All_f(cmd_state_t *cmd)
Definition cvar.c:940
void Cvar_Set_f(cmd_state_t *cmd)
Definition cvar.c:1060
void Cvar_LockDefaults_f(cmd_state_t *cmd)
Definition cvar.c:871
cvar_state_t cvars_all
Definition cvar.c:28
cvar_state_t cvars_null
Definition cvar.c:29
void Cvar_SetA_f(cmd_state_t *cmd)
Definition cvar.c:1085
void Cvar_List_f(cmd_state_t *cmd)
Definition cvar.c:1008
void Cvar_ResetToDefaults_SaveOnly_f(cmd_state_t *cmd)
Definition cvar.c:965
#define CMDBUFSIZE
maximum script size that can be loaded by the exec command (8192 in Quake)
Definition qdefs.h:100
cactive_t state
Definition client.h:568
qbool(* Handle)(struct cmd_state_s *, struct cmd_function_s *, const char *, size_t, enum cmd_source_s)
Definition cmd.h:147
cmd_buf_t * cbuf
Definition host.h:51
#define Thread_CreateMutex()
Definition thread.h:15
#define Mem_AllocPool(name, flags, parent)
Definition zone.h:104

References ca_dedicated, host_static_t::cbuf, cbuf_mempool, CF_CLIENT, CF_CLIENT_FROM_SERVER, CF_SERVER, CF_SERVER_FROM_CLIENT, CF_SHARED, CF_USERINFO, cls, cmd_iter_t::cmd, Cmd_AddCommand(), Cmd_AddInterpreter(), Cmd_Alias_f(), Cmd_Apropos_f(), Cmd_CL_Callback(), Cmd_Defer_f(), Cmd_Echo_f(), Cmd_Exec_f(), cmd_iter_all, Cmd_List_f(), cmd_local, cmd_serverfromclient, Cmd_StuffCmds_f(), Cmd_SV_Callback(), Cmd_Toggle_f(), Cmd_UnAlias_f(), cmd_userdefined_all, cmd_userdefined_null, Cmd_Wait_f(), CMDBUFSIZE, Cvar_Del_f(), Cvar_List_f(), Cvar_LockDefaults_f(), Cvar_ResetToDefaults_All_f(), Cvar_ResetToDefaults_NoSaveOnly_f(), Cvar_ResetToDefaults_SaveOnly_f(), Cvar_Set_f(), Cvar_SetA_f(), cvars_all, cvars_null, cmd_buf_t::deferred, cmd_buf_t::free, cmd_state_t::Handle, host, cmd_buf_t::lock, cmd_buf_t::maxsize, Mem_Alloc, Mem_AllocPool, llist_t::next, NULL, llist_t::prev, cmd_buf_t::start, client_static_t::state, tempmempool, Thread_CreateMutex, and cmd_buf_t::wait.

Referenced by Host_Init().

◆ Cmd_NoOperation_f()

void Cmd_NoOperation_f ( cmd_state_t * cmd)

Definition at line 2240 of file cmd.c.

2241{
2242}

Referenced by S_Init().

◆ Cmd_PreprocessAndExecuteString()

void Cmd_PreprocessAndExecuteString ( cmd_state_t * cmd,
const char * text,
size_t textlen,
cmd_source_t src,
qbool lockmutex )

Like Cmd_ExecuteString, but with variable expansion.

Definition at line 1323 of file cmd.c.

1324{
1325 char preprocessed[MAX_INPUTLINE];
1326 size_t preprocessed_len;
1327 const char *firstchar;
1328
1329 firstchar = text;
1330 while(*firstchar && ISWHITESPACE(*firstchar))
1331 ++firstchar;
1332 if((strncmp(firstchar, "alias", 5) || !ISWHITESPACE(firstchar[5]))
1333 && (strncmp(firstchar, "bind", 4) || !ISWHITESPACE(firstchar[4]))
1334 && (strncmp(firstchar, "in_bind", 7) || !ISWHITESPACE(firstchar[7])))
1335 {
1336 if((preprocessed_len = Cmd_PreprocessString(cmd, text, preprocessed, sizeof(preprocessed), NULL)))
1337 Cmd_ExecuteString(cmd, preprocessed, preprocessed_len, src, lockmutex);
1338 }
1339 else
1340 Cmd_ExecuteString(cmd, text, textlen, src, lockmutex);
1341}
void Cmd_ExecuteString(cmd_state_t *cmd, const char *text, size_t textlen, cmd_source_t src, qbool lockmutex)
Parses a single line of text into arguments and tries to execute it.
Definition cmd.c:2068
static size_t Cmd_PreprocessString(cmd_state_t *cmd, const char *intext, char *outtext, unsigned maxoutlen, cmd_alias_t *alias)
Cmd_PreprocessString.
Definition cmd.c:1176
#define MAX_INPUTLINE
maximum size of console commandline, QuakeC strings, and many other text processing buffers
Definition qdefs.h:94
#define ISWHITESPACE(ch)
Definition qdefs.h:184

References cmd(), Cmd_ExecuteString(), Cmd_PreprocessString(), ISWHITESPACE, MAX_INPUTLINE, NULL, and src.

Referenced by Cbuf_Execute(), and RCon_Execute().

◆ Cmd_QuoteString()

qbool Cmd_QuoteString ( char * out,
size_t outlen,
const char * in,
const char * quoteset,
qbool putquotes )

quotes a string so that it can be used as a command argument again; quoteset is a string that contains one or more of ", \, $ and specifies the characters to be quoted (you usually want to either pass ""\" or ""\$").

Returns true on success, and false on overrun (in which case out will contain a part of the quoted string). If putquotes is set, the enclosing quote marks are also put.

Definition at line 1000 of file cmd.c.

1001{
1002 qbool quote_quot = !!strchr(quoteset, '"');
1003 qbool quote_backslash = !!strchr(quoteset, '\\');
1004 qbool quote_dollar = !!strchr(quoteset, '$');
1005
1006 if(putquotes)
1007 {
1008 if(outlen <= 2)
1009 {
1010 *out++ = 0;
1011 return false;
1012 }
1013 *out++ = '"'; --outlen;
1014 --outlen;
1015 }
1016
1017 while(*in)
1018 {
1019 if(*in == '"' && quote_quot)
1020 {
1021 if(outlen <= 2)
1022 goto fail;
1023 *out++ = '\\'; --outlen;
1024 *out++ = '"'; --outlen;
1025 }
1026 else if(*in == '\\' && quote_backslash)
1027 {
1028 if(outlen <= 2)
1029 goto fail;
1030 *out++ = '\\'; --outlen;
1031 *out++ = '\\'; --outlen;
1032 }
1033 else if(*in == '$' && quote_dollar)
1034 {
1035 if(outlen <= 2)
1036 goto fail;
1037 *out++ = '$'; --outlen;
1038 *out++ = '$'; --outlen;
1039 }
1040 else
1041 {
1042 if(outlen <= 1)
1043 goto fail;
1044 *out++ = *in; --outlen;
1045 }
1046 ++in;
1047 }
1048 if(putquotes)
1049 *out++ = '"';
1050 *out++ = 0;
1051 return true;
1052fail:
1053 if(putquotes)
1054 *out++ = '"';
1055 *out++ = 0;
1056 return false;
1057}
bool qbool
Definition qtypes.h:9

Referenced by Cmd_ExecuteAlias(), Cmd_GetCvarValue(), Cvar_WriteVariables(), Key_PrintBindList(), and Key_WriteBindings().

◆ Cmd_RestoreInitState()

void Cmd_RestoreInitState ( void )

Restores cvars, commands and aliases to their init values and deletes any that were added since init.

Definition at line 2180 of file cmd.c.

2181{
2182 cmd_iter_t *cmd_iter;
2183 for (cmd_iter = cmd_iter_all; cmd_iter->cmd; cmd_iter++)
2184 {
2185 cmd_state_t *cmd = cmd_iter->cmd;
2186 cmd_function_t *f, **fp;
2187 cmd_alias_t *a, **ap;
2188 for (fp = &cmd->userdefined->qc_functions; (f = *fp);)
2189 {
2190 if (f->initstate)
2191 fp = &f->next;
2192 else
2193 {
2194 // destroy this command, it didn't exist at init
2195 Con_DPrintf("Cmd_RestoreInitState: Destroying command %s\n", f->name);
2196 *fp = f->next;
2197 Z_Free(f);
2198 }
2199 }
2200 for (fp = &cmd->engine_functions; (f = *fp);)
2201 {
2202 if (f->initstate)
2203 fp = &f->next;
2204 else
2205 {
2206 // destroy this command, it didn't exist at init
2207 Con_DPrintf("Cmd_RestoreInitState: Destroying command %s\n", f->name);
2208 *fp = f->next;
2209 Z_Free(f);
2210 }
2211 }
2212 for (ap = &cmd->userdefined->alias; (a = *ap);)
2213 {
2214 if (a->initstate)
2215 {
2216 // restore this alias, it existed at init
2217 if (strcmp(a->value ? a->value : "", a->initialvalue ? a->initialvalue : ""))
2218 {
2219 Con_DPrintf("Cmd_RestoreInitState: Restoring alias %s\n", a->name);
2220 if (a->value)
2221 Z_Free(a->value);
2222 a->value = Mem_strdup(zonemempool, a->initialvalue);
2223 }
2224 ap = &a->next;
2225 }
2226 else
2227 {
2228 // free this alias, it didn't exist at init...
2229 Con_DPrintf("Cmd_RestoreInitState: Destroying alias %s\n", a->name);
2230 *ap = a->next;
2231 if (a->value)
2232 Z_Free(a->value);
2233 Z_Free(a);
2234 }
2235 }
2236 }
2238}
void Cvar_RestoreInitState(cvar_state_t *cvars)
Definition cvar.c:901
mempool_t * zonemempool
Definition zone.c:796
#define Mem_strdup(pool, s)
Definition zone.h:97

References a, cmd(), cmd_iter_t::cmd, cmd_iter_all, Con_DPrintf(), Cvar_RestoreInitState(), cvars_all, f, Mem_strdup, cmd_alias_t::next, Z_Free, and zonemempool.

Referenced by Host_LoadConfig_f().

◆ Cmd_SaveInitState()

void Cmd_SaveInitState ( void )

called by Host_Init, this marks cvars, commands and aliases with their init values

Definition at line 2159 of file cmd.c.

2160{
2161 cmd_iter_t *cmd_iter;
2162 for (cmd_iter = cmd_iter_all; cmd_iter->cmd; cmd_iter++)
2163 {
2164 cmd_state_t *cmd = cmd_iter->cmd;
2166 cmd_alias_t *a;
2167 for (f = cmd->userdefined->qc_functions; f; f = f->next)
2168 f->initstate = true;
2169 for (f = cmd->engine_functions; f; f = f->next)
2170 f->initstate = true;
2171 for (a = cmd->userdefined->alias; a; a = a->next)
2172 {
2173 a->initstate = true;
2174 a->initialvalue = Mem_strdup(zonemempool, a->value);
2175 }
2176 }
2178}
void Cvar_SaveInitState(cvar_state_t *cvars)
Definition cvar.c:892

References a, cmd(), cmd_iter_t::cmd, cmd_iter_all, Cvar_SaveInitState(), cvars_all, f, Mem_strdup, and zonemempool.

Referenced by Host_Init().

◆ Cmd_Shutdown()

void Cmd_Shutdown ( void )

Definition at line 1575 of file cmd.c.

1576{
1577 cmd_iter_t *cmd_iter;
1578 for (cmd_iter = cmd_iter_all; cmd_iter->cmd; cmd_iter++)
1579 {
1580 cmd_state_t *cmd = cmd_iter->cmd;
1581
1582 if (cmd->cbuf->lock)
1583 {
1584 // we usually have this locked when we get here from Host_Quit_f
1585 Cbuf_Unlock(cmd->cbuf);
1586 }
1587
1588 Mem_FreePool(&cmd->mempool);
1589 }
1590}
#define Mem_FreePool(pool)
Definition zone.h:105

References Cbuf_Unlock(), cmd(), cmd_iter_t::cmd, cmd_iter_all, and Mem_FreePool.

Referenced by Host_Shutdown().

◆ Cmd_SV_Callback()

qbool Cmd_SV_Callback ( cmd_state_t * cmd,
cmd_function_t * func,
const char * text,
size_t textlen,
cmd_source_t src )

Definition at line 2045 of file cmd.c.

2046{
2047 if(func->qcfunc && (func->flags & CF_SERVER))
2048 return SV_VM_ConsoleCommand(text, textlen);
2049 else if (src == src_client)
2050 {
2051 if((func->flags & CF_CHEAT) && !sv_cheats.integer)
2052 SV_ClientPrintf(CON_WARN "No cheats allowed. The server must have sv_cheats set to 1\n");
2053 else
2054 func->function(cmd);
2055 return true;
2056 }
2057 return false;
2058}
cvar_t sv_cheats
Definition sv_ccmds.c:28
#define CF_CHEAT
command or cvar that gives an unfair advantage over other players and is blocked unless sv_cheats is ...
Definition cmd.h:52
void SV_ClientPrintf(const char *fmt,...) DP_FUNC_PRINTF(1)
Definition sv_send.c:72

References CF_CHEAT, CF_SERVER, cmd(), CON_WARN, cmd_function_t::flags, cmd_function_t::function, cvar_t::integer, cmd_function_t::qcfunc, src, src_client, sv_cheats, SV_ClientPrintf(), and SV_VM_ConsoleCommand().

Referenced by Cmd_Init().

Variable Documentation

◆ cmd_local

◆ cmd_serverfromclient

cmd_state_t* cmd_serverfromclient
extern

command interpreter for server commands received over network from clients uses cmddefs_null

Definition at line 26 of file cmd.c.

Referenced by Cmd_Init(), SV_ReadClientMessage(), and VM_SV_clientcommand().

◆ cmd_userdefined_all

cmd_userdefined_t cmd_userdefined_all
extern

aliases and csqc functions

Definition at line 28 of file cmd.c.

Referenced by Cmd_Init().

◆ cmd_userdefined_null

cmd_userdefined_t cmd_userdefined_null
extern

intentionally empty

Definition at line 29 of file cmd.c.

Referenced by Cmd_Init().

◆ host_stuffcmdsrun

qbool host_stuffcmdsrun
extern

Definition at line 41 of file cmd.c.

Referenced by Cmd_StuffCmds_f().