3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is part of the SourceMod/SourcePawn SDK. This file may only be used
8 * or modified under the Terms and Conditions of its License Agreement, which is found
9 * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
10 * may change at any time. To view the latest information, see:
11 * http://www.sourcemod.net/license.php
16 #if defined _console_included
19 #define _console_included
22 * Console variable bound values used with Get/SetConVarBounds()
26 ConVarBound_Upper = 0,
31 * Console variable query helper values.
35 QUERYCOOKIE_FAILED = 0,
39 * Console variable query result values.
41 enum ConVarQueryResult
43 ConVarQuery_Okay = 0, /**< Retrieval of client convar value was successful. */
44 ConVarQuery_NotFound, /**< Client convar was not found. */
45 ConVarQuery_NotValid, /**< A console command with the same name was found, but there is no convar. */
46 ConVarQuery_Protected /**< Client convar was found, but it is protected. The server cannot retrieve its value. */
50 * @section Flags for console commands and console variables. The descriptions
51 * for each constant come directly from the Source SDK.
53 #define FCVAR_NONE 0 /**< The default, no flags at all */
54 #define FCVAR_UNREGISTERED (1<<0) /**< If this is set, don't add to linked list, etc. */
55 #define FCVAR_LAUNCHER (1<<1) /**< Defined by launcher. */
56 #define FCVAR_GAMEDLL (1<<2) /**< Defined by the game DLL. */
57 #define FCVAR_CLIENTDLL (1<<3) /**< Defined by the client DLL. */
58 #define FCVAR_MATERIAL_SYSTEM (1<<4) /**< Defined by the material system. */
59 #define FCVAR_PROTECTED (1<<5) /**< It's a server cvar, but we don't send the data since it's a password, etc. Sends 1 if it's not bland/zero, 0 otherwise as value. */
60 #define FCVAR_SPONLY (1<<6) /**< This cvar cannot be changed by clients connected to a multiplayer server. */
61 #define FCVAR_ARCHIVE (1<<7) /**< Set to cause it to be saved to vars.rc */
62 #define FCVAR_NOTIFY (1<<8) /**< Notifies players when changed. */
63 #define FCVAR_USERINFO (1<<9) /**< Changes the client's info string. */
64 #define FCVAR_PRINTABLEONLY (1<<10) /**< This cvar's string cannot contain unprintable characters (e.g., used for player name, etc.) */
65 #define FCVAR_UNLOGGED (1<<11) /**< If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a log */
66 #define FCVAR_NEVER_AS_STRING (1<<12) /**< Never try to print that cvar. */
67 #define FCVAR_REPLICATED (1<<13) /**< Server setting enforced on clients. */
68 #define FCVAR_CHEAT (1<<14) /**< Only useable in singleplayer / debug / multiplayer & sv_cheats */
69 #define FCVAR_STUDIORENDER (1<<15) /**< Defined by the studiorender system. */
70 #define FCVAR_DEMO (1<<16) /**< Record this cvar when starting a demo file. */
71 #define FCVAR_DONTRECORD (1<<17) /**< Don't record these command in demo files. */
72 #define FCVAR_PLUGIN (1<<18) /**< Defined by a 3rd party plugin. */
73 #define FCVAR_DATACACHE (1<<19) /**< Defined by the datacache system. */
74 #define FCVAR_TOOLSYSTEM (1<<20) /**< Defined by an IToolSystem library */
75 #define FCVAR_FILESYSTEM (1<<21) /**< Defined by the file system. */
76 #define FCVAR_NOT_CONNECTED (1<<22) /**< Cvar cannot be changed by a client that is connected to a server. */
77 #define FCVAR_SOUNDSYSTEM (1<<23) /**< Defined by the soundsystem library. */
78 #define FCVAR_ARCHIVE_XBOX (1<<24) /**< Cvar written to config.cfg on the Xbox. */
79 #define FCVAR_INPUTSYSTEM (1<<25) /**< Defined by the inputsystem DLL. */
80 #define FCVAR_NETWORKSYSTEM (1<<26) /**< Defined by the network system. */
81 #define FCVAR_VPHYSICS (1<<27) /**< Defined by vphysics. */
88 * Executes a server command as if it were on the server console (or RCON)
90 * @param format Formatting rules.
91 * @param ... Variable number of format parameters.
94 native ServerCommand(const String:format[], any:...);
97 * Inserts a server command at the beginning of the server command buffer.
99 * @param format Formatting rules.
100 * @param ... Variable number of format parameters.
103 native InsertServerCommand(const String:format[], any:...);
106 * Executes every command in the server's command buffer, rather than once per frame.
110 native ServerExecute();
113 * Executes a client command. Note that this will not work on clients unless
114 * they have cl_restrict_server_commands set to 0.
116 * @param client Index of the client.
117 * @param fmt Format of the client command.
118 * @param ... Format parameters/
120 * @error Invalid client index, or client not connected.
122 native ClientCommand(client, const String:fmt[], any:...);
125 * Sends a message to the server console.
127 * @param format Formatting rules.
128 * @param ... Variable number of format parameters.
131 native PrintToServer(const String:format[], any:...);
134 * Sends a message to a client's console.
136 * @param client Player index.
137 * @param format Formatting rules.
138 * @param ... Variable number of format parameters.
140 * @error If the client is not connected an error will be thrown.
142 native PrintToConsole(client, const String:format[], any:...);
145 * Called when a server-only command is invoked.
147 * @params args Number of arguments that were in the argument string.
148 * @return An Action value. Not handling the command
149 * means that Source will report it as "not found."
151 functag SrvCmd Action:public(args);
154 * Creates a server-only console command, or hooks an already existing one.
156 * @param cmd Name of the command to hook or create.
157 * @param callback A function to use as a callback for when the command is invoked.
158 * @param description Optional description to use for command creation.
159 * @param flags Optional flags to use for command creation.
161 * @error Command name is the same as an existing convar.
163 native RegServerCmd(const String:cmd[], SrvCmd:callback, const String:description[]="", flags=0);
166 * Called when a generic console command is invoked.
168 * @param client Index of the client, or 0 from the server.
169 * @param args Number of arguments that were in the argument string.
170 * @return An Action value. Not handling the command
171 * means that Source will report it as "not found."
173 functag ConCmd Action:public(client, args);
176 * Creates a console command, or hooks an already existing one.
178 * @param cmd Name of the command to hook or create.
179 * @param callback A function to use as a callback for when the command is invoked.
180 * @param description Optional description to use for command creation.
181 * @param flags Optional flags to use for command creation.
183 * @error Command name is the same as an existing convar.
185 native RegConsoleCmd(const String:cmd[], ConCmd:callback, const String:description[]="", flags=0);
188 * Creates a console command as an administrative command. If the command does not exist,
189 * it is created. When this command is invoked, the access rights of the player are
190 * automatically checked before allowing it to continue.
192 * @param cmd String containing command to register.
193 * @param callback A function to use as a callback for when the command is invoked.
194 * @param adminflags Administrative flags (bitstring) to use for permissions.
195 * @param group String containing the command group to use. If empty,
196 * the plugin's filename will be used instead.
197 * @param description Optional description to use for help.
198 * @param flags Optional console flags.
200 * @error Command name is the same as an existing convar.
202 native RegAdminCmd(const String:cmd[],
205 const String:description[]="",
206 const String:group[]="",
210 * Returns the number of arguments from the current console or server command.
211 * @note Unlike the HL2 engine call, this does not include the command itself.
213 * @return Number of arguments to the current command.
218 * Retrieves a command argument given its index, from the current console or
220 * @note Argument indexes start at 1; 0 retrieves the command name.
222 * @param argnum Argument number to retrieve.
223 * @param buffer Buffer to use for storing the string.
224 * @param maxlength Maximum length of the buffer.
227 native GetCmdArg(argnum, String:buffer[], maxlength);
230 * Retrieves the entire command argument string in one lump from the current
231 * console or server command.
233 * @param buffer Buffer to use for storing the string.
234 * @param maxlength Maximum length of the buffer.
237 native GetCmdArgString(String:buffer[], maxlength);
240 * Creates a new console variable.
242 * @param name Name of new convar.
243 * @param defaultValue String containing the default value of new convar.
244 * @param description Optional description of the convar.
245 * @param flags Optional bitstring of flags determining how the convar should be handled. See FCVAR_* constants for more details.
246 * @param hasMin Optional boolean that determines if the convar has a minimum value.
247 * @param min Minimum floating point value that the convar can have if hasMin is true.
248 * @param hasMax Optional boolean that determines if the convar has a maximum value.
249 * @param max Maximum floating point value that the convar can have if hasMax is true.
250 * @return A handle to the newly created convar. If the convar already exists, INVALID_HANDLE is returned.
251 * @error Convar name is blank or is the same as an existing console command.
253 native Handle:CreateConVar(const String:name[], const String:defaultValue[], const String:description[]="", flags=0, bool:hasMin=false, Float:min=0.0, bool:hasMax=false, Float:max=0.0);
256 * Searches for a console variable.
258 * @param name Name of convar to find.
259 * @return A handle to the convar if it is found. INVALID_HANDLE otherwise.
261 native Handle:FindConVar(const String:name[]);
264 * Called when a console variable's value is changed.
266 * @param convar Handle to the convar that was changed.
267 * @param oldValue String containing the value of the convar before it was changed.
268 * @param newValue String containing the new value of the convar.
271 functag ConVarChanged public(Handle:convar, const String:oldValue[], const String:newValue[]);
274 * Creates a hook for when a console variable's value is changed.
276 * @param convar Handle to the convar.
277 * @param callback An OnConVarChanged function pointer.
279 * @error Invalid or corrupt Handle or invalid callback function.
281 native HookConVarChange(Handle:convar, ConVarChanged:callback);
284 * Removes a hook for when a console variable's value is changed.
286 * @param convar Handle to the convar.
287 * @param callback An OnConVarChanged function pointer.
289 * @error Invalid or corrupt Handle, invalid callback function, or no active hook on convar.
291 native UnhookConVarChange(Handle:convar, ConVarChanged:callback);
294 * Returns the boolean value of a console variable.
296 * @param convar Handle to the convar.
297 * @return The boolean value of the convar.
298 * @error Invalid or corrupt Handle.
300 native bool:GetConVarBool(Handle:convar);
303 * Sets the boolean value of a console variable.
305 * @param convar Handle to the convar.
306 * @param value New boolean value.
308 * @error Invalid or corrupt Handle.
310 native SetConVarBool(Handle:convar, bool:value);
313 * Returns the integer value of a console variable.
315 * @param convar Handle to the convar.
316 * @return The integer value of the convar.
317 * @error Invalid or corrupt Handle.
319 native GetConVarInt(Handle:convar);
322 * Sets the integer value of a console variable.
324 * @param convar Handle to the convar.
325 * @param value New integer value.
327 * @error Invalid or corrupt Handle.
329 native SetConVarInt(Handle:convar, value);
332 * Returns the floating point value of a console variable.
334 * @param convar Handle to the convar.
335 * @return The floating point value of the convar.
336 * @error Invalid or corrupt Handle.
338 native Float:GetConVarFloat(Handle:convar);
341 * Sets the floating point value of a console variable.
343 * @param convar Handle to the convar.
344 * @param value New floating point value.
346 * @error Invalid or corrupt Handle.
348 native SetConVarFloat(Handle:convar, Float:value);
351 * Retrieves the string value of a console variable.
353 * @param convar Handle to the convar.
354 * @param value Buffer to store the value of the convar.
355 * @param maxlength Maximum length of string buffer.
357 * @error Invalid or corrupt Handle.
359 native GetConVarString(Handle:convar, String:value[], maxlength);
362 * Sets the string value of a console variable.
364 * @param convar Handle to the convar.
365 * @param value New string value.
367 * @error Invalid or corrupt Handle.
369 native SetConVarString(Handle:convar, const String:value[]);
372 * Returns the bitstring of flags on a console variable.
374 * @param convar Handle to the convar.
375 * @return A bitstring containing the FCVAR_* flags that are enabled.
376 * @error Invalid or corrupt Handle.
378 native GetConVarFlags(Handle:convar);
381 * Sets the bitstring of flags on a console variable.
383 * @param convar Handle to the convar.
384 * @param flags A bitstring containing the FCVAR_* flags to enable.
386 * @error Invalid or corrupt Handle.
388 native SetConVarFlags(Handle:convar, flags);
391 * Retrieves the specified bound of a console variable.
393 * @param convar Handle to the convar.
394 * @param type Type of bound to retrieve, ConVarBound_Lower or ConVarBound_Upper.
395 * @param value By-reference cell to store the specified floating point bound value.
396 * @return True if the convar has the specified bound set, false otherwise.
397 * @error Invalid or corrupt Handle.
399 native bool:GetConVarBounds(Handle:convar, ConVarBounds:type, &Float:value);
402 * Sets the specified bound of a console variable.
404 * @param convar Handle to the convar.
405 * @param type Type of bound to set, ConVarBound_Lower or ConVarBound_Upper
406 * @param set If set to true, convar will use specified bound. If false, bound will be removed.
407 * @param value Floating point value to use as the specified bound.
409 * @error Invalid or corrupt Handle.
411 native SetConVarBounds(Handle:convar, ConVarBounds:type, bool:set, Float:value=0.0);
414 * Retrieves the name of a console variable.
416 * @param convar Handle to the convar.
417 * @param value Buffer to store the name of the convar.
418 * @param maxlength Maximum length of string buffer.
420 * @error Invalid or corrupt Handle.
422 native GetConVarName(Handle:convar, const String:name[], maxlength);
425 * Resets the console variable to its default value.
427 * @param convar Handle to the convar.
429 * @error Invalid or corrupt Handle.
431 native ResetConVar(Handle:convar);
433 funcenum ConVarQueryFinished
436 * Called when a query to retrieve a client's console variable has finished.
438 * @param cookie Unique identifier of query.
439 * @param client Player index.
440 * @param result Result of query that tells one whether or not query was successful.
441 * See ConVarQueryResult enum for more details.
442 * @param convarName Name of client convar that was queried.
443 * @param convarValue Value of client convar that was queried if successful. This will be "" if it was not.
444 * @param value Value that was passed when query was started.
447 public(QueryCookie:cookie, client, ConVarQueryResult:result, const String:cvarName[], const String:cvarValue[], any:value),
450 * Called when a query to retrieve a client's console variable has finished.
452 * @param cookie Unique identifier of query.
453 * @param client Player index.
454 * @param result Result of query that tells one whether or not query was successful.
455 * See ConVarQueryResult enum for more details.
456 * @param convarName Name of client convar that was queried.
457 * @param convarValue Value of client convar that was queried if successful. This will be "" if it was not.
460 public(QueryCookie:cookie, client, ConVarQueryResult:result, const String:cvarName[], const String:cvarValue[])
464 * Starts a query to retrieve the value of a client's console variable.
466 * @param client Player index.
467 * @param name Name of client convar to query.
468 * @param callback A function to use as a callback when the query has finished.
469 * @param value Optional value to pass to the callback function.
470 * @return A cookie that uniquely identifies the query.
471 * Returns QUERYCOOKIE_FAILED on failure, such as when used on a bot.
473 native QueryCookie:QueryClientConVar(client, const String:cvarName[], ConVarQueryFinished:callback, any:value=0);