plugins/include/console.inc
author Scott Ehlert <ds@alliedmods.net>
Thu Apr 05 10:55:40 2007 +0000 (2007-04-05)
changeset 669 ce01c2eb020c
parent 634 85108309e453
child 696 d5cc8d0fa899
permissions -rw-r--r--
Various things:
- Fixed inline translations when using %T
- "Improved" caching of server language
- Renamed Translator::GetServerLanguageCode() to GetServerLanguage()
- Added some more comments to sm_globals.h
- Natives folder in project file mysteriously was moved inside Interfaces, so moved it back o_O
- DS hates empty if statements :o
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
/**
dvander@619
    22
 * @section Flags for console commands and console variables.  The descriptions 
dvander@619
    23
 * 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@522
    55
/**
dvander@619
    56
 * @endsection
dvander@619
    57
 */
dvander@619
    58
dvander@619
    59
/**
dvander@522
    60
 * Executes a server command as if it were on the server console (or RCON)
dvander@522
    61
 *
dvander@522
    62
 * @param format		Formatting rules.
dvander@522
    63
 * @param ...			Variable number of format parameters.
dvander@522
    64
 * @noreturn
dvander@522
    65
 */
ds@634
    66
native ServerCommand(const String:format[], any:...);
dvander@522
    67
dvander@522
    68
/**
dvander@522
    69
 * Inserts a server command at the beginning of the server command buffer.
dvander@522
    70
 *
dvander@522
    71
 * @param format		Formatting rules.
dvander@522
    72
 * @param ...			Variable number of format parameters.
dvander@522
    73
 * @noreturn
dvander@522
    74
 */
ds@634
    75
native InsertServerCommand(const String:format[], any:...);
dvander@522
    76
dvander@522
    77
/**
dvander@522
    78
 * Executes every command in the server's command buffer, rather than once per frame.
dvander@522
    79
 *
dvander@522
    80
 * @noreturn
dvander@522
    81
 */
dvander@522
    82
native ServerExecute();
dvander@480
    83
dvander@480
    84
/**
dvander@532
    85
 * Executes a client command.  Note that this will not work on clients unless
dvander@532
    86
 * they have cl_restrict_server_commands set to 0.
dvander@532
    87
 *
dvander@532
    88
 * @param client		Index of the client.
dvander@532
    89
 * @param fmt			Format of the client command.
dvander@532
    90
 * @param ...			Format parameters/
dvander@532
    91
 * @noreturn
dvander@532
    92
 * @error				Invalid client index, or client not connected.
dvander@532
    93
 */
ds@634
    94
native ClientCommand(client, const String:fmt[], any:...);
dvander@532
    95
dvander@532
    96
/**
dvander@480
    97
 * Sends a message to the server console.
dvander@480
    98
 *
dvander@480
    99
 * @param format		Formatting rules.
dvander@480
   100
 * @param ...			Variable number of format parameters.
dvander@480
   101
 * @noreturn
dvander@480
   102
 */
ds@634
   103
native PrintToServer(const String:format[], any:...);
dvander@480
   104
dvander@480
   105
/**
dvander@480
   106
 * Sends a message to a client's console.
dvander@480
   107
 *
dvander@480
   108
 * @param client		Player index.
dvander@480
   109
 * @param format		Formatting rules.
dvander@480
   110
 * @param ...			Variable number of format parameters.
dvander@480
   111
 * @noreturn
dvander@480
   112
 * @error			If the client is not connected an error will be thrown.
dvander@480
   113
 */
ds@634
   114
native PrintToConsole(client, const String:format[], any:...);
dvander@480
   115
ds@457
   116
/**
dvander@498
   117
 * Called when a server-only command is invoked.  
dvander@498
   118
 *
dvander@520
   119
 * @params args			Number of arguments that were in the argument string.
dvander@498
   120
 * @return				A Result value.  Not handling the command
dvander@498
   121
 *						means that Source will report it as "not found."
dvander@498
   122
 */
dvander@520
   123
functag SrvCmd Action:public(args);
dvander@498
   124
dvander@498
   125
/**
dvander@498
   126
 * Creates a server-only console command, or hooks an already existing one.  
dvander@498
   127
 *
dvander@498
   128
 * @param cmd			Name of the command to hook or create.
dvander@498
   129
 * @param callback		A function to use as a callback for when the command is invoked.
dvander@498
   130
 * @param description	Optional description to use for command creation.
dvander@498
   131
 * @param flags			Optional flags to use for command creation.
dvander@498
   132
 * @noreturn
ds@579
   133
 * @error				Command name is the same as an existing convar.
dvander@498
   134
 */
dvander@498
   135
