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