plugins/include/console.inc
author David Anderson <dvander@alliedmods.net>
Sat Feb 17 09:12:21 2007 +0000 (2007-02-17)
changeset 517 da53a0fa5721
parent 514 4c02b38c26ed
child 520 7676d61cde2d
permissions -rw-r--r--
added functions for getting arguments
ds@457
     1
/**
ds@475
     2
 * vim: set ts=4 :
ds@457
     3
 * ===============================================================
ds@457
     4
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
ds@457
     5
 * ===============================================================
ds@457
     6
 *
ds@457
     7
 *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
ds@457
     8
 * or modified under the Terms and Conditions of its License Agreement, which is found 
ds@457
     9
 * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
ds@457
    10
 * may change at any time.  To view the latest information, see:
ds@457
    11
 *   http://www.sourcemod.net/license.php
ds@457
    12
 *
ds@457
    13
 * Version: $Id$
ds@457
    14
 */
ds@457
    15
 
ds@457
    16
#if defined _console_included
ds@457
    17
 #endinput
ds@457
    18
#endif
ds@457
    19
#define _console_included
ds@457
    20
ds@457
    21
/**
ds@457
    22
 * Flags for console commands and console variables
ds@457
    23
 * @note The descriptions for each constant come directly from the Source SDK.
ds@457
    24
 */
ds@475
    25
#define FCVAR_NONE				0		/**< The default, no flags at all */
ds@475
    26
#define FCVAR_UNREGISTERED		(1<<0)	/**< If this is set, don't add to linked list, etc. */
ds@475
    27
#define FCVAR_LAUNCHER			(1<<1)	/**< Defined by launcher. */
ds@475
    28
#define FCVAR_GAMEDLL			(1<<2)	/**< Defined by the game DLL. */
ds@475
    29
#define FCVAR_CLIENTDLL			(1<<3)	/**< Defined by the client DLL. */
ds@475
    30
#define FCVAR_MATERIAL_SYSTEM	(1<<4)	/**< Defined by the material system. */
ds@475
    31
#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
    32
#define FCVAR_SPONLY			(1<<6)	/**< This cvar cannot be changed by clients connected to a multiplayer server. */
ds@475
    33
#define	FCVAR_ARCHIVE			(1<<7)	/**< Set to cause it to be saved to vars.rc */
ds@475
    34
#define	FCVAR_NOTIFY			(1<<8)	/**< Notifies players when changed. */
ds@475
    35
#define	FCVAR_USERINFO			(1<<9)	/**< Changes the client's info string. */
ds@475
    36
#define FCVAR_PRINTABLEONLY		(1<<10)	/**< This cvar's string cannot contain unprintable characters (e.g., used for player name, etc.) */
ds@475
    37
#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
    38
#define FCVAR_NEVER_AS_STRING	(1<<12)	/**< Never try to print that cvar. */
ds@475
    39
#define FCVAR_REPLICATED		(1<<13)	/**< Server setting enforced on clients. */
ds@475
    40
#define FCVAR_CHEAT				(1<<14)	/**< Only useable in singleplayer / debug / multiplayer & sv_cheats */
ds@475
    41
#define FCVAR_STUDIORENDER		(1<<15)	/**< Defined by the studiorender system. */
ds@475
    42
#define FCVAR_DEMO				(1<<16)	/**< Record this cvar when starting a demo file. */
ds@475
    43
#define FCVAR_DONTRECORD		(1<<17)	/**< Don't record these command in demo files. */
ds@475
    44
#define FCVAR_PLUGIN			(1<<18)	/**< Defined by a 3rd party plugin. */
ds@475
    45
#define FCVAR_DATACACHE			(1<<19)	/**< Defined by the datacache system. */
ds@475
    46
#define FCVAR_TOOLSYSTEM		(1<<20)	/**< Defined by an IToolSystem library */
ds@475
    47
#define FCVAR_FILESYSTEM		(1<<21)	/**< Defined by the file system. */
ds@475
    48
#define FCVAR_NOT_CONNECTED		(1<<22)	/**< Cvar cannot be changed by a client that is connected to a server. */
ds@475
    49