native RegServerCmd(const String:cmd[], SrvCmd:callback, const String:description[]="", flags=0);
dvander@498
   136
dvander@498
   137
/**
dvander@498
   138
 * Called when a generic console command is invoked.
dvander@498
   139
 *
dvander@498
   140
 * @param client		Index of the client, or 0 from the server.
dvander@520
   141
 * @param args			Number of arguments that were in the argument string.
dvander@498
   142
 * @return				A Result value.  Not handling the command
dvander@498
   143
 *						means that Source will report it as "not found."
dvander@498
   144
 */
dvander@520
   145
functag ConCmd Action:public(client, args);
dvander@498
   146
dvander@498
   147
/**
dvander@498
   148
 * Creates a console command, or hooks an already existing one.
dvander@498
   149
 *
dvander@498
   150
 * @param cmd			Name of the command to hook or create.
dvander@498
   151
 * @param callback		A function to use as a callback for when the command is invoked.
dvander@498
   152
 * @param description	Optional description to use for command creation.
dvander@498
   153
 * @param flags			Optional flags to use for command creation.
dvander@498
   154
 * @noreturn
ds@579
   155
 * @error				Command name is the same as an existing convar.
dvander@498
   156
 */
dvander@498
   157
native RegConsoleCmd(const String:cmd[], ConCmd:callback, const String:description[]="", flags=0);
dvander@498
   158
dvander@498
   159
/**
dvander@498
   160
 * Creates a console command as an administrative command.  If the command does not exist,
dvander@520
   161
 * it is created.  When this command is invoked, the access rights of the player are 
dvander@520
   162
 * automatically checked before allowing it to continue.
dvander@498
   163
 *
dvander@498
   164
 * @param cmd			String containing command to register.
dvander@498
   165
 * @param callback		A function to use as a callback for when the command is invoked.
dvander@498
   166
 * @param adminflags	Administrative flags (bitstring) to use for permissions.
dvander@498
   167
 * @param group			String containing the command group to use.  If empty,
dvander@498
   168
 * 						the plugin's filename will be used instead.
dvander@498
   169
 * @param description	Optional description to use for help.
dvander@498
   170
 * @param flags			Optional console flags.
dvander@498
   171
 * @noreturn
ds@579
   172
 * @error				Command name is the same as an existing convar.
dvander@498
   173
 */
dvander@514
   174
native RegAdminCmd(const String:cmd[],
dvander@514
   175
					ConCmd:callback,
dvander@514
   176
					adminflags,
dvander@514
   177
					const String:description[]="",
dvander@514
   178
					const String:group[]="",
dvander@514
   179
					flags=0);
dvander@517
   180
					
dvander@517
   181
/**
dvander@517
   182
 * Returns the number of arguments from the current console or server command.
dvander@517
   183
 * @note Unlike the HL2 engine call, this does not include the command itself.
dvander@517
   184
 *
dvander@517
   185
 * @return				Number of arguments to the current command.
dvander@517
   186
 */
dvander@517
   187
native GetCmdArgs();
dvander@517
   188
dvander@517
   189
/**
dvander@517
   190
 * Retrieves a command argument given its index, from the current console or 
dvander@517
   191
 * server command.
dvander@517
   192
 * @note Argument indexes start at 1; 0 retrieves the command name.
dvander@517
   193
 *
dvander@517
   194
 * @param argnum		Argument number to retrieve.
dvander@517
   195
 * @param buffer		Buffer to use for storing the string.
dvander@517
   196
 * @param maxlength		Maximum length of the buffer.
dvander@517
   197
 * @noreturn
dvander@517
   198
 */
dvander@517
   199
native GetCmdArg(argnum, String:buffer[], maxlength);
dvander@517
   200
dvander@517
   201
/**
dvander@517
   202
 * Retrieves the entire command argument string in one lump from the current 
dvander@517
   203
 * console or server command.
dvander@517
   204
 *
dvander@517
   205
 * @param buffer		Buffer to use for storing the string.
dvander@517
   206
 * @param maxlength		Maximum length of the buffer.
dvander@517
   207
 * @noreturn
dvander@517
   208
 */
dvander@517
   209
native GetCmdArgString(String:buffer[], maxlength);
dvander@498
   210
dvander@498
   211
