Add Cookie methodmap (#1012)
This commit is contained in:
parent
4f3c3175e6
commit
352f078b07
@ -1104,7 +1104,7 @@ static cell_t smn_KvGetSectionSymbol(IPluginContext *pCtx, const cell_t *params)
|
|||||||
static cell_t KeyValues_Import(IPluginContext *pContext, const cell_t *params)
|
static cell_t KeyValues_Import(IPluginContext *pContext, const cell_t *params)
|
||||||
{
|
{
|
||||||
// This version takes (dest, src). The original is (src, dest).
|
// This version takes (dest, src). The original is (src, dest).
|
||||||
cell_t new_params[3] = {
|
const cell_t new_params[3] = {
|
||||||
2,
|
2,
|
||||||
params[2],
|
params[2],
|
||||||
params[1],
|
params[1],
|
||||||
|
@ -471,6 +471,58 @@ cell_t GetClientCookieTime(IPluginContext *pContext, const cell_t *params)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cell_t Cookie_Set(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
// This version takes (handle, client, value). The original is (client, handle, value).
|
||||||
|
const cell_t new_params[4] = {
|
||||||
|
3,
|
||||||
|
params[2],
|
||||||
|
params[1],
|
||||||
|
params[3]
|
||||||
|
};
|
||||||
|
|
||||||
|
return SetClientPrefCookie(pContext, new_params);
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell_t Cookie_Get(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
// This verson takes (handle, client, buffer, maxlen). The original is (client, handle, buffer, maxlen).
|
||||||
|
const cell_t new_params[5] = {
|
||||||
|
4,
|
||||||
|
params[2],
|
||||||
|
params[1],
|
||||||
|
params[3],
|
||||||
|
params[4]
|
||||||
|
};
|
||||||
|
|
||||||
|
return GetClientPrefCookie(pContext, new_params);
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell_t Cookie_SetByAuthId(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
// This version takes (handle, authid, value). The original is (authid, handle, value).
|
||||||
|
const cell_t new_params[4] = {
|
||||||
|
3,
|
||||||
|
params[2],
|
||||||
|
params[1],
|
||||||
|
params[3]
|
||||||
|
};
|
||||||
|
|
||||||
|
return SetAuthIdCookie(pContext, new_params);
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell_t Cookie_GetClientTime(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
// This version takes (handle, client). The original is (client, handle)
|
||||||
|
const cell_t new_params[3] = {
|
||||||
|
2,
|
||||||
|
params[2],
|
||||||
|
params[1],
|
||||||
|
};
|
||||||
|
|
||||||
|
return GetClientCookieTime(pContext, new_params);
|
||||||
|
}
|
||||||
|
|
||||||
sp_nativeinfo_t g_ClientPrefNatives[] =
|
sp_nativeinfo_t g_ClientPrefNatives[] =
|
||||||
{
|
{
|
||||||
{"RegClientCookie", RegClientPrefCookie},
|
{"RegClientCookie", RegClientPrefCookie},
|
||||||
@ -486,5 +538,15 @@ sp_nativeinfo_t g_ClientPrefNatives[] =
|
|||||||
{"SetCookieMenuItem", AddSettingsMenuItem},
|
{"SetCookieMenuItem", AddSettingsMenuItem},
|
||||||
{"SetCookiePrefabMenu", AddSettingsPrefabMenuItem},
|
{"SetCookiePrefabMenu", AddSettingsPrefabMenuItem},
|
||||||
{"GetClientCookieTime", GetClientCookieTime},
|
{"GetClientCookieTime", GetClientCookieTime},
|
||||||
|
|
||||||
|
{"Cookie.Cookie", RegClientPrefCookie},
|
||||||
|
{"Cookie.Find", FindClientPrefCookie},
|
||||||
|
{"Cookie.Set", Cookie_Set},
|
||||||
|
{"Cookie.Get", Cookie_Get},
|
||||||
|
{"Cookie.SetByAuthId", Cookie_SetByAuthId},
|
||||||
|
{"Cookie.SetPrefabMenu", AddSettingsPrefabMenuItem},
|
||||||
|
{"Cookie.GetClientTime", Cookie_GetClientTime},
|
||||||
|
{"Cookie.AccessLevel.get", GetCookieAccess},
|
||||||
|
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
@ -42,7 +42,7 @@ enum CookieAccess
|
|||||||
{
|
{
|
||||||
CookieAccess_Public, /**< Visible and Changeable by users */
|
CookieAccess_Public, /**< Visible and Changeable by users */
|
||||||
CookieAccess_Protected, /**< Read only to users */
|
CookieAccess_Protected, /**< Read only to users */
|
||||||
CookieAccess_Private /**< Completely hidden cookie */
|
CookieAccess_Private, /**< Completely hidden cookie */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,7 +53,7 @@ enum CookieMenu
|
|||||||
CookieMenu_YesNo, /**< Yes/No menu with "yes"/"no" results saved into the cookie */
|
CookieMenu_YesNo, /**< Yes/No menu with "yes"/"no" results saved into the cookie */
|
||||||
CookieMenu_YesNo_Int, /**< Yes/No menu with 1/0 saved into the cookie */
|
CookieMenu_YesNo_Int, /**< Yes/No menu with 1/0 saved into the cookie */
|
||||||
CookieMenu_OnOff, /**< On/Off menu with "on"/"off" results saved into the cookie */
|
CookieMenu_OnOff, /**< On/Off menu with "on"/"off" results saved into the cookie */
|
||||||
CookieMenu_OnOff_Int /**< On/Off menu with 1/0 saved into the cookie */
|
CookieMenu_OnOff_Int, /**< On/Off menu with 1/0 saved into the cookie */
|
||||||
};
|
};
|
||||||
|
|
||||||
enum CookieMenuAction
|
enum CookieMenuAction
|
||||||
@ -71,9 +71,26 @@ enum CookieMenuAction
|
|||||||
*
|
*
|
||||||
* INPUT : Client index and any data if available.
|
* INPUT : Client index and any data if available.
|
||||||
*/
|
*/
|
||||||
CookieMenuAction_SelectOption = 1
|
CookieMenuAction_SelectOption = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cookie Menu Callback prototype
|
||||||
|
*
|
||||||
|
* @param client Client index.
|
||||||
|
* @param action CookieMenuAction being performed.
|
||||||
|
* @param info Info data passed.
|
||||||
|
* @param buffer Outbut buffer.
|
||||||
|
* @param maxlen Max length of the output buffer.
|
||||||
|
*/
|
||||||
|
typedef CookieMenuHandler = function void (
|
||||||
|
int client,
|
||||||
|
CookieMenuAction action,
|
||||||
|
any info,
|
||||||
|
char[] buffer,
|
||||||
|
int maxlen
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note:
|
* Note:
|
||||||
*
|
*
|
||||||
@ -82,6 +99,77 @@ enum CookieMenuAction
|
|||||||
* errors by the clientprefs extension.
|
* errors by the clientprefs extension.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
methodmap Cookie < Handle {
|
||||||
|
// Creates a new Client preference cookie.
|
||||||
|
//
|
||||||
|
// Handles returned can be closed via CloseHandle() when
|
||||||
|
// no longer needed.
|
||||||
|
//
|
||||||
|
// @param name Name of the new preference cookie.
|
||||||
|
// @param description Optional description of the preference cookie.
|
||||||
|
// @param access What CookieAccess level to assign to this cookie.
|
||||||
|
// @return A handle to the newly created cookie. If the cookie already
|
||||||
|
// exists, a handle to it will still be returned.
|
||||||
|
// @error Cookie name is blank.
|
||||||
|
public native Cookie(const char[] name, const char[] description, CookieAccess access);
|
||||||
|
|
||||||
|
// Searches for a Client preference cookie.
|
||||||
|
//
|
||||||
|
// Handles returned by Cookie.Find can be closed via CloseHandle() when
|
||||||
|
// no longer needed.
|
||||||
|
//
|
||||||
|
// @param name Name of cookie to find.
|
||||||
|
// @return A handle to the cookie if it is found. INVALID_HANDLE otherwise.
|
||||||
|
public static native Cookie Find(const char[] name);
|
||||||
|
|
||||||
|
// Set the value of a Client preference cookie.
|
||||||
|
//
|
||||||
|
// @param client Client index.
|
||||||
|
// @param value String value to set.
|
||||||
|
// @error Invalid cookie handle or invalid client index.
|
||||||
|
public native void Set(int client, const char[] value);
|
||||||
|
|
||||||
|
// Retrieve the value of a Client preference cookie.
|
||||||
|
//
|
||||||
|
// @param client Client index.
|
||||||
|
// @param buffer Copyback buffer for value.
|
||||||
|
// @param maxlen Maximum length of the buffer.
|
||||||
|
// @error Invalid cookie handle or invalid client index.
|
||||||
|
public native void Get(int client, char[] buffer, int maxlen);
|
||||||
|
|
||||||
|
// Sets the value of a Client preference cookie based on an authID string.
|
||||||
|
//
|
||||||
|
// @param authID String Auth/STEAM ID of player to set.
|
||||||
|
// @param value String value to set.
|
||||||
|
// @error Invalid cookie handle.
|
||||||
|
public native void SetByAuthId(const char[] authID, const char[] value);
|
||||||
|
|
||||||
|
// Add a new prefab item to the client cookie settings menu.
|
||||||
|
//
|
||||||
|
// Note: This handles everything automatically and does not require a callback
|
||||||
|
//
|
||||||
|
// @param type A CookieMenu prefab menu type.
|
||||||
|
// @param display Text to show on the menu.
|
||||||
|
// @param handler Optional handler callback for translations and output on selection
|
||||||
|
// @param info Info data to pass to the callback.
|
||||||
|
// @error Invalid cookie handle.
|
||||||
|
public native void SetPrefabMenu(CookieMenu type, const char[] display, CookieMenuHandler handler=INVALID_FUNCTION, any info=0);
|
||||||
|
|
||||||
|
// Returns the last updated timestamp for a client cookie
|
||||||
|
//
|
||||||
|
// @param client Client index.
|
||||||
|
// @return Last updated timestamp.
|
||||||
|
public native int GetClientTime(int client);
|
||||||
|
|
||||||
|
// Returns the access level of a cookie
|
||||||
|
//
|
||||||
|
// @return CookieAccess access level.
|
||||||
|
// @error Invalid cookie handle.
|
||||||
|
property CookieAccess AccessLevel {
|
||||||
|
public native get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Client preference cookie.
|
* Creates a new Client preference cookie.
|
||||||
*
|
*
|
||||||
@ -155,22 +243,6 @@ native bool AreClientCookiesCached(int client);
|
|||||||
*/
|
*/
|
||||||
forward void OnClientCookiesCached(int client);
|
forward void OnClientCookiesCached(int client);
|
||||||
|
|
||||||
/**
|
|
||||||
* Cookie Menu Callback prototype
|
|
||||||
*
|
|
||||||
* @param client Client index.
|
|
||||||
* @param action CookieMenuAction being performed.
|
|
||||||
* @param info Info data passed.
|
|
||||||
* @param buffer Outbut buffer.
|
|
||||||
* @param maxlen Max length of the output buffer.
|
|
||||||
*/
|
|
||||||
typedef CookieMenuHandler = function void (
|
|
||||||
int client,
|
|
||||||
CookieMenuAction action,
|
|
||||||
any info,
|
|
||||||
char[] buffer,
|
|
||||||
int maxlen
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new prefab item to the client cookie settings menu.
|
* Add a new prefab item to the client cookie settings menu.
|
||||||
@ -279,5 +351,14 @@ public void __ext_cprefs_SetNTVOptional()
|
|||||||
MarkNativeAsOptional("ReadCookieIterator");
|
MarkNativeAsOptional("ReadCookieIterator");
|
||||||
MarkNativeAsOptional("GetCookieAccess");
|
MarkNativeAsOptional("GetCookieAccess");
|
||||||
MarkNativeAsOptional("GetClientCookieTime");
|
MarkNativeAsOptional("GetClientCookieTime");
|
||||||
|
|
||||||
|
MarkNativeAsOptional("Cookie.Cookie");
|
||||||
|
MarkNativeAsOptional("Cookie.Find");
|
||||||
|
MarkNativeAsOptional("Cookie.Set");
|
||||||
|
MarkNativeAsOptional("Cookie.Get");
|
||||||
|
MarkNativeAsOptional("Cookie.SetByAuthId");
|
||||||
|
MarkNativeAsOptional("Cookie.SetPrefabMenu");
|
||||||
|
MarkNativeAsOptional("Cookie.GetClientTime");
|
||||||
|
MarkNativeAsOptional("Cookie.AccessLevel.get");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user