plugins/include/console.inc
author David Anderson <dvander@alliedmods.net>
Fri Jul 11 05:14:32 2008 +0000 (2008-07-11)
branchrefac-jit
changeset 2190 880e81f30b5e
parent 2168 c24a6fa957db
permissions -rw-r--r--
GetContext() now returns 'this' as a hack (shouldn't+can't be accessed anyway)
dvander@2168
     1
/**
dvander@2168
     2
 * vim: set ts=4 :
dvander@2168
     3
 * =============================================================================
dvander@2168
     4
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
dvander@2168
     5
 * =============================================================================
dvander@2168
     6
 *
dvander@2168
     7
 * This file is part of the SourceMod/SourcePawn SDK.
dvander@2168
     8
 *
dvander@2168
     9
 * This program is free software; you can redistribute it and/or modify it under
dvander@2168
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
dvander@2168
    11
 * Free Software Foundation.
dvander@2168
    12
 * 
dvander@2168
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
dvander@2168
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
dvander@2168
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
dvander@2168
    16
 * details.
dvander@2168
    17
 *
dvander@2168
    18
 * You should have received a copy of the GNU General Public License along with
dvander@2168
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@2168
    20
 *
dvander@2168
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
dvander@2168
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
dvander@2168
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
dvander@2168
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
dvander@2168
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
dvander@2168
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
dvander@2168
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
dvander@2168
    28
 * or <http://www.sourcemod.net/license.php>.
dvander@2168
    29
 *
dvander@2168
    30
 * Version: $Id$
dvander@2168
    31
 */
dvander@2168
    32
 
dvander@2168
    33
#if defined _console_included
dvander@2168
    34
 #endinput
dvander@2168
    35
#endif
dvander@2168
    36
#define _console_included
dvander@2168
    37
dvander@2168
    38
#define INVALID_FCVAR_FLAGS		(-1)
dvander@2168
    39
dvander@2168
    40
/**
dvander@2168
    41
 * Console variable bound values used with Get/SetConVarBounds()
dvander@2168
    42
 */
dvander@2168
    43
enum ConVarBounds
dvander@2168
    44
{
dvander@2168
    45
	ConVarBound_Upper = 0,
dvander@2168
    46
	ConVarBound_Lower
dvander@2168
    47
};
dvander@2168
    48
dvander@2168
    49
/**
dvander@2168
    50
 * Console variable query helper values.
dvander@2168
    51
 */
dvander@2168
    52
enum QueryCookie
dvander@2168
    53
{
dvander@2168
    54
	QUERYCOOKIE_FAILED = 0,
dvander@2168
    55
};
dvander@2168
    56
dvander@2168
    57
/**
dvander@2168
    58
 * Reply sources for commands.
dvander@2168
    59
 */
dvander@2168
    60
enum ReplySource
dvander@2168
    61
{
dvander@2168
    62
	SM_REPLY_TO_CONSOLE = 0,
dvander@2168
    63
	SM_REPLY_TO_CHAT = 1,
dvander@2168
    64
};
dvander@2168
    65
dvander@2168
    66
/**
dvander@2168
    67
 * Console variable query result values.
dvander@2168
    68
 */
dvander@2168
    69
enum ConVarQueryResult
dvander@2168
    70
{
dvander@2168
    71
	ConVarQuery_Okay = 0,				/**< Retrieval of client convar value was successful. */
dvander@2168
    72
	ConVarQuery_NotFound,				/**< Client convar was not found. */
dvander@2168
    73
	ConVarQuery_NotValid,				/**< A console command with the same name was found, but there is no convar. */
dvander@2168
    74
	ConVarQuery_Protected				/**< Client convar was found, but it is protected. The server cannot retrieve its value. */
dvander@2168
    75
};
dvander@2168
    76
dvander@2168
    77
/**
dvander@2168
    78
 * @section Flags for console commands and console variables.  The descriptions 
dvander@2168
    79
 * for each constant come directly from the Source SDK.
dvander@2168
    80
 */
dvander@2168
    81
#define FCVAR_NONE				0		/**< The default, no flags at all */
dvander@2168
    82
#define FCVAR_UNREGISTERED		(1<<0)	/**< If this is set, don't add to linked list, etc. */
dvander@2168
    83
#define FCVAR_LAUNCHER			(1<<1)	/**< Defined by launcher. */
dvander@2168
    84
#define FCVAR_GAMEDLL			(1<<2)	/**< Defined by the game DLL. */
dvander@2168
    85
#define FCVAR_CLIENTDLL			(1<<3)	/**< Defined by the client DLL. */
dvander@2168
    86
#define FCVAR_MATERIAL_SYSTEM	(1<<4)	/**< Defined by the material system. */
dvander@2168
    87
#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. */
dvander@2168
    88
#define FCVAR_SPONLY			(1<<6)	/**< This cvar cannot be changed by clients connected to a multiplayer server. */
dvander@2168
    89
#define	FCVAR_ARCHIVE			(1<<7)	/**< Set to cause it to be saved to vars.rc */
dvander@2168
    90
#define	FCVAR_NOTIFY			(1<<8)	/**< Notifies players when changed. */
dvander@2168
    91
#define	FCVAR_USERINFO			(1<<9)	/**< Changes the client's info string. */
dvander@2168
    92
#define FCVAR_PRINTABLEONLY		(1<<10)	/**< This cvar's string cannot contain unprintable characters (e.g., used for player name, etc.) */
dvander@2168
    93
#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 */
dvander@2168
    94
#define FCVAR_NEVER_AS_STRING	(1<<12)	/**< Never try to print that cvar. */
dvander@2168
    95
#define FCVAR_REPLICATED		(1<<13)	/**< Server setting enforced on clients. */
dvander@2168
    96
#define FCVAR_CHEAT				(1<<14)	/**< Only useable in singleplayer / debug / multiplayer & sv_cheats */
dvander@2168
    97
