plugins/include/clientprefs.inc
author Asher Baker <asherkin@gmail.com>
Sun May 27 01:50:57 2012 +0100 (2012-05-27)
changeset 3507 d1b6fde18611
parent 3411 0a2e40a50757
child 3967 ceafb87d38a7
permissions -rw-r--r--
Fixed error when reloading dependant plugins using aliased natives (bug 5302, r=psychonic).
pred@2009
     1
/**
pred@2009
     2
 * vim: set ts=4 :
pred@2009
     3
 * =============================================================================
skamonkey@3219
     4
 * SourceMod (C)2004-2011 AlliedModders LLC.  All rights reserved.
pred@2009
     5
 * =============================================================================
pred@2009
     6
 *
pred@2009
     7
 * This file is part of the SourceMod/SourcePawn SDK.
pred@2009
     8
 *
pred@2009
     9
 * This program is free software; you can redistribute it and/or modify it under
pred@2009
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
pred@2009
    11
 * Free Software Foundation.
pred@2009
    12
 * 
pred@2009
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
pred@2009
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
pred@2009
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
pred@2009
    16
 * details.
pred@2009
    17
 *
pred@2009
    18
 * You should have received a copy of the GNU General Public License along with
pred@2009
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
pred@2009
    20
 *
pred@2009
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
pred@2009
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
pred@2009
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
pred@2009
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
pred@2009
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
pred@2009
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
pred@2009
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
pred@2009
    28
 * or <http://www.sourcemod.net/license.php>.
pred@2009
    29
 *
pred@2009
    30
 * Version: $Id$
pred@2009
    31
 */
pred@2009
    32
 
pred@2009
    33
#if defined _clientprefs_included
pred@2009
    34
 #endinput
pred@2009
    35
#endif
pred@2009
    36
#define _clientprefs_included
pred@2009
    37
pred@2009
    38
/**
pred@2048
    39
 * Cookie access types for client viewing
pred@2048
    40
 */
pred@2048
    41
enum CookieAccess
pred@2048
    42
{
pred@2048
    43
	CookieAccess_Public,			/**< Visible and Changeable by users */
pred@2048
    44
	CookieAccess_Protected,			/**< Read only to users */
pred@2048
    45
	CookieAccess_Private,			/**< Completely hidden cookie */
pred@2048
    46
};
pred@2048
    47
pred@2048
    48
/**
pred@2048
    49
 * Cookie Prefab menu types
pred@2048
    50
 */
pred@2048
    51
enum CookieMenu
pred@2048
    52
{
pred@2048
    53
	CookieMenu_YesNo,			/**< Yes/No menu with "yes"/"no" results saved into the cookie */
pred@2048
    54
	CookieMenu_YesNo_Int,		/**< Yes/No menu with 1/0 saved into the cookie */
pred@2048
    55
	CookieMenu_OnOff,			/**< On/Off menu with "on"/"off" results saved into the cookie */
pred@2048
    56
	CookieMenu_OnOff_Int,		/**< On/Off menu with 1/0 saved into the cookie */
pred@2048
    57
};
pred@2048
    58
pred@2048
    59
enum CookieMenuAction
pred@2048
    60
{
pred@2048
    61
	/**
pred@2048
    62
	 * An option is being drawn for a menu.
pred@2048
    63
	 *
pred@2048
    64
	 * INPUT : Client index and data if available.
pred@2048
    65
	 * OUTPUT: Buffer for rendering, maxlength of buffer.
pred@2048
    66
	 */
pred@2048
    67
	CookieMenuAction_DisplayOption = 0,
pred@2048
    68
	
pred@2048
    69
	/**
pred@2048
    70
	 * A menu option has been selected.
pred@2048
    71
	 *
pred@2048
    72
	 * INPUT : Client index and any data if available.
pred@2048
    73
	 */
pred@2048
    74
	CookieMenuAction_SelectOption = 1,
pred@2048
    75
};
pred@2048
    76
pred@2048
    77
/**
pred@2207
    78
 * Note:
pred@2207
    79
 * 
pred@2207
    80
 * A successful return value/result on any client prefs native only guarantees that the local cache has been updated.
pred@2207
    81
 * Database connection problems can still prevent the data from being permanently saved. Connection problems will be logged as
pred@2207
    82
 * errors by the clientprefs extension.
pred@2207
    83
 */
pred@2207
    84
pred@2207
    85
/**
pred@2009
    86
 * Creates a new Client preference cookie.
pred@2009
    87
 *
dvander@2862
    88
 * Handles returned by RegClientCookie can be closed via CloseHandle() when
dvander@2862
    89
 * no longer needed.
dvander@2862
    90
 *
pred@2009
    91
 * @param name			Name of the new preference cookie.
pred@2009
    92
 * @param description	Optional description of the preference cookie.
pred@2048
    93
 * @param access		What CookieAccess level to assign to this cookie.
dvander@2862
    94
 * @return				A handle to the newly created cookie. If the cookie already
dvander@2862
    95
 *                      exists, a handle to it will still be returned.
pred@2009
    96
 * @error				Cookie name is blank.
pred@2009
    97
 */
