Add C++ definitions.

This commit is contained in:
David Anderson 2014-11-09 15:39:13 -08:00
parent 9886eea487
commit 65dfd3cdd1
2 changed files with 266 additions and 64 deletions

View File

@ -1182,28 +1182,19 @@ static cell_t SendConVarValue(IPluginContext *pContext, const cell_t *params)
CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]); CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
if (!pPlayer) if (!pPlayer)
{
return pContext->ThrowNativeError("Client index %d is invalid", params[1]); return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
}
if (!pPlayer->IsConnected()) if (!pPlayer->IsConnected())
{
return pContext->ThrowNativeError("Client %d is not connected", params[1]); return pContext->ThrowNativeError("Client %d is not connected", params[1]);
}
if (pPlayer->IsFakeClient()) if (pPlayer->IsFakeClient())
{
return pContext->ThrowNativeError("Client %d is fake and cannot be targeted", params[1]); return pContext->ThrowNativeError("Client %d is fake and cannot be targeted", params[1]);
}
INetChannel *netchan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(params[1])); INetChannel *netchan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(params[1]));
if (netchan == NULL) if (netchan == NULL)
{
return 0; return 0;
}
netchan->SendData(buffer); netchan->SendData(buffer);
return 1; return 1;
} }
@ -1247,6 +1238,59 @@ static cell_t RemoveCommandListener(IPluginContext *pContext, const cell_t *para
return 1; return 1;
} }
static cell_t ConVar_BoolValue_set(IPluginContext *pContext, const cell_t *params)
{
static cell_t new_params[5] = {
4,
params[1],
params[2],
0, /* Default replicate setting. */
0, /* Default replicate setting. */
};
return sm_SetConVarNum(pContext, new_params);
}
static cell_t ConVar_IntValue_set(IPluginContext *pContext, const cell_t *params)
{
static cell_t new_params[5] = {
4,
params[1],
params[2],
0, /* Default replicate setting. */
0, /* Default replicate setting. */
};
return sm_SetConVarNum(pContext, new_params);
}
static cell_t ConVar_FloatValue_set(IPluginContext *pContext, const cell_t *params)
{
static cell_t new_params[5] = {
4,
params[1],
params[2],
0, /* Default replicate setting. */
0, /* Default replicate setting. */
};
return sm_SetConVarFloat(pContext, new_params);
}
static cell_t ConVar_ReplicateToClient(IPluginContext *pContext, const cell_t *params)
{
// Old version is (client, handle, value).
// New version is (handle, client, value).
static cell_t new_params[4] = {
3,
params[2],
params[1],
params[3],
};
return SendConVarValue(pContext, new_params);
}
REGISTER_NATIVES(consoleNatives) REGISTER_NATIVES(consoleNatives)
{ {
{"CreateConVar", sm_CreateConVar}, {"CreateConVar", sm_CreateConVar},
@ -1287,5 +1331,29 @@ REGISTER_NATIVES(consoleNatives)
{"SendConVarValue", SendConVarValue}, {"SendConVarValue", SendConVarValue},
{"AddCommandListener", AddCommandListener}, {"AddCommandListener", AddCommandListener},
{"RemoveCommandListener", RemoveCommandListener}, {"RemoveCommandListener", RemoveCommandListener},
// Transitional syntax support.
{"ConVar.BoolValue.get", sm_GetConVarBool},
{"ConVar.BoolValue.set", ConVar_BoolValue_set},
{"ConVar.FloatValue.get", sm_GetConVarFloat},
{"ConVar.FloatValue.set", ConVar_FloatValue_set},
{"ConVar.IntValue.get", sm_GetConVarInt},
{"ConVar.IntValue.set", ConVar_IntValue_set},
{"ConVar.Flags.get", sm_GetConVarFlags},
{"ConVar.Flags.set", sm_SetConVarFlags},
{"ConVar.SetBool", sm_SetConVarNum},
{"ConVar.SetInt", sm_SetConVarNum},
{"ConVar.SetFloat", sm_SetConVarFloat},
{"ConVar.GetString", sm_GetConVarString},
{"ConVar.SetString", sm_SetConVarString},
{"ConVar.RestoreDefault", sm_ResetConVar},
{"ConVar.GetDefault", GetConVarDefault},
{"ConVar.GetBounds", sm_GetConVarBounds},
{"ConVar.SetBounds", sm_SetConVarBounds},
{"ConVar.GetName", sm_GetConVarName},
{"ConVar.ReplicateToClient", ConVar_ReplicateToClient},
{"ConVar.AddChangeHook", sm_HookConVarChange},
{"ConVar.RemoveChangeHook", sm_UnhookConVarChange},
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -44,12 +44,19 @@ enum ConVarBounds
*/ */
enum ConVarQueryResult enum ConVarQueryResult
{ {
ConVarQuery_Okay = 0, /**< Retrieval of client convar value was successful. */ ConVarQuery_Okay = 0, //< Retrieval of client convar value was successful. */
ConVarQuery_NotFound, /**< Client convar was not found. */ ConVarQuery_NotFound, //< Client convar was not found. */
ConVarQuery_NotValid, /**< A console command with the same name was found, but there is no convar. */ 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. */ 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. // Creates a new console variable.
// //
// @param name Name of new convar. // @param name Name of new convar.
@ -76,20 +83,156 @@ native ConVar CreateConVar(
// @return A ConVar object if found; null otherwise. // @return A ConVar object if found; null otherwise.
native ConVar FindConVar(const char[] name); native ConVar FindConVar(const char[] name);
// A ConVar is a configurable, named setting in the srcds console.
// Most of these aren't properties because they're more complex
methodmap ConVar < Handle 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.
* Called when a console variable's value is changed. property int IntValue {
* public native get();
* @param convar Handle to the convar that was changed. public native set(int value);
* @param oldValue String containing the value of the convar before it was changed. }
* @param newValue String containing the new value of the convar.
*/ // Retrieves or sets a float value for the convar.
typedef ConVarChanged = function void (ConVar convar, const char[] oldValue, const char[] newValue); 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. * Creates a hook for when a console variable's value is changed.
@ -142,7 +285,7 @@ native void SetConVarBool(Handle convar, bool value, bool replicate=false, bool
* @return The integer value of the convar. * @return The integer value of the convar.
* @error Invalid or corrupt Handle. * @error Invalid or corrupt Handle.
*/ */
native GetConVarInt(Handle convar); native int GetConVarInt(Handle convar);
/** /**
* Sets the integer value of a console variable. * Sets the integer value of a console variable.
@ -255,10 +398,9 @@ native int GetConVarFlags(Handle convar);
* *
* @param convar Handle to the convar. * @param convar Handle to the convar.
* @param flags A bitstring containing the FCVAR_* flags to enable. * @param flags A bitstring containing the FCVAR_* flags to enable.
* @noreturn
* @error Invalid or corrupt Handle. * @error Invalid or corrupt Handle.
*/ */
native SetConVarFlags(Handle convar, flags); native void SetConVarFlags(Handle convar, flags);
/** /**
* Retrieves the specified bound of a console variable. * Retrieves the specified bound of a console variable.
@ -288,38 +430,42 @@ native void SetConVarBounds(Handle convar, ConVarBounds type, bool set, float va
* @param convar Handle to the convar. * @param convar Handle to the convar.
* @param name Buffer to store the name of the convar. * @param name Buffer to store the name of the convar.
* @param maxlength Maximum length of string buffer. * @param maxlength Maximum length of string buffer.
* @noreturn
* @error Invalid or corrupt Handle. * @error Invalid or corrupt Handle.
*/ */
native GetConVarName(Handle convar, char[] name, maxlength); 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 union ConVarQueryFinished
{ {
/** // Called when a query to retrieve a client's console variable has finished.
* Called when a query to retrieve a client's console variable has finished. //
* // @param cookie Unique identifier of query.
* @param cookie Unique identifier of query. // @param client Player index.
* @param client Player index. // @param result Result of query that tells one whether or not query was successful.
* @param result Result of query that tells one whether or not query was successful. // See ConVarQueryResult enum for more details.
* See ConVarQueryResult enum for more details. // @param convarName Name of client convar that was queried.
* @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 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.
* @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); 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.
* Called when a query to retrieve a client's console variable has finished. //
* // @param cookie Unique identifier of query.
* @param cookie Unique identifier of query. // @param client Player index.
* @param client Player index. // @param result Result of query that tells one whether or not query was successful.
* @param result Result of query that tells one whether or not query was successful. // See ConVarQueryResult enum for more details.
* See ConVarQueryResult enum for more details. // @param convarName Name of client convar that was queried.
* @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 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); function void (QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue);
}; };
@ -345,15 +491,3 @@ stock bool IsValidConVarChar(int c)
{ {
return (c == '_' || IsCharAlpha(c) || IsCharNumeric(c)); return (c == '_' || IsCharAlpha(c) || IsCharNumeric(c));
} }
/**
* 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);