#define FCVAR_SOUNDSYSTEM		(1<<23)	/**< Defined by the soundsystem library. */
ds@475
    50
#define FCVAR_ARCHIVE_XBOX		(1<<24)	/**< Cvar written to config.cfg on the Xbox. */
ds@475
    51
#define FCVAR_INPUTSYSTEM		(1<<25)	/**< Defined by the inputsystem DLL. */
ds@475
    52
#define FCVAR_NETWORKSYSTEM		(1<<26)	/**< Defined by the network system. */
ds@476
    53
#define FCVAR_VPHYSICS			(1<<27)	/**< Defined by vphysics. */
ds@457
    54
dvander@480
    55
dvander@480
    56
/**
dvander@480
    57
 * Sends a message to the server console.
dvander@480
    58
 *
dvander@480
    59
 * @param format		Formatting rules.
dvander@480
    60
 * @param ...			Variable number of format parameters.
dvander@480
    61
 * @noreturn
dvander@480
    62
 */
dvander@480
    63
native PrintToServer(const String:format[], {Handle,Float,String,_}:...);
dvander@480
    64
dvander@480
    65
/**
dvander@480
    66
 * Sends a message to a client's console.
dvander@480
    67
 *
dvander@480
    68
 * @param client		Player index.
dvander@480
    69
 * @param format		Formatting rules.
dvander@480
    70
 * @param ...			Variable number of format parameters.
dvander@480
    71
 * @noreturn
dvander@480
    72
 * @error			If the client is not connected an error will be thrown.
dvander@480
    73
 */
dvander@480
    74
native PrintToConsole(client, const String:format[], {Handle,Float,String,_}:...);
dvander@480
    75
ds@457
    76
/**
dvander@498
    77
 * Called when a server-only command is invoked.  
dvander@498
    78
 *
dvander@498
    79
 * @return				A Result value.  Not handling the command
dvander@498
    80
 *						means that Source will report it as "not found."
dvander@498
    81
 */
dvander@500
    82
functag SrvCmd Action:public(argCount);
dvander@498
    83
dvander@498
    84
/**
dvander@498
    85
 * Creates a server-only console command, or hooks an already existing one.  
dvander@498
    86
 *
dvander@498
    87
 * @param cmd			Name of the command to hook or create.
dvander@498
    88
 * @param callback		A function to use as a callback for when the command is invoked.
dvander@498
    89
 * @param description	Optional description to use for command creation.
dvander@498
    90
 * @param flags			Optional flags to use for command creation.
dvander@498
    91
 * @noreturn
dvander@498
    92
 */
dvander@498
    93
native RegServerCmd(const String:cmd[], SrvCmd:callback, const String:description[]="", flags=0);
dvander@498
    94
dvander@498
    95
/**
dvander@498
    96
 * Called when a generic console command is invoked.
dvander@498
    97
 *
dvander@498
    98
 * @param client		Index of the client, or 0 from the server.
dvander@498
    99
 * @return				A Result value.  Not handling the command
dvander@498
   100
 *						means that Source will report it as "not found."
dvander@498
   101
 */
dvander@500
   102
functag ConCmd Action:public(client, argCount);
dvander@498
   103
dvander@498
   104
/**
dvander@498
   105
 * Creates a console command, or hooks an already existing one.
dvander@498
   106
 *
dvander@498
   107
 * @param cmd			Name of the command to hook or create.
dvander@498
   108
 * @param callback		A function to use as a callback for when the command is invoked.
dvander@498
   109
 * @param description	Optional description to use for command creation.
dvander@498
   110
 * @param flags			Optional flags to use for command creation.
dvander@498
   111
 * @noreturn
dvander@498
   112
 */
dvander@498
   113
native RegConsoleCmd(const String:cmd[], ConCmd:callback, const String:description[]="", flags=0);
dvander@498
   114
dvander@498
   115