#define FCVAR_STUDIORENDER		(1<<15)	/**< Defined by the studiorender system. */
dvander@2168
    98
#define FCVAR_DEMO				(1<<16)	/**< Record this cvar when starting a demo file. */
dvander@2168
    99
#define FCVAR_DONTRECORD		(1<<17)	/**< Don't record these command in demo files. */
dvander@2168
   100
#define FCVAR_PLUGIN			(1<<18)	/**< Defined by a 3rd party plugin. */
dvander@2168
   101
#define FCVAR_DATACACHE			(1<<19)	/**< Defined by the datacache system. */
dvander@2168
   102
#define FCVAR_TOOLSYSTEM		(1<<20)	/**< Defined by an IToolSystem library */
dvander@2168
   103
#define FCVAR_FILESYSTEM		(1<<21)	/**< Defined by the file system. */
dvander@2168
   104
#define FCVAR_NOT_CONNECTED		(1<<22)	/**< Cvar cannot be changed by a client that is connected to a server. */
dvander@2168
   105
#define FCVAR_SOUNDSYSTEM		(1<<23)	/**< Defined by the soundsystem library. */
dvander@2168
   106
#define FCVAR_ARCHIVE_XBOX		(1<<24)	/**< Cvar written to config.cfg on the Xbox. */
dvander@2168
   107
#define FCVAR_INPUTSYSTEM		(1<<25)	/**< Defined by the inputsystem DLL. */
dvander@2168
   108
#define FCVAR_NETWORKSYSTEM		(1<<26)	/**< Defined by the network system. */
dvander@2168
   109
#define FCVAR_VPHYSICS			(1<<27)	/**< Defined by vphysics. */
dvander@2168
   110
dvander@2168
   111
/**
dvander@2168
   112
 * @endsection
dvander@2168
   113
 */
dvander@2168
   114
dvander@2168
   115
/**
dvander@2168
   116
 * Executes a server command as if it were on the server console (or RCON)
dvander@2168
   117
 *
dvander@2168
   118
 * @param format		Formatting rules.
dvander@2168
   119
 * @param ...			Variable number of format parameters.
dvander@2168
   120
 * @noreturn
dvander@2168
   121
 */
dvander@2168
   122
native ServerCommand(const String:format[], any:...);
dvander@2168
   123
dvander@2168
   124
/**
dvander@2168
   125
 * Inserts a server command at the beginning of the server command buffer.
dvander@2168
   126
 *
dvander@2168
   127
 * @param format		Formatting rules.
dvander@2168
   128
 * @param ...			Variable number of format parameters.
dvander@2168
   129
 * @noreturn
dvander@2168
   130
 */
dvander@2168
   131
native InsertServerCommand(const String:format[], any:...);
dvander@2168
   132
dvander@2168
   133
/**
dvander@2168
   134
 * Executes every command in the server's command buffer, rather than once per frame.
dvander@2168
   135
 *
dvander@2168
   136
 * @noreturn
dvander@2168
   137
 */
dvander@2168
   138
native ServerExecute();
dvander@2168
   139
dvander@2168
   140
/**
dvander@2168
   141
 * Executes a client command.  Note that this will not work on clients unless
dvander@2168
   142
 * they have cl_restrict_server_commands set to 0.
dvander@2168
   143
 *
dvander@2168
   144
 * @param client		Index of the client.
dvander@2168
   145
 * @param fmt			Format of the client command.
dvander@2168
   146
 * @param ...			Format parameters/
dvander@2168
   147
 * @noreturn
dvander@2168
   148
 * @error				Invalid client index, or client not connected.
dvander@2168
   149
 */
dvander@2168
   150
native ClientCommand(client, const String:fmt[], any:...);
dvander@2168
   151
dvander@2168
   152
/**
dvander@2168
   153
 * Executes a client command on the server without being networked.
dvander@2168
   154
 *
dvander@2168
   155
 * FakeClientCommand() overwrites the command tokenization buffer.  This can 
dvander@2168
   156
 * cause undesired effects because future calls to GetCmdArg* will return 
dvander@2168
   157
 * data from the FakeClientCommand(), not the parent command.  If you are in 
dvander@2168
   158
 * a hook where this matters (for example, a "say" hook), you should use 
dvander@2168
   159
 * FakeClientCommandEx() instead.
dvander@2168
   160
 *
dvander@2168
   161
 * @param client		Index of the client.
dvander@2168
   162
 * @param fmt			Format of the client command.
dvander@2168
   163
 * @param ...			Format parameters
dvander@2168
   164
 * @noreturn
dvander@2168
   165
 * @error				Invalid client index, or client not connected.
dvander@2168
   166
 */
dvander@2168
   167
native FakeClientCommand(client, const String:fmt[], any:...);
dvander@2168
   168
dvander@2168
   169
/**
dvander@2168
   170
 * Executes a client command on the server without being networked.  The 
dvander@2168
   171
 * execution of the client command is delayed by one frame to prevent any 
dvander@2168
   172
 * re-entrancy issues that might surface with FakeClientCommand().
dvander@2168
   173
 *
dvander@2168
   174
 * @param client		Index of the client.
dvander@2168
   175
 * @param fmt			Format of the client command.
dvander@2168
   176
 * @param ...			Format parameters
dvander@2168
   177
 * @noreturn
dvander@2168
   178
 * @error				Invalid client index, or client not connected.
dvander@2168
   179
 */
dvander@2168
   180
native FakeClientCommandEx(client, const String:fmt[], any:...);
dvander@2168
   181
dvander@2168
   182
/**
dvander@2168
   183
 * Sends a message to the server console.
dvander@2168
   184
 *
dvander@2168
   185
 * @param format		Formatting rules.
dvander@2168
   186
 * @param ...			Variable number of format parameters.
dvander@2168
   187
 * @noreturn
dvander@2168
   188
 */
