2016-01-19 23:57:32 +01:00
# pragma semicolon 1
# include <sourcemod>
# include <geoip>
2018-08-06 16:38:53 +02:00
# include <multicolors>
2019-01-08 18:12:12 +01:00
# include <clientprefs>
2019-06-08 15:42:33 +02:00
# include <PlayerManager>
2016-01-19 23:57:32 +01:00
# pragma newdecls required
2018-07-23 11:04:35 +02:00
char g_sDataFile [ 128 ] ;
char g_sCustomMessageFile [ 128 ] ;
Database g_hDatabase ;
Handle g_hCustomMessageFile ;
Handle g_hCustomMessageFile2 ;
2019-01-08 18:12:12 +01:00
bool g_bHideCsays [ MAXPLAYERS + 1 ] = { false , . . . } ;
Handle g_hCookieHideCsays = null ;
2018-07-23 11:04:35 +02:00
2019-02-24 11:56:01 +01:00
ConVar g_cvHlstatsServerName ;
2018-07-23 11:04:35 +02:00
# define MSGLENGTH 100
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
2016-01-19 23:57:32 +01:00
public Plugin myinfo = {
2018-07-23 17:06:03 +02:00
name = " Connect Announce " ,
2019-01-08 18:12:12 +01:00
author = " Neon + Botox + Dogan " ,
description = " Connect Announcer with special features for VIPS " ,
2019-10-29 16:36:30 +01:00
version = " 3.1 " ,
2018-07-23 17:06:03 +02:00
url = " "
2016-01-19 23:57:32 +01:00
}
2018-07-23 11:04:35 +02:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnPluginStart ( )
2016-01-19 23:57:32 +01:00
{
2019-02-24 11:56:01 +01:00
g_cvHlstatsServerName = CreateConVar ( " sm_connectannounce_hlstats_server_name " , " css-ze " , " Hlstats server name to check the rank for " ) ;
AutoExecConfig ( true ) ;
2018-07-23 11:04:35 +02:00
BuildPath ( Path_SM , g_sCustomMessageFile , sizeof ( g_sCustomMessageFile ) , " configs/connect_announce/custom-messages.cfg " ) ;
BuildPath ( Path_SM , g_sDataFile , sizeof ( g_sDataFile ) , " configs/connect_announce/settings.cfg " ) ;
2019-02-24 11:56:01 +01:00
Database . Connect ( OnDatabaseConnect , " hlstatsx " ) ;
2018-07-23 11:04:35 +02:00
RegAdminCmd ( " sm_joinmsg " , Command_JoinMsg , ADMFLAG_CUSTOM1 , " Sets a custom message which will be shown upon connecting to the server " ) ;
RegAdminCmd ( " sm_resetjoinmsg " , Command_ResetJoinMsg , ADMFLAG_CUSTOM1 , " Resets your custom connect message " ) ;
2019-01-08 18:12:12 +01:00
2019-10-29 16:36:30 +01:00
RegAdminCmd ( " sm_hide_connect_csays " , OnToggleHideCsays , ADMFLAG_CUSTOM1 , " Toggle blocking connect csay messages " ) ;
2019-01-08 18:12:12 +01:00
g_hCookieHideCsays = RegClientCookie ( " csays_blocked " , " are csays blocked " , CookieAccess_Protected ) ;
2019-01-16 14:25:57 +01:00
SetCookieMenuItem ( MenuHandler_CookieMenu , 0 , " Hide Connect Csays " ) ;
2019-01-08 18:12:12 +01:00
}
2019-02-24 11:56:01 +01:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnDatabaseConnect ( Database db , const char [ ] error , any data )
{
if ( db = = INVALID_HANDLE | | strlen ( error ) > 0 )
{
LogError ( " Error connecting to database: %s " , error ) ;
return ;
}
g_hDatabase = db ;
}
2019-10-29 16:36:30 +01:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientCookiesCached ( int client )
{
if ( IsClientAuthorized ( client ) )
ReadClientCookies ( client ) ;
}
2019-01-08 18:12:12 +01:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
2019-01-16 14:25:57 +01:00
public void ToggleHideCsays ( int client )
2019-01-08 18:12:12 +01:00
{
g_bHideCsays [ client ] = ! g_bHideCsays [ client ] ;
2019-01-16 14:25:57 +01:00
SetClientCookie ( client , g_hCookieHideCsays , g_bHideCsays [ client ] ? " 1 " : " " ) ;
2019-01-16 17:21:45 +01:00
CPrintToChat ( client , " {cyan}[ConnectAnnounce] {white}%s " , g_bHideCsays [ client ] ? " You hid Connect Csay Messages. " : " You unhid Connect Csay Messages. " ) ;
2019-01-08 18:12:12 +01:00
}
2019-01-16 14:25:57 +01:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
2019-10-29 16:36:30 +01:00
public void ReadClientCookies ( int client )
2019-01-08 18:12:12 +01:00
{
char sBuffer [ 2 ] ;
2019-10-29 16:36:30 +01:00
if ( CheckCommandAccess ( client , " " , ADMFLAG_CUSTOM1 ) )
GetClientCookie ( client , g_hCookieHideCsays , sBuffer , sizeof ( sBuffer ) ) ;
2019-01-08 18:12:12 +01:00
if ( sBuffer [ 0 ] ! = '\0' )
g_bHideCsays [ client ] = true ;
else
g_bHideCsays [ client ] = false ;
}
2019-01-16 14:25:57 +01:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
2019-01-08 18:12:12 +01:00
public void OnClientDisconnect ( int client )
{
g_bHideCsays [ client ] = false ;
}
2019-01-16 14:25:57 +01:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnToggleHideCsays ( int client , int args )
{
ToggleHideCsays ( client ) ;
return Plugin_Handled ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ShowSettingsMenu ( int client )
2019-01-08 18:12:12 +01:00
{
2019-10-29 16:36:30 +01:00
if ( ! CheckCommandAccess ( client , " " , ADMFLAG_CUSTOM1 ) )
{
PrintToChat ( client , " [SM] You don't have access to these Settings. " ) ;
return ;
}
2019-01-16 14:25:57 +01:00
Menu menu = new Menu ( MenuHandler_MainMenu ) ;
menu . SetTitle ( " ConnectCsay Settings " , client ) ;
char sBuffer [ 128 ] ;
Format ( sBuffer , sizeof ( sBuffer ) , " Hiding Connect Csays: %s " , g_bHideCsays [ client ] ? " Enabled " : " Disabled " ) ;
2019-01-08 18:12:12 +01:00
2019-01-16 14:25:57 +01:00
menu . AddItem ( " 0 " , sBuffer ) ;
menu . ExitBackButton = true ;
menu . Display ( client , MENU_TIME_FOREVER ) ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void MenuHandler_CookieMenu ( int client , CookieMenuAction action , any info , char [ ] buffer , int maxlen )
{
switch ( action )
2019-01-08 18:12:12 +01:00
{
2019-01-16 14:25:57 +01:00
case ( CookieMenuAction_DisplayOption ) :
{
Format ( buffer , maxlen , " ConnectAnnounce " , client ) ;
}
case ( CookieMenuAction_SelectOption ) :
2019-01-08 18:12:12 +01:00
{
2019-01-16 14:25:57 +01:00
ShowSettingsMenu ( client ) ;
2019-01-08 18:12:12 +01:00
}
}
2019-01-16 14:25:57 +01:00
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public int MenuHandler_MainMenu ( Menu menu , MenuAction action , int client , int selection )
{
switch ( action )
{
case ( MenuAction_Select ) :
{
switch ( selection )
{
case ( 0 ) : ToggleHideCsays ( client ) ;
}
2019-01-08 18:12:12 +01:00
2019-01-16 14:25:57 +01:00
ShowSettingsMenu ( client ) ;
}
case ( MenuAction_Cancel ) :
{
ShowCookieMenu ( client ) ;
}
case ( MenuAction_End ) :
{
delete menu ;
}
}
2018-07-23 11:04:35 +02:00
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action Command_JoinMsg ( int client , int args )
{
if ( ! client )
{
ReplyToCommand ( client , " [ConnectAnnounce] Cannot use command from server console " ) ;
return Plugin_Handled ;
}
char sAuth [ 32 ] ;
GetClientAuthId ( client , AuthId_Steam2 , sAuth , sizeof ( sAuth ) ) ;
2019-07-07 22:44:43 +02:00
delete g_hCustomMessageFile ;
2018-07-23 11:04:35 +02:00
g_hCustomMessageFile = CreateKeyValues ( " custom_messages " ) ;
if ( ! FileToKeyValues ( g_hCustomMessageFile , g_sCustomMessageFile ) )
{
SetFailState ( " [ConnectAnnounce] Config file missing! " ) ;
return Plugin_Handled ;
}
KvRewind ( g_hCustomMessageFile ) ;
if ( args < 1 )
{
if ( KvJumpToKey ( g_hCustomMessageFile , sAuth ) )
{
char sCustomMessage [ 256 ] ;
KvGetString ( g_hCustomMessageFile , " message " , sCustomMessage , sizeof ( sCustomMessage ) , " " ) ;
if ( StrEqual ( sCustomMessage , " reset " ) )
{
CPrintToChat ( client , " [ConnectAnnounce] No Join Message set! Use sm_joinmsg <your message here> to set one. " ) ;
return Plugin_Handled ;
}
CPrintToChat ( client , " [ConnectAnnounce] Your Join Message is: %s " , sCustomMessage ) ;
}
else
CPrintToChat ( client , " [ConnectAnnounce] No Join Message set! Use sm_joinmsg <your message here> to set one. " ) ;
}
else
{
char sArg [ 512 ] ;
int iLength ;
iLength = GetCmdArgString ( sArg , sizeof ( sArg ) ) ;
if ( iLength > MSGLENGTH )
{
ReplyToCommand ( client , " [ConnectAnnounce] Maximum message length is %d characters! " , MSGLENGTH ) ;
return Plugin_Handled ;
}
2019-02-24 11:56:01 +01:00
StripQuotes ( sArg ) ;
2018-07-23 11:04:35 +02:00
if ( KvJumpToKey ( g_hCustomMessageFile , sAuth , true ) )
KvSetString ( g_hCustomMessageFile , " message " , sArg ) ;
else
{
SetFailState ( " [ConnectAnnounce] Could not find/create Key Value! " ) ;
return Plugin_Handled ;
}
KvRewind ( g_hCustomMessageFile ) ;
KeyValuesToFile ( g_hCustomMessageFile , g_sCustomMessageFile ) ;
CPrintToChat ( client , " [ConnectAnnounce] Your Join Message is: %s " , sArg ) ;
}
KvRewind ( g_hCustomMessageFile ) ;
return Plugin_Handled ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action Command_ResetJoinMsg ( int client , int args )
{
if ( ! client )
{
ReplyToCommand ( client , " [ConnectAnnounce] Cannot use command from server console " ) ;
return Plugin_Handled ;
}
char sAuth [ 32 ] ;
GetClientAuthId ( client , AuthId_Steam2 , sAuth , sizeof ( sAuth ) ) ;
2019-07-07 22:44:43 +02:00
delete g_hCustomMessageFile ;
2018-07-23 11:04:35 +02:00
g_hCustomMessageFile = CreateKeyValues ( " custom_messages " ) ;
if ( ! FileToKeyValues ( g_hCustomMessageFile , g_sCustomMessageFile ) )
{
SetFailState ( " [ConnectAnnounce] Config file missing! " ) ;
return Plugin_Handled ;
}
2018-07-23 17:06:03 +02:00
2018-07-23 11:04:35 +02:00
KvRewind ( g_hCustomMessageFile ) ;
2018-07-23 17:06:03 +02:00
2018-07-23 11:04:35 +02:00
if ( KvJumpToKey ( g_hCustomMessageFile , sAuth , true ) )
KvSetString ( g_hCustomMessageFile , " message " , " reset " ) ;
2018-07-23 17:06:03 +02:00
2018-07-23 11:04:35 +02:00
KvRewind ( g_hCustomMessageFile ) ;
2018-07-23 17:06:03 +02:00
2018-07-23 11:04:35 +02:00
KeyValuesToFile ( g_hCustomMessageFile , g_sCustomMessageFile ) ;
2018-07-23 17:06:03 +02:00
2018-07-23 11:04:35 +02:00
CPrintToChat ( client , " [ConnectAnnounce] Your Join Message got reset. " ) ;
return Plugin_Handled ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void TQueryCB ( Handle owner , Handle rs , const char [ ] error , any data )
{
int client = 0 ;
if ( ( client = GetClientOfUserId ( data ) ) = = 0 )
{
return ;
}
int iRank = - 1 ;
if ( SQL_GetRowCount ( rs ) > 0 )
{
int iField ;
SQL_FetchRow ( rs ) ;
SQL_FieldNameToNum ( rs , " rank " , iField ) ;
iRank = SQL_FetchInt ( rs , iField ) ;
iRank + = 1 ;
}
Handle hFile = OpenFile ( g_sDataFile , " r " ) ;
static char sRawMsg [ 301 ] ;
if ( hFile ! = INVALID_HANDLE )
{
ReadFileLine ( hFile , sRawMsg , sizeof ( sRawMsg ) ) ;
TrimString ( sRawMsg ) ;
2019-07-07 22:44:43 +02:00
delete hFile ;
2018-07-23 11:04:35 +02:00
}
else
{
LogError ( " [SM] File not found! (configs/ConnectAnnounce/settings.txt) " ) ;
2016-01-19 23:57:32 +01:00
return ;
2018-07-23 11:04:35 +02:00
}
2016-01-19 23:57:32 +01:00
static char sIP [ 16 ] ;
2018-03-23 14:18:30 +01:00
static char sAuth [ 32 ] ;
2016-01-19 23:57:32 +01:00
static char sCountry [ 32 ] ;
2018-07-23 11:04:35 +02:00
static char sName [ 128 ] ;
2016-01-19 23:57:32 +01:00
GetClientAuthId ( client , AuthId_Steam2 , sAuth , sizeof ( sAuth ) ) ;
2018-07-23 11:04:35 +02:00
GetClientName ( client , sName , sizeof ( sName ) ) ;
AdminId aid ;
if ( StrContains ( sRawMsg , " {PLAYERTYPE} " ) )
{
aid = GetUserAdmin ( client ) ;
if ( GetAdminFlag ( aid , Admin_Generic ) )
{
ReplaceString ( sRawMsg , sizeof ( sRawMsg ) , " {PLAYERTYPE} " , " Admin " ) ;
}
else if ( GetAdminFlag ( aid , Admin_Custom1 ) )
{
ReplaceString ( sRawMsg , sizeof ( sRawMsg ) , " {PLAYERTYPE} " , " VIP " ) ;
}
else if ( GetAdminFlag ( aid , Admin_Custom6 ) )
{
ReplaceString ( sRawMsg , sizeof ( sRawMsg ) , " {PLAYERTYPE} " , " Member " ) ;
}
else
{
ReplaceString ( sRawMsg , sizeof ( sRawMsg ) , " {PLAYERTYPE} " , " Player " ) ;
}
}
if ( StrContains ( sRawMsg , " {RANK} " ) )
{
if ( iRank ! = - 1 )
{
char sBuffer [ 16 ] ;
Format ( sBuffer , sizeof ( sBuffer ) , " [#%d] " , iRank ) ;
ReplaceString ( sRawMsg , sizeof ( sRawMsg ) , " {RANK} " , sBuffer ) ;
}
}
2016-01-19 23:57:32 +01:00
2018-07-23 11:04:35 +02:00
if ( StrContains ( sRawMsg , " {NOSTEAM} " ) )
{
2019-06-08 15:42:33 +02:00
if ( ! PM_IsPlayerSteam ( client ) )
2018-07-23 11:04:35 +02:00
ReplaceString ( sRawMsg , sizeof ( sRawMsg ) , " {NOSTEAM} " , " <NoSteam> " ) ;
else
ReplaceString ( sRawMsg , sizeof ( sRawMsg ) , " {NOSTEAM} " , " " ) ;
}
2018-03-23 14:18:30 +01:00
2018-07-23 11:04:35 +02:00
if ( StrContains ( sRawMsg , " {STEAMID} " ) )
{
ReplaceString ( sRawMsg , sizeof ( sRawMsg ) , " {STEAMID} " , sAuth ) ;
}
if ( StrContains ( sRawMsg , " {NAME} " ) )
{
ReplaceString ( sRawMsg , sizeof ( sRawMsg ) , " {NAME} " , sName ) ;
}
if ( StrContains ( sRawMsg , " {COUNTRY} " ) )
{
if ( GetClientIP ( client , sIP , sizeof ( sIP ) ) & & GeoipCountry ( sIP , sCountry , sizeof ( sCountry ) ) )
{
char sBuffer [ 128 ] ;
Format ( sBuffer , sizeof ( sBuffer ) , " from %s " , sCountry ) ;
ReplaceString ( sRawMsg , sizeof ( sRawMsg ) , " {COUNTRY} " , sBuffer ) ;
}
else
ReplaceString ( sRawMsg , sizeof ( sRawMsg ) , " {COUNTRY} " , " " ) ;
}
2018-07-23 17:06:03 +02:00
2018-07-23 11:04:35 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////
2019-01-08 18:12:12 +01:00
2018-08-06 16:38:53 +02:00
if ( ! CheckCommandAccess ( client , " sm_joinmsg " , ADMFLAG_CUSTOM1 ) )
2019-01-08 18:12:12 +01:00
{
2018-08-06 16:38:53 +02:00
CPrintToChatAll ( sRawMsg ) ;
return ;
}
2018-07-23 17:06:03 +02:00
2019-07-07 22:44:43 +02:00
delete g_hCustomMessageFile2 ;
2018-07-23 11:04:35 +02:00
g_hCustomMessageFile2 = CreateKeyValues ( " custom_messages " ) ;
if ( ! FileToKeyValues ( g_hCustomMessageFile2 , g_sCustomMessageFile ) )
{
SetFailState ( " [ConnectAnnounce] Config file missing! " ) ;
return ;
}
KvRewind ( g_hCustomMessageFile2 ) ;
2018-07-23 17:06:03 +02:00
2018-08-06 16:38:53 +02:00
char sBanned [ 16 ] ;
2018-07-23 11:04:35 +02:00
char sFinalMessage [ 512 ] ;
char sCustomMessage [ 256 ] ;
if ( KvJumpToKey ( g_hCustomMessageFile2 , sAuth ) )
2018-07-23 17:06:03 +02:00
{
2018-08-06 16:38:53 +02:00
KvGetString ( g_hCustomMessageFile2 , " banned " , sBanned , sizeof ( sBanned ) , " " ) ;
2018-07-23 11:04:35 +02:00
KvGetString ( g_hCustomMessageFile2 , " message " , sCustomMessage , sizeof ( sCustomMessage ) , " " ) ;
2019-01-09 01:00:30 +01:00
if ( StrEqual ( sCustomMessage , " reset " ) | | StrEqual ( sBanned , " true " ) )
{
2018-07-23 11:04:35 +02:00
CPrintToChatAll ( sRawMsg ) ;
2019-01-09 01:00:30 +01:00
for ( int i = 1 ; i < = MaxClients ; i + + )
{
2019-10-29 16:36:30 +01:00
if ( IsClientInGame ( i ) )
2019-01-09 01:00:30 +01:00
{
2019-10-29 16:45:30 +01:00
if ( g_bHideCsays [ i ] )
2019-10-29 16:36:30 +01:00
continue ;
2019-01-09 01:00:30 +01:00
PrintCenterText ( i , " %s %s %s " , " [VIP] " , sName , " connected " ) ;
}
}
}
2018-07-23 11:04:35 +02:00
else
2018-07-23 17:06:03 +02:00
{
2018-07-23 11:04:35 +02:00
Format ( sFinalMessage , sizeof ( sFinalMessage ) , " %s %s " , sRawMsg , sCustomMessage ) ;
CPrintToChatAll ( sFinalMessage ) ;
2019-01-09 01:00:30 +01:00
for ( int i = 1 ; i < = MaxClients ; i + + )
{
2019-10-29 16:36:30 +01:00
if ( IsClientInGame ( i ) )
2019-01-09 01:00:30 +01:00
{
2019-10-29 16:45:30 +01:00
if ( g_bHideCsays [ i ] )
2019-10-29 16:36:30 +01:00
continue ;
2019-01-09 01:00:30 +01:00
CRemoveTags ( sCustomMessage , 256 ) ;
2019-10-15 21:38:29 +02:00
PrintCenterText ( i , " %s %s %s %s " , " [VIP] " , sName , " connected " , sCustomMessage ) ;
2019-01-09 01:00:30 +01:00
}
}
2018-07-23 11:04:35 +02:00
}
}
2016-01-19 23:57:32 +01:00
else
2019-01-11 17:12:56 +01:00
{
2018-07-23 11:04:35 +02:00
CPrintToChatAll ( sRawMsg ) ;
2019-01-11 17:12:56 +01:00
for ( int i = 1 ; i < = MaxClients ; i + + )
{
2019-10-29 16:36:30 +01:00
if ( IsClientInGame ( i ) )
2019-01-11 17:12:56 +01:00
{
2019-10-29 16:45:30 +01:00
if ( g_bHideCsays [ i ] )
2019-10-29 16:36:30 +01:00
continue ;
2019-01-11 17:12:56 +01:00
PrintCenterText ( i , " %s %s %s " , " [VIP] " , sName , " connected " ) ;
}
}
}
2018-07-23 11:04:35 +02:00
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientPostAdminCheck ( int client )
{
if ( IsFakeClient ( client ) )
return ;
2019-10-29 16:36:30 +01:00
if ( AreClientCookiesCached ( client ) )
ReadClientCookies ( client ) ;
2019-02-24 11:56:01 +01:00
if ( g_hDatabase = = INVALID_HANDLE )
return ;
2018-07-23 11:04:35 +02:00
static char sAuth [ 32 ] ;
GetClientAuthId ( client , AuthId_Steam2 , sAuth , sizeof ( sAuth ) ) ;
strcopy ( sAuth , sizeof ( sAuth ) , sAuth [ 8 ] ) ;
2018-07-23 17:06:03 +02:00
2019-02-24 11:56:01 +01:00
char sServer [ 16 ] ;
g_cvHlstatsServerName . GetString ( sServer , sizeof ( sServer ) ) ;
2018-07-23 11:04:35 +02:00
char sQuery [ 512 ] ;
2019-02-24 11:56:01 +01:00
Format ( sQuery , sizeof ( sQuery ) , " SELECT COUNT(*) AS rank FROM hlstats_Players WHERE hlstats_Players.game = '%s' AND hideranking = 0 AND skill > (SELECT skill from hlstats_Players JOIN hlstats_PlayerUniqueIds ON hlstats_Players.playerId = hlstats_PlayerUniqueIds.playerId WHERE uniqueId = '%s' AND hlstats_PlayerUniqueIds.game = '%s') " , sServer , sAuth , sServer ) ;
g_hDatabase . Query ( TQueryCB , sQuery , GetClientUserId ( client ) ) ;
2019-01-08 18:12:12 +01:00
}