/**
dvander@498
   116
 * Creates a console command as an administrative command.  If the command does not exist,
dvander@513
   117
 * it is created. 
dvander@498
   118
 *
dvander@498
   119
 * @param cmd			String containing command to register.
dvander@498
   120
 * @param callback		A function to use as a callback for when the command is invoked.
dvander@498
   121
 * @param adminflags	Administrative flags (bitstring) to use for permissions.
dvander@498
   122
 * @param group			String containing the command group to use.  If empty,
dvander@498
   123
 * 						the plugin's filename will be used instead.
dvander@498
   124
 * @param description	Optional description to use for help.
dvander@498
   125
 * @param flags			Optional console flags.
dvander@498
   126
 * @noreturn
dvander@498
   127
 */
dvander@514
   128
native RegAdminCmd(const String:cmd[],
dvander@514
   129
					ConCmd:callback,
dvander@514
   130
					adminflags,
dvander@514
   131
					const String:description[]="",
dvander@514
   132
					const String:group[]="",
dvander@514
   133
					flags=0);
dvander@517
   134
					
dvander@517
   135
/**
dvander@517
   136
 * Returns the number of arguments from the current console or server command.
dvander@517
   137
 * @note Unlike the HL2 engine call, this does not include the command itself.
dvander@517
   138
 *
dvander@517
   139
 * @return				Number of arguments to the current command.
dvander@517
   140
 */
dvander@517
   141
native GetCmdArgs();
dvander@517
   142
dvander@517
   143
/**
dvander@517
   144
 * Retrieves a command argument given its index, from the current console or 
dvander@517
   145
 * server command.
dvander@517
   146
 * @note Argument indexes start at 1; 0 retrieves the command name.
dvander@517
   147
 *
dvander@517
   148
 * @param argnum		Argument number to retrieve.
dvander@517
   149
 * @param buffer		Buffer to use for storing the string.
dvander@517
   150
 * @param maxlength		Maximum length of the buffer.
dvander@517
   151
 * @noreturn
dvander@517
   152
 */
dvander@517
   153
native GetCmdArg(argnum, String:buffer[], maxlength);
dvander@517
   154
dvander@517
   155
/**
dvander@517
   156
 * Retrieves the entire command argument string in one lump from the current 
dvander@517
   157
 * console or server command.
dvander@517
   158
 *
dvander@517
   159
 * @param buffer		Buffer to use for storing the string.
dvander@517
   160
 * @param maxlength		Maximum length of the buffer.
dvander@517
   161
 * @noreturn
dvander@517
   162
 */
dvander@517
   163
native GetCmdArgString(String:buffer[], maxlength);
dvander@498
   164
dvander@498
   165
/**
ds@457
   166
 * Creates a new console variable.
ds@457
   167
 *
ds@475
   168
 * @param name			Name of new convar.
ds@475
   169
 * @param defaultValue	String containing the default value of new convar.
ds@475
   170
 * @param helpText		Optional description of the convar.
ds@475
   171
 * @param flags			Optional bitstream of flags determining how the convar should be handled. (See FCVAR_* constants for more details)
ds@475
   172
 * @param hasMin		Optional boolean that determines if the convar has a minimum value.
ds@475
   173
 * @param min			Minimum floating point value that the convar can have if hasMin is true.
ds@475
   174
 * @param hasMax		Optional boolean that determines if the convar has a maximum value.
ds@475
   175
 * @param max			Maximum floating point value that the convar can have if hasMax is true.
ds@457
   176
 * @return				A handle to the newly created convar. If the convar already exists, INVALID_HANDLE is returned.
ds@475
   177
 * @error				Convar name is blank or is the same as a console command.
ds@457
   178
 */
ds@457
   179
native Handle:CreateConVar(const String:name[], const String:defaultValue[], const String:helpText[]="", flags=0, bool:hasMin=false, Float:min=0.0, bool:hasMax=false, Float:max=0.0);
ds@457
   180
ds@457
   181
/**
ds@457
   182
 * Searches for a console variable.
ds@457
   183
 *
ds@475
   184
 * @param name			Name of convar to find.
ds@475
   185
 * @return				A handle to the convar if it is found. INVALID_HANDLE otherwise.
ds@457
   186
 */
ds@457
   187
native Handle:FindConVar(const String:name[]);
ds@457
   188
ds@457
   189