dvander@2168
   189
native PrintToServer(const String:format[], any:...);
dvander@2168
   190
dvander@2168
   191
/**
dvander@2168
   192
 * Sends a message to a client's console.
dvander@2168
   193
 *
dvander@2168
   194
 * @param client		Client index.
dvander@2168
   195
 * @param format		Formatting rules.
dvander@2168
   196
 * @param ...			Variable number of format parameters.
dvander@2168
   197
 * @noreturn
dvander@2168
   198
 * @error				If the client is not connected an error will be thrown.
dvander@2168
   199
 */
dvander@2168
   200
native PrintToConsole(client, const String:format[], any:...);
dvander@2168
   201
dvander@2168
   202
/**
dvander@2168
   203
 * Reples to a message in a command.
dvander@2168
   204
 *
dvander@2168
   205
 * A client index of 0 will use PrintToServer().
dvander@2168
   206
 * If the command was from the console, PrintToConsole() is used.
dvander@2168
   207
 * If the command was from chat, PrintToChat() is used.
dvander@2168
   208
 *
dvander@2168
   209
 * @param client		Client index, or 0 for server.
dvander@2168
   210
 * @param format		Formatting rules.
dvander@2168
   211
 * @param ...			Variable number of format parameters.
dvander@2168
   212
 * @noreturn
dvander@2168
   213
 * @error				If the client is not connected or invalid.
dvander@2168
   214
 */
dvander@2168
   215
native ReplyToCommand(client, const String:format[], any:...);
dvander@2168
   216
dvander@2168
   217
/**
dvander@2168
   218
 * Returns the current reply source of a command.
dvander@2168
   219
 *
dvander@2168
   220
 * @return				ReplySource value.
dvander@2168
   221
 */
dvander@2168
   222
native ReplySource:GetCmdReplySource();
dvander@2168
   223
dvander@2168
   224
/**
dvander@2168
   225
 * Sets the current reply source of a command.
dvander@2168
   226
 *
dvander@2168
   227
 * Only use this if you know what you are doing.  You should save the old value
dvander@2168
   228
 * and restore it once you are done.
dvander@2168
   229
 *
dvander@2168
   230
 * @param source		New ReplySource value.
dvander@2168
   231
 * @return				Old ReplySource value.
dvander@2168
   232
 */
dvander@2168
   233
native ReplySource:SetCmdReplySource(ReplySource:source);
dvander@2168
   234
dvander@2168
   235
/**
dvander@2168
   236
 * Returns whether the current say hook is a chat trigger.
dvander@2168
   237
 *
dvander@2168
   238
 * This function is only meaningful inside say or say_team hooks.
dvander@2168
   239
 *
dvander@2168
   240
 * @return				True if a chat trigger, false otherwise.
dvander@2168
   241
 */
dvander@2168
   242
native bool:IsChatTrigger();
dvander@2168
   243
dvander@2168
   244
/**
dvander@2168
   245
 * Displays usage of an admin command to users depending on the 
dvander@2168
   246
 * setting of the sm_show_activity cvar.  All users receive a message 
dvander@2168
   247
 * in their chat text, except for the originating client, who receives 
dvander@2168
   248
 * the message based on the current ReplySource.
dvander@2168
   249
 *
dvander@2168
   250
 * @param client		Client index doing the action, or 0 for server.
dvander@2168
   251
 * @param tag			Tag to prepend to the message.
dvander@2168
   252
 * @param format		Formatting rules.
dvander@2168
   253
 * @param ...			Variable number of format parameters.
dvander@2168
   254
 * @noreturn
dvander@2168
   255
 * @error
dvander@2168
   256
 */
dvander@2168
   257
native ShowActivity2(client, const String:tag[], const String:format[], any:...);
dvander@2168
   258
dvander@2168
   259
/**
dvander@2168
   260
 * Displays usage of an admin command to users depending on the 
dvander@2168
   261
 * setting of the sm_show_activity cvar.  
dvander@2168
   262
 *
dvander@2168
   263
 * This version does not display a message to the originating client 
dvander@2168
   264
 * if used from chat triggers or menus.  If manual replies are used 
dvander@2168
   265
 * for these cases, then this function will suffice.  Otherwise, 
dvander@2168
   266
 * ShowActivity2() is slightly more useful.
dvander@2168
   267
 *
dvander@2168
   268
 * @param client		Client index doing the action, or 0 for server.
dvander@2168
   269
 * @param format		Formatting rules.
dvander@2168
   270
 * @param ...			Variable number of format parameters.
dvander@2168
   271
 * @noreturn
dvander@2168
   272
 * @error
dvander@2168
   273
 */
dvander@2168
   274
native ShowActivity(client, const String:format[], any:...);
dvander@2168
   275
dvander@2168
   276
/**
dvander@2168
   277
 * Same as ShowActivity(), except the tag parameter is used instead of
dvander@2168
   278
 * "[SM] " (note that you must supply any spacing).
dvander@2168
   279
 *
dvander@2168
   280
 * @param client		Client index doing the action, or 0 for server.
dvander@2168
   281
 * @param tag			Tag to display with.
dvander@2168
   282
 * @param format		Formatting rules.
dvander@2168
   283
 * @param ...			Variable number of format parameters.
dvander@2168
   284
 * @noreturn
dvander@2168
   285
 * @error
dvander@2168
   286
 */
dvander@2168
   287
native ShowActivityEx(client, const String:tag[], const String:format[], any:...);
dvander@2168
   288
dvander@2168
   289
/**
dvander@2168
   290
 * Called when a server-only command is invoked.  
dvander@2168
   291
 *
dvander@2168
   292
 * @params args			Number of arguments that were in the argument string.
dvander@2168
   293
 * @return				An Action value.  Not handling the command
dvander@2168
   294
 *						means that Source will report it as "not found."
dvander@2168
   295
 */
