plugins/include/clientprefs.inc
author David Anderson <dvander@alliedmods.net>
Sun Jul 06 04:49:55 2008 +0000 (2008-07-06)
branchrefac-jit
changeset 2168 c24a6fa957db
permissions -rw-r--r--
jit refactoring branch
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 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  * Creates a new Client preference cookie.
    79  *
    80  * @param name			Name of the new preference cookie.
    81  * @param description	Optional description of the preference cookie.
    82  * @param access		What CookieAccess level to assign to this cookie.
    83  * @return				A handle to the newly created cookie. If the cookie already exists, a handle to it will still be returned.
    84  * @error				Cookie name is blank.
    85  */
    86 native Handle:RegClientCookie(const String:name[], const String:description[], CookieAccess:access);
    87 
    88 /**
    89  * Searches for a Client preference cookie.
    90  *
    91  * @param name			Name of cookie to find.
    92  * @return				A handle to the cookie if it is found. INVALID_HANDLE otherwise.
    93  */
    94 native Handle:FindClientCookie(const String:name[]);
    95 
    96 /**
    97  * Set the value of a Client preference cookie.
    98  *
    99  * @param client		Client index.
   100  * @param cookie		Client preference cookie handle.
   101  * @param value			String value to set.
   102  * @noreturn			
   103  * @error				Invalid cookie handle or invalid client index.
   104  */
   105 native SetClientCookie(client, Handle:cookie, const String:value[]);
   106 
   107 /**
   108  * Retrieve the value of a Client preference cookie.
   109  *
   110  * @param client		Client index.
   111  * @param cookie		Client preference cookie handle.
   112  * @param buffer		Copyback buffer for value.
   113  * @param maxlen		Maximum length of the buffer.
   114  * @noreturn
   115  * @error				Invalid cookie handle or invalid client index.
   116  */
   117 native GetClientCookie(client, Handle:cookie, String:buffer[], maxlen);
   118 
   119 /**
   120  * Checks if a clients cookies have been loaded from the database.
   121  *
   122  * @param client		Client index.
   123  * @return 				True if loaded, false otherwise.
   124  * @error				Invalid client index.
   125  */
   126 native bool:AreClientCookiesCached(client);
   127 
   128 /**
   129  * Called once a client's saved cookies have been loaded from the database.
   130  *
   131  * @param client		Client index.
   132  */
   133 forward OnClientCookiesCached(client);
   134 
   135 /**
   136  * Cookie Menu Callback prototype
   137  *
   138  * @param client		Client index.
   139  * @param action		CookeMenuAction being performed.
   140  * @param data			Info data passed.
   141  * @param buffer		Outbut buffer.
   142  * @param maxlen		Max length of the output buffer.			
   143  */
   144 functag CookieMenuHandler public(client, CookieMenuAction:action, any:info, String:buffer[], maxlen);
   145 
   146 /**
   147  * Add a new prefab item to the client cookie settings menu.
   148  *
   149  * Note: This handles everything automatically and does not require a callback
   150  *
   151  * @param cookie		Client preference cookie handle.
   152  * @param type			A CookieMenu prefab menu type.
   153  * @param display		Text to show on the menu.
   154  * @param handler		Optional handler callback for translations and output on selection
   155  * @param info			Info data to pass to the callback.
   156  * @noreturn
   157  * @error				Invalid cookie handle.
   158  */
   159 native SetCookiePrefabMenu(Handle:cookie, CookieMenu:type, const String:display[], CookieMenuHandler:handler=CookieMenuHandler:-1, info=0);
   160 
   161 /**
   162  * Adds a new item to the client cookie settings menu.
   163  *
   164  * Note: This only adds the top level menu item. You need to handle any submenus from the callback.
   165  *
   166  * @param handler		A MenuHandler callback function.
   167  * @param info			Data to pass to the callback.
   168  * @param display		Text to show on the menu.
   169  * @noreturn
   170  * @error				Invalid cookie handle.
   171  */
   172 native SetCookieMenuItem(CookieMenuHandler:handler, any:info, const String:display[]);
   173 
   174 /**
   175  * Displays the settings menu to a client.
   176  *
   177  * @param client		Client index.
   178  * @noreturn
   179  */
   180 native ShowCookieMenu(client);
   181 
   182 /**
   183  * Gets a cookie iterator.  Must be freed with CloseHandle().
   184  *
   185  * @return				A new cookie iterator.
   186  */
   187 native Handle:GetCookieIterator();
   188 
   189 /**
   190  * Reads a cookie iterator, then advances to the next cookie if any.
   191  *
   192  * @param iter			Cookie iterator Handle.
   193  * @param name			Name buffer.
   194  * @param nameLen		Name buffer size.
   195  * @param access		Access level of the cookie.
   196  * @param desc			Cookie description buffer.
   197  * @param descLen		Cookie description buffer size.
   198  * @param 
   199  * @return				True on success, false if there are no more commands.
   200  */
   201 native bool:ReadCookieIterator(Handle:iter, 
   202 								String:name[], 
   203 								nameLen,
   204 								&CookieAccess:access, 
   205 								String:desc[]="", 
   206 								descLen=0);
   207 								
   208 /**
   209  * Returns the access level of a cookie
   210  *
   211  * @param cookie		Client preference cookie handle.
   212  * @return				CookieAccess access level.
   213  * @error				Invalid cookie handle.	
   214  */
   215 native CookieAccess:GetCookieAccess(Handle:cookie);
   216 
   217 /**
   218  * Do not edit below this line!
   219  */
   220 public Extension:__ext_clientprefs = 
   221 {
   222 	name = "Client Preferences",
   223 	file = "clientprefs.ext",
   224 	autoload = 1,
   225 #if defined REQUIRE_EXTENSIONS
   226 	required = 1,
   227 #else
   228 	required = 0,
   229 #endif
   230 };