pred@2048
    98
native Handle:RegClientCookie(const String:name[], const String:description[], CookieAccess:access);
pred@2009
    99
pred@2009
   100
/**
pred@2009
   101
 * Searches for a Client preference cookie.
pred@2009
   102
 *
dvander@2862
   103
 * Handles returned by FindClientCookie can be closed via CloseHandle() when
dvander@2862
   104
 * no longer needed.
dvander@2862
   105
 *
pred@2009
   106
 * @param name			Name of cookie to find.
pred@2009
   107
 * @return				A handle to the cookie if it is found. INVALID_HANDLE otherwise.
pred@2009
   108
 */
pred@2048
   109
native Handle:FindClientCookie(const String:name[]);
pred@2009
   110
pred@2009
   111
/**
pred@2009
   112
 * Set the value of a Client preference cookie.
pred@2009
   113
 *
pred@2009
   114
 * @param client		Client index.
pred@2009
   115
 * @param cookie		Client preference cookie handle.
pred@2009
   116
 * @param value			String value to set.
pred@2009
   117
 * @noreturn			
pred@2009
   118
 * @error				Invalid cookie handle or invalid client index.
pred@2009
   119
 */
pred@2048
   120
native SetClientCookie(client, Handle:cookie, const String:value[]);
pred@2009
   121
pred@2009
   122
/**
pred@2009
   123
 * Retrieve the value of a Client preference cookie.
pred@2009
   124
 *
pred@2009
   125
 * @param client		Client index.
pred@2009
   126
 * @param cookie		Client preference cookie handle.
pred@2009
   127
 * @param buffer		Copyback buffer for value.
pred@2009
   128
 * @param maxlen		Maximum length of the buffer.
pred@2048
   129
 * @noreturn
pred@2009
   130
 * @error				Invalid cookie handle or invalid client index.
pred@2009
   131
 */
pred@2048
   132
native GetClientCookie(client, Handle:cookie, String:buffer[], maxlen);
pred@2009
   133
pred@2009
   134
/**
datal30mb@3411
   135
 * Sets the value of a Client preference cookie based on an authID string.
datal30mb@3411
   136
 *
datal30mb@3411
   137
 * @param authID		String Auth/STEAM ID of player to set.
datal30mb@3411
   138
 * @param cookie		Client preference cookie handle.
datal30mb@3411
   139
 * @param value			String value to set.
datal30mb@3411
   140
 * @noreturn
datal30mb@3411
   141
 * @error			Invalid cookie handle.
datal30mb@3411
   142
 */
datal30mb@3411
   143
native SetAuthIdCookie(const String:authID[], Handle:cookie, const String:value[]);
datal30mb@3411
   144
datal30mb@3411
   145
/**
pred@2009
   146
 * Checks if a clients cookies have been loaded from the database.
pred@2009
   147
 *
pred@2009
   148
 * @param client		Client index.
pred@2009
   149
 * @return 				True if loaded, false otherwise.
pred@2009
   150
 * @error				Invalid client index.
pred@2009
   151
 */
pred@2009
   152
native bool:AreClientCookiesCached(client);
pred@2009
   153
pred@2009
   154
/**
pred@2009
   155
 * Called once a client's saved cookies have been loaded from the database.
pred@2009
   156
 *
pred@2009
   157
 * @param client		Client index.
pred@2009
   158
 */
pred@2048
   159
forward OnClientCookiesCached(client);
pred@2048
   160
pred@2048
   161
/**
pred@2048
   162
 * Cookie Menu Callback prototype
pred@2048
   163
 *
pred@2048
   164
 * @param client		Client index.
pred@2048
   165
 * @param action		CookeMenuAction being performed.
pred@2048
   166
 * @param data			Info data passed.
pred@2048
   167
 * @param buffer		Outbut buffer.
pred@2048
   168
 * @param maxlen		Max length of the output buffer.			
pred@2048
   169
 */
dvander@2317
   170
functag public CookieMenuHandler(client, CookieMenuAction:action, any:info, String:buffer[], maxlen);
pred@2048
   171
pred@2048
   172
/**
pred@2048
   173
 * Add a new prefab item to the client cookie settings menu.
pred@2048
   174
 *
pred@2048
   175
 * Note: This handles everything automatically and does not require a callback
pred@2048
   176
 *
pred@2048
   177
 * @param cookie		Client preference cookie handle.
pred@2048
   178
 * @param type			A CookieMenu prefab menu type.
pred@2048
   179
 * @param display		Text to show on the menu.
pred@2048
   180
 * @param handler		Optional handler callback for translations and output on selection
pred@2048
   181
 * @param info			Info data to pass to the callback.
pred@2048
   182
 * @noreturn
pred@2048
   183
 * @error				Invalid cookie handle.
pred@2048
   184
 */
pred@2048
   185
native SetCookiePrefabMenu(Handle:cookie, CookieMenu:type, const String:display[], CookieMenuHandler:handler=CookieMenuHandler:-1, info=0);
pred@2048
   186
pred@2048
   187
