plugins/include/clientprefs.inc
author Nicholas Hastings <skamonkey@gmail.com>
Wed Jul 06 22:34:21 2011 -0400 (2011-07-06)
changeset 3340 7eb2b72e42d8
parent 3254 45f2ca7eb3f9
child 3411 0a2e40a50757
permissions -rw-r--r--
Added native interface for Basecomm plugin (bug 2594, r=fyren).
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
/**
pred@2009
   135
 * Checks if a clients cookies have been loaded from the database.
pred@2009
   136
 *
pred@2009
   137
 * @param client		Client index.
pred@2009
   138
 * @return 				True if loaded, false otherwise.
pred@2009
   139
 * @error				Invalid client index.
pred@2009
   140
 */
pred@2009
   141
native bool:AreClientCookiesCached(client);
pred@2009
   142
pred@2009
   143
/**
pred@2009
   144
 * Called once a client's saved cookies have been loaded from the database.
pred@2009
   145
 *
pred@2009
   146
 * @param client		Client index.
pred@2009
   147
 */
pred@2048
   148
forward OnClientCookiesCached(client);
pred@2048
   149
pred@2048
   150
/**
pred@2048
   151
 * Cookie Menu Callback prototype
pred@2048
   152
 *
pred@2048
   153
 * @param client		Client index.
pred@2048
   154
 * @param action		CookeMenuAction being performed.
pred@2048
   155
 * @param data			Info data passed.
pred@2048
   156
 * @param buffer		Outbut buffer.
pred@2048
   157
 * @param maxlen		Max length of the output buffer.			
pred@2048
   158
 */
dvander@2317
   159
functag public CookieMenuHandler(client, CookieMenuAction:action, any:info, String:buffer[], maxlen);
pred@2048
   160
pred@2048
   161
/**
pred@2048
   162
 * Add a new prefab item to the client cookie settings menu.
pred@2048
   163
 *
pred@2048
   164
 * Note: This handles everything automatically and does not require a callback
pred@2048
   165
 *
pred@2048
   166
 * @param cookie		Client preference cookie handle.
pred@2048
   167
 * @param type			A CookieMenu prefab menu type.
pred@2048
   168
 * @param display		Text to show on the menu.
pred@2048
   169
 * @param handler		Optional handler callback for translations and output on selection
pred@2048
   170
 * @param info			Info data to pass to the callback.
pred@2048
   171
 * @noreturn
pred@2048
   172
 * @error				Invalid cookie handle.
pred@2048
   173
 */
pred@2048
   174
native SetCookiePrefabMenu(Handle:cookie, CookieMenu:type, const String:display[], CookieMenuHandler:handler=CookieMenuHandler:-1, info=0);
pred@2048
   175
pred@2048
   176
/**
pred@2048
   177
 * Adds a new item to the client cookie settings menu.
pred@2048
   178
 *
pred@2048
   179
 * Note: This only adds the top level menu item. You need to handle any submenus from the callback.
pred@2048
   180
 *
pred@2048
   181
 * @param handler		A MenuHandler callback function.
pred@2048
   182
 * @param info			Data to pass to the callback.
pred@2048
   183
 * @param display		Text to show on the menu.
pred@2048
   184
 * @noreturn
pred@2048
   185
 * @error				Invalid cookie handle.
pred@2048
   186
 */
pred@2048
   187
native SetCookieMenuItem(CookieMenuHandler:handler, any:info, const String:display[]);
pred@2009
   188
pred@2048
   189
/**
pred@2048
   190
 * Displays the settings menu to a client.
pred@2048
   191
 *
pred@2048
   192
 * @param client		Client index.
pred@2048
   193
 * @noreturn
pred@2048
   194
 */
pred@2048
   195
native ShowCookieMenu(client);
pred@2048
   196
pred@2048
   197
/**
pred@2048
   198
 * Gets a cookie iterator.  Must be freed with CloseHandle().
pred@2048
   199
 *
pred@2048
   200
 * @return				A new cookie iterator.
pred@2048
   201
 */