dvander@2168
   296
functag SrvCmd Action:public(args);
dvander@2168
   297
dvander@2168
   298
/**
dvander@2168
   299
 * Creates a server-only console command, or hooks an already existing one.  
dvander@2168
   300
 *
dvander@2168
   301
 * @param cmd			Name of the command to hook or create.
dvander@2168
   302
 * @param callback		A function to use as a callback for when the command is invoked.
dvander@2168
   303
 * @param description	Optional description to use for command creation.
dvander@2168
   304
 * @param flags			Optional flags to use for command creation.
dvander@2168
   305
 * @noreturn
dvander@2168
   306
 * @error				Command name is the same as an existing convar.
dvander@2168
   307
 */
dvander@2168
   308
native RegServerCmd(const String:cmd[], SrvCmd:callback, const String:description[]="", flags=0);
dvander@2168
   309
dvander@2168
   310
/**
dvander@2168
   311
 * Called when a generic console command is invoked.
dvander@2168
   312
 *
dvander@2168
   313
 * @param client		Index of the client, or 0 from the server.
dvander@2168
   314
 * @param args			Number of arguments that were in the argument string.
dvander@2168
   315
 * @return				An Action value.  Not handling the command
dvander@2168
   316
 *						means that Source will report it as "not found."
dvander@2168
   317
 */
dvander@2168
   318
functag ConCmd Action:public(client, args);
dvander@2168
   319
dvander@2168
   320
/**
dvander@2168
   321
 * Creates a console command, or hooks an already existing one.
dvander@2168
   322
 *
dvander@2168
   323
 * @param cmd			Name of the command to hook or create.
dvander@2168
   324
 * @param callback		A function to use as a callback for when the command is invoked.
dvander@2168
   325
 * @param description	Optional description to use for command creation.
dvander@2168
   326
 * @param flags			Optional flags to use for command creation.
dvander@2168
   327
 * @noreturn
dvander@2168
   328
 * @error				Command name is the same as an existing convar.
dvander@2168
   329
 */
dvander@2168
   330
native RegConsoleCmd(const String:cmd[], ConCmd:callback, const String:description[]="", flags=0);
dvander@2168
   331
dvander@2168
   332
/**
dvander@2168
   333
 * Creates a console command as an administrative command.  If the command does not exist,
dvander@2168
   334
 * it is created.  When this command is invoked, the access rights of the player are 
dvander@2168
   335
 * automatically checked before allowing it to continue.
dvander@2168
   336
 *
dvander@2168
   337
 * @param cmd			String containing command to register.
dvander@2168
   338
 * @param callback		A function to use as a callback for when the command is invoked.
dvander@2168
   339
 * @param adminflags	Administrative flags (bitstring) to use for permissions.
dvander@2168
   340
 * @param description	Optional description to use for help.
dvander@2168
   341
 * @param group			String containing the command group to use.  If empty,
dvander@2168
   342
 * 						the plugin's filename will be used instead.
dvander@2168
   343
 * @param flags			Optional console flags.
dvander@2168
   344
 * @noreturn
dvander@2168
   345
 * @error				Command name is the same as an existing convar.
dvander@2168
   346
 */
dvander@2168
   347
native RegAdminCmd(const String:cmd[],
dvander@2168
   348
					ConCmd:callback,
dvander@2168
   349
					adminflags,
dvander@2168
   350
					const String:description[]="",
dvander@2168
   351
					const String:group[]="",
dvander@2168
   352
					flags=0);
dvander@2168
   353
					
dvander@2168
   354
/**
dvander@2168
   355
 * Returns the number of arguments from the current console or server command.
dvander@2168
   356
 * @note Unlike the HL2 engine call, this does not include the command itself.
dvander@2168
   357
 *
dvander@2168
   358
 * @return				Number of arguments to the current command.
dvander@2168
   359
 */
dvander@2168
   360
native GetCmdArgs();
dvander@2168
   361
dvander@2168
   362
/**
dvander@2168
   363
 * Retrieves a command argument given its index, from the current console or 
dvander@2168
   364
 * server command.
dvander@2168
   365
 * @note Argument indexes start at 1; 0 retrieves the command name.
dvander@2168
   366
 *
dvander@2168
   367
 * @param argnum		Argument number to retrieve.
dvander@2168
   368
 * @param buffer		Buffer to use for storing the string.
dvander@2168
   369
 * @param maxlength		Maximum length of the buffer.
dvander@2168
   370
 * @return				Length of string written to buffer.
dvander@2168
   371
 */
dvander@2168
   372
native GetCmdArg(argnum, String:buffer[], maxlength);
dvander@2168
   373
dvander@2168
   374
/**
dvander@2168
   375
 * Retrieves the entire command argument string in one lump from the current 
dvander@2168
   376
 * console or server command.
dvander@2168
   377
 *
dvander@2168
   378
 * @param buffer		Buffer to use for storing the string.
dvander@2168
   379
 * @param maxlength		Maximum length of the buffer.
dvander@2168
   380
 * @return				Length of string written to buffer.
dvander@2168
   381
 */
dvander@2168
   382
native GetCmdArgString(String:buffer[], maxlength);
dvander@2168
   383
dvander@2168
   384
/**
dvander@2168
   385
 * Creates a new console variable.
dvander@2168
   386
 *
dvander@2168
   387
 * @param name			Name of new convar.
dvander@2168
   388
 * @param defaultValue	String containing the default value of new convar.
dvander@2168
   389
 * @param description	Optional description of the convar.
dvander@2168
   390
 * @param flags			Optional bitstring of flags determining how the convar should be handled. See FCVAR_* constants for more details.
dvander@2168
   391
 * @param hasMin		Optional boolean that determines if the convar has a minimum value.
dvander@2168
   392
 * @param min			Minimum floating point value that the convar can have if hasMin is true.
dvander@2168
   393
 * @param hasMax		Optional boolean that determines if the convar has a maximum value.
dvander@2168
   394
 * @param max			Maximum floating point value that the convar can have if hasMax is true.
dvander@2168
   395
 * @return				A handle to the newly created convar. If the convar already exists, a handle to it will still be returned.
dvander@2168
   396
 * @error				Convar name is blank or is the same as an existing console command.
dvander@2168
   397
 */
