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