3 * =============================================================================
4 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
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.
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
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/>.
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>.
33 #if defined _clientprefs_included
36 #define _clientprefs_included
39 * Cookie access types for client viewing
43 CookieAccess_Public, /**< Visible and Changeable by users */
44 CookieAccess_Protected, /**< Read only to users */
45 CookieAccess_Private, /**< Completely hidden cookie */
49 * Cookie Prefab menu types
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 */
62 * An option is being drawn for a menu.
64 * INPUT : Client index and data if available.
65 * OUTPUT: Buffer for rendering, maxlength of buffer.
67 CookieMenuAction_DisplayOption = 0,
70 * A menu option has been selected.
72 * INPUT : Client index and any data if available.
74 CookieMenuAction_SelectOption = 1,
78 * Creates a new Client preference cookie.
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.
86 native Handle:RegClientCookie(const String:name[], const String:description[], CookieAccess:access);
89 * Searches for a Client preference cookie.
91 * @param name Name of cookie to find.
92 * @return A handle to the cookie if it is found. INVALID_HANDLE otherwise.
94 native Handle:FindClientCookie(const String:name[]);
97 * Set the value of a Client preference cookie.
99 * @param client Client index.
100 * @param cookie Client preference cookie handle.
101 * @param value String value to set.
103 * @error Invalid cookie handle or invalid client index.
105 native SetClientCookie(client, Handle:cookie, const String:value[]);
108 * Retrieve the value of a Client preference cookie.
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.
115 * @error Invalid cookie handle or invalid client index.
117 native GetClientCookie(client, Handle:cookie, String:buffer[], maxlen);
120 * Checks if a clients cookies have been loaded from the database.
122 * @param client Client index.
123 * @return True if loaded, false otherwise.
124 * @error Invalid client index.
126 native bool:AreClientCookiesCached(client);
129 * Called once a client's saved cookies have been loaded from the database.
131 * @param client Client index.
133 forward OnClientCookiesCached(client);
136 * Cookie Menu Callback prototype
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.
144 functag CookieMenuHandler public(client, CookieMenuAction:action, any:info, String:buffer[], maxlen);
147 * Add a new prefab item to the client cookie settings menu.
149 * Note: This handles everything automatically and does not require a callback
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.
157 * @error Invalid cookie handle.
159 native SetCookiePrefabMenu(Handle:cookie, CookieMenu:type, const String:display[], CookieMenuHandler:handler=CookieMenuHandler:-1, info=0);
162 * Adds a new item to the client cookie settings menu.
164 * Note: This only adds the top level menu item. You need to handle any submenus from the callback.
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.
170 * @error Invalid cookie handle.
172 native SetCookieMenuItem(CookieMenuHandler:handler, any:info, const String:display[]);
175 * Displays the settings menu to a client.
177 * @param client Client index.
180 native ShowCookieMenu(client);
183 * Gets a cookie iterator. Must be freed with CloseHandle().
185 * @return A new cookie iterator.
187 native Handle:GetCookieIterator();
190 * Reads a cookie iterator, then advances to the next cookie if any.
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.
199 * @return True on success, false if there are no more commands.
201 native bool:ReadCookieIterator(Handle:iter,
204 &CookieAccess:access,
209 * Returns the access level of a cookie
211 * @param cookie Client preference cookie handle.
212 * @return CookieAccess access level.
213 * @error Invalid cookie handle.
215 native CookieAccess:GetCookieAccess(Handle:cookie);
218 * Do not edit below this line!
220 public Extension:__ext_clientprefs =
222 name = "Client Preferences",
223 file = "clientprefs.ext",
225 #if defined REQUIRE_EXTENSIONS