dvander@2168
   398
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);
dvander@2168
   399
dvander@2168
   400
/**
dvander@2168
   401
 * Searches for a console variable.
dvander@2168
   402
 *
dvander@2168
   403
 * @param name			Name of convar to find.
dvander@2168
   404
 * @return				A handle to the convar if it is found. INVALID_HANDLE otherwise.
dvander@2168
   405
 */
dvander@2168
   406
native Handle:FindConVar(const String:name[]);
dvander@2168
   407
dvander@2168
   408
/**
dvander@2168
   409
 * Called when a console variable's value is changed.
dvander@2168
   410
 *
dvander@2168
   411
 * @param convar		Handle to the convar that was changed.
dvander@2168
   412
 * @param oldValue		String containing the value of the convar before it was changed.
dvander@2168
   413
 * @param newValue		String containing the new value of the convar.
dvander@2168
   414
 * @noreturn
dvander@2168
   415
 */
dvander@2168
   416
functag ConVarChanged public(Handle:convar, const String:oldValue[], const String:newValue[]);
dvander@2168
   417
dvander@2168
   418
/**
dvander@2168
   419
 * Creates a hook for when a console variable's value is changed.
dvander@2168
   420
 *
dvander@2168
   421
 * @param convar		Handle to the convar.
dvander@2168
   422
 * @param callback		An OnConVarChanged function pointer.
dvander@2168
   423
 * @noreturn
dvander@2168
   424
 * @error				Invalid or corrupt Handle or invalid callback function.
dvander@2168
   425
 */
dvander@2168
   426
native HookConVarChange(Handle:convar, ConVarChanged:callback);
dvander@2168
   427
dvander@2168
   428
/**
dvander@2168
   429
 * Removes a hook for when a console variable's value is changed.
dvander@2168
   430
 *
dvander@2168
   431
 * @param convar		Handle to the convar.
dvander@2168
   432
 * @param callback		An OnConVarChanged function pointer.
dvander@2168
   433
 * @noreturn
dvander@2168
   434
 * @error				Invalid or corrupt Handle, invalid callback function, or no active hook on convar.
dvander@2168
   435
 */
dvander@2168
   436
native UnhookConVarChange(Handle:convar, ConVarChanged:callback);
dvander@2168
   437
dvander@2168
   438
/**
dvander@2168
   439
 * Returns the boolean value of a console variable.
dvander@2168
   440
 *
dvander@2168
   441
 * @param convar		Handle to the convar.
dvander@2168
   442
 * @return				The boolean value of the convar.
dvander@2168
   443
 * @error				Invalid or corrupt Handle.
dvander@2168
   444
 */
dvander@2168
   445
native bool:GetConVarBool(Handle:convar);
dvander@2168
   446
dvander@2168
   447
/**
dvander@2168
   448
 * Sets the boolean value of a console variable.
dvander@2168
   449
 *
dvander@2168
   450
 * @param convar		Handle to the convar.
dvander@2168
   451
 * @param value			New boolean value.
dvander@2168
   452
 * @param replicate		If set to true, the new convar value will be set on all clients.
dvander@2168
   453
 *						This will only work if the convar has the FCVAR_REPLICATED flag
dvander@2168
   454
 *						and actually exists on clients.
dvander@2168
   455
 * @param notify		If set to true, clients will be notified that the convar has changed.
dvander@2168
   456
 *						This will only work if the convar has the FCVAR_NOTIFY flag.
dvander@2168
   457
 * @noreturn
dvander@2168
   458
 * @error				Invalid or corrupt Handle.
dvander@2168
   459
 */
dvander@2168
   460
native SetConVarBool(Handle:convar, bool:value, bool:replicate=false, bool:notify=false);
dvander@2168
   461
dvander@2168
   462
/**
dvander@2168
   463
 * Returns the integer value of a console variable.
dvander@2168
   464
 *
dvander@2168
   465
 * @param convar		Handle to the convar.
dvander@2168
   466
 * @return				The integer value of the convar.
dvander@2168
   467
 * @error				Invalid or corrupt Handle.
dvander@2168
   468
 */
dvander@2168
   469
native GetConVarInt(Handle:convar);
dvander@2168
   470
dvander@2168
   471
/**
dvander@2168
   472
 * Sets the integer value of a console variable.
dvander@2168
   473
 *
dvander@2168
   474
 * @param convar		Handle to the convar.
dvander@2168
   475
 * @param value			New integer value.
dvander@2168
   476
 * @param replicate		If set to true, the new convar value will be set on all clients.
dvander@2168
   477
 *						This will only work if the convar has the FCVAR_REPLICATED flag
dvander@2168
   478
 *						and actually exists on clients.
dvander@2168
   479
 * @param notify		If set to true, clients will be notified that the convar has changed.
dvander@2168
   480
 *						This will only work if the convar has the FCVAR_NOTIFY flag.
dvander@2168
   481
 * @noreturn
dvander@2168
   482
 * @error				Invalid or corrupt Handle.
dvander@2168
   483
 */
dvander@2168
   484
native SetConVarInt(Handle:convar, value, bool:replicate=false, bool:notify=false);
dvander@2168
   485
dvander@2168
   486
/**
dvander@2168
   487
 * Returns the floating point value of a console variable.
dvander@2168
   488
 *
dvander@2168
   489
 * @param convar		Handle to the convar.
dvander@2168
   490
 * @return				The floating point value of the convar.
dvander@2168
   491
 * @error				Invalid or corrupt Handle.
dvander@2168
   492
 */
