-
-
Notifications
You must be signed in to change notification settings - Fork 429
/
clientprefs.inc
433 lines (389 loc) · 14.6 KB
/
clientprefs.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod (C)2004-2011 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This file is part of the SourceMod/SourcePawn SDK.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#if defined _clientprefs_included
#endinput
#endif
#define _clientprefs_included
/**
* Cookie access types for client viewing
*/
enum CookieAccess
{
CookieAccess_Public, /**< Visible and Changeable by users */
CookieAccess_Protected, /**< Read only to users */
CookieAccess_Private /**< Completely hidden cookie */
};
/**
* Cookie Prefab menu types
*/
enum CookieMenu
{
CookieMenu_YesNo, /**< Yes/No menu with "yes"/"no" results saved into the cookie */
CookieMenu_YesNo_Int, /**< Yes/No menu with 1/0 saved into the cookie */
CookieMenu_OnOff, /**< On/Off menu with "on"/"off" results saved into the cookie */
CookieMenu_OnOff_Int /**< On/Off menu with 1/0 saved into the cookie */
};
enum CookieMenuAction
{
/**
* An option is being drawn for a menu.
*
* INPUT : Client index and data if available.
* OUTPUT: Buffer for rendering, maxlength of buffer.
*/
CookieMenuAction_DisplayOption = 0,
/**
* A menu option has been selected.
*
* INPUT : Client index and any data if available.
*/
CookieMenuAction_SelectOption = 1
};
#define COOKIE_MAX_NAME_LENGTH 30 /**< Maximum Cookie name length. */
#define COOKIE_MAX_DESCRIPTION_LENGTH 255 /**< Maximum Cookie description length. */
/**
* Cookie Menu Callback prototype
*
* @param client Client index.
* @param action CookieMenuAction being performed.
* @param info Info data passed.
* @param buffer Outbut buffer.
* @param maxlen Max length of the output buffer.
*/
typedef CookieMenuHandler = function void (
int client,
CookieMenuAction action,
any info,
char[] buffer,
int maxlen
);
/**
* Note:
*
* A successful return value/result on any client prefs native only guarantees that the local cache has been updated.
* Database connection problems can still prevent the data from being permanently saved. Connection problems will be logged as
* errors by the clientprefs extension.
*/
methodmap Cookie < Handle {
// Creates a new Client preference cookie.
//
// Handles returned can be closed via CloseHandle() when
// no longer needed.
//
// @param name Name of the new preference cookie.
// @param description Optional description of the preference cookie.
// @param access What CookieAccess level to assign to this cookie.
// @return A handle to the newly created cookie. If the cookie already
// exists, a handle to it will still be returned.
// @error Cookie name is blank.
public native Cookie(const char[] name, const char[] description, CookieAccess access);
// Searches for a Client preference cookie.
//
// Handles returned by Cookie.Find can be closed via CloseHandle() when
// no longer needed.
//
// @param name Name of cookie to find.
// @return A handle to the cookie if it is found, null otherwise.
public static native Cookie Find(const char[] name);
// Set the value of a Client preference cookie.
//
// @param client Client index.
// @param value String value to set.
// @error Invalid cookie handle or invalid client index.
public native void Set(int client, const char[] value);
// Set the integer value of a Client preference cookie.
//
// @param client Client index.
// @param value Integer value to set.
// @error Invalid cookie handle or invalid client index.
public void SetInt(int client, int value) {
char sValue[11];
IntToString(value, sValue, sizeof(sValue));
this.Set(client, sValue);
}
// Set the float value of a Client preference cookie.
//
// @param client Client index.
// @param value Float value to set.
// @error Invalid cookie handle or invalid client index.
public void SetFloat(int client, float value) {
char sValue[32];
FloatToString(value, sValue, sizeof(sValue));
this.Set(client, sValue);
}
// Retrieve the value of a Client preference cookie.
//
// @param client Client index.
// @param buffer Copyback buffer for value.
// @param maxlen Maximum length of the buffer.
// @error Invalid cookie handle or invalid client index.
public native void Get(int client, char[] buffer, int maxlen);
// Retrieve the integer value of a Client preference cookie.
//
// @param client Client index.
// @return Integer value of cookie
// @error Invalid cookie handle or invalid client index.
public int GetInt(int client, int defaultValue = 0)
{
char buffer[11];
this.Get(client, buffer, sizeof(buffer));
int value;
if (!StringToIntEx(buffer, value))
{
value = defaultValue;
}
return value;
}
// Retrieve the float value of a Client preference cookie.
//
// @param client Client index.
// @return Float value of cookie
// @error Invalid cookie handle or invalid client index.
public float GetFloat(int client, float defaultValue = 0.0)
{
char buffer[32];
this.Get(client, buffer, sizeof(buffer));
float value;
if (!StringToFloatEx(buffer, value))
{
value = defaultValue;
}
return value;
}
// Set the value of a Client preference cookie based on an authID string.
//
// @param authID String Auth/STEAM ID of player to set.
// @param value String value to set.
// @error Invalid cookie handle.
public native void SetByAuthId(const char[] authID, const char[] value);
// Add a new prefab item to the client cookie settings menu.
//
// Note: This handles everything automatically and does not require a callback
//
// @param type A CookieMenu prefab menu type.
// @param display Text to show on the menu.
// @param handler Optional handler callback for translations and output on selection
// @param info Info data to pass to the callback.
// @error Invalid cookie handle.
public native void SetPrefabMenu(CookieMenu type, const char[] display, CookieMenuHandler handler=INVALID_FUNCTION, any info=0);
// Returns the last updated timestamp for a client cookie
//
// @param client Client index.
// @return Last updated timestamp.
public native int GetClientTime(int client);
// Returns the access level of a cookie
//
// @return CookieAccess access level.
// @error Invalid cookie handle.
property CookieAccess AccessLevel {
public native get();
}
};
/**
* Creates a new Client preference cookie.
*
* Handles returned by RegClientCookie can be closed via CloseHandle() when
* no longer needed.
*
* @param name Name of the new preference cookie.
* @param description Optional description of the preference cookie.
* @param access What CookieAccess level to assign to this cookie.
* @return A handle to the newly created cookie. If the cookie already
* exists, a handle to it will still be returned.
* @error Cookie name is blank.
*/
native Cookie RegClientCookie(const char[] name, const char[] description, CookieAccess access);
/**
* Searches for a Client preference cookie.
*
* Handles returned by FindClientCookie can be closed via CloseHandle() when
* no longer needed.
*
* @param name Name of cookie to find.
* @return A handle to the cookie if it is found, null otherwise.
*/
native Cookie FindClientCookie(const char[] name);
/**
* Set the value of a Client preference cookie.
*
* @param client Client index.
* @param cookie Client preference cookie handle.
* @param value String value to set.
* @error Invalid cookie handle or invalid client index.
*/
native void SetClientCookie(int client, Handle cookie, const char[] value);
/**
* Retrieve the value of a Client preference cookie.
*
* @param client Client index.
* @param cookie Client preference cookie handle.
* @param buffer Copyback buffer for value.
* @param maxlen Maximum length of the buffer.
* @error Invalid cookie handle or invalid client index.
*/
native void GetClientCookie(int client, Handle cookie, char[] buffer, int maxlen);
/**
* Sets the value of a Client preference cookie based on an authID string.
*
* @param authID String Auth/STEAM ID of player to set.
* @param cookie Client preference cookie handle.
* @param value String value to set.
* @error Invalid cookie handle.
*/
native void SetAuthIdCookie(const char[] authID, Handle cookie, const char[] value);
/**
* Checks if a clients cookies have been loaded from the database.
*
* @param client Client index.
* @return True if loaded, false otherwise.
* @error Invalid client index.
*/
native bool AreClientCookiesCached(int client);
/**
* Called once a client's saved cookies have been loaded from the database.
*
* @param client Client index.
*/
forward void OnClientCookiesCached(int client);
/**
* Add a new prefab item to the client cookie settings menu.
*
* Note: This handles everything automatically and does not require a callback
*
* @param cookie Client preference cookie handle.
* @param type A CookieMenu prefab menu type.
* @param display Text to show on the menu.
* @param handler Optional handler callback for translations and output on selection
* @param info Info data to pass to the callback.
* @error Invalid cookie handle.
*/
native void SetCookiePrefabMenu(Handle cookie, CookieMenu type, const char[] display, CookieMenuHandler handler=INVALID_FUNCTION, any info=0);
/**
* Adds a new item to the client cookie settings menu.
*
* Note: This only adds the top level menu item. You need to handle any submenus from the callback.
*
* @param handler A MenuHandler callback function.
* @param info Data to pass to the callback.
* @param display Text to show on the menu.
* @error Invalid cookie handle.
*/
native void SetCookieMenuItem(CookieMenuHandler handler, any info, const char[] display);
/**
* Displays the settings menu to a client.
*
* @param client Client index.
*/
native void ShowCookieMenu(int client);
/**
* Gets a cookie iterator. Must be freed with CloseHandle().
*
* @return A new cookie iterator.
*/
native Handle GetCookieIterator();
/**
* Reads a cookie iterator, then advances to the next cookie if any.
*
* @param iter Cookie iterator Handle.
* @param name Name buffer.
* @param nameLen Name buffer size.
* @param access Access level of the cookie.
* @param desc Cookie description buffer.
* @param descLen Cookie description buffer size.
* @return True on success, false if there are no more commands.
*/
native bool ReadCookieIterator(Handle iter,
char[] name,
int nameLen,
CookieAccess &access,
char[] desc="",
int descLen=0);
/**
* Returns the access level of a cookie
*
* @param cookie Client preference cookie handle.
* @return CookieAccess access level.
* @error Invalid cookie handle.
*/
native CookieAccess GetCookieAccess(Handle cookie);
/**
* Returns the last updated timestamp for a client cookie
*
* @param client Client index.
* @param cookie Cookie handle.
* @return Last updated timestamp.
*/
native int GetClientCookieTime(int client, Handle cookie);
/**
* Do not edit below this line!
*/
public Extension __ext_cprefs =
{
name = "Client Preferences",
file = "clientprefs.ext",
#if defined AUTOLOAD_EXTENSIONS
autoload = 1,
#else
autoload = 0,
#endif
#if defined REQUIRE_EXTENSIONS
required = 1,
#else
required = 0,
#endif
};
#if !defined REQUIRE_EXTENSIONS
public void __ext_cprefs_SetNTVOptional()
{
MarkNativeAsOptional("RegClientCookie");
MarkNativeAsOptional("FindClientCookie");
MarkNativeAsOptional("SetClientCookie");
MarkNativeAsOptional("GetClientCookie");
MarkNativeAsOptional("SetAuthIdCookie");
MarkNativeAsOptional("AreClientCookiesCached");
MarkNativeAsOptional("SetCookiePrefabMenu");
MarkNativeAsOptional("SetCookieMenuItem");
MarkNativeAsOptional("ShowCookieMenu");
MarkNativeAsOptional("GetCookieIterator");
MarkNativeAsOptional("ReadCookieIterator");
MarkNativeAsOptional("GetCookieAccess");
MarkNativeAsOptional("GetClientCookieTime");
MarkNativeAsOptional("Cookie.Cookie");
MarkNativeAsOptional("Cookie.Find");
MarkNativeAsOptional("Cookie.Set");
MarkNativeAsOptional("Cookie.Get");
MarkNativeAsOptional("Cookie.SetByAuthId");
MarkNativeAsOptional("Cookie.SetPrefabMenu");
MarkNativeAsOptional("Cookie.GetClientTime");
MarkNativeAsOptional("Cookie.AccessLevel.get");
}
#endif