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