pred@2048
   202
native Handle:GetCookieIterator();
pred@2048
   203
pred@2048
   204
/**
pred@2048
   205
 * Reads a cookie iterator, then advances to the next cookie if any.
pred@2048
   206
 *
pred@2048
   207
 * @param iter			Cookie iterator Handle.
pred@2048
   208
 * @param name			Name buffer.
pred@2048
   209
 * @param nameLen		Name buffer size.
pred@2048
   210
 * @param access		Access level of the cookie.
pred@2048
   211
 * @param desc			Cookie description buffer.
pred@2048
   212
 * @param descLen		Cookie description buffer size.
pred@2048
   213
 * @param 
pred@2048
   214
 * @return				True on success, false if there are no more commands.
pred@2048
   215
 */
pred@2048
   216
native bool:ReadCookieIterator(Handle:iter, 
pred@2048
   217
								String:name[], 
pred@2048
   218
								nameLen,
pred@2048
   219
								&CookieAccess:access, 
pred@2048
   220
								String:desc[]="", 
pred@2048
   221
								descLen=0);
pred@2048
   222
								
pred@2048
   223
/**
pred@2048
   224
 * Returns the access level of a cookie
pred@2048
   225
 *
pred@2048
   226
 * @param cookie		Client preference cookie handle.
pred@2048
   227
 * @return				CookieAccess access level.
pred@2048
   228
 * @error				Invalid cookie handle.	
pred@2048
   229
 */
pred@2048
   230
native CookieAccess:GetCookieAccess(Handle:cookie);
pred@2009
   231
pred@2009
   232
/**
pred@2668
   233
 * Returns the last updated timestamp for a client cookie
pred@2668
   234
 *
pred@2668
   235
 * @param client		Client index.
pred@2668
   236
 * @param cookie		Cookie handle.
pred@2668
   237
 * @return			Last updated timestamp.
pred@2668
   238
 */
pred@2668
   239
native GetClientCookieTime(client, Handle:cookie);
pred@2668
   240
pred@2668
   241
/**
pred@2009
   242
 * Do not edit below this line!
pred@2009
   243
 */
skamonkey@3254
   244
public Extension:__ext_cprefs = 
pred@2009
   245
{
pred@2009
   246
	name = "Client Preferences",
pred@2009
   247
	file = "clientprefs.ext",
pred@2009
   248
	autoload = 1,
pred@2009
   249
#if defined REQUIRE_EXTENSIONS
pred@2009
   250
	required = 1,
pred@2009
   251
#else
pred@2009
   252
	required = 0,
pred@2009
   253
#endif
pred@2009
   254
};
skamonkey@3219
   255
skamonkey@3219
   256
#if !defined REQUIRE_EXTENSIONS
skamonkey@3254
   257
public __ext_cprefs_SetNTVOptional()
skamonkey@3219
   258
{
skamonkey@3219
   259
	MarkNativeAsOptional("RegClientCookie");
skamonkey@3219
   260
	MarkNativeAsOptional("FindClientCookie");
skamonkey@3219
   261
	MarkNativeAsOptional("SetClientCookie");
skamonkey@3219
   262
	MarkNativeAsOptional("GetClientCookie");
skamonkey@3219
   263
	MarkNativeAsOptional("AreClientCookiesCached");
skamonkey@3219
   264
	MarkNativeAsOptional("SetCookiePrefabMenu");
skamonkey@3219
   265
	MarkNativeAsOptional("SetCookieMenuItem");
skamonkey@3219
   266
	MarkNativeAsOptional("ShowCookieMenu");
skamonkey@3219
   267
	MarkNativeAsOptional("GetCookieIterator");
skamonkey@3219
   268
	MarkNativeAsOptional("ReadCookieIterator");
skamonkey@3219
   269
	MarkNativeAsOptional("GetCookieAccess");
skamonkey@3219
   270
	MarkNativeAsOptional("GetClientCookieTime");
skamonkey@3219
   271
}
skamonkey@3219
   272
#endif