Merge pull request #199 from alliedmodders/tr-convars

Port ConVars to transitional syntax.
This commit is contained in:
David Anderson
2014-11-19 22:38:56 -08:00
23 changed files with 883 additions and 670 deletions
-352
View File
@@ -37,15 +37,6 @@
#define INVALID_FCVAR_FLAGS (-1)
/**
* Console variable bound values used with Get/SetConVarBounds()
*/
enum ConVarBounds
{
ConVarBound_Upper = 0,
ConVarBound_Lower
};
/**
* Console variable query helper values.
*/
@@ -63,17 +54,6 @@ enum ReplySource
SM_REPLY_TO_CHAT = 1,
};
/**
* Console variable query result values.
*/
enum ConVarQueryResult
{
ConVarQuery_Okay = 0, /**< Retrieval of client convar value was successful. */
ConVarQuery_NotFound, /**< Client convar was not found. */
ConVarQuery_NotValid, /**< A console command with the same name was found, but there is no convar. */
ConVarQuery_Protected /**< Client convar was found, but it is protected. The server cannot retrieve its value. */
};
/**
* @section Flags for console commands and console variables. The descriptions
* for each constant come directly from the Source SDK.
@@ -424,293 +404,6 @@ native GetCmdArg(argnum, String:buffer[], maxlength);
*/
native GetCmdArgString(String:buffer[], maxlength);
/**
* Creates a new console variable.
*
* @param name Name of new convar.
* @param defaultValue String containing the default value of new convar.
* @param description Optional description of the convar.
* @param flags Optional bitstring of flags determining how the convar should be handled. See FCVAR_* constants for more details.
* @param hasMin Optional boolean that determines if the convar has a minimum value.
* @param min Minimum floating point value that the convar can have if hasMin is true.
* @param hasMax Optional boolean that determines if the convar has a maximum value.
* @param max Maximum floating point value that the convar can have if hasMax is true.
* @return A handle to the newly created convar. If the convar already exists, a handle to it will still be returned.
* @error Convar name is blank or is the same as an existing console command.
*/
native ConVar: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);
/**
* Searches for a console variable.
*
* @param name Name of convar to find.
* @return A handle to the convar if it is found. INVALID_HANDLE otherwise.
*/
native ConVar:FindConVar(const String:name[]);
/**
* Called when a console variable's value is changed.
*
* @param convar Handle to the convar that was changed.
* @param oldValue String containing the value of the convar before it was changed.
* @param newValue String containing the new value of the convar.
* @noreturn
*/
typedef ConVarChanged = function void (ConVar convar, const char[] oldValue, const char[] newValue);
/**
* Creates a hook for when a console variable's value is changed.
*
* @param convar Handle to the convar.
* @param callback An OnConVarChanged function pointer.
* @noreturn
* @error Invalid or corrupt Handle or invalid callback function.
*/
native HookConVarChange(Handle:convar, ConVarChanged:callback);
/**
* Removes a hook for when a console variable's value is changed.
*
* @param convar Handle to the convar.
* @param callback An OnConVarChanged function pointer.
* @noreturn
* @error Invalid or corrupt Handle, invalid callback function, or no active hook on convar.
*/
native UnhookConVarChange(Handle:convar, ConVarChanged:callback);
/**
* Returns the boolean value of a console variable.
*
* @param convar Handle to the convar.
* @return The boolean value of the convar.
* @error Invalid or corrupt Handle.
*/
native bool:GetConVarBool(Handle:convar);
/**
* Sets the boolean value of a console variable.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param value New boolean value.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @noreturn
* @error Invalid or corrupt Handle.
*/
native SetConVarBool(Handle:convar, bool:value, bool:replicate=false, bool:notify=false);
/**
* Returns the integer value of a console variable.
*
* @param convar Handle to the convar.
* @return The integer value of the convar.
* @error Invalid or corrupt Handle.
*/
native GetConVarInt(Handle:convar);
/**
* Sets the integer value of a console variable.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param value New integer value.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @noreturn
* @error Invalid or corrupt Handle.
*/
native SetConVarInt(Handle:convar, value, bool:replicate=false, bool:notify=false);
/**
* Returns the floating point value of a console variable.
*
* @param convar Handle to the convar.
* @return The floating point value of the convar.
* @error Invalid or corrupt Handle.
*/
native Float:GetConVarFloat(Handle:convar);
/**
* Sets the floating point value of a console variable.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param value New floating point value.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @noreturn
* @error Invalid or corrupt Handle.
*/
native SetConVarFloat(Handle:convar, Float:value, bool:replicate=false, bool:notify=false);
/**
* Retrieves the string value of a console variable.
*
* @param convar Handle to the convar.
* @param value Buffer to store the value of the convar.
* @param maxlength Maximum length of string buffer.
* @noreturn
* @error Invalid or corrupt Handle.
*/
native GetConVarString(Handle:convar, String:value[], maxlength);
/**
* Sets the string value of a console variable.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param value New string value.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @noreturn
* @error Invalid or corrupt Handle.
*/
native SetConVarString(Handle:convar, const String:value[], bool:replicate=false, bool:notify=false);
/**
* Resets the console variable to its default value.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @noreturn
* @error Invalid or corrupt Handle.
*/
native ResetConVar(Handle:convar, bool:replicate=false, bool:notify=false);
/**
* Retrieves the default string value of a console variable.
*
* @param convar Handle to the convar.
* @param value Buffer to store the default value of the convar.
* @param maxlength Maximum length of string buffer.
* @return Number of bytes written to the buffer (UTF-8 safe).
* @error Invalid or corrupt Handle.
*/
native GetConVarDefault(Handle:convar, String:value[], maxlength);
/**
* Returns the bitstring of flags on a console variable.
*
* @param convar Handle to the convar.
* @return A bitstring containing the FCVAR_* flags that are enabled.
* @error Invalid or corrupt Handle.
*/
native GetConVarFlags(Handle:convar);
/**
* Sets the bitstring of flags on a console variable.
*
* @param convar Handle to the convar.
* @param flags A bitstring containing the FCVAR_* flags to enable.
* @noreturn
* @error Invalid or corrupt Handle.
*/
native SetConVarFlags(Handle:convar, flags);
/**
* Retrieves the specified bound of a console variable.
*
* @param convar Handle to the convar.
* @param type Type of bound to retrieve, ConVarBound_Lower or ConVarBound_Upper.
* @param value By-reference cell to store the specified floating point bound value.
* @return True if the convar has the specified bound set, false otherwise.
* @error Invalid or corrupt Handle.
*/
native bool:GetConVarBounds(Handle:convar, ConVarBounds:type, &Float:value);
/**
* Sets the specified bound of a console variable.
*
* @param convar Handle to the convar.
* @param type Type of bound to set, ConVarBound_Lower or ConVarBound_Upper
* @param set If set to true, convar will use specified bound. If false, bound will be removed.
* @param value Floating point value to use as the specified bound.
* @noreturn
* @error Invalid or corrupt Handle.
*/
native SetConVarBounds(Handle:convar, ConVarBounds:type, bool:set, Float:value=0.0);
/**
* Retrieves the name of a console variable.
*
* @param convar Handle to the convar.
* @param name Buffer to store the name of the convar.
* @param maxlength Maximum length of string buffer.
* @noreturn
* @error Invalid or corrupt Handle.
*/
native GetConVarName(Handle:convar, String:name[], maxlength);
union ConVarQueryFinished
{
/**
* Called when a query to retrieve a client's console variable has finished.
*
* @param cookie Unique identifier of query.
* @param client Player index.
* @param result Result of query that tells one whether or not query was successful.
* See ConVarQueryResult enum for more details.
* @param convarName Name of client convar that was queried.
* @param convarValue Value of client convar that was queried if successful. This will be "" if it was not.
* @param value Value that was passed when query was started.
* @noreturn
*/
function void (QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue, any value);
/**
* Called when a query to retrieve a client's console variable has finished.
*
* @param cookie Unique identifier of query.
* @param client Player index.
* @param result Result of query that tells one whether or not query was successful.
* See ConVarQueryResult enum for more details.
* @param convarName Name of client convar that was queried.
* @param convarValue Value of client convar that was queried if successful. This will be "" if it was not.
* @noreturn
*/
function void (QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue);
};
/**
* Starts a query to retrieve the value of a client's console variable.
*
* @param client Player index.
* @param cvarName Name of client convar to query.
* @param callback A function to use as a callback when the query has finished.
* @param value Optional value to pass to the callback function.
* @return A cookie that uniquely identifies the query.
* Returns QUERYCOOKIE_FAILED on failure, such as when used on a bot.
*/
native QueryCookie:QueryClientConVar(client, const String:cvarName[], ConVarQueryFinished:callback, any:value=0);
/**
* Gets a command iterator. Must be freed with CloseHandle().
*
@@ -781,17 +474,6 @@ native bool:CheckAccess(AdminId:id,
flags,
bool:override_only=false);
/**
* Returns true if the supplied character is valid in a ConVar name.
*
* @param c Character to validate.
* @return True is valid for ConVars, false otherwise
*/
stock bool:IsValidConVarChar(c)
{
return (c == '_' || IsCharAlpha(c) || IsCharNumeric(c));
}
/**
* Returns the bitstring of flags of a command.
*
@@ -850,17 +532,6 @@ native Handle:FindFirstConCommand(String:buffer[], max_size, &bool:isCommand, &f
*/
native bool:FindNextConCommand(Handle:search, String:buffer[], max_size, &bool:isCommand, &flags=0, String:description[]="", descrmax_size=0);
/**
* Replicates a convar value to a specific client. This does not change the actual convar value.
*
* @param client Client index
* @param convar ConVar handle
* @param value String value to send
* @return True on success, false on failure
* @error Invalid client index, client not in game, or client is fake
*/
native bool:SendConVarValue(client, Handle:convar, const String:value[]);
/**
* Adds an informational string to the server's public "tags".
* This string should be a short, unique identifier.
@@ -969,26 +640,3 @@ forward Action:OnClientSayCommand(client, const String:command[], const String:s
*
*/
forward void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs);
// Most of these aren't properties because they're more complex
methodmap ConVar < Handle
{
public ConVar() = CreateConVar;
public GetBool() = GetConVarBool;
public SetBool() = SetConVarBool;
public GetInt() = GetConVarInt;
public SetInt() = SetConVarInt;
public GetFloat() = GetConVarFloat;
public SetFloat() = SetConVarFloat;
public GetString() = GetConVarString;
public SetString() = SetConVarString;
public RestoreDefaultValue() = ResetConVar;
public GetFlags() = GetConVarFlags;
public SetFlags() = SetConVarFlags;
public GetBounds() = GetConVarBounds;
public SetBounds() = SetConVarBounds;
public GetDefaultValue() = GetConVarDefault;
public GetName() = GetConVarName;
public AddChangeHook() = HookConVarChange;
public RemoveChangeHook() = UnhookConVarChange;
}
+493
View File
@@ -0,0 +1,493 @@
/**
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod (C)2004-2014 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This file is part of the SourceMod/SourcePawn SDK.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
/**
* Console variable bound values used with Get/SetConVarBounds()
*/
enum ConVarBounds
{
ConVarBound_Upper = 0,
ConVarBound_Lower
};
/**
* Console variable query result values.
*/
enum ConVarQueryResult
{
ConVarQuery_Okay = 0, //< Retrieval of client convar value was successful. */
ConVarQuery_NotFound, //< Client convar was not found. */
ConVarQuery_NotValid, //< A console command with the same name was found, but there is no convar. */
ConVarQuery_Protected //< Client convar was found, but it is protected. The server cannot retrieve its value. */
};
// Called when a console variable's value is changed.
//
// @param convar Handle to the convar that was changed.
// @param oldValue String containing the value of the convar before it was changed.
// @param newValue String containing the new value of the convar.
typedef ConVarChanged = function void (ConVar convar, const char[] oldValue, const char[] newValue);
// Creates a new console variable.
//
// @param name Name of new convar.
// @param defaultValue String containing the default value of new convar.
// @param description Optional description of the convar.
// @param flags Optional bitstring of flags determining how the convar should be handled. See FCVAR_* constants for more details.
// @param hasMin Optional boolean that determines if the convar has a minimum value.
// @param min Minimum floating point value that the convar can have if hasMin is true.
// @param hasMax Optional boolean that determines if the convar has a maximum value.
// @param max Maximum floating point value that the convar can have if hasMax is true.
// @return A handle to the newly created convar. If the convar already exists, a handle to it will still be returned.
// @error Convar name is blank or is the same as an existing console command.
native ConVar CreateConVar(
const char[] name,
const char[] defaultValue,
const char[] description="",
int flags=0,
bool hasMin=false, float min=0.0,
bool hasMax=false, float max=0.0);
// Searches for a console variable.
//
// @param name Name of convar to find.
// @return A ConVar object if found; null otherwise.
native ConVar FindConVar(const char[] name);
// A ConVar is a configurable, named setting in the srcds console.
methodmap ConVar < Handle
{
// Retrieves or sets a boolean value for the convar.
property bool BoolValue {
public native get();
public native set(bool b);
}
// Retrieves or sets an integer value for the convar.
property int IntValue {
public native get();
public native set(int value);
}
// Retrieves or sets a float value for the convar.
property float FloatValue {
public native get();
public native set(float value);
}
// Gets or sets the flag bits (FCVAR_*) on the convar.
property int Flags {
public native get();
public native set(int flags);
}
// Sets the boolean value of a console variable.
//
// Note: The replicate and notify params are only relevant for the
// original, Dark Messiah, and Episode 1 engines. Newer engines
// automatically do these things when the convar value is changed.
//
// @param value New boolean value.
// @param replicate If set to true, the new convar value will be set on all clients.
// This will only work if the convar has the FCVAR_REPLICATED flag
// and actually exists on clients.
// @param notify If set to true, clients will be notified that the convar has changed.
// This will only work if the convar has the FCVAR_NOTIFY flag.
public native void SetBool(bool value, bool replicate=false, bool notify=false);
// Sets the integer value of a console variable.
//
// Note: The replicate and notify params are only relevant for the
// original, Dark Messiah, and Episode 1 engines. Newer engines
// automatically do these things when the convar value is changed.
//
// @param value New integer value.
// @param replicate If set to true, the new convar value will be set on all clients.
// This will only work if the convar has the FCVAR_REPLICATED flag
// and actually exists on clients.
// @param notify If set to true, clients will be notified that the convar has changed.
// This will only work if the convar has the FCVAR_NOTIFY flag.
public native void SetInt(int value, bool replicate=false, bool notify=false);
// Sets the floating point value of a console variable.
//
// Note: The replicate and notify params are only relevant for the
// original, Dark Messiah, and Episode 1 engines. Newer engines
// automatically do these things when the convar value is changed.
//
// @param value New floating point value.
// @param replicate If set to true, the new convar value will be set on all clients.
// This will only work if the convar has the FCVAR_REPLICATED flag
// and actually exists on clients.
// @param notify If set to true, clients will be notified that the convar has changed.
// This will only work if the convar has the FCVAR_NOTIFY flag.
public native void SetFloat(float value, bool replicate=false, bool notify=false);
// Retrieves the string value of a console variable.
//
// @param convar Handle to the convar.
// @param value Buffer to store the value of the convar.
// @param maxlength Maximum length of string buffer.
public native void GetString(char[] value, int maxlength);
// Sets the string value of a console variable.
//
// Note: The replicate and notify params are only relevant for the
// original, Dark Messiah, and Episode 1 engines. Newer engines
// automatically do these things when the convar value is changed.
//
// @param value New string value.
// @param replicate If set to true, the new convar value will be set on all clients.
// This will only work if the convar has the FCVAR_REPLICATED flag
// and actually exists on clients.
// @param notify If set to true, clients will be notified that the convar has changed.
// This will only work if the convar has the FCVAR_NOTIFY flag.
public native void SetString(const char[] value, bool replicate=false, bool notify=false);
// Resets the console variable to its default value.
//
// Note: The replicate and notify params are only relevant for the
// original, Dark Messiah, and Episode 1 engines. Newer engines
// automatically do these things when the convar value is changed.
//
// @param replicate If set to true, the new convar value will be set on all clients.
// This will only work if the convar has the FCVAR_REPLICATED flag
// and actually exists on clients.
// @param notify If set to true, clients will be notified that the convar has changed.
// This will only work if the convar has the FCVAR_NOTIFY flag.
public native void RestoreDefault(bool replicate=false, bool notify=false);
// Retrieves the default string value of a console variable.
//
// @param value Buffer to store the default value of the convar.
// @param maxlength Maximum length of string buffer.
// @return Number of bytes written to the buffer (UTF-8 safe).
public native int GetDefault(char[] value, int maxlength);
// Retrieves the specified bound of a console variable.
//
// @param type Type of bound to retrieve, ConVarBound_Lower or ConVarBound_Upper.
// @param value By-reference cell to store the specified floating point bound value.
// @return True if the convar has the specified bound set, false otherwise.
public native bool GetBounds(ConVarBounds type, float &value);
// Sets the specified bound of a console variable.
//
// @param type Type of bound to set, ConVarBound_Lower or ConVarBound_Upper
// @param set If set to true, convar will use specified bound. If false, bound will be removed.
// @param value Floating point value to use as the specified bound.
public native void SetBounds(ConVarBounds type, bool set, float value=0.0);
// Retrieves the name of a console variable.
//
// @param name Buffer to store the name of the convar.
// @param maxlength Maximum length of string buffer.
public native void GetName(char[] name, maxlength);
// Replicates a convar value to a specific client. This does not change the actual convar value.
//
// @param client Client index
// @param value String value to send
// @return True on success, false on failure
// @error Invalid client index, client not in game, or client is fake
public native bool ReplicateToClient(int client, const char[] value);
// Creates a hook for when a console variable's value is changed.
//
// @param callback An OnConVarChanged function pointer.
public native void AddChangeHook(ConVarChanged callback);
// Removes a hook for when a console variable's value is changed.
//
// @param convar Handle to the convar.
// @param callback An OnConVarChanged function pointer.
// @error No active hook on convar.
public native void RemoveChangeHook(ConVarChanged callback);
}
/**
* Creates a hook for when a console variable's value is changed.
*
* @param convar Handle to the convar.
* @param callback An OnConVarChanged function pointer.
* @error Invalid or corrupt Handle or invalid callback function.
*/
native void HookConVarChange(Handle convar, ConVarChanged callback);
/**
* Removes a hook for when a console variable's value is changed.
*
* @param convar Handle to the convar.
* @param callback An OnConVarChanged function pointer.
* @error Invalid or corrupt Handle, invalid callback function, or no active hook on convar.
*/
native void UnhookConVarChange(Handle convar, ConVarChanged callback);
/**
* Returns the boolean value of a console variable.
*
* @param convar Handle to the convar.
* @return The boolean value of the convar.
* @error Invalid or corrupt Handle.
*/
native bool GetConVarBool(Handle convar);
/**
* Sets the boolean value of a console variable.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param value New boolean value.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @error Invalid or corrupt Handle.
*/
native void SetConVarBool(Handle convar, bool value, bool replicate=false, bool notify=false);
/**
* Returns the integer value of a console variable.
*
* @param convar Handle to the convar.
* @return The integer value of the convar.
* @error Invalid or corrupt Handle.
*/
native int GetConVarInt(Handle convar);
/**
* Sets the integer value of a console variable.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param value New integer value.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @error Invalid or corrupt Handle.
*/
native void SetConVarInt(Handle convar, int value, bool replicate=false, bool notify=false);
/**
* Returns the floating point value of a console variable.
*
* @param convar Handle to the convar.
* @return The floating point value of the convar.
* @error Invalid or corrupt Handle.
*/
native float GetConVarFloat(Handle convar);
/**
* Sets the floating point value of a console variable.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param value New floating point value.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @error Invalid or corrupt Handle.
*/
native void SetConVarFloat(Handle convar, float value, bool replicate=false, bool notify=false);
/**
* Retrieves the string value of a console variable.
*
* @param convar Handle to the convar.
* @param value Buffer to store the value of the convar.
* @param maxlength Maximum length of string buffer.
* @error Invalid or corrupt Handle.
*/
native void GetConVarString(Handle convar, char[] value, int maxlength);
/**
* Sets the string value of a console variable.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param value New string value.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @error Invalid or corrupt Handle.
*/
native void SetConVarString(Handle convar, const char[] value, bool replicate=false, bool notify=false);
/**
* Resets the console variable to its default value.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @error Invalid or corrupt Handle.
*/
native void ResetConVar(Handle convar, bool replicate=false, bool notify=false);
/**
* Retrieves the default string value of a console variable.
*
* @param convar Handle to the convar.
* @param value Buffer to store the default value of the convar.
* @param maxlength Maximum length of string buffer.
* @return Number of bytes written to the buffer (UTF-8 safe).
* @error Invalid or corrupt Handle.
*/
native int GetConVarDefault(Handle convar, char[] value, int maxlength);
/**
* Returns the bitstring of flags on a console variable.
*
* @param convar Handle to the convar.
* @return A bitstring containing the FCVAR_* flags that are enabled.
* @error Invalid or corrupt Handle.
*/
native int GetConVarFlags(Handle convar);
/**
* Sets the bitstring of flags on a console variable.
*
* @param convar Handle to the convar.
* @param flags A bitstring containing the FCVAR_* flags to enable.
* @error Invalid or corrupt Handle.
*/
native void SetConVarFlags(Handle convar, flags);
/**
* Retrieves the specified bound of a console variable.
*
* @param convar Handle to the convar.
* @param type Type of bound to retrieve, ConVarBound_Lower or ConVarBound_Upper.
* @param value By-reference cell to store the specified floating point bound value.
* @return True if the convar has the specified bound set, false otherwise.
* @error Invalid or corrupt Handle.
*/
native bool GetConVarBounds(Handle convar, ConVarBounds type, float &value);
/**
* Sets the specified bound of a console variable.
*
* @param convar Handle to the convar.
* @param type Type of bound to set, ConVarBound_Lower or ConVarBound_Upper
* @param set If set to true, convar will use specified bound. If false, bound will be removed.
* @param value Floating point value to use as the specified bound.
* @error Invalid or corrupt Handle.
*/
native void SetConVarBounds(Handle convar, ConVarBounds type, bool set, float value=0.0);
/**
* Retrieves the name of a console variable.
*
* @param convar Handle to the convar.
* @param name Buffer to store the name of the convar.
* @param maxlength Maximum length of string buffer.
* @error Invalid or corrupt Handle.
*/
native void GetConVarName(Handle convar, char[] name, maxlength);
/**
* Replicates a convar value to a specific client. This does not change the actual convar value.
*
* @param client Client index
* @param convar ConVar handle
* @param value String value to send
* @return True on success, false on failure
* @error Invalid client index, client not in game, or client is fake
*/
native bool SendConVarValue(int client, Handle convar, const char[] value);
union ConVarQueryFinished
{
// Called when a query to retrieve a client's console variable has finished.
//
// @param cookie Unique identifier of query.
// @param client Player index.
// @param result Result of query that tells one whether or not query was successful.
// See ConVarQueryResult enum for more details.
// @param convarName Name of client convar that was queried.
// @param convarValue Value of client convar that was queried if successful. This will be "" if it was not.
// @param value Value that was passed when query was started.
function void (QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue, any value);
// Called when a query to retrieve a client's console variable has finished.
//
// @param cookie Unique identifier of query.
// @param client Player index.
// @param result Result of query that tells one whether or not query was successful.
// See ConVarQueryResult enum for more details.
// @param convarName Name of client convar that was queried.
// @param convarValue Value of client convar that was queried if successful. This will be "" if it was not.
function void (QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue);
};
/**
* Starts a query to retrieve the value of a client's console variable.
*
* @param client Player index.
* @param cvarName Name of client convar to query.
* @param callback A function to use as a callback when the query has finished.
* @param value Optional value to pass to the callback function.
* @return A cookie that uniquely identifies the query.
* Returns QUERYCOOKIE_FAILED on failure, such as when used on a bot.
*/
native QueryCookie QueryClientConVar(int client, const char[] cvarName, ConVarQueryFinished callback, any value=0);
/**
* Returns true if the supplied character is valid in a ConVar name.
*
* @param c Character to validate.
* @return True is valid for ConVars, false otherwise
*/
stock bool IsValidConVarChar(int c)
{
return (c == '_' || IsCharAlpha(c) || IsCharNumeric(c));
}
+1
View File
@@ -64,6 +64,7 @@ struct Plugin
#include <textparse>
#include <clients>
#include <console>
#include <convars>
#include <events>
#include <bitbuffer>
#include <protobuf>