plugins/clientprefs.sp
author FlaminSarge <flaminsarge@gmail.com>
Mon Aug 12 01:18:01 2013 +0100 (2013-08-12)
changeset 4001 608bc5be1ef0
parent 3958 2378da680448
permissions -rw-r--r--
Add support for more CalcIsAttackCritical helpers. (bug 5576, 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 		CloseHandle(iter);		
    90 		return Plugin_Handled;
    91 	}
    92 	
    93 	if (client == 0)
    94 	{
    95 		PrintToServer("%T", "No Console", LANG_SERVER);
    96 		return Plugin_Handled;	
    97 	}
    98 	
    99 	decl String:name[30];
   100 	name[0] = '\0';
   101 	GetCmdArg(1, name, sizeof(name));
   102 	
   103 	new Handle:cookie = FindClientCookie(name);
   104 	
   105 	if (cookie == INVALID_HANDLE)
   106 	{
   107 		ReplyToCommand(client, "[SM] %t", "Cookie not Found", name);
   108 		return Plugin_Handled;
   109 	}
   110 	
   111 	new CookieAccess:access = GetCookieAccess(cookie);
   112 	
   113 	if (access == CookieAccess_Private)
   114 	{
   115 		ReplyToCommand(client, "[SM] %t", "Cookie not Found", name);
   116 		CloseHandle(cookie);
   117 		return Plugin_Handled;
   118 	}
   119 	
   120 	decl String:value[100];
   121 	value[0] = '\0';
   122 	
   123 	if (args == 1)
   124 	{
   125 		GetClientCookie(client, cookie, value, sizeof(value));
   126 		ReplyToCommand(client, "[SM] %t", "Cookie Value", name, value);
   127 		
   128 		CloseHandle(cookie);
   129 		return Plugin_Handled;
   130 	}
   131 	
   132 	if (access == CookieAccess_Protected)
   133 	{
   134 		ReplyToCommand(client, "[SM] %t", "Protected Cookie", name);
   135 		CloseHandle(cookie);
   136 		return Plugin_Handled;
   137 	}
   138 	
   139 	/* Set the new value of the cookie */
   140 	
   141 	GetCmdArg(2, value, sizeof(value));
   142 	
   143 	SetClientCookie(client, cookie, value);
   144 	CloseHandle(cookie);
   145 	ReplyToCommand(client, "[SM] %t", "Cookie Changed Value", name, value);
   146 	
   147 	return Plugin_Handled;
   148 }
   149 
   150 public Action:Command_Settings(client, args)
   151 {
   152 	if (client == 0)
   153 	{
   154 		PrintToServer("%T", "No Console", LANG_SERVER);
   155 		return Plugin_Handled;	
   156 	}
   157 	
   158 	ShowCookieMenu(client);
   159 	
   160 	return Plugin_Handled;
   161 }