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