/**
ds@457
   212
 * Creates a new console variable.
ds@457
   213
 *
ds@475
   214
 * @param name			Name of new convar.
ds@475
   215
 * @param defaultValue	String containing the default value of new convar.
ds@582
   216
 * @param description	Optional description of the convar.
ds@576
   217
 * @param flags			Optional bitstring of flags determining how the convar should be handled. See FCVAR_* constants for more details.
ds@475
   218
 * @param hasMin		Optional boolean that determines if the convar has a minimum value.
ds@475
   219
 * @param min			Minimum floating point value that the convar can have if hasMin is true.
ds@475
   220
 * @param hasMax		Optional boolean that determines if the convar has a maximum value.
ds@475
   221
 * @param max			Maximum floating point value that the convar can have if hasMax is true.
ds@457
   222
 * @return				A handle to the newly created convar. If the convar already exists, INVALID_HANDLE is returned.
ds@579
   223
 * @error				Convar name is blank or is the same as an existing console command.
ds@457
   224
 */
ds@582
   225
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
   226
ds@457
   227
/**
ds@457
   228
 * Searches for a console variable.
ds@457
   229
 *
ds@475
   230
 * @param name			Name of convar to find.
ds@475
   231
 * @return				A handle to the convar if it is found. INVALID_HANDLE otherwise.
ds@457
   232
 */
ds@457
   233
native Handle:FindConVar(const String:name[]);
ds@457
   234
ds@457
   235
/**
ds@465
   236
 * Called when a console variable's value is changed.
ds@465
   237
 *
ds@475
   238
 * @param convar		Handle to the convar that was changed.
ds@475
   239
 * @param oldValue		String containing the value of the convar before it was changed.
ds@475
   240
 * @param newValue		String containing the new value of the convar.
ds@465
   241
 * @noreturn
ds@465
   242
 */
ds@582
   243
functag ConVarChanged public(Handle:convar, const String:oldValue[], const String:newValue[]);
ds@465
   244
ds@465
   245
/**
ds@465
   246
 * Creates a hook for when a console variable's value is changed.
ds@465
   247
 *
ds@475
   248
 * @param convar		Handle to the convar.
ds@475
   249
 * @param callback		An OnConVarChanged function pointer.
ds@465
   250
 * @noreturn
ds@475
   251
 * @error				Invalid or corrupt Handle or invalid callback function.
ds@465
   252
 */
ds@582
   253
native HookConVarChange(Handle:convar, ConVarChanged:callback);
ds@465
   254
ds@465
   255
/**
ds@465
   256
 * Removes a hook for when a console variable's value is changed.
ds@465
   257
 *
ds@475
   258
 * @param convar		Handle to the convar.
ds@475
   259
 * @param callback		An OnConVarChanged function pointer.
ds@472
   260
 * @noreturn
ds@475
   261
 * @error				Invalid or corrupt Handle, invalid callback function, or no active hook on convar.
ds@465
   262
 */
ds@582
   263
native UnhookConVarChange(Handle:convar, ConVarChanged:callback);
ds@465
   264
ds@465
   265
/**
ds@457
   266
 * Returns the boolean value of a console variable.
ds@457
   267
 *
ds@475
   268
 * @param convar		Handle to the convar.
ds@475
   269
 * @return				The boolean value of the convar.
ds@475
   270
 * @error				Invalid or corrupt Handle.
ds@457
   271
 */
ds@457
   272
native bool:GetConVarBool(Handle:convar);
ds@457
   273
ds@457
   274
/**
ds@457
   275
 * Sets the boolean value of a console variable.
ds@457
   276
 *
ds@475
   277
 * @param convar		Handle to the convar.
ds@475
   278
 * @param value			New boolean value.
ds@457
   279
 * @noreturn
ds@475
   280
 * @error				Invalid or corrupt Handle.
ds@457
   281
 */
ds@457
   282
native SetConVarBool(Handle:convar, bool:value);
ds@457
   283
ds@457
   284
/**
ds@457
   285
 * Returns the integer value of a console variable.
ds@457
   286
 *
ds@475
   287
 * @param convar		Handle to the convar.
ds@475
   288
 * @return				The integer value of the convar.
ds@475
   289
 * @error				Invalid or corrupt Handle.
ds@457
   290
 */
ds@457
   291
native GetConVarInt(Handle:convar);
ds@457
   292
ds@457
   293
/**
ds@457
   294
 * Sets the integer value of a console variable.
ds@457
   295
 *
ds@475
   296
 * @param convar		Handle to the convar.
ds@475
   297
 * @param value			New integer value.
ds@457
   298
 * @noreturn
ds@475
   299
 * @error				Invalid or corrupt Handle.
ds@457
   300
 */
ds@457
   301
native SetConVarInt(Handle:convar, value);
ds@457
   302
ds@457
   303
/**
ds@457
   304
 * Returns the floating point value of a console variable.
ds@457
   305
 *
ds@475
   306
 * @param convar		Handle to the convar.
ds@475
   307
 * @return				The floating point value of the convar.
ds@475
   308
 * @error				Invalid or corrupt Handle.
ds@457
   309
 */
