plugins/clientprefs.sp
author Tony <aangione@gmail.com>
Sun May 27 01:51:06 2012 +0100 (2012-05-27)
changeset 3510 c72cfe0c6a57
parent 2207 3a97a56ded62
child 3958 2378da680448
permissions -rw-r--r--
Adding missing SetMenuNoVoteButton native declaration (bug 4522, r=asherkin).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Map Management Plugin
     5  * Provides all map related functionality, including map changing, map voting,
     6  * and nextmap.
     7  *
     8  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     9  * =============================================================================
    10  *
    11  * This program is free software; you can redistribute it and/or modify it under
    12  * the terms of the GNU General Public License, version 3.0, as published by the
    13  * Free Software Foundation.
    14  * 
    15  * This program is distributed in the hope that it will be useful, but WITHOUT
    16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    17  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    18  * details.
    19  *
    20  * You should have received a copy of the GNU General Public License along with
    21  * this program.  If not, see <http://www.gnu.org/licenses/>.
    22  *
    23  * As a special exception, AlliedModders LLC gives you permission to link the
    24  * code of this program (as well as its derivative works) to "Half-Life 2," the
    25  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    26  * by the Valve Corporation.  You must obey the GNU General Public License in
    27  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    28  * this exception to all derivative works.  AlliedModders LLC defines further
    29  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    30  * or <http://www.sourcemod.net/license.php>.
    31  *
    32  * Version: $Id$
    33  */
    34  
    35 
    36 #pragma semicolon 1
    37 #include <sourcemod>
    38 #include <clientprefs>
    39 
    40 public Plugin:myinfo =
    41 {
    42 	name = "Client Preferences",
    43 	author = "AlliedModders LLC",
    44 	description = "Client peferences and settings menu",
    45 	version = SOURCEMOD_VERSION,
    46 	url = "http://www.sourcemod.net/"
    47 };
    48 
    49 public OnPluginStart()
    50 {
    51 	LoadTranslations("clientprefs.phrases");
    52 	
    53 	RegConsoleCmd("sm_cookies", Command_Cookie, "sm_cookies <name> [value]");
    54 	RegConsoleCmd("sm_settings", Command_Settings);	
    55 }
    56 
    57 public Action:Command_Cookie(client, args)
    58 {
    59 	if (args == 0)
    60 	{
    61 		ReplyToCommand(client, "[SM] Usage: sm_cookies <name> [value]");
    62 		ReplyToCommand(client, "[SM] %t", "Printing Cookie List");
    63 		
    64 		/* Show list of cookies */
    65 		new Handle:iter = GetCookieIterator();
    66 		
    67 		decl String:name[30];
    68 		name[0] = '\0';
    69 		decl String:description[255];
    70 		description[0] = '\0';
    71 		
    72 		PrintToConsole(client, "%t:", "Cookie List");
    73 		
    74 		new CookieAccess:access;
    75 		
    76 		while (ReadCookieIterator(iter, 
    77 								name, 
    78 								sizeof(name),
    79 								access, 
    80 								description, 
    81 								sizeof(description)) != false)
    82 		{
    83 			if (access < CookieAccess_Private)
    84 			{
    85 				PrintToConsole(client, "%s - %s", name, description);
    86 			}
    87 		}
    88 		
    89 		return Plugin_Handled;
    90 	}
    91 	
    92 	if (client == 0)
    93 	{
    94 		PrintToServer("%T", "No Console", LANG_SERVER);
    95 		return Plugin_Handled;	
    96 	}
    97 	
    98 	decl String:name[30];
    99 	name[0] = '\0';
   100 	GetCmdArg(1, name, sizeof(name));
   101 	
   102 	new Handle:cookie = FindClientCookie(name);
   103 	
   104 	if (cookie == INVALID_HANDLE)
   105 	{
   106 		ReplyToCommand(client, "[SM] %t", "Cookie not Found", name);
   107 		return Plugin_Handled;
   108 	}
   109 	
   110 	new CookieAccess:access = GetCookieAccess(cookie);
   111 	
   112 	if (access == CookieAccess_Private)
   113 	{
   114 		ReplyToCommand(client, "[SM] %t", "Cookie not Found", name);
   115 		return Plugin_Handled;
   116 	}
   117 	
   118 	decl String:value[100];
   119 	value[0] = '\0';
   120 	
   121 	if (args == 1)
   122 	{
   123 		GetClientCookie(client, cookie, value, sizeof(value));
   124 		ReplyToCommand(client, "[SM] %t", "Cookie Value", name, value);
   125 		
   126 		return Plugin_Handled;
   127 	}
   128 	
   129 	if (access == CookieAccess_Protected)
   130 	{
   131 		ReplyToCommand(client, "[SM] %t", "Protected Cookie", name);
   132 		return Plugin_Handled;
   133 	}
   134 	
   135 	/* Set the new value of the cookie */
   136 	
   137 	GetCmdArg(2, value, sizeof(value));
   138 	
   139 	SetClientCookie(client, cookie, value);
   140 	ReplyToCommand(client, "[SM] %t", "Cookie Changed Value", name, value);
   141 	
   142 	return Plugin_Handled;
   143 }
   144 
   145 public Action:Command_Settings(client, args)
   146 {
   147 	if (client == 0)
   148 	{
   149 		PrintToServer("%T", "No Console", LANG_SERVER);
   150 		return Plugin_Handled;	
   151 	}
   152 	
   153 	ShowCookieMenu(client);
   154 	
   155 	return Plugin_Handled;
   156 }