dvander@2168
   493
native Float:GetConVarFloat(Handle:convar);
dvander@2168
   494
dvander@2168
   495
/**
dvander@2168
   496
 * Sets the floating point value of a console variable.
dvander@2168
   497
 *
dvander@2168
   498
 * @param convar		Handle to the convar.
dvander@2168
   499
 * @param value			New floating point value.
dvander@2168
   500
 * @param replicate		If set to true, the new convar value will be set on all clients.
dvander@2168
   501
 *						This will only work if the convar has the FCVAR_REPLICATED flag
dvander@2168
   502
 *						and actually exists on clients.
dvander@2168
   503
 * @param notify		If set to true, clients will be notified that the convar has changed.
dvander@2168
   504
 *						This will only work if the convar has the FCVAR_NOTIFY flag.
dvander@2168
   505
 * @noreturn
dvander@2168
   506
 * @error				Invalid or corrupt Handle.
dvander@2168
   507
 */
dvander@2168
   508
native SetConVarFloat(Handle:convar, Float:value, bool:replicate=false, bool:notify=false);
dvander@2168
   509
dvander@2168
   510
/**
dvander@2168
   511
 * Retrieves the string value of a console variable.
dvander@2168
   512
 *
dvander@2168
   513
 * @param convar		Handle to the convar.
dvander@2168
   514
 * @param value			Buffer to store the value of the convar.
dvander@2168
   515
 * @param maxlength		Maximum length of string buffer.
dvander@2168
   516
 * @noreturn
dvander@2168
   517
 * @error				Invalid or corrupt Handle.     
dvander@2168
   518
 */
dvander@2168
   519
native GetConVarString(Handle:convar, String:value[], maxlength);
dvander@2168
   520
dvander@2168
   521
/**
dvander@2168
   522
 * Sets the string value of a console variable.
dvander@2168
   523
 *
dvander@2168
   524
 * @param convar		Handle to the convar.
dvander@2168
   525
 * @param value			New string value.
dvander@2168
   526
 * @param replicate		If set to true, the new convar value will be set on all clients.
dvander@2168
   527
 *						This will only work if the convar has the FCVAR_REPLICATED flag
dvander@2168
   528
 *						and actually exists on clients.
dvander@2168
   529
 * @param notify		If set to true, clients will be notified that the convar has changed.
dvander@2168
   530
 *						This will only work if the convar has the FCVAR_NOTIFY flag.
dvander@2168
   531
 * @noreturn
dvander@2168
   532
 * @error				Invalid or corrupt Handle.
dvander@2168
   533
 */
dvander@2168
   534
native SetConVarString(Handle:convar, const String:value[], bool:replicate=false, bool:notify=false);
dvander@2168
   535
dvander@2168
   536
/**
dvander@2168
   537
 * Resets the console variable to its default value.
dvander@2168
   538
 *
dvander@2168
   539
 * @param convar		Handle to the convar.
dvander@2168
   540
 * @param replicate		If set to true, the new convar value will be set on all clients.
dvander@2168
   541
 *						This will only work if the convar has the FCVAR_REPLICATED flag
dvander@2168
   542
 *						and actually exists on clients.
dvander@2168
   543
 * @param notify		If set to true, clients will be notified that the convar has changed.
dvander@2168
   544
 *						This will only work if the convar has the FCVAR_NOTIFY flag.
dvander@2168
   545
 * @noreturn
dvander@2168
   546
 * @error				Invalid or corrupt Handle.
dvander@2168
   547
 */
dvander@2168
   548
native ResetConVar(Handle:convar, bool:replicate=false, bool:notify=false);
dvander@2168
   549
dvander@2168
   550
/**
dvander@2168
   551
 * Returns the bitstring of flags on a console variable.
dvander@2168
   552
 *
dvander@2168
   553
 * @param convar		Handle to the convar.
dvander@2168
   554
 * @return				A bitstring containing the FCVAR_* flags that are enabled.
dvander@2168
   555
 * @error				Invalid or corrupt Handle.
dvander@2168
   556
 */
dvander@2168
   557
native GetConVarFlags(Handle:convar);
dvander@2168
   558
dvander@2168
   559
/**
dvander@2168
   560
 * Sets the bitstring of flags on a console variable.
dvander@2168
   561
 *
dvander@2168
   562
 * @param convar		Handle to the convar.
dvander@2168
   563
 * @param flags			A bitstring containing the FCVAR_* flags to enable.
dvander@2168
   564
 * @noreturn
dvander@2168
   565
 * @error				Invalid or corrupt Handle.
dvander@2168
   566
 */
dvander@2168
   567
native SetConVarFlags(Handle:convar, flags);
dvander@2168
   568
dvander@2168
   569
/**
dvander@2168
   570
 * Retrieves the specified bound of a console variable.
dvander@2168
   571
 *
dvander@2168
   572
 * @param convar		Handle to the convar.
dvander@2168
   573
 * @param type			Type of bound to retrieve, ConVarBound_Lower or ConVarBound_Upper.
dvander@2168
   574
 * @param value			By-reference cell to store the specified floating point bound value.
dvander@2168
   575
 * @return				True if the convar has the specified bound set, false otherwise.
dvander@2168
   576
 * @error				Invalid or corrupt Handle.
dvander@2168
   577
 */
dvander@2168
   578
native bool:GetConVarBounds(Handle:convar, ConVarBounds:type, &Float:value);
dvander@2168
   579
dvander@2168
   580
/**
dvander@2168
   581
 * Sets the specified bound of a console variable.
dvander@2168
   582
 *
dvander@2168
   583
 * @param convar		Handle to the convar.
dvander@2168
   584
 * @param type			Type of bound to set, ConVarBound_Lower or ConVarBound_Upper
dvander@2168
   585
 * @param set			If set to true, convar will use specified bound. If false, bound will be removed.
dvander@2168
   586
 * @param value			Floating point value to use as the specified bound.
dvander@2168
   587
 * @noreturn
dvander@2168
   588
 * @error				Invalid or corrupt Handle.
dvander@2168
   589
 */
