plugins/clientprefs.sp
author Scott Ehlert <ds@alliedmods.net>
Fri Nov 14 09:18:30 2008 -0600 (2008-11-14)
changeset 2400 76b7b4575e21
parent 2207 3a97a56ded62
child 3958 2378da680448
permissions -rw-r--r--
Added preliminary support for Left 4 Dead; some things may not yet work.
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
		
pred@2048
    89
		return Plugin_Handled;
pred@2048
    90
	}
pred@2048
    91
	
pred@2076
    92
	if (client == 0)
pred@2076
    93
	{
pred@2076
    94
		PrintToServer("%T", "No Console", LANG_SERVER);
pred@2076
    95
		return Plugin_Handled;	
pred@2076
    96
	}
pred@2076
    97
	
pred@2048
    98
	decl String:name[30];
pred@2048
    99
	name[0] = '\0';
pred@2048
   100
	GetCmdArg(1, name, sizeof(name));
pred@2048
   101
	
pred@2048
   102
	new Handle:cookie = FindClientCookie(name);
pred@2048
   103
	
pred@2048
   104
	if (cookie == INVALID_HANDLE)
pred@2048
   105
	{
pred@2048
   106
		ReplyToCommand(client, "[SM] %t", "Cookie not Found", name);
pred@2048
   107
		return Plugin_Handled;
pred@2048
   108
	}
pred@2048
   109
	
pred@2048
   110
	new CookieAccess:access = GetCookieAccess(cookie);
pred@2048
   111
	
pred@2048
   112
	if (access == CookieAccess_Private)
pred@2048
   113
	{
pred@2048
   114
		ReplyToCommand(client, "[SM] %t", "Cookie not Found", name);
pred@2048
   115
		return Plugin_Handled;
pred@2048
   116
	}
pred@2048
   117
	
pred@2048
   118
	decl String:value[100];
pred@2048
   119
	value[0] = '\0';
pred@2048
   120
	
pred@2048
   121
	if (args == 1)
pred@2048
   122
	{
pred@2048
   123
		GetClientCookie(client, cookie, value, sizeof(value));
pred@2048
   124
		ReplyToCommand(client, "[SM] %t", "Cookie Value", name, value);
pred@2048
   125
		
pred@2048
   126
		return Plugin_Handled;
pred@2048
   127
	}
pred@2048
   128
	
pred@2048
   129
	if (access == CookieAccess_Protected)
pred@2048
   130
	{
pred@2048
   131
		ReplyToCommand(client, "[SM] %t", "Protected Cookie", name);
pred@2048
   132
		return Plugin_Handled;
pred@2048
   133
	}
pred@2048
   134
	
pred@2048
   135
	/* Set the new value of the cookie */
pred@2048
   136
	
pred@2048
   137
	GetCmdArg(2, value, sizeof(value));
pred@2048
   138
	
pred@2048
   139
	SetClientCookie(client, cookie, value);
pred@2048
   140
	ReplyToCommand(client, "[SM] %t", "Cookie Changed Value", name, value);
pred@2048
   141
	
pred@2048
   142
	return Plugin_Handled;
pred@2048
   143
}
pred@2048
   144
pred@2048
   145
public Action:Command_Settings(client, args)
pred@2048
   146
{
pred@2048
   147
	if (client == 0)
pred@2048
   148
	{
pred@2048
   149
		PrintToServer("%T", "No Console", LANG_SERVER);
pred@2048
   150
		return Plugin_Handled;	
pred@2048
   151
	}
pred@2048
   152
	
pred@2048
   153
	ShowCookieMenu(client);
pred@2048
   154
	
pred@2048
   155
	return Plugin_Handled;
pred@2048
   156
}