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