2008-05-12 10:06:47 +02:00
/ * *
* 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>
2016-05-11 15:32:34 +02:00
# pragma newdecls required
public Plugin myinfo =
2008-05-12 10:06:47 +02:00
{
name = " Client Preferences " ,
author = " AlliedModders LLC " ,
2019-12-15 01:12:14 +01:00
description = " Client preferences and settings menu " ,
2008-05-12 10:06:47 +02:00
version = SOURCEMOD_VERSION ,
url = " http://www.sourcemod.net/ "
} ;
2016-05-11 15:32:34 +02:00
public void OnPluginStart ( )
2008-05-12 10:06:47 +02:00
{
LoadTranslations ( " clientprefs.phrases " ) ;
2008-05-12 10:56:24 +02:00
RegConsoleCmd ( " sm_cookies " , Command_Cookie , " sm_cookies <name> [value] " ) ;
2008-05-12 10:06:47 +02:00
RegConsoleCmd ( " sm_settings " , Command_Settings ) ;
}
2016-05-11 15:32:34 +02:00
public Action Command_Cookie ( int client , int args )
2008-05-12 10:06:47 +02:00
{
if ( args = = 0 )
{
2008-07-15 02:24:08 +02:00
ReplyToCommand ( client , " [SM] Usage: sm_cookies <name> [value] " ) ;
2008-05-12 10:06:47 +02:00
ReplyToCommand ( client , " [SM] %t " , " Printing Cookie List " ) ;
/* Show list of cookies */
2016-05-11 15:32:34 +02:00
Handle iter = GetCookieIterator ( ) ;
2008-05-12 10:06:47 +02:00
2016-05-11 15:32:34 +02:00
char name [ 30 ] ;
char description [ 255 ] ;
2008-05-12 10:06:47 +02:00
PrintToConsole ( client , " %t: " , " Cookie List " ) ;
2016-05-11 15:32:34 +02:00
CookieAccess access ;
2008-05-12 10:06:47 +02:00
2020-07-09 05:38:35 +02:00
int count = 1 ;
while ( ReadCookieIterator ( iter , name , sizeof ( name ) , access , description , sizeof ( description ) ) ! = false )
2008-05-12 10:06:47 +02:00
{
if ( access < CookieAccess_Private )
{
2020-07-09 05:38:35 +02:00
PrintToConsole ( client , " [%03d] %s - %s " , count + + , name , description ) ;
2008-05-12 10:06:47 +02:00
}
}
2014-11-16 01:30:45 +01:00
delete iter ;
2008-05-12 10:06:47 +02:00
return Plugin_Handled ;
}
2008-05-25 05:26:31 +02:00
if ( client = = 0 )
{
PrintToServer ( " %T " , " No Console " , LANG_SERVER ) ;
return Plugin_Handled ;
}
2016-05-11 15:32:34 +02:00
char name [ 30 ] ;
2020-07-09 05:38:35 +02:00
2008-05-12 10:06:47 +02:00
GetCmdArg ( 1 , name , sizeof ( name ) ) ;
2016-05-11 15:32:34 +02:00
Handle cookie = FindClientCookie ( name ) ;
2008-05-12 10:06:47 +02:00
2014-11-16 01:30:45 +01:00
if ( cookie = = null )
2008-05-12 10:06:47 +02:00
{
ReplyToCommand ( client , " [SM] %t " , " Cookie not Found " , name ) ;
return Plugin_Handled ;
}
2016-05-11 15:32:34 +02:00
CookieAccess access = GetCookieAccess ( cookie ) ;
2008-05-12 10:06:47 +02:00
if ( access = = CookieAccess_Private )
{
ReplyToCommand ( client , " [SM] %t " , " Cookie not Found " , name ) ;
2014-11-16 01:30:45 +01:00
delete cookie ;
2008-05-12 10:06:47 +02:00
return Plugin_Handled ;
}
2016-05-11 15:32:34 +02:00
char value [ 100 ] ;
2008-05-12 10:06:47 +02:00
if ( args = = 1 )
{
2020-07-09 05:38:35 +02:00
Handle iter = GetCookieIterator ( ) ;
2008-05-12 10:06:47 +02:00
GetClientCookie ( client , cookie , value , sizeof ( value ) ) ;
ReplyToCommand ( client , " [SM] %t " , " Cookie Value " , name , value ) ;
2020-07-09 05:38:35 +02:00
char CookieName [ 30 ] ;
char description [ 255 ] ;
while ( ReadCookieIterator ( iter , CookieName , sizeof ( CookieName ) , access , description , sizeof ( description ) ) ! = false ) // We're allowed to re-use access since we're about to return anyways.
{
if ( StrEqual ( CookieName , name , true ) )
{
TrimString ( description ) ;
if ( description [ 0 ] ! = EOS )
ReplyToCommand ( client , " - %s " , description ) ;
break ;
}
}
delete iter ;
2014-11-16 01:30:45 +01:00
delete cookie ;
2008-05-12 10:06:47 +02:00
return Plugin_Handled ;
}
if ( access = = CookieAccess_Protected )
{
ReplyToCommand ( client , " [SM] %t " , " Protected Cookie " , name ) ;
2014-11-16 01:30:45 +01:00
delete cookie ;
2008-05-12 10:06:47 +02:00
return Plugin_Handled ;
}
/* Set the new value of the cookie */
GetCmdArg ( 2 , value , sizeof ( value ) ) ;
SetClientCookie ( client , cookie , value ) ;
2014-11-16 01:30:45 +01:00
delete cookie ;
2008-05-12 10:06:47 +02:00
ReplyToCommand ( client , " [SM] %t " , " Cookie Changed Value " , name , value ) ;
return Plugin_Handled ;
}
2016-05-11 15:32:34 +02:00
public Action Command_Settings ( int client , int args )
2008-05-12 10:06:47 +02:00
{
if ( client = = 0 )
{
PrintToServer ( " %T " , " No Console " , LANG_SERVER ) ;
return Plugin_Handled ;
}
ShowCookieMenu ( client ) ;
return Plugin_Handled ;
2016-05-11 15:32:34 +02:00
}