CLIENT PREFS ARE GO!!1!shiftone!!1!

Fully implemented amb734 - Including console interface and menu for clients to use.

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%402140
This commit is contained in:
Matt Woodrow
2008-05-12 08:06:47 +00:00
parent 6e91780e73
commit d88ba02fde
22 changed files with 1177 additions and 112 deletions
+150
View File
@@ -0,0 +1,150 @@
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod Map Management Plugin
* Provides all map related functionality, including map changing, map voting,
* and nextmap.
*
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* 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$
*/
#pragma semicolon 1
#include <sourcemod>
#include <clientprefs>
public Plugin:myinfo =
{
name = "Client Preferences",
author = "AlliedModders LLC",
description = "Client peferences and settings menu",
version = SOURCEMOD_VERSION,
url = "http://www.sourcemod.net/"
};
public OnPluginStart()
{
LoadTranslations("clientprefs.phrases");
RegConsoleCmd("sm_cookie", Command_Cookie, "sm_cookie <name> [value]");
RegConsoleCmd("sm_settings", Command_Settings);
}
public Action:Command_Cookie(client, args)
{
if (args == 0)
{
ReplyToCommand(client, "[SM] Usage: sm_cookie <name> [value]");
ReplyToCommand(client, "[SM] %t", "Printing Cookie List");
/* Show list of cookies */
new Handle:iter = GetCookieIterator();
decl String:name[30];
name[0] = '\0';
decl String:description[255];
description[0] = '\0';
PrintToConsole(client, "%t:", "Cookie List");
new CookieAccess:access;
while (ReadCookieIterator(iter,
name,
sizeof(name),
access,
description,
sizeof(description)) != false)
{
if (access < CookieAccess_Private)
{
PrintToConsole(client, "%s - %s", name, description);
}
}
return Plugin_Handled;
}
decl String:name[30];
name[0] = '\0';
GetCmdArg(1, name, sizeof(name));
new Handle:cookie = FindClientCookie(name);
if (cookie == INVALID_HANDLE)
{
ReplyToCommand(client, "[SM] %t", "Cookie not Found", name);
return Plugin_Handled;
}
new CookieAccess:access = GetCookieAccess(cookie);
if (access == CookieAccess_Private)
{
ReplyToCommand(client, "[SM] %t", "Cookie not Found", name);
return Plugin_Handled;
}
decl String:value[100];
value[0] = '\0';
if (args == 1)
{
GetClientCookie(client, cookie, value, sizeof(value));
ReplyToCommand(client, "[SM] %t", "Cookie Value", name, value);
return Plugin_Handled;
}
if (access == CookieAccess_Protected)
{
ReplyToCommand(client, "[SM] %t", "Protected Cookie", name);
return Plugin_Handled;
}
/* Set the new value of the cookie */
GetCmdArg(2, value, sizeof(value));
SetClientCookie(client, cookie, value);
ReplyToCommand(client, "[SM] %t", "Cookie Changed Value", name, value);
return Plugin_Handled;
}
public Action:Command_Settings(client, args)
{
if (client == 0)
{
PrintToServer("%T", "No Console", LANG_SERVER);
return Plugin_Handled;
}
ShowCookieMenu(client);
return Plugin_Handled;
}
+127 -5
View File
@@ -35,15 +35,55 @@
#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,
};
/**
* Creates a new Client preference cookie.
*
* @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 Handle:RegClientPrefCookie(const String:name[], const String:description[]);
native Handle:RegClientCookie(const String:name[], const String:description[], CookieAccess:access);
/**
* Searches for a Client preference cookie.
@@ -51,7 +91,7 @@ native Handle:RegClientPrefCookie(const String:name[], const String:description[
* @param name Name of cookie to find.
* @return A handle to the cookie if it is found. INVALID_HANDLE otherwise.
*/
native Handle:FindClientPrefCookie(const String:name[]);
native Handle:FindClientCookie(const String:name[]);
/**
* Set the value of a Client preference cookie.
@@ -62,7 +102,7 @@ native Handle:FindClientPrefCookie(const String:name[]);
* @noreturn
* @error Invalid cookie handle or invalid client index.
*/
native SetClientPrefCookie(client, Handle:cookie, const String:value[]);
native SetClientCookie(client, Handle:cookie, const String:value[]);
/**
* Retrieve the value of a Client preference cookie.
@@ -71,9 +111,10 @@ native SetClientPrefCookie(client, Handle:cookie, const String:value[]);
* @param cookie Client preference cookie handle.
* @param buffer Copyback buffer for value.
* @param maxlen Maximum length of the buffer.
* @noreturn
* @error Invalid cookie handle or invalid client index.
*/
native GetClientPrefCookie(client, Handle:cookie, String:buffer[], maxlen);
native GetClientCookie(client, Handle:cookie, String:buffer[], maxlen);
/**
* Checks if a clients cookies have been loaded from the database.
@@ -89,8 +130,89 @@ native bool:AreClientCookiesCached(client);
*
* @param client Client index.
*/
forward OnClientCookiesLoaded(client);
forward OnClientCookiesCached(client);
/**
* Cookie Menu Callback prototype
*
* @param client Client index.
* @param action CookeMenuAction being performed.
* @param data Info data passed.
* @param buffer Outbut buffer.
* @param maxlen Max length of the output buffer.
*/
functag CookieMenuHandler public(client, CookieMenuAction:action, any:info, String:buffer[], maxlen);
/**
* 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.
* @noreturn
* @error Invalid cookie handle.
*/
native SetCookiePrefabMenu(Handle:cookie, CookieMenu:type, const String:display[], CookieMenuHandler:handler=CookieMenuHandler:-1, 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.
* @noreturn
* @error Invalid cookie handle.
*/
native SetCookieMenuItem(CookieMenuHandler:handler, any:info, const String:display[]);
/**
* Displays the settings menu to a client.
*
* @param client Client index.
* @noreturn
*/
native ShowCookieMenu(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.
* @param
* @return True on success, false if there are no more commands.
*/
native bool:ReadCookieIterator(Handle:iter,
String:name[],
nameLen,
&CookieAccess:access,
String:desc[]="",
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);
/**
* Do not edit below this line!
+41 -8
View File
@@ -1,26 +1,59 @@
#include <sourcemod>
#include "../include/clientprefs.inc"
#include <clientprefs.inc>
new Handle:g_Cookie;
new Handle:g_Cookie2;
new Handle:g_Cookie3;
new Handle:g_Cookie4;
new Handle:g_Cookie5;
public OnPluginStart()
{
g_Cookie = RegClientPrefCookie("test-cookie", "A basic testing cookie");
g_Cookie = RegClientCookie("test-cookie", "A basic testing cookie", CookieAccess_Public);
g_Cookie2 = RegClientCookie("test-cookie2", "A basic testing cookie", CookieAccess_Protected);
g_Cookie3 = RegClientCookie("test-cookie3", "A basic testing cookie", CookieAccess_Public);
g_Cookie4 = RegClientCookie("test-cookie4", "A basic testing cookie", CookieAccess_Private);
g_Cookie5 = RegClientCookie("test-cookie5", "A basic testing cookie", CookieAccess_Public);
SetCookiePrefabMenu(g_Cookie, CookieMenu_YesNo, "Cookie 1", CookieSelected, any:g_Cookie);
SetCookiePrefabMenu(g_Cookie2, CookieMenu_YesNo_Int, "Cookie 2");
SetCookiePrefabMenu(g_Cookie3, CookieMenu_OnOff, "Cookie 3");
SetCookiePrefabMenu(g_Cookie4, CookieMenu_OnOff_Int, "Cookie 4");
SetCookieMenuItem(CookieSelected, g_Cookie5, "Get Cookie 5 value");
}
public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
public CookieSelected(client, CookieMenuAction:action, any:info, String:buffer[], maxlen)
{
if (action == CookieMenuAction_DisplayOption)
{
PrintToChat(client, "About to draw item. Current text is : %s", buffer);
Format(buffer, maxlen, "HELLLLLLLLLLO");
}
else
{
LogMessage("SELECTED!");
new String:value[100];
GetClientCookie(client, info, value, sizeof(value));
PrintToChat(client, "Value is : %s", value);
}
}
public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
{
LogMessage("Connect Cookie state: %s", AreClientCookiesCached(client) ? "YES" : "NO");
}
public OnClientCookiesLoaded(client)
public OnClientCookiesCached(client)
{
LogMessage("Loaded Cookie state: %s", AreClientCookiesCached(client) ? "YES" : "NO");
new String:hi[100];
GetClientPrefCookie(client, g_Cookie, hi, sizeof(hi));
GetClientCookie(client, g_Cookie, hi, sizeof(hi));
LogMessage("Test: %s",hi);
SetClientPrefCookie(client, g_Cookie, "somethingsomething");
GetClientPrefCookie(client, g_Cookie, hi, sizeof(hi));
SetClientCookie(client, g_Cookie, "somethingsomething");
GetClientCookie(client, g_Cookie, hi, sizeof(hi));
LogMessage("Test: %s",hi);
}
}