plugins/include/console.inc
author Asher Baker <asherkin@gmail.com>
Sun May 27 01:50:57 2012 +0100 (2012-05-27)
changeset 3507 d1b6fde18611
parent 3389 68d3e56f4bb7
child 3967 ceafb87d38a7
permissions -rw-r--r--
Fixed error when reloading dependant plugins using aliased natives (bug 5302, r=psychonic).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     9  * This program is free software; you can redistribute it and/or modify it under
    10  * the terms of the GNU General Public License, version 3.0, as published by the
    11  * Free Software Foundation.
    12  * 
    13  * This program is distributed in the hope that it will be useful, but WITHOUT
    14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    16  * details.
    17  *
    18  * You should have received a copy of the GNU General Public License along with
    19  * this program.  If not, see <http://www.gnu.org/licenses/>.
    20  *
    21  * As a special exception, AlliedModders LLC gives you permission to link the
    22  * code of this program (as well as its derivative works) to "Half-Life 2," the
    23  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    24  * by the Valve Corporation.  You must obey the GNU General Public License in
    25  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    26  * this exception to all derivative works.  AlliedModders LLC defines further
    27  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    28  * or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32  
    33 #if defined _console_included
    34  #endinput
    35 #endif
    36 #define _console_included
    37 
    38 #define INVALID_FCVAR_FLAGS		(-1)
    39 
    40 /**
    41  * Console variable bound values used with Get/SetConVarBounds()
    42  */
    43 enum ConVarBounds
    44 {
    45 	ConVarBound_Upper = 0,
    46 	ConVarBound_Lower
    47 };
    48 
    49 /**
    50  * Console variable query helper values.
    51  */
    52 enum QueryCookie
    53 {
    54 	QUERYCOOKIE_FAILED = 0,
    55 };
    56 
    57 /**
    58  * Reply sources for commands.
    59  */
    60 enum ReplySource
    61 {
    62 	SM_REPLY_TO_CONSOLE = 0,
    63 	SM_REPLY_TO_CHAT = 1,
    64 };
    65 
    66 /**
    67  * Console variable query result values.
    68  */
    69 enum ConVarQueryResult
    70 {
    71 	ConVarQuery_Okay = 0,				/**< Retrieval of client convar value was successful. */
    72 	ConVarQuery_NotFound,				/**< Client convar was not found. */
    73 	ConVarQuery_NotValid,				/**< A console command with the same name was found, but there is no convar. */
    74 	ConVarQuery_Protected				/**< Client convar was found, but it is protected. The server cannot retrieve its value. */
    75 };
    76 
    77 /**
    78  * @section Flags for console commands and console variables.  The descriptions 
    79  * for each constant come directly from the Source SDK.
    80  */
    81 #define FCVAR_NONE				0		/**< The default, no flags at all */
    82 #define FCVAR_UNREGISTERED		(1<<0)	/**< If this is set, don't add to linked list, etc. */
    83 #define FCVAR_LAUNCHER			(1<<1)	/**< Defined by launcher. */
    84 #define FCVAR_GAMEDLL			(1<<2)	/**< Defined by the game DLL. */
    85 #define FCVAR_CLIENTDLL			(1<<3)	/**< Defined by the client DLL. */
    86 #define FCVAR_MATERIAL_SYSTEM	(1<<4)	/**< Defined by the material system. */
    87 #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. */
    88 #define FCVAR_SPONLY			(1<<6)	/**< This cvar cannot be changed by clients connected to a multiplayer server. */
    89 #define	FCVAR_ARCHIVE			(1<<7)	/**< Set to cause it to be saved to vars.rc */
    90 #define	FCVAR_NOTIFY			(1<<8)	/**< Notifies players when changed. */
    91 #define	FCVAR_USERINFO			(1<<9)	/**< Changes the client's info string. */
    92 #define FCVAR_PRINTABLEONLY		(1<<10)	/**< This cvar's string cannot contain unprintable characters (e.g., used for player name, etc.) */
    93 #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 */
    94 #define FCVAR_NEVER_AS_STRING	(1<<12)	/**< Never try to print that cvar. */
    95 #define FCVAR_REPLICATED		(1<<13)	/**< Server setting enforced on clients. */
    96 #define FCVAR_CHEAT				(1<<14)	/**< Only useable in singleplayer / debug / multiplayer & sv_cheats */
    97 #define FCVAR_STUDIORENDER		(1<<15)	/**< Defined by the studiorender system. */
    98 #define FCVAR_DEMO				(1<<16)	/**< Record this cvar when starting a demo file. */
    99 #define FCVAR_DONTRECORD		(1<<17)	/**< Don't record these command in demo files. */
   100 #define FCVAR_PLUGIN			(1<<18)	/**< Defined by a 3rd party plugin. */
   101 #define FCVAR_DATACACHE			(1<<19)	/**< Defined by the datacache system. */
   102 #define FCVAR_TOOLSYSTEM		(1<<20)	/**< Defined by an IToolSystem library */
   103 #define FCVAR_FILESYSTEM		(1<<21)	/**< Defined by the file system. */
   104 #define FCVAR_NOT_CONNECTED		(1<<22)	/**< Cvar cannot be changed by a client that is connected to a server. */
   105 #define FCVAR_SOUNDSYSTEM		(1<<23)	/**< Defined by the soundsystem library. */
   106 #define FCVAR_ARCHIVE_XBOX		(1<<24)	/**< Cvar written to config.cfg on the Xbox. */
   107 #define FCVAR_INPUTSYSTEM		(1<<25)	/**< Defined by the inputsystem DLL. */
   108 #define FCVAR_NETWORKSYSTEM		(1<<26)	/**< Defined by the network system. */
   109 #define FCVAR_VPHYSICS			(1<<27)	/**< Defined by vphysics. */
   110 
   111 /**
   112  * @endsection
   113  */
   114 
   115 /**
   116  * Executes a server command as if it were on the server console (or RCON)
   117  *
   118  * @param format		Formatting rules.
   119  * @param ...			Variable number of format parameters.
   120  * @noreturn
   121  */
   122 native ServerCommand(const String:format[], any:...);
   123 
   124 /**
   125  * Executes a server command as if it were on the server console (or RCON) 
   126  * and stores the printed text into buffer.
   127  *
   128  * Warning: This calls ServerExecute internally and may have issues if
   129  * certain commands are in the buffer, only use when you really need
   130  * the response.
   131  * Also, on L4D2 this will not print the command output to the server console.
   132  *
   133  * @param buffer		String to store command result into.
   134  * @param maxlen		Length of buffer.
   135  * @param format		Formatting rules.
   136  * @param ...			Variable number of format parameters.
   137  * @noreturn
   138  */
   139 native ServerCommandEx(String:buffer[], maxlen, const String:format[], any:...);
   140 
   141 /**
   142  * Inserts a server command at the beginning of the server command buffer.
   143  *
   144  * @param format		Formatting rules.
   145  * @param ...			Variable number of format parameters.
   146  * @noreturn
   147  */
   148 native InsertServerCommand(const String:format[], any:...);
   149 
   150 /**
   151  * Executes every command in the server's command buffer, rather than once per frame.
   152  *
   153  * @noreturn
   154  */
   155 native ServerExecute();
   156 
   157 /**
   158  * Executes a client command.  Note that this will not work on clients unless
   159  * they have cl_restrict_server_commands set to 0.
   160  *
   161  * @param client		Index of the client.
   162  * @param fmt			Format of the client command.
   163  * @param ...			Format parameters/
   164  * @noreturn
   165  * @error				Invalid client index, or client not connected.
   166  */
   167 native ClientCommand(client, const String:fmt[], any:...);
   168 
   169 /**
   170  * Executes a client command on the server without being networked.
   171  *
   172  * FakeClientCommand() overwrites the command tokenization buffer.  This can 
   173  * cause undesired effects because future calls to GetCmdArg* will return 
   174  * data from the FakeClientCommand(), not the parent command.  If you are in 
   175  * a hook where this matters (for example, a "say" hook), you should use 
   176  * FakeClientCommandEx() instead.
   177  *
   178  * @param client		Index of the client.
   179  * @param fmt			Format of the client command.
   180  * @param ...			Format parameters
   181  * @noreturn
   182  * @error				Invalid client index, or client not connected.
   183  */
   184 native FakeClientCommand(client, const String:fmt[], any:...);
   185 
   186 /**
   187  * Executes a client command on the server without being networked.  The 
   188  * execution of the client command is delayed by one frame to prevent any 
   189  * re-entrancy issues that might surface with FakeClientCommand().
   190  *
   191  * @param client		Index of the client.
   192  * @param fmt			Format of the client command.
   193  * @param ...			Format parameters
   194  * @noreturn
   195  * @error				Invalid client index, or client not connected.
   196  */
   197 native FakeClientCommandEx(client, const String:fmt[], any:...);
   198 
   199 /**
   200  * Sends a message to the server console.
   201  *
   202  * @param format		Formatting rules.
   203  * @param ...			Variable number of format parameters.
   204  * @noreturn
   205  */
   206 native PrintToServer(const String:format[], any:...);
   207 
   208 /**
   209  * Sends a message to a client's console.
   210  *
   211  * @param client		Client index.
   212  * @param format		Formatting rules.
   213  * @param ...			Variable number of format parameters.
   214  * @noreturn
   215  * @error				If the client is not connected an error will be thrown.
   216  */
   217 native PrintToConsole(client, const String:format[], any:...);
   218 
   219 /**
   220  * Reples to a message in a command.
   221  *
   222  * A client index of 0 will use PrintToServer().
   223  * If the command was from the console, PrintToConsole() is used.
   224  * If the command was from chat, PrintToChat() is used.
   225  *
   226  * @param client		Client index, or 0 for server.
   227  * @param format		Formatting rules.
   228  * @param ...			Variable number of format parameters.
   229  * @noreturn
   230  * @error				If the client is not connected or invalid.
   231  */
   232 native ReplyToCommand(client, const String:format[], any:...);
   233 
   234 /**
   235  * Returns the current reply source of a command.
   236  *
   237  * @return				ReplySource value.
   238  */
   239 native ReplySource:GetCmdReplySource();
   240 
   241 /**
   242  * Sets the current reply source of a command.
   243  *
   244  * Only use this if you know what you are doing.  You should save the old value
   245  * and restore it once you are done.
   246  *
   247  * @param source		New ReplySource value.
   248  * @return				Old ReplySource value.
   249  */
   250 native ReplySource:SetCmdReplySource(ReplySource:source);
   251 
   252 /**
   253  * Returns whether the current say hook is a chat trigger.
   254  *
   255  * This function is only meaningful inside say or say_team hooks.
   256  *
   257  * @return				True if a chat trigger, false otherwise.
   258  */
   259 native bool:IsChatTrigger();
   260 
   261 /**
   262  * Displays usage of an admin command to users depending on the 
   263  * setting of the sm_show_activity cvar.  All users receive a message 
   264  * in their chat text, except for the originating client, who receives 
   265  * the message based on the current ReplySource.
   266  *
   267  * @param client		Client index doing the action, or 0 for server.
   268  * @param tag			Tag to prepend to the message.
   269  * @param format		Formatting rules.
   270  * @param ...			Variable number of format parameters.
   271  * @noreturn
   272  * @error
   273  */
   274 native ShowActivity2(client, const String:tag[], const String:format[], any:...);
   275 
   276 /**
   277  * Displays usage of an admin command to users depending on the 
   278  * setting of the sm_show_activity cvar.  
   279  *
   280  * This version does not display a message to the originating client 
   281  * if used from chat triggers or menus.  If manual replies are used 
   282  * for these cases, then this function will suffice.  Otherwise, 
   283  * ShowActivity2() is slightly more useful.
   284  *
   285  * @param client		Client index doing the action, or 0 for server.
   286  * @param format		Formatting rules.
   287  * @param ...			Variable number of format parameters.
   288  * @noreturn
   289  * @error
   290  */
   291 native ShowActivity(client, const String:format[], any:...);
   292 
   293 /**
   294  * Same as ShowActivity(), except the tag parameter is used instead of
   295  * "[SM] " (note that you must supply any spacing).
   296  *
   297  * @param client		Client index doing the action, or 0 for server.
   298  * @param tag			Tag to display with.
   299  * @param format		Formatting rules.
   300  * @param ...			Variable number of format parameters.
   301  * @noreturn
   302  * @error
   303  */
   304 native ShowActivityEx(client, const String:tag[], const String:format[], any:...);
   305 
   306 /**
   307  * Given an originating client and a target client, returns the string 
   308  * that describes the originating client according to the sm_show_activity cvar.
   309  *
   310  * For example, "ADMIN", "PLAYER", or a player's name could be placed in this buffer.
   311  *
   312  * @param client        Originating client; may be 0 for server console.
   313  * @param target        Targeted client.
   314  * @param namebuf       Name buffer.
   315  * @param maxlength     Maximum size of the name buffer.
   316  * @return              True if activity should be shown.  False otherwise.  In either 
   317  *                      case, the name buffer is filled.  The return value can be used 
   318  *                      to broadcast a "safe" name to all players regardless of the 
   319  *                      sm_show_activity filters.
   320  * @error               Invalid client index or client not connected.
   321  */
   322 native FormatActivitySource(client, target, const String:namebuf[], maxlength);
   323 
   324 /**
   325  * Called when a server-only command is invoked.  
   326  *
   327  * @params args			Number of arguments that were in the argument string.
   328  * @return				An Action value.  Not handling the command
   329  *						means that Source will report it as "not found."
   330  */
   331 functag public Action:SrvCmd(args);
   332 
   333 /**
   334  * Creates a server-only console command, or hooks an already existing one.  
   335  *
   336  * Server commands are case sensitive.
   337  *
   338  * @param cmd			Name of the command to hook or create.
   339  * @param callback		A function to use as a callback for when the command is invoked.
   340  * @param description	Optional description to use for command creation.
   341  * @param flags			Optional flags to use for command creation.
   342  * @noreturn
   343  * @error				Command name is the same as an existing convar.
   344  */
   345 native RegServerCmd(const String:cmd[], SrvCmd:callback, const String:description[]="", flags=0);
   346 
   347 /**
   348  * Called when a generic console command is invoked.
   349  *
   350  * @param client		Index of the client, or 0 from the server.
   351  * @param args			Number of arguments that were in the argument string.
   352  * @return				An Action value.  Not handling the command
   353  *						means that Source will report it as "not found."
   354  */
   355 functag public Action:ConCmd(client, args);
   356 
   357 /**
   358  * Creates a console command, or hooks an already existing one.
   359  *
   360  * Console commands are case sensitive.  However, if the command already exists in the game, 
   361  * the a client may enter the command in any case.  SourceMod corrects for this automatically, 
   362  * and you should only hook the "real" version of the command.
   363  *
   364  * @param cmd			Name of the command to hook or create.
   365  * @param callback		A function to use as a callback for when the command is invoked.
   366  * @param description	Optional description to use for command creation.
   367  * @param flags			Optional flags to use for command creation.
   368  * @noreturn
   369  * @error				Command name is the same as an existing convar.
   370  */
   371 native RegConsoleCmd(const String:cmd[], ConCmd:callback, const String:description[]="", flags=0);
   372 
   373 /**
   374  * Creates a console command as an administrative command.  If the command does not exist,
   375  * it is created.  When this command is invoked, the access rights of the player are 
   376  * automatically checked before allowing it to continue.
   377  *
   378  * Admin commands are case sensitive from both the client and server.
   379  *
   380  * @param cmd			String containing command to register.
   381  * @param callback		A function to use as a callback for when the command is invoked.
   382  * @param adminflags	Administrative flags (bitstring) to use for permissions.
   383  * @param description	Optional description to use for help.
   384  * @param group			String containing the command group to use.  If empty,
   385  * 						the plugin's filename will be used instead.
   386  * @param flags			Optional console flags.
   387  * @noreturn
   388  * @error				Command name is the same as an existing convar.
   389  */
   390 native RegAdminCmd(const String:cmd[],
   391 					ConCmd:callback,
   392 					adminflags,
   393 					const String:description[]="",
   394 					const String:group[]="",
   395 					flags=0);
   396 					
   397 /**
   398  * Returns the number of arguments from the current console or server command.
   399  * @note Unlike the HL2 engine call, this does not include the command itself.
   400  *
   401  * @return				Number of arguments to the current command.
   402  */
   403 native GetCmdArgs();
   404 
   405 /**
   406  * Retrieves a command argument given its index, from the current console or 
   407  * server command.
   408  * @note Argument indexes start at 1; 0 retrieves the command name.
   409  *
   410  * @param argnum		Argument number to retrieve.
   411  * @param buffer		Buffer to use for storing the string.
   412  * @param maxlength		Maximum length of the buffer.
   413  * @return				Length of string written to buffer.
   414  */
   415 native GetCmdArg(argnum, String:buffer[], maxlength);
   416 
   417 /**
   418  * Retrieves the entire command argument string in one lump from the current 
   419  * console or server command.
   420  *
   421  * @param buffer		Buffer to use for storing the string.
   422  * @param maxlength		Maximum length of the buffer.
   423  * @return				Length of string written to buffer.
   424  */
   425 native GetCmdArgString(String:buffer[], maxlength);
   426 
   427 /**
   428  * Creates a new console variable.
   429  *
   430  * @param name			Name of new convar.
   431  * @param defaultValue	String containing the default value of new convar.
   432  * @param description	Optional description of the convar.
   433  * @param flags			Optional bitstring of flags determining how the convar should be handled. See FCVAR_* constants for more details.
   434  * @param hasMin		Optional boolean that determines if the convar has a minimum value.
   435  * @param min			Minimum floating point value that the convar can have if hasMin is true.
   436  * @param hasMax		Optional boolean that determines if the convar has a maximum value.
   437  * @param max			Maximum floating point value that the convar can have if hasMax is true.
   438  * @return				A handle to the newly created convar. If the convar already exists, a handle to it will still be returned.
   439  * @error				Convar name is blank or is the same as an existing console command.
   440  */
   441 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);
   442 
   443 /**
   444  * Searches for a console variable.
   445  *
   446  * @param name			Name of convar to find.
   447  * @return				A handle to the convar if it is found. INVALID_HANDLE otherwise.
   448  */
   449 native Handle:FindConVar(const String:name[]);
   450 
   451 /**
   452  * Called when a console variable's value is changed.
   453  *
   454  * @param convar		Handle to the convar that was changed.
   455  * @param oldValue		String containing the value of the convar before it was changed.
   456  * @param newValue		String containing the new value of the convar.
   457  * @noreturn
   458  */
   459 functag public ConVarChanged(Handle:convar, const String:oldValue[], const String:newValue[]);
   460 
   461 /**
   462  * Creates a hook for when a console variable's value is changed.
   463  *
   464  * @param convar		Handle to the convar.
   465  * @param callback		An OnConVarChanged function pointer.
   466  * @noreturn
   467  * @error				Invalid or corrupt Handle or invalid callback function.
   468  */
   469 native HookConVarChange(Handle:convar, ConVarChanged:callback);
   470 
   471 /**
   472  * Removes a hook for when a console variable's value is changed.
   473  *
   474  * @param convar		Handle to the convar.
   475  * @param callback		An OnConVarChanged function pointer.
   476  * @noreturn
   477  * @error				Invalid or corrupt Handle, invalid callback function, or no active hook on convar.
   478  */
   479 native UnhookConVarChange(Handle:convar, ConVarChanged:callback);
   480 
   481 /**
   482  * Returns the boolean value of a console variable.
   483  *
   484  * @param convar		Handle to the convar.
   485  * @return				The boolean value of the convar.
   486  * @error				Invalid or corrupt Handle.
   487  */
   488 native bool:GetConVarBool(Handle:convar);
   489 
   490 /**
   491  * Sets the boolean value of a console variable.
   492  *
   493  * Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
   494  * Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
   495  *
   496  * @param convar		Handle to the convar.
   497  * @param value			New boolean value.
   498  * @param replicate		If set to true, the new convar value will be set on all clients.
   499  *						This will only work if the convar has the FCVAR_REPLICATED flag
   500  *						and actually exists on clients.
   501  * @param notify		If set to true, clients will be notified that the convar has changed.
   502  *						This will only work if the convar has the FCVAR_NOTIFY flag.
   503  * @noreturn
   504  * @error				Invalid or corrupt Handle.
   505  */
   506 native SetConVarBool(Handle:convar, bool:value, bool:replicate=false, bool:notify=false);
   507 
   508 /**
   509  * Returns the integer value of a console variable.
   510  *
   511  * @param convar		Handle to the convar.
   512  * @return				The integer value of the convar.
   513  * @error				Invalid or corrupt Handle.
   514  */
   515 native GetConVarInt(Handle:convar);
   516 
   517 /**
   518  * Sets the integer value of a console variable.
   519  *
   520  * Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
   521  * Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
   522  *
   523  * @param convar		Handle to the convar.
   524  * @param value			New integer value.
   525  * @param replicate		If set to true, the new convar value will be set on all clients.
   526  *						This will only work if the convar has the FCVAR_REPLICATED flag
   527  *						and actually exists on clients.
   528  * @param notify		If set to true, clients will be notified that the convar has changed.
   529  *						This will only work if the convar has the FCVAR_NOTIFY flag.
   530  * @noreturn
   531  * @error				Invalid or corrupt Handle.
   532  */
   533 native SetConVarInt(Handle:convar, value, bool:replicate=false, bool:notify=false);
   534 
   535 /**
   536  * Returns the floating point value of a console variable.
   537  *
   538  * @param convar		Handle to the convar.
   539  * @return				The floating point value of the convar.
   540  * @error				Invalid or corrupt Handle.
   541  */
   542 native Float:GetConVarFloat(Handle:convar);
   543 
   544 /**
   545  * Sets the floating point value of a console variable.
   546  *
   547  * Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
   548  * Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
   549  *
   550  * @param convar		Handle to the convar.
   551  * @param value			New floating point value.
   552  * @param replicate		If set to true, the new convar value will be set on all clients.
   553  *						This will only work if the convar has the FCVAR_REPLICATED flag
   554  *						and actually exists on clients.
   555  * @param notify		If set to true, clients will be notified that the convar has changed.
   556  *						This will only work if the convar has the FCVAR_NOTIFY flag.
   557  * @noreturn
   558  * @error				Invalid or corrupt Handle.
   559  */
   560 native SetConVarFloat(Handle:convar, Float:value, bool:replicate=false, bool:notify=false);
   561 
   562 /**
   563  * Retrieves the string value of a console variable.
   564  *
   565  * @param convar		Handle to the convar.
   566  * @param value			Buffer to store the value of the convar.
   567  * @param maxlength		Maximum length of string buffer.
   568  * @noreturn
   569  * @error				Invalid or corrupt Handle.     
   570  */
   571 native GetConVarString(Handle:convar, String:value[], maxlength);
   572 
   573 /**
   574  * Sets the string value of a console variable.
   575  *
   576  * Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
   577  * Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
   578  *
   579  * @param convar		Handle to the convar.
   580  * @param value			New string value.
   581  * @param replicate		If set to true, the new convar value will be set on all clients.
   582  *						This will only work if the convar has the FCVAR_REPLICATED flag
   583  *						and actually exists on clients.
   584  * @param notify		If set to true, clients will be notified that the convar has changed.
   585  *						This will only work if the convar has the FCVAR_NOTIFY flag.
   586  * @noreturn
   587  * @error				Invalid or corrupt Handle.
   588  */
   589 native SetConVarString(Handle:convar, const String:value[], bool:replicate=false, bool:notify=false);
   590 
   591 /**
   592  * Resets the console variable to its default value.
   593  *
   594  * Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
   595  * Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
   596  *
   597  * @param convar		Handle to the convar.
   598  * @param replicate		If set to true, the new convar value will be set on all clients.
   599  *						This will only work if the convar has the FCVAR_REPLICATED flag
   600  *						and actually exists on clients.
   601  * @param notify		If set to true, clients will be notified that the convar has changed.
   602  *						This will only work if the convar has the FCVAR_NOTIFY flag.
   603  * @noreturn
   604  * @error				Invalid or corrupt Handle.
   605  */
   606 native ResetConVar(Handle:convar, bool:replicate=false, bool:notify=false);
   607 
   608 /**
   609  * Retrieves the default string value of a console variable.
   610  *
   611  * @param convar		Handle to the convar.
   612  * @param value			Buffer to store the default value of the convar.
   613  * @param maxlength		Maximum length of string buffer.
   614  * @return				Number of bytes written to the buffer (UTF-8 safe).
   615  * @error				Invalid or corrupt Handle.
   616  */
   617 native GetConVarDefault(Handle:convar, String:value[], maxlength);
   618 
   619 /**
   620  * Returns the bitstring of flags on a console variable.
   621  *
   622  * @param convar		Handle to the convar.
   623  * @return				A bitstring containing the FCVAR_* flags that are enabled.
   624  * @error				Invalid or corrupt Handle.
   625  */
   626 native GetConVarFlags(Handle:convar);
   627 
   628 /**
   629  * Sets the bitstring of flags on a console variable.
   630  *
   631  * @param convar		Handle to the convar.
   632  * @param flags			A bitstring containing the FCVAR_* flags to enable.
   633  * @noreturn
   634  * @error				Invalid or corrupt Handle.
   635  */
   636 native SetConVarFlags(Handle:convar, flags);
   637 
   638 /**
   639  * Retrieves the specified bound of a console variable.
   640  *
   641  * @param convar		Handle to the convar.
   642  * @param type			Type of bound to retrieve, ConVarBound_Lower or ConVarBound_Upper.
   643  * @param value			By-reference cell to store the specified floating point bound value.
   644  * @return				True if the convar has the specified bound set, false otherwise.
   645  * @error				Invalid or corrupt Handle.
   646  */
   647 native bool:GetConVarBounds(Handle:convar, ConVarBounds:type, &Float:value);
   648 
   649 /**
   650  * Sets the specified bound of a console variable.
   651  *
   652  * @param convar		Handle to the convar.
   653  * @param type			Type of bound to set, ConVarBound_Lower or ConVarBound_Upper
   654  * @param set			If set to true, convar will use specified bound. If false, bound will be removed.
   655  * @param value			Floating point value to use as the specified bound.
   656  * @noreturn
   657  * @error				Invalid or corrupt Handle.
   658  */
   659 native SetConVarBounds(Handle:convar, ConVarBounds:type, bool:set, Float:value=0.0);
   660 
   661 /**
   662  * Retrieves the name of a console variable.
   663  *
   664  * @param convar		Handle to the convar.
   665  * @param name			Buffer to store the name of the convar.
   666  * @param maxlength		Maximum length of string buffer.
   667  * @noreturn
   668  * @error				Invalid or corrupt Handle.     
   669  */
   670 native GetConVarName(Handle:convar, String:name[], maxlength);
   671 
   672 funcenum ConVarQueryFinished
   673 {	
   674 	/**
   675 	 * Called when a query to retrieve a client's console variable has finished.
   676 	 *
   677 	 * @param cookie		Unique identifier of query.
   678 	 * @param client		Player index.
   679 	 * @param result		Result of query that tells one whether or not query was successful.
   680 	 *						See ConVarQueryResult enum for more details.
   681 	 * @param convarName	Name of client convar that was queried.
   682 	 * @param convarValue	Value of client convar that was queried if successful. This will be "" if it was not.
   683 	 * @param value			Value that was passed when query was started.
   684 	 * @noreturn
   685 	 */
   686 	public(QueryCookie:cookie, client, ConVarQueryResult:result, const String:cvarName[], const String:cvarValue[], any:value),
   687 	
   688 	/**
   689 	 * Called when a query to retrieve a client's console variable has finished.
   690 	 *
   691 	 * @param cookie		Unique identifier of query.
   692 	 * @param client		Player index.
   693 	 * @param result		Result of query that tells one whether or not query was successful.
   694 	 *						See ConVarQueryResult enum for more details.
   695 	 * @param convarName	Name of client convar that was queried.
   696 	 * @param convarValue	Value of client convar that was queried if successful. This will be "" if it was not.
   697 	 * @noreturn
   698 	 */
   699 	public(QueryCookie:cookie, client, ConVarQueryResult:result, const String:cvarName[], const String:cvarValue[])
   700 };
   701 
   702 /**
   703  * Starts a query to retrieve the value of a client's console variable.
   704  *
   705  * @param client		Player index.
   706  * @param name			Name of client convar to query.
   707  * @param callback		A function to use as a callback when the query has finished.
   708  * @param value			Optional value to pass to the callback function.
   709  * @return				A cookie that uniquely identifies the query. 
   710  *						Returns QUERYCOOKIE_FAILED on failure, such as when used on a bot.
   711  */
   712 native QueryCookie:QueryClientConVar(client, const String:cvarName[], ConVarQueryFinished:callback, any:value=0);
   713 
   714 /**
   715  * Gets a command iterator.  Must be freed with CloseHandle().
   716  *
   717  * @return				A new command iterator.
   718  */
   719 native Handle:GetCommandIterator();
   720 
   721 /**
   722  * Reads a command iterator, then advances to the next command if any.
   723  * Only SourceMod specific commands are returned.
   724  *
   725  * @param iter			Command iterator Handle.
   726  * @param name			Name buffer.
   727  * @param nameLen		Name buffer size.
   728  * @param eflags		Effective default flags of a command.
   729  * @param desc			Command description buffer.
   730  * @param descLen		Command description buffer size.
   731  * @return				True on success, false if there are no more commands.
   732  */
   733 native bool:ReadCommandIterator(Handle:iter, 
   734 								String:name[], 
   735 								nameLen, 
   736 								&eflags=0, 
   737 								String:desc[]="", 
   738 								descLen=0);
   739 
   740 /**
   741  * Returns whether a client has access to a given command string.  The string 
   742  * can be any override string, as overrides can be independent of 
   743  * commands.  This feature essentially allows you to create custom 
   744  * flags using the override system.
   745  *
   746  * @param client		Client index.
   747  * @param command		Command name.  If the command is not found, the default 
   748  *						flags are used.
   749  * @param flags			Flag string to use as a default, if the command or override 
   750  *						is not found.
   751  * @param override_only	If true, SourceMod will not attempt to find a matching 
   752  *						command, and it will only use the default flags specified.
   753  *						Otherwise, SourceMod will ignore the default flags if 
   754  *						there is a matching admin command.
   755  * @return				True if the client has access, false otherwise.
   756  */
   757 native bool:CheckCommandAccess(client, 
   758 							   const String:command[],
   759 							   flags,
   760 							   bool:override_only=false);
   761 
   762 /**
   763  * Returns whether an admin has access to a given command string.  The string 
   764  * can be any override string, as overrides can be independent of 
   765  * commands.  This feature essentially allows you to create custom flags
   766  * using the override system.
   767  *
   768  * @param id			AdminId of the admin.
   769  * @param command		Command name.  If the command is not found, the default 
   770  *						flags are used.
   771  * @param flags			Flag string to use as a default, if the command or override 
   772  *						is not found.
   773  * @param override_only	If true, SourceMod will not attempt to find a matching 
   774  *						command, and it will only use the default flags specified.
   775  *						Otherwise, SourceMod will ignore the default flags if 
   776  *						there is a matching admin command.
   777  * @return				True if the admin has access, false otherwise.
   778  */
   779 native bool:CheckAccess(AdminId:id, 
   780 							   const String:command[],
   781 							   flags,
   782 							   bool:override_only=false);
   783 
   784 /**
   785  * Returns true if the supplied character is valid in a ConVar name.
   786  *
   787  * @param c			Character to validate.
   788  * @return			True is valid for ConVars, false otherwise
   789  */
   790 stock bool:IsValidConVarChar(c)
   791 {
   792 	return (c == '_' || IsCharAlpha(c) || IsCharNumeric(c));
   793 }
   794 
   795 /**
   796  * Returns the bitstring of flags of a command.
   797  *
   798  * @param name		Name of the command.
   799  * @return			A bitstring containing the FCVAR_* flags that are enabled 
   800  *					or INVALID_FCVAR_FLAGS if command not found.
   801  */
   802 native GetCommandFlags(const String:name[]);
   803 
   804 /**
   805  * Sets the bitstring of flags of a command.
   806  *
   807  * @param name		Name of the command.
   808  * @param flags		A bitstring containing the FCVAR_* flags to enable.
   809  * @return			True on success, otherwise false.
   810  */
   811 native bool:SetCommandFlags(const String:name[], flags);
   812 
   813 /**
   814  * Starts a ConCommandBase search, traversing the list of ConVars and 
   815  * ConCommands.  If a Handle is returned, the next entry must be read 
   816  * via FindNextConCommand().  The order of the list is undefined.
   817  *
   818  * @param buffer		Buffer to store entry name.
   819  * @param max_size		Maximum size of the buffer.
   820  * @param isCommand		Variable to store whether the entry is a command. 
   821  *						If it is not a command, it is a ConVar.
   822  * @param flags			Variable to store entry flags.
   823  * @param description		Buffer to store the description, empty if no description present.
   824  * @param descrmax_size		Maximum size of the description buffer.
   825  * @return				On success, a ConCmdIter Handle is returned, which 
   826  *						can be read via FindNextConCommand(), and must be 
   827  *						closed via CloseHandle().  Additionally, the output 
   828  *						parameters will be filled with information of the 
   829  *						first ConCommandBase entry.
   830  *						On failure, INVALID_HANDLE is returned, and the 
   831  *						contents of outputs is undefined.
   832  */
   833 native Handle:FindFirstConCommand(String:buffer[], max_size, &bool:isCommand, &flags=0, String:description[]="", descrmax_size=0);
   834 
   835 /**
   836  * Reads the next entry in a ConCommandBase iterator.
   837  *
   838  * @param search		ConCmdIter Handle to search.
   839  * @param buffer		Buffer to store entry name.
   840  * @param max_size		Maximum size of the buffer.
   841  * @param isCommand		Variable to store whether the entry is a command.
   842  *						If it is not a command, it is a ConVar.
   843  * @param flags			Variable to store entry flags.
   844  * @param description		Buffer to store the description, empty if no description present.
   845  * @param descrmax_size		Maximum size of the description buffer.
   846  * @return				On success, the outputs are filled, the iterator is 
   847  *						advanced to the next entry, and true is returned.  
   848  *						If no more entries exist, false is returned, and the 
   849  *						contents of outputs is undefined.
   850  */
   851 native bool:FindNextConCommand(Handle:search, String:buffer[], max_size, &bool:isCommand, &flags=0, String:description[]="", descrmax_size=0);
   852 
   853 /**
   854  * Replicates a convar value to a specific client. This does not change the actual convar value.
   855  *
   856  * @param client		Client index
   857  * @param convar		ConVar handle
   858  * @param value			String value to send
   859  * @return				True on success, false on failure
   860  * @error 				Invalid client index, client not in game, or client is fake
   861  */
   862 native bool:SendConVarValue(client, Handle:convar, const String:value[]);
   863 
   864 /**
   865  * Adds an informational string to the server's public "tags".
   866  * This string should be a short, unique identifier.
   867  *
   868  * Note: Tags are automatically removed when a plugin unloads.
   869  * Note: Currently, this function does nothing because of bugs in the Valve master.
   870  *
   871  * @param tag			Tag string to append.
   872  * @noreturn
   873  */
   874 native AddServerTag(const String:tag[]);
   875 
   876 /**
   877  * Removes a tag previously added by the calling plugin.
   878  *
   879  * @param tag			Tag string to remove.
   880  * @noreturn
   881  */
   882 native RemoveServerTag(const String:tag[]);
   883 
   884 /**
   885  * Callback for command listeners. This is invoked whenever any command
   886  * reaches the server, from the server console itself or a player.
   887  *
   888  * Clients may be in the process of connecting when they are executing commands
   889  * IsClientConnected(client) is not guaranteed to return true.  Other functions
   890  * such as GetClientIP() may not work at this point either.
   891  *
   892  * Returning Plugin_Handled or Plugin_Stop will prevent the original,
   893  * baseline code from running.
   894  *
   895  * -- TEXT BELOW IS IMPLEMENTATION, AND NOT GUARANTEED --
   896  * Even if returning Plugin_Handled or Plugin_Stop, some callbacks will still
   897  * trigger. These are:
   898  *  * C++ command dispatch hooks from Metamod:Source plugins
   899  *  * Reg*Cmd() hooks that did not create new commands.
   900  *
   901  * @param client        Client, or 0 for server.
   902  *                      Client may not be connected or in game.
   903  * @param command       Command name, lower case. To get name as typed, use
   904  *                      GetCmdArg() and specify argument 0.
   905  * @param argc          Argument count.
   906  * @return				Action to take (see extended notes above).
   907  */
   908 functag public Action:CommandListener(client, const String:command[], argc);
   909 
   910 #define FEATURECAP_COMMANDLISTENER  "command listener"
   911 
   912 /**
   913  * Adds a callback that will fire when a command is sent to the server.
   914  *
   915  * Registering commands is designed to create a new command as part of the UI,
   916  * whereas this is a lightweight hook on a command string, existing or not.
   917  * Using Reg*Cmd to intercept is in poor practice, as it physically creates a
   918  * new command and can slow down dispatch in general.
   919  *
   920  * To see if this feature is available, use FeatureType_Capability and 
   921  * FEATURECAP_COMMANDLISTENER.
   922  *
   923  * @param callback      Callback.
   924  * @param command		Command, or if not specified, a global listener.
   925  *                      The command is case insensitive.
   926  * @return              True if this feature is available on the current game,
   927  *                      false otherwise.
   928  */
   929 native bool:AddCommandListener(CommandListener:callback, const String:command[]="");
   930 
   931 /**
   932  * Removes a previously added command listener, in reverse order of being added.
   933  *
   934  * @param callback		Callback.
   935  * @param command		Command, or if not specified, a global listener.
   936  *                      The command is case insensitive.
   937  * @error				Callback has no active listeners.
   938  */
   939 native RemoveCommandListener(CommandListener:callback, const String:command[]="");
   940