/**
ds@465
   190
 * Called when a console variable's value is changed.
ds@465
   191
 *
ds@475
   192
 * @param convar		Handle to the convar that was changed.
ds@475
   193
 * @param oldValue		String containing the value of the convar before it was changed.
ds@475
   194
 * @param newValue		String containing the new value of the convar.
ds@465
   195
 * @noreturn
ds@465
   196
 */
ds@465
   197
functag OnConVarChanged public(Handle:convar, const String:oldValue[], const String:newValue[]);
ds@465
   198
ds@465
   199
/**
ds@465
   200
 * Creates a hook for when a console variable's value is changed.
ds@465
   201
 *
ds@475
   202
 * @param convar		Handle to the convar.
ds@475
   203
 * @param callback		An OnConVarChanged function pointer.
ds@465
   204
 * @noreturn
ds@475
   205
 * @error				Invalid or corrupt Handle or invalid callback function.
ds@465
   206
 */
ds@465
   207
native HookConVarChange(Handle:convar, OnConVarChanged:callback);
ds@465
   208
ds@465
   209
/**
ds@465
   210
 * Removes a hook for when a console variable's value is changed.
ds@465
   211
 *
ds@475
   212
 * @param convar		Handle to the convar.
ds@475
   213
 * @param callback		An OnConVarChanged function pointer.
ds@472
   214
 * @noreturn
ds@475
   215
 * @error				Invalid or corrupt Handle, invalid callback function, or no active hook on convar.
ds@465
   216
 */
ds@472
   217
native UnhookConVarChange(Handle:convar, OnConVarChanged:callback);
ds@465
   218
ds@465
   219
/**
ds@457
   220
 * Returns the boolean value of a console variable.
ds@457
   221
 *
ds@475
   222
 * @param convar		Handle to the convar.
ds@475
   223
 * @return				The boolean value of the convar.
ds@475
   224
 * @error				Invalid or corrupt Handle.
ds@457
   225
 */
ds@457
   226
native bool:GetConVarBool(Handle:convar);
ds@457
   227
ds@457
   228
/**
ds@457
   229
 * Sets the boolean value of a console variable.
ds@457
   230
 *
ds@475
   231
 * @param convar		Handle to the convar.
ds@475
   232
 * @param value			New boolean value.
ds@457
   233
 * @noreturn
ds@475
   234
 * @error				Invalid or corrupt Handle.
ds@457
   235
 */
ds@457
   236
native SetConVarBool(Handle:convar, bool:value);
ds@457
   237
ds@457
   238
/**
ds@457
   239
 * Returns the integer value of a console variable.
ds@457
   240
 *
ds@475
   241
 * @param convar		Handle to the convar.
ds@475
   242
 * @return				The integer value of the convar.
ds@475
   243
 * @error				Invalid or corrupt Handle.
ds@457
   244
 */
ds@457
   245
native GetConVarInt(Handle:convar);
ds@457
   246
ds@457
   247
/**
ds@457
   248
 * Sets the integer value of a console variable.
ds@457
   249
 *
ds@475
   250
 * @param convar		Handle to the convar.
ds@475
   251
 * @param value			New integer value.
ds@457
   252
 * @noreturn
ds@475
   253
 * @error				Invalid or corrupt Handle.
ds@457
   254
 */
ds@457
   255
native SetConVarInt(Handle:convar, value);
ds@457
   256
ds@457
   257
/**
ds@457
   258
 * Returns the floating point value of a console variable.
ds@457
   259
 *
ds@475
   260
 * @param convar		Handle to the convar.
ds@475
   261
 * @return				The floating point value of the convar.
ds@475
   262
 * @error				Invalid or corrupt Handle.
ds@457
   263
 */
ds@457
   264
native Float:GetConVarFloat(Handle:convar);
ds@457
   265
ds@457
   266
/**
ds@457
   267
 * Sets the floating point value of a console variable.
ds@457
   268
 *
ds@475
   269
 * @param convar		Handle to the convar.
ds@475
   270
 * @param value			New floating point value.
ds@457
   271
 * @noreturn
ds@475
   272
 * @error				Invalid or corrupt Handle.
ds@457
   273
 */
ds@457
   274
