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