pred@2009: /**
pred@2009: * vim: set ts=4 :
pred@2009: * =============================================================================
pred@2009: * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
pred@2009: * =============================================================================
pred@2009: *
pred@2009: * This file is part of the SourceMod/SourcePawn SDK.
pred@2009: *
pred@2009: * This program is free software; you can redistribute it and/or modify it under
pred@2009: * the terms of the GNU General Public License, version 3.0, as published by the
pred@2009: * Free Software Foundation.
pred@2009: *
pred@2009: * This program is distributed in the hope that it will be useful, but WITHOUT
pred@2009: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
pred@2009: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
pred@2009: * details.
pred@2009: *
pred@2009: * You should have received a copy of the GNU General Public License along with
pred@2009: * this program. If not, see .
pred@2009: *
pred@2009: * As a special exception, AlliedModders LLC gives you permission to link the
pred@2009: * code of this program (as well as its derivative works) to "Half-Life 2," the
pred@2009: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
pred@2009: * by the Valve Corporation. You must obey the GNU General Public License in
pred@2009: * all respects for all other code used. Additionally, AlliedModders LLC grants
pred@2009: * this exception to all derivative works. AlliedModders LLC defines further
pred@2009: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
pred@2009: * or .
pred@2009: *
pred@2009: * Version: $Id$
pred@2009: */
pred@2009:
pred@2009: #if defined _clientprefs_included
pred@2009: #endinput
pred@2009: #endif
pred@2009: #define _clientprefs_included
pred@2009:
pred@2009: /**
pred@2048: * Cookie access types for client viewing
pred@2048: */
pred@2048: enum CookieAccess
pred@2048: {
pred@2048: CookieAccess_Public, /**< Visible and Changeable by users */
pred@2048: CookieAccess_Protected, /**< Read only to users */
pred@2048: CookieAccess_Private, /**< Completely hidden cookie */
pred@2048: };
pred@2048:
pred@2048: /**
pred@2048: * Cookie Prefab menu types
pred@2048: */
pred@2048: enum CookieMenu
pred@2048: {
pred@2048: CookieMenu_YesNo, /**< Yes/No menu with "yes"/"no" results saved into the cookie */
pred@2048: CookieMenu_YesNo_Int, /**< Yes/No menu with 1/0 saved into the cookie */
pred@2048: CookieMenu_OnOff, /**< On/Off menu with "on"/"off" results saved into the cookie */
pred@2048: CookieMenu_OnOff_Int, /**< On/Off menu with 1/0 saved into the cookie */
pred@2048: };
pred@2048:
pred@2048: enum CookieMenuAction
pred@2048: {
pred@2048: /**
pred@2048: * An option is being drawn for a menu.
pred@2048: *
pred@2048: * INPUT : Client index and data if available.
pred@2048: * OUTPUT: Buffer for rendering, maxlength of buffer.
pred@2048: */
pred@2048: CookieMenuAction_DisplayOption = 0,
pred@2048:
pred@2048: /**
pred@2048: * A menu option has been selected.
pred@2048: *
pred@2048: * INPUT : Client index and any data if available.
pred@2048: */
pred@2048: CookieMenuAction_SelectOption = 1,
pred@2048: };
pred@2048:
pred@2048: /**
pred@2207: * Note:
pred@2207: *
pred@2207: * A successful return value/result on any client prefs native only guarantees that the local cache has been updated.
pred@2207: * Database connection problems can still prevent the data from being permanently saved. Connection problems will be logged as
pred@2207: * errors by the clientprefs extension.
pred@2207: */
pred@2207:
pred@2207: /**
pred@2009: * Creates a new Client preference cookie.
pred@2009: *
pred@2009: * @param name Name of the new preference cookie.
pred@2009: * @param description Optional description of the preference cookie.
pred@2048: * @param access What CookieAccess level to assign to this cookie.
pred@2009: * @return A handle to the newly created cookie. If the cookie already exists, a handle to it will still be returned.
pred@2009: * @error Cookie name is blank.
pred@2009: */
pred@2048: native Handle:RegClientCookie(const String:name[], const String:description[], CookieAccess:access);
pred@2009:
pred@2009: /**
pred@2009: * Searches for a Client preference cookie.
pred@2009: *
pred@2009: * @param name Name of cookie to find.
pred@2009: * @return A handle to the cookie if it is found. INVALID_HANDLE otherwise.
pred@2009: */
pred@2048: native Handle:FindClientCookie(const String:name[]);
pred@2009:
pred@2009: /**
pred@2009: * Set the value of a Client preference cookie.
pred@2009: *
pred@2009: * @param client Client index.
pred@2009: * @param cookie Client preference cookie handle.
pred@2009: * @param value String value to set.
pred@2009: * @noreturn
pred@2009: * @error Invalid cookie handle or invalid client index.
pred@2009: */
pred@2048: native SetClientCookie(client, Handle:cookie, const String:value[]);
pred@2009:
pred@2009: /**
pred@2009: * Retrieve the value of a Client preference cookie.
pred@2009: *
pred@2009: * @param client Client index.
pred@2009: * @param cookie Client preference cookie handle.
pred@2009: * @param buffer Copyback buffer for value.
pred@2009: * @param maxlen Maximum length of the buffer.
pred@2048: * @noreturn
pred@2009: * @error Invalid cookie handle or invalid client index.
pred@2009: */
pred@2048: native GetClientCookie(client, Handle:cookie, String:buffer[], maxlen);
pred@2009:
pred@2009: /**
pred@2009: * Checks if a clients cookies have been loaded from the database.
pred@2009: *
pred@2009: * @param client Client index.
pred@2009: * @return True if loaded, false otherwise.
pred@2009: * @error Invalid client index.
pred@2009: */
pred@2009: native bool:AreClientCookiesCached(client);
pred@2009:
pred@2009: /**
pred@2009: * Called once a client's saved cookies have been loaded from the database.
pred@2009: *
pred@2009: * @param client Client index.
pred@2009: */
pred@2048: forward OnClientCookiesCached(client);
pred@2048:
pred@2048: /**
pred@2048: * Cookie Menu Callback prototype
pred@2048: *
pred@2048: * @param client Client index.
pred@2048: * @param action CookeMenuAction being performed.
pred@2048: * @param data Info data passed.
pred@2048: * @param buffer Outbut buffer.
pred@2048: * @param maxlen Max length of the output buffer.
pred@2048: */
dvander@2317: functag public CookieMenuHandler(client, CookieMenuAction:action, any:info, String:buffer[], maxlen);
pred@2048:
pred@2048: /**
pred@2048: * Add a new prefab item to the client cookie settings menu.
pred@2048: *
pred@2048: * Note: This handles everything automatically and does not require a callback
pred@2048: *
pred@2048: * @param cookie Client preference cookie handle.
pred@2048: * @param type A CookieMenu prefab menu type.
pred@2048: * @param display Text to show on the menu.
pred@2048: * @param handler Optional handler callback for translations and output on selection
pred@2048: * @param info Info data to pass to the callback.
pred@2048: * @noreturn
pred@2048: * @error Invalid cookie handle.
pred@2048: */
pred@2048: native SetCookiePrefabMenu(Handle:cookie, CookieMenu:type, const String:display[], CookieMenuHandler:handler=CookieMenuHandler:-1, info=0);
pred@2048:
pred@2048: /**
pred@2048: * Adds a new item to the client cookie settings menu.
pred@2048: *
pred@2048: * Note: This only adds the top level menu item. You need to handle any submenus from the callback.
pred@2048: *
pred@2048: * @param handler A MenuHandler callback function.
pred@2048: * @param info Data to pass to the callback.
pred@2048: * @param display Text to show on the menu.
pred@2048: * @noreturn
pred@2048: * @error Invalid cookie handle.
pred@2048: */
pred@2048: native SetCookieMenuItem(CookieMenuHandler:handler, any:info, const String:display[]);
pred@2009:
pred@2048: /**
pred@2048: * Displays the settings menu to a client.
pred@2048: *
pred@2048: * @param client Client index.
pred@2048: * @noreturn
pred@2048: */
pred@2048: native ShowCookieMenu(client);
pred@2048:
pred@2048: /**
pred@2048: * Gets a cookie iterator. Must be freed with CloseHandle().
pred@2048: *
pred@2048: * @return A new cookie iterator.
pred@2048: */
pred@2048: native Handle:GetCookieIterator();
pred@2048:
pred@2048: /**
pred@2048: * Reads a cookie iterator, then advances to the next cookie if any.
pred@2048: *
pred@2048: * @param iter Cookie iterator Handle.
pred@2048: * @param name Name buffer.
pred@2048: * @param nameLen Name buffer size.
pred@2048: * @param access Access level of the cookie.
pred@2048: * @param desc Cookie description buffer.
pred@2048: * @param descLen Cookie description buffer size.
pred@2048: * @param
pred@2048: * @return True on success, false if there are no more commands.
pred@2048: */
pred@2048: native bool:ReadCookieIterator(Handle:iter,
pred@2048: String:name[],
pred@2048: nameLen,
pred@2048: &CookieAccess:access,
pred@2048: String:desc[]="",
pred@2048: descLen=0);
pred@2048:
pred@2048: /**
pred@2048: * Returns the access level of a cookie
pred@2048: *
pred@2048: * @param cookie Client preference cookie handle.
pred@2048: * @return CookieAccess access level.
pred@2048: * @error Invalid cookie handle.
pred@2048: */
pred@2048: native CookieAccess:GetCookieAccess(Handle:cookie);
pred@2009:
pred@2009: /**
pred@2009: * Do not edit below this line!
pred@2009: */
pred@2009: public Extension:__ext_clientprefs =
pred@2009: {
pred@2009: name = "Client Preferences",
pred@2009: file = "clientprefs.ext",
pred@2009: autoload = 1,
pred@2009: #if defined REQUIRE_EXTENSIONS
pred@2009: required = 1,
pred@2009: #else
pred@2009: required = 0,
pred@2009: #endif
pred@2009: };