dvander@2168
   590
native SetConVarBounds(Handle:convar, ConVarBounds:type, bool:set, Float:value=0.0);
dvander@2168
   591
dvander@2168
   592
/**
dvander@2168
   593
 * Retrieves the name of a console variable.
dvander@2168
   594
 *
dvander@2168
   595
 * @param convar		Handle to the convar.
dvander@2168
   596
 * @param value			Buffer to store the name of the convar.
dvander@2168
   597
 * @param maxlength		Maximum length of string buffer.
dvander@2168
   598
 * @noreturn
dvander@2168
   599
 * @error				Invalid or corrupt Handle.     
dvander@2168
   600
 */
dvander@2168
   601
native GetConVarName(Handle:convar, const String:name[], maxlength);
dvander@2168
   602
dvander@2168
   603
funcenum ConVarQueryFinished
dvander@2168
   604
{	
dvander@2168
   605
	/**
dvander@2168
   606
	 * Called when a query to retrieve a client's console variable has finished.
dvander@2168
   607
	 *
dvander@2168
   608
	 * @param cookie		Unique identifier of query.
dvander@2168
   609
	 * @param client		Player index.
dvander@2168
   610
	 * @param result		Result of query that tells one whether or not query was successful.
dvander@2168
   611
	 *						See ConVarQueryResult enum for more details.
dvander@2168
   612
	 * @param convarName	Name of client convar that was queried.
dvander@2168
   613
	 * @param convarValue	Value of client convar that was queried if successful. This will be "" if it was not.
dvander@2168
   614
	 * @param value			Value that was passed when query was started.
dvander@2168
   615
	 * @noreturn
dvander@2168
   616
	 */
dvander@2168
   617
	public(QueryCookie:cookie, client, ConVarQueryResult:result, const String:cvarName[], const String:cvarValue[], any:value),
dvander@2168
   618
	
dvander@2168
   619
	/**
dvander@2168
   620
	 * Called when a query to retrieve a client's console variable has finished.
dvander@2168
   621
	 *
dvander@2168
   622
	 * @param cookie		Unique identifier of query.
dvander@2168
   623
	 * @param client		Player index.
dvander@2168
   624
	 * @param result		Result of query that tells one whether or not query was successful.
dvander@2168
   625
	 *						See ConVarQueryResult enum for more details.
dvander@2168
   626
	 * @param convarName	Name of client convar that was queried.
dvander@2168
   627
	 * @param convarValue	Value of client convar that was queried if successful. This will be "" if it was not.
dvander@2168
   628
	 * @noreturn
dvander@2168
   629
	 */
dvander@2168
   630
	public(QueryCookie:cookie, client, ConVarQueryResult:result, const String:cvarName[], const String:cvarValue[])
dvander@2168
   631
};
dvander@2168
   632
dvander@2168
   633
/**
dvander@2168
   634
 * Starts a query to retrieve the value of a client's console variable.
dvander@2168
   635
 *
dvander@2168
   636
 * @param client		Player index.
dvander@2168
   637
 * @param name			Name of client convar to query.
dvander@2168
   638
 * @param callback		A function to use as a callback when the query has finished.
dvander@2168
   639
 * @param value			Optional value to pass to the callback function.
dvander@2168
   640
 * @return				A cookie that uniquely identifies the query. 
dvander@2168
   641
 *						Returns QUERYCOOKIE_FAILED on failure, such as when used on a bot.
dvander@2168
   642
 */
dvander@2168
   643
native QueryCookie:QueryClientConVar(client, const String:cvarName[], ConVarQueryFinished:callback, any:value=0);
dvander@2168
   644
dvander@2168
   645
/**
dvander@2168
   646
 * Gets a command iterator.  Must be freed with CloseHandle().
dvander@2168
   647
 *
dvander@2168
   648
 * @return				A new command iterator.
dvander@2168
   649
 */
dvander@2168
   650
native Handle:GetCommandIterator();
dvander@2168
   651
dvander@2168
   652
/**
dvander@2168
   653
 * Reads a command iterator, then advances to the next command if any.
dvander@2168
   654
 * Only SourceMod specific commands are returned.
dvander@2168
   655
 *
dvander@2168
   656
 * @param iter			Command iterator Handle.
dvander@2168
   657
 * @param name			Name buffer.
dvander@2168
   658
 * @param nameLen		Name buffer size.
dvander@2168
   659
 * @param eflags		Effective default flags of a command.
dvander@2168
   660
 * @param desc			Command description buffer.
dvander@2168
   661
 * @param descLen		Command description buffer size.
dvander@2168
   662
 * @return				True on success, false if there are no more commands.
dvander@2168
   663
 */
dvander@2168
   664
native bool:ReadCommandIterator(Handle:iter, 
dvander@2168
   665
								String:name[], 
dvander@2168
   666
								nameLen, 
dvander@2168
   667
								&eflags=0, 
dvander@2168
   668
								String:desc[]="", 
dvander@2168
   669
								descLen=0);
dvander@2168
   670
dvander@2168
   671
/**
dvander@2168
   672
 * Returns whether a client has access to a given command string.  The string 
dvander@2168
   673
 * can also be any override string, as overrides can be independent of 
dvander@2168
   674
 * commands.  This important feature essentially allows you to create custom 
dvander@2168
   675
 * flags using the override system.
dvander@2168
   676
 *
dvander@2168
   677
 * @param client		Client index.
dvander@2168
   678
 * @param command		Command name.  If the command is not found, the default 
dvander@2168
   679
 *						flags are used.
dvander@2168
   680
 * @param flags			Flag string to use as a default, if the command or override 
dvander@2168
   681
 *						is not found.
dvander@2168
   682
 * @param override_only	If true, SourceMod will not attempt to find a matching 
dvander@2168
   683
 *						command, and it will only use the default flags specified.
dvander@2168
   684
 *						Otherwise, SourceMod will ignore the default flags if 
dvander@2168
   685
 *						there is a matching admin command.
dvander@2168
   686
 * @return				True if the client has access, false otherwise.
dvander@2168
   687
 */