/**
pred@2048
   188
 * Adds a new item to the client cookie settings menu.
pred@2048
   189
 *
pred@2048
   190
 * Note: This only adds the top level menu item. You need to handle any submenus from the callback.
pred@2048
   191
 *
pred@2048
   192
 * @param handler		A MenuHandler callback function.
pred@2048
   193
 * @param info			Data to pass to the callback.
pred@2048
   194
 * @param display		Text to show on the menu.
pred@2048
   195
 * @noreturn
pred@2048
   196
 * @error				Invalid cookie handle.
pred@2048
   197
 */
pred@2048
   198
native SetCookieMenuItem(CookieMenuHandler:handler, any:info, const String:display[]);
pred@2009
   199
pred@2048
   200
/**
pred@2048
   201
 * Displays the settings menu to a client.
pred@2048
   202
 *
pred@2048
   203
 * @param client		Client index.
pred@2048
   204
 * @noreturn
pred@2048
   205
 */
pred@2048
   206
native ShowCookieMenu(client);
pred@2048
   207
pred@2048
   208
/**
pred@2048
   209
 * Gets a cookie iterator.  Must be freed with CloseHandle().
pred@2048
   210
 *
pred@2048
   211
 * @return				A new cookie iterator.
pred@2048
   212
 */
pred@2048
   213
native Handle:GetCookieIterator();
pred@2048
   214
pred@2048
   215
/**
pred@2048
   216
 * Reads a cookie iterator, then advances to the next cookie if any.
pred@2048
   217
 *
pred@2048
   218
 * @param iter			Cookie iterator Handle.
pred@2048
   219
 * @param name			Name buffer.
pred@2048
   220
 * @param nameLen		Name buffer size.
pred@2048
   221
 * @param access		Access level of the cookie.
pred@2048
   222
 * @param desc			Cookie description buffer.
pred@2048
   223
 * @param descLen		Cookie description buffer size.
pred@2048
   224
 * @param 
pred@2048
   225
 * @return				True on success, false if there are no more commands.
pred@2048
   226
 */
pred@2048
   227
native bool:ReadCookieIterator(Handle:iter, 
pred@2048
   228
								String:name[], 
pred@2048
   229
								nameLen,
pred@2048
   230
								&CookieAccess:access, 
pred@2048
   231
								String:desc[]="", 
pred@2048
   232
								descLen=0);
pred@2048
   233
								
pred@2048
   234
/**
pred@2048
   235
 * Returns the access level of a cookie
pred@2048
   236
 *
pred@2048
   237
 * @param cookie		Client preference cookie handle.
pred@2048
   238
 * @return				CookieAccess access level.
pred@2048
   239
 * @error				Invalid cookie handle.	
pred@2048
   240
 */
pred@2048
   241
native CookieAccess:GetCookieAccess(Handle:cookie);
pred@2009
   242
pred@2009
   243
/**
pred@2668
   244
 * Returns the last updated timestamp for a client cookie
pred@2668
   245
 *
pred@2668
   246
 * @param client		Client index.
pred@2668
   247
 * @param cookie		Cookie handle.
pred@2668
   248
 * @return			Last updated timestamp.
pred@2668
   249
 */
pred@2668
   250
native GetClientCookieTime(client, Handle:cookie);
pred@2668
   251
pred@2668
   252
/**
pred@2009
   253
 * Do not edit below this line!
pred@2009
   254
 */
skamonkey@3254
   255
public Extension:__ext_cprefs = 
pred@2009
   256
{
pred@2009
   257
	name = "Client Preferences",
pred@2009
   258
	file = "clientprefs.ext",
pred@2009
   259
	autoload = 1,
pred@2009
   260
#if defined REQUIRE_EXTENSIONS
pred@2009
   261
	required = 1,
pred@2009
   262
#else
pred@2009
   263
	required = 0,
pred@2009
   264
#endif
pred@2009
   265
};
skamonkey@3219
   266
skamonkey@3219
   267
#if !defined REQUIRE_EXTENSIONS
skamonkey@3254
   268
public __ext_cprefs_SetNTVOptional()
skamonkey@3219
   269
{
skamonkey@3219
   270
	MarkNativeAsOptional("RegClientCookie");
skamonkey@3219
   271
	MarkNativeAsOptional("FindClientCookie");
skamonkey@3219
   272
	MarkNativeAsOptional("SetClientCookie");
skamonkey@3219
   273
	MarkNativeAsOptional("GetClientCookie");
skamonkey@3219
   274
	MarkNativeAsOptional("AreClientCookiesCached");
skamonkey@3219
   275
	MarkNativeAsOptional("SetCookiePrefabMenu");
skamonkey@3219
   276
	MarkNativeAsOptional("SetCookieMenuItem");
skamonkey@3219
   277
	MarkNativeAsOptional("ShowCookieMenu");
skamonkey@3219
   278
	MarkNativeAsOptional("GetCookieIterator");
skamonkey@3219
   279
	MarkNativeAsOptional("ReadCookieIterator");
skamonkey@3219
   280
	MarkNativeAsOptional("GetCookieAccess");
skamonkey@3219
   281
	MarkNativeAsOptional("GetClientCookieTime");
skamonkey@3219
   282
}
skamonkey@3219
   283
#endif