ds@457
   310
native Float:GetConVarFloat(Handle:convar);
ds@457
   311
ds@457
   312
/**
ds@457
   313
 * Sets the floating point value of a console variable.
ds@457
   314
 *
ds@475
   315
 * @param convar		Handle to the convar.
ds@475
   316
 * @param value			New floating point value.
ds@457
   317
 * @noreturn
ds@475
   318
 * @error				Invalid or corrupt Handle.
ds@457
   319
 */
ds@457
   320
native SetConVarFloat(Handle:convar, Float:value);
ds@457
   321
ds@457
   322
/**
ds@457
   323
 * Retrieves the string value of a console variable.
ds@457
   324
 *
ds@475
   325
 * @param convar		Handle to the convar.
ds@475
   326
 * @param value			Buffer to store the value of the convar.
ds@475
   327
 * @param maxlength		Maximum length of string buffer.
ds@457
   328
 * @noreturn
ds@475
   329
 * @error				Invalid or corrupt Handle.     
ds@457
   330
 */
ds@465
   331
native GetConVarString(Handle:convar, String:value[], maxlength);
ds@457
   332
ds@457
   333
/**
ds@457
   334
 * Sets the string value of a console variable.
ds@457
   335
 *
ds@475
   336
 * @param convar		Handle to the convar.
ds@475
   337
 * @param value			New string value.
ds@457
   338
 * @noreturn
ds@475
   339
 * @error				Invalid or corrupt Handle.
ds@457
   340
 */
ds@457
   341
native SetConVarString(Handle:convar, const String:value[]);
ds@457
   342
ds@457
   343
/**
ds@457
   344
 * Returns the bitstring of flags on a console variable.
ds@457
   345
 *
ds@475
   346
 * @param convar		Handle to the convar.
ds@475
   347
 * @return				A bitstring containing the FCVAR_* flags that are enabled.
ds@475
   348
 * @error				Invalid or corrupt Handle.
ds@457
   349
 */
ds@457
   350
native GetConVarFlags(Handle:convar);
ds@457
   351
ds@457
   352
/**
ds@457
   353
 * Sets the bitstring of flags on a console variable.
ds@457
   354
 *
ds@475
   355
 * @param convar		Handle to the convar.
ds@475
   356
 * @param flags			A bitstring containing the FCVAR_* flags to enable.
ds@457
   357
 * @noreturn
ds@475
   358
 * @error				Invalid or corrupt Handle.
ds@457
   359
 */
ds@457
   360
native SetConVarFlags(Handle:convar, flags);
ds@457
   361
ds@457
   362
/**
ds@465
   363
 * Retrieves the name of a console variable.
ds@465
   364
 *
ds@475
   365
 * @param convar		Handle to the convar.
ds@475
   366
 * @param value			Buffer to store the name of the convar.
ds@475
   367
 * @param maxlength		Maximum length of string buffer.
ds@465
   368
 * @noreturn
ds@475
   369
 * @error				Invalid or corrupt Handle.     
ds@465
   370
 */
ds@465
   371
native GetConVarName(Handle:convar, const String:name[], maxlength);
ds@465
   372
ds@465
   373
/**
ds@457
   374
 * Retrieves the minimum floating point value that a console variable can contain.
ds@457
   375
 *
ds@475
   376
 * @param convar		Handle to the convar.
ds@475
   377
 * @param min			By-reference cell to store the minimum floating point value.
ds@475
   378
 * @return				True if the convar has a minimum value set, false otherwise.
ds@475
   379
 * @error				Invalid or corrupt Handle.
ds@457
   380
 */
ds@457
   381
native bool:GetConVarMin(Handle:convar, &Float:min);
ds@457
   382
ds@457
   383
/**
ds@457
   384
 * Retrieves the maximum floating point value that a console variable can contain.
ds@457
   385
 *
ds@475
   386
 * @param convar		Handle to the convar.
ds@475
   387
 * @param min			By-reference cell to store the maximum floating point value.
ds@475
   388
 * @return				True if the convar has a maximum value set, false otherwise.
ds@475
   389
 * @error				Invalid or corrupt Handle.
ds@457
   390
 */
ds@457
   391
native bool:GetConVarMax(Handle:convar, &Float:max);
ds@457
   392
ds@457
   393
/**
ds@457
   394
 * Resets the console variable to its default value.
ds@457
   395
 *
ds@475
   396
 * @param convar		Handle to the convar.
ds@457
   397
 * @noreturn
ds@475
   398
 * @error				Invalid or corrupt Handle.
ds@457
   399
 */
ds@457
   400
native ResetConVar(Handle:convar);