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