native SetConVarFloat(Handle:convar, Float:value);
ds@457
   275
ds@457
   276
/**
ds@457
   277
 * Retrieves the string value of a console variable.
ds@457
   278
 *
ds@475
   279
 * @param convar		Handle to the convar.
ds@475
   280
 * @param value			Buffer to store the value of the convar.
ds@475
   281
 * @param maxlength		Maximum length of string buffer.
ds@457
   282
 * @noreturn
ds@475
   283
 * @error				Invalid or corrupt Handle.     
ds@457
   284
 */
ds@465
   285
native GetConVarString(Handle:convar, String:value[], maxlength);
ds@457
   286
ds@457
   287
/**
ds@457
   288
 * Sets the string value of a console variable.
ds@457
   289
 *
ds@475
   290
 * @param convar		Handle to the convar.
ds@475
   291
 * @param value			New string value.
ds@457
   292
 * @noreturn
ds@475
   293
 * @error				Invalid or corrupt Handle.
ds@457
   294
 */
ds@457
   295
native SetConVarString(Handle:convar, const String:value[]);
ds@457
   296
ds@457
   297
/**
ds@457
   298
 * Returns the bitstring of flags on a console variable.
ds@457
   299
 *
ds@475
   300
 * @param convar		Handle to the convar.
ds@475
   301
 * @return				A bitstring containing the FCVAR_* flags that are enabled.
ds@475
   302
 * @error				Invalid or corrupt Handle.
ds@457
   303
 */
ds@457
   304
native GetConVarFlags(Handle:convar);
ds@457
   305
ds@457
   306
/**
ds@457
   307
 * Sets the bitstring of flags on a console variable.
ds@457
   308
 *
ds@475
   309
 * @param convar		Handle to the convar.
ds@475
   310
 * @param flags			A bitstring containing the FCVAR_* flags to enable.
ds@457
   311
 * @noreturn
ds@475
   312
 * @error				Invalid or corrupt Handle.
ds@457
   313
 */
ds@457
   314
native SetConVarFlags(Handle:convar, flags);
ds@457
   315
ds@457
   316
/**
ds@465
   317
 * Retrieves the name of a console variable.
ds@465
   318
 *
ds@475
   319
 * @param convar		Handle to the convar.
ds@475
   320
 * @param value			Buffer to store the name of the convar.
ds@475
   321
 * @param maxlength		Maximum length of string buffer.
ds@465
   322
 * @noreturn
ds@475
   323
 * @error				Invalid or corrupt Handle.     
ds@465
   324
 */
ds@465
   325
native GetConVarName(Handle:convar, const String:name[], maxlength);
ds@465
   326
ds@465
   327
/**
ds@457
   328
 * Retrieves the minimum floating point value that a console variable can contain.
ds@457
   329
 *
ds@475
   330
 * @param convar		Handle to the convar.
ds@475
   331
 * @param min			By-reference cell to store the minimum floating point value.
ds@475
   332
 * @return				True if the convar has a minimum value set, false otherwise.
ds@475
   333
 * @error				Invalid or corrupt Handle.
ds@457
   334
 */
ds@457
   335
native bool:GetConVarMin(Handle:convar, &Float:min);
ds@457
   336
ds@457
   337
/**
ds@457
   338
 * Retrieves the maximum floating point value that a console variable can contain.
ds@457
   339
 *
ds@475
   340
 * @param convar		Handle to the convar.
ds@475
   341
 * @param min			By-reference cell to store the maximum floating point value.
ds@475
   342
 * @return				True if the convar has a maximum value set, false otherwise.
ds@475
   343
 * @error				Invalid or corrupt Handle.
ds@457
   344
 */
ds@457
   345
native bool:GetConVarMax(Handle:convar, &Float:max);
ds@457
   346
ds@457
   347
/**
ds@457
   348
 * Resets the console variable to its default value.
ds@457
   349
 *
ds@475
   350
 * @param convar		Handle to the convar.
ds@457
   351
 * @noreturn
ds@475
   352
 * @error				Invalid or corrupt Handle.
ds@457
   353
 */
ds@457
   354
native ResetConVar(Handle:convar);