FTEQW
Documentation of the FTE engine source tree.
cmd.h
Go to the documentation of this file.
1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19*/
20
21// cmd.h -- Command buffer and command execution
22
23//===========================================================================
24
25/*FIXME: rewrite this to use something like the following
26typedef struct
27{
28 qbyte groups:27;
29 qbyte cvarlatch:1; //latches cvars so the user cannot change them till next map. should be RESTRICT_LOCAL to avoid users cheating by restrict-to-block server commands.
30 qbyte seat:4; //for splitscreen binds etc. 1 based! 0 uses in_forceseat/first.
31} cmdaccess_t;
32enum {
33//core groups
34 CAG_OWNER = 1<<0, //commands that came from the keyboard (or stdin).
35 CAG_MENUQC = 1<<1, //menuqc (mostly allowed to do stuff - but often also has CAG_DOWNLOADED)
36 CAG_CSQC = 1<<2, //csqc localcmds, nearly always has CAG_DOWNLOADED, so a load of denies
37 CAG_SSQC = 1<<3, //ssqc localcmds, able to poke quite a lot of things, generally unrestricted.
38 CAG_SERVER = 1<<4, //ssqc stuffcmds, typically same access as csqc
39//special groups:
40 CAG_DOWNLOADED = 1<<5, //for execs that read from a downloaded(untrusted) package. also flagged by qc modules if they were from such packages (so usually included from csqc).
41 CAG_SCRIPT = 1<<6, //added for binds (with more than one command), or for aliases/configs. exists for +lookdown's denies (using explicit checks, to avoid cheat bypasses).
42//custom groups:
43 CAG_RCON = 1<<7, //commands that came from rcon.
44
45//groups of groups, for default masks or special denies
46 CAG_DEFAULTALLOW = CAG_OWNER|CAG_MENUQC|CAG_CSQC|CAG_SSQC|CAG_SERVER|CAG_RCON,
47 CAG_INSECURE = CAG_DOWNLOADED|CAG_SERVER|CAG_CSQC, //csqc included mostly for consistency.
48
49 // userN: defaults to no commands
50 // vip: BAN_VIP users
51 // mapper: BAN_MAPPER users
52};
53
54 //stuff can be accessed when:
55 // if ((command.allows&cbuf.groups) && !(command.denies&cbuf.groups)) accessisallowed;
56 //cvars:
57 // separate allow-read, deny-read, allow-write, deny-write masks (set according to the older flags, to keep things simple)
58 //aliases:
59 // alias execution ors in the group(s) that created it (and 'script'). some execution chains could end up with a LOT of groups... FIXME: is that a problem? just don't put potentially restricted things in aliases?
60 //binds:
61 // also ors the creator's group - no `bind w doevil` and waiting.
62 //multiple cbufs:
63 // ssqc still has a dedicated cbuf, so that wait commands cause THAT cbuf to wait, not others.
64 // rcon+readcmd have a separate cbuf, to try to isolate prints
65 //seats:
66 // there's no security needed between seats, but server should maybe be blocked from seat switching commands (acting only as asserts), to catch bugs.
67 //
68 //'p2 nameofalias' sets seat to 2, overriding in_forceseat.
69 //+lookup etc is blocked when allow_scripts==0 and indirect is set.
70typedef struct
71{
72 cmdpermissions_t p; //access rights
73} cmdstate_t;
74void Cbuf_AddText(const char *text, qboolean addnl, qboolean insert); //null for local? all commands must be \n terminated.
75char *Cbuf_GetNext(cmdpermissions_t permissions, qboolean ignoresemicolon);
76void Cbuf_Execute(cbuf_t *cbuf);
77void Cmd_ExecuteString (const char *text, const cmdstate_t *cstate);
78
79//rcon can use a private cbuf, allowing it to parse properly despite level changes
80//cbuf must internally track cmdpermissions_t of different blocks. inserstions/additions may merge, others force \n termination (network can do its own buffering).
81
82typedef void (*xcommand_t) (const cmdstate_t *cstate);
83*/
84
85/*
86
87Any number of commands can be added in a frame, from several different sources.
88Most commands come from either keybindings or console line input, but remote
89servers can also send across commands and entire text files can be execed.
90
91The + command line options are also added to the command buffer.
92
93The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute ();
94
95*/
96
97void Cbuf_Waited(void);
98
99void Cbuf_Init (void);
100// allocates an initial text buffer that will grow as needed
101
102void Cbuf_AddText (const char *text, int level);
103// as new commands are generated from the console or keybindings,
104// the text is added to the end of the command buffer.
105
106void Cbuf_InsertText (const char *text, int level, qboolean addnl);
107// when a command wants to issue other commands immediately, the text is
108// inserted at the beginning of the buffer, before any remaining unexecuted
109// commands.
110
111char *Cbuf_GetNext(int level, qboolean ignoresemicolon);
112
113void Cbuf_Execute (void);
114// Pulls off \n terminated lines of text from the command buffer and sends
115// them through Cmd_ExecuteString. Stops when the buffer is empty.
116// Normally called once per frame, but may be explicitly invoked.
117// Do not call inside a command function!
118
120void Cbuf_ExecuteLevel(int level);
121//executes only a single cbuf level. can be used to restrict cbuf execution to some 'safe' set of commands, so there are no surprise 'map' commands.
122//will not magically make all commands safe to exec, but will prevent user commands slipping in too.
123
124//===========================================================================
125
126/*
127
128Command execution takes a null terminated string, breaks it into tokens,
129then searches for a command or variable that matches the first token.
130
131*/
132
133typedef void (*xcommand_t) (void);
135{
136 //if repl is specified, then that is the text that will be used if this is the sole autocomplete, to complete using strings that are not actually valid.
137 void(*cb)(const char *arg, const char *desc, const char *repl, struct xcommandargcompletioncb_s *ctx);
138 //private stuff follows.
139};
140typedef void (*xcommandargcompletion_t)(int argn, const char *partial, struct xcommandargcompletioncb_s *ctx);
141
142int Cmd_Level(const char *name);
143void Cmd_EnumerateLevel(int level, char *buf, size_t bufsize);
144
145void Cmd_Init (void);
146void Cmd_Shutdown(void);
147void Cmd_StuffCmds (void);
148
149void Cmd_RemoveCommands (xcommand_t function); //unregister all commands that use the same function. for wrappers and stuff.
150void Cmd_RemoveCommand (const char *cmd_name);
151qboolean Cmd_AddCommand (const char *cmd_name, xcommand_t function);
152qboolean Cmd_AddCommandD (const char *cmd_name, xcommand_t function, const char *description);
153qboolean Cmd_AddCommandAD (const char *cmd_name, xcommand_t function, xcommandargcompletion_t argcomplete, const char *description);
154// called by the init functions of other parts of the program to
155// register commands and functions to call for them.
156// The cmd_name is referenced later, so it should not be in temp memory
157// if function is NULL, the command will be forwarded to the server
158// as a clc_stringcmd instead of executed locally
159
160qboolean Cmd_Exists (const char *cmd_name);
161char *Cmd_AliasExist(const char *name, int restrictionlevel);
162// used by the cvar code to check for cvar / command name overlap
163
164const char *Cmd_Describe (const char *cmd_name);
165
166typedef struct
167{
168 char *guessed; //this is the COMPLETED partial.
169 char *partial; //the requested string that we completed
171 size_t num, extra; //valid count, and ommitted count (if we were too lazy to find more)
175 const char *text;
176 const char *repl; //used for sole matches
177 const char *desc;
178 } completions[50];
180cmd_completion_t *Cmd_Complete(const char *partial, qboolean caseinsens); //calculates and caches info.
181
182//these should probably be removed some time
183char *Cmd_CompleteCommand (const char *partial, qboolean fullonly, qboolean caseinsens, int matchnum, const char **descptr);
184qboolean Cmd_IsCommand (const char *line);
185// attempts to match a partial command for automatic command line completion
186// returns NULL if nothing fits
187
188int VARGS Cmd_Argc (void);
189char *VARGS Cmd_Argv (int arg);
190char *VARGS Cmd_Args (void);
191extern int Cmd_ExecLevel;
192
193//if checkheader is false, an opening { is expected to already have been parsed.
194//otherwise returns the contents of the block much like c.
195//returns a zoned string.
196char *Cmd_ParseMultiline(qboolean checkheader);
197
199// The functions that execute commands get their parameters with these
200// functions. Cmd_Argv () will return an empty string, not a NULL
201// if arg > argc, so string operations are always safe.
202
203int Cmd_CheckParm (const char *parm);
204// Returns the position (1 to argc-1) in the command's argument list
205// where the given parameter apears, or 0 if not present
206
207char *Cmd_AliasExist(const char *name, int restrictionlevel);
208void Alias_WipeStuffedAliases(void);
209
210void Cmd_AddMacro(char *s, char *(*f)(void), int disputableintentions);
211#define Cmd_AddMacroD(s,f,unsafe,desc) Cmd_AddMacro(s,f,unsafe)
212
213void Cmd_TokenizePunctation (char *text, char *punctuation);
214const char *Cmd_TokenizeString (const char *text, qboolean expandmacros, qboolean qctokenize);
215// Takes a null terminated string. Does not need to be /n terminated.
216// breaks the string up into arg tokens.
217
218void Cmd_ExecuteString (const char *text, int restrictionlevel);
219
220void Cmd_Args_Set(const char *newargs, size_t len);
221
222//higher levels have greater access, BUT BE SURE TO CHECK Cmd_IsInsecure()
223#define RESTRICT_MAX_TOTAL 31
224#define RESTRICT_MAX_USER 29
225#define RESTRICT_DEFAULT 20
226#define RESTRICT_MIN 1
227#define RESTRICT_TEAMPLAY 0 //this is blocked from everything but aliases.
228
229#define RESTRICT_MAX RESTRICT_MAX_USER
230
231#define RESTRICT_LOCAL (RESTRICT_MAX) //commands typed at the console
232#define RESTRICT_INSECURE (RESTRICT_MAX+1) //commands from csqc or untrusted sources (really should be a separate flag, requires cbuf rewrite)
233#define RESTRICT_SERVER (RESTRICT_MAX+2) //commands from ssqc (untrusted, but allowed to lock cvars)
234#define RESTRICT_SERVERSEAT(x) (RESTRICT_SERVER+x)
235#define RESTRICT_RCON rcon_level.ival
236//#define RESTRICT_SSQC RESTRICT_MAX-2
237
238#define Cmd_FromGamecode() (Cmd_ExecLevel>=RESTRICT_SERVER) //cheat provention. block cheats if its not fromgamecode
239#define Cmd_IsInsecure() (Cmd_ExecLevel>=RESTRICT_INSECURE) //prevention from the server from breaking/crashing/wiping us. if this returns true, block file access etc.
240
241// Parses a single line of text into arguments and tries to execute it
242// as if it was typed at the console
243
244void Cmd_ForwardToServer (void);
245// adds the current command line as a clc_stringcmd to the client message.
246// things like godmode, noclip, etc, are commands directed to the server,
247// so when they are typed in at the console, they will need to be forwarded.
248
251
252void Cmd_ShiftArgs (int ammount, qboolean expandstring);
253
254char *Cmd_ExpandString (const char *data, char *dest, int destlen, int *accesslevel, qboolean expandargs, qboolean expandcvars, qboolean expandmacros);
255qboolean If_EvaluateBoolean(const char *text, int restriction);
256
257extern cvar_t rcon_level;
258
259void Cmd_AddTimer(float delay, void(*callback)(int iarg, void *data), int iarg, void *data, size_t datasize); //wrong place, gah
260
qboolean
Definition: api_menu.h:34
void(QDECL *vgui_frame)(void)
qboolean Cmd_Exists(const char *cmd_name)
Definition: cmd.c:2322
char *VARGS Cmd_Args(void)
Definition: cmd.c:1596
void Cmd_MessageTrigger(char *message, int type)
void Cmd_Args_Set(const char *newargs, size_t len)
Definition: cmd.c:1603
qboolean Cmd_AddCommandD(const char *cmd_name, xcommand_t function, const char *description)
Definition: cmd.c:2126
int Cmd_ExecLevel
Definition: cmd.c:36
char * Cmd_CompleteCommand(const char *partial, qboolean fullonly, qboolean caseinsens, int matchnum, const char **descptr)
Definition: cmd.c:2642
char * Cmd_ParseMultiline(qboolean checkheader)
Definition: cmd.c:1106
void Cmd_AddMacro(char *s, char *(*f)(void), int disputableintentions)
Definition: cmd.c:95
void Cmd_TokenizePunctation(char *text, char *punctuation)
Definition: cmd.c:2025
void Cmd_ExecuteString(const char *text, int restrictionlevel)
Definition: cmd.c:2959
char * Cbuf_GetNext(int level, qboolean ignoresemicolon)
Definition: cmd.c:392
void Cbuf_ExecuteLevel(int level)
Definition: cmd.c:458
void Cbuf_Execute(void)
Definition: cmd.c:554
cvar_t cmd_gamecodelevel
Definition: sv_user.c:84
void(* xcommand_t)(void)
Definition: cmd.h:133
int Cmd_CheckParm(const char *parm)
Definition: cmd.c:3129
qboolean Cmd_AddCommand(const char *cmd_name, xcommand_t function)
Definition: cmd.c:2130
int VARGS Cmd_Argc(void)
Definition: cmd.c:1571
void Alias_WipeStuffedAliases(void)
Definition: cmd.c:1513
void Cmd_Init(void)
Definition: cmd.c:4427
cmd_completion_t * Cmd_Complete(const char *partial, qboolean caseinsens)
Definition: cmd.c:2521
void Cmd_EnumerateLevel(int level, char *buf, size_t bufsize)
Definition: cmd.c:2266
void Cbuf_InsertText(const char *text, int level, qboolean addnl)
Definition: cmd.c:356
qboolean Cmd_FilterMessage(char *message, qboolean sameteam)
void Cbuf_Waited(void)
Definition: cmd.c:190
void Cmd_RemoveCommand(const char *cmd_name)
Definition: cmd.c:2135
cvar_t rcon_level
Definition: cmd.c:27
qboolean Cmd_IsCommand(const char *line)
Definition: keys.c:421
void Cbuf_AddText(const char *text, int level)
Definition: cmd.c:304
void Cmd_StuffCmds(void)
Definition: cmd.c:591
char * Cmd_AliasExist(const char *name, int restrictionlevel)
Definition: cmd.c:1380
void Cmd_ShiftArgs(int ammount, qboolean expandstring)
Definition: cmd.c:1629
const char * Cmd_TokenizeString(const char *text, qboolean expandmacros, qboolean qctokenize)
Definition: cmd.c:1968
void Cmd_AddTimer(float delay, void(*callback)(int iarg, void *data), int iarg, void *data, size_t datasize)
Definition: cmd.c:246
void Cbuf_Init(void)
Definition: cmd.c:285
void(* xcommandargcompletion_t)(int argn, const char *partial, struct xcommandargcompletioncb_s *ctx)
Definition: cmd.h:140
const char * Cmd_Describe(const char *cmd_name)
Definition: cmd.c:2340
void Cmd_ForwardToServer(void)
Definition: cmd.c:2777
void Cmd_RemoveCommands(xcommand_t function)
Definition: cmd.c:2157
int Cmd_Level(const char *name)
Definition: cmd.c:2296
char *VARGS Cmd_Argv(int arg)
Definition: cmd.c:1581
cvar_t cmd_allowaccess
Definition: cmd.h:198
qboolean cmd_blockwait
Definition: cmd.c:38
char * Cmd_ExpandString(const char *data, char *dest, int destlen, int *accesslevel, qboolean expandargs, qboolean expandcvars, qboolean expandmacros)
Definition: cmd.c:1787
qboolean Cmd_AddCommandAD(const char *cmd_name, xcommand_t function, xcommandargcompletion_t argcomplete, const char *description)
Definition: cmd.c:2085
void Cmd_Shutdown(void)
Definition: cmd.c:4305
qboolean If_EvaluateBoolean(const char *text, int restriction)
Definition: cmd.c:3544
void dNearCallback * callback
Definition: com_phys_ode.c:655
int num
Definition: com_phys_ode.c:314
char * text
Definition: decomp.c:375
s
Definition: execloop.h:53
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: gl_vidcommon.c:351
GLint level
Definition: gl_vidcommon.c:42
GLsizei bufsize
Definition: gl_vidcommon.c:312
static EGLSurface EGLSurface EGLContext ctx
Definition: gl_videgl.c:47
GLint GLenum type
Definition: glquake.h:157
GLuint GLcharARB * name
Definition: glquake.h:155
GLenum GLsizei len
Definition: glsupp.h:502
const char * desc
Definition: m_options.c:1101
char ** data
Definition: p_script.c:63
static LPCSTR LPCSTR LPVOID parm
Definition: snd_directx.c:1076
qboolean text_alloced
Definition: cmd.h:173
qboolean desc_alloced
Definition: cmd.h:174
const char * desc
Definition: cmd.h:177
const char * repl
Definition: cmd.h:176
const char * text
Definition: cmd.h:175
Definition: cmd.h:167
char * guessed
Definition: cmd.h:168
size_t extra
Definition: cmd.h:171
char * partial
Definition: cmd.h:169
qboolean caseinsens
Definition: cmd.h:170
Definition: cvar.h:59
Definition: cmd.h:135
void(* cb)(const char *arg, const char *desc, const char *repl, struct xcommandargcompletioncb_s *ctx)
Definition: cmd.h:137
static enum mysql_option option const char * arg
Definition: sv_sql.c:28
unsigned char buf[KBRINGSIZE]
Definition: sys_dos.c:27