dvander@2168
   688
native bool:CheckCommandAccess(client, 
dvander@2168
   689
							   const String:command[],
dvander@2168
   690
							   flags,
dvander@2168
   691
							   bool:override_only=false);
dvander@2168
   692
dvander@2168
   693
/**
dvander@2168
   694
 * Returns true if the supplied character is valid in a ConVar name.
dvander@2168
   695
 *
dvander@2168
   696
 * @param c			Character to validate.
dvander@2168
   697
 * @return			True is valid for ConVars, false otherwise
dvander@2168
   698
 */
dvander@2168
   699
stock bool:IsValidConVarChar(c)
dvander@2168
   700
{
dvander@2168
   701
	return (c == '_' || IsCharAlpha(c) || IsCharNumeric(c));
dvander@2168
   702
}
dvander@2168
   703
dvander@2168
   704
/**
dvander@2168
   705
 * Returns the bitstring of flags of a command.
dvander@2168
   706
 *
dvander@2168
   707
 * @param name		Name of the command.
dvander@2168
   708
 * @return			A bitstring containing the FCVAR_* flags that are enabled 
dvander@2168
   709
 *					or INVALID_FCVAR_FLAGS if command not found.
dvander@2168
   710
 */
dvander@2168
   711
native GetCommandFlags(const String:name[]);
dvander@2168
   712
dvander@2168
   713
/**
dvander@2168
   714
 * Sets the bitstring of flags of a command.
dvander@2168
   715
 *
dvander@2168
   716
 * @param name		Name of the command.
dvander@2168
   717
 * @param flags		A bitstring containing the FCVAR_* flags to enable.
dvander@2168
   718
 * @return			True on success, otherwise false.
dvander@2168
   719
 */
dvander@2168
   720
native bool:SetCommandFlags(const String:name[], flags);
dvander@2168
   721
dvander@2168
   722
/**
dvander@2168
   723
 * Starts a ConCommandBase search, traversing the list of ConVars and 
dvander@2168
   724
 * ConCommands.  If a Handle is returned, the next entry must be read 
dvander@2168
   725
 * via FindNextConCommand().  The order of the list is undefined.
dvander@2168
   726
 *
dvander@2168
   727
 * @param buffer		Buffer to store entry name.
dvander@2168
   728
 * @param max_size		Maximum size of the buffer.
dvander@2168
   729
 * @param isCommand		Variable to store whether the entry is a command. 
dvander@2168
   730
 *						If it is not a command, it is a ConVar.
dvander@2168
   731
 * @param flags			Variable to store entry flags.
dvander@2168
   732
 * @param description		Buffer to store the description, empty if no description present.
dvander@2168
   733
 * @param descrmax_size		Maximum size of the description buffer.
dvander@2168
   734
 * @return				On success, a ConCmdIter Handle is returned, which 
dvander@2168
   735
 *						can be read via FindNextConCommand(), and must be 
dvander@2168
   736
 *						closed via CloseHandle().  Additionally, the output 
dvander@2168
   737
 *						parameters will be filled with information of the 
dvander@2168
   738
 *						first ConCommandBase entry.
dvander@2168
   739
 *						On failure, INVALID_HANDLE is returned, and the 
dvander@2168
   740
 *						contents of outputs is undefined.
dvander@2168
   741
 */
dvander@2168
   742
native Handle:FindFirstConCommand(String:buffer[], max_size, &bool:isCommand, &flags=0, String:description[]="", descrmax_size=0);
dvander@2168
   743
dvander@2168
   744
/**
dvander@2168
   745
 * Reads the next entry in a ConCommandBase iterator.
dvander@2168
   746
 *
dvander@2168
   747
 * @param search		ConCmdIter Handle to search.
dvander@2168
   748
 * @param buffer		Buffer to store entry name.
dvander@2168
   749
 * @param max_size		Maximum size of the buffer.
dvander@2168
   750
 * @param isCommand		Variable to store whether the entry is a command.
dvander@2168
   751
 *						If it is not a command, it is a ConVar.
dvander@2168
   752
 * @param flags			Variable to store entry flags.
dvander@2168
   753
 * @param description		Buffer to store the description, empty if no description present.
dvander@2168
   754
 * @param descrmax_size		Maximum size of the description buffer.
dvander@2168
   755
 * @return				On success, the outputs are filled, the iterator is 
dvander@2168
   756
 *						advanced to the next entry, and true is returned.  
dvander@2168
   757
 *						If no more entries exist, false is returned, and the 
dvander@2168
   758
 *						contents of outputs is undefined.
dvander@2168
   759
 */
dvander@2168
   760
native bool:FindNextConCommand(Handle:search, String:buffer[], max_size, &bool:isCommand, &flags=0, String:description[]="", descrmax_size=0);
dvander@2168
   761
dvander@2168
   762
/**
dvander@2168
   763
 * Replicates a convar value to a specific client. This does not change the actual convar value.
dvander@2168
   764
 *
dvander@2168
   765
 * @param client		Client index
dvander@2168
   766
 * @param convar		ConVar handle
dvander@2168
   767
 * @param value			String value to send
dvander@2168
   768
 * @return				True on success, false on failure
dvander@2168
   769
 * @error 				Invalid client index, client not in game, or client is fake
dvander@2168
   770
 */
dvander@2168
   771
native bool:SendConVarValue(client, Handle:convar, const String:value[]);