2019-05-27 02:11:27 +02:00
# pragma semicolon 1
# include <sourcemod>
# include <multicolors>
2019-07-10 22:55:35 +02:00
# include <ccc>
2019-05-27 02:11:27 +02:00
2019-05-27 12:09:45 +02:00
bool g_bNewPlayer [ MAXPLAYERS + 1 ] = { false , . . . } ;
2019-07-10 22:55:35 +02:00
bool g_bNewPlayerChatBlock [ MAXPLAYERS + 1 ] = { false , . . . } ;
2019-05-27 02:11:27 +02:00
2019-05-27 19:17:13 +02:00
ConVar g_cvServerType ;
char g_cServerMessage [ 128 ] ;
2019-05-27 02:11:27 +02:00
Database g_hDatabase ;
public Plugin myinfo =
{
name = " ConnectAnnounceNewPlayers " ,
2019-05-27 14:50:32 +02:00
author = " Dogan " ,
2019-05-27 02:11:27 +02:00
description = " Connect Announcer for new Players " ,
2019-07-10 22:55:35 +02:00
version = " 1.3.0 " ,
2019-05-27 02:11:27 +02:00
url = " "
}
public void OnPluginStart ( )
{
Database . Connect ( SQL_OnDatabaseConnect , " unloze_newplayers " ) ;
2019-05-27 19:17:13 +02:00
g_cvServerType = CreateConVar ( " sm_server_type " , " 1 " , " Server related private message for new players: 1 = ze; 2 = mg; 3 = zr; any other value = neutral " ) ;
2019-05-30 15:29:54 +02:00
AddMultiTargetFilter ( " @newplayer " , Filter_NewPlayers , " New Players " , false ) ;
RegConsoleCmd ( " sm_newplayer " , Command_DisplayNewPlayers , " Shows the number of new players " ) ;
2019-05-27 19:17:13 +02:00
AutoExecConfig ( true , " plugin.ConnectAnnounceNewPlayers " ) ;
GetConVars ( ) ;
}
2019-06-08 17:27:00 +02:00
public void OnPluginEnd ( )
{
RemoveMultiTargetFilter ( " @newplayer " , Filter_NewPlayers ) ;
}
2019-05-27 19:17:13 +02:00
public void GetConVars ( )
{
if ( g_cvServerType . IntValue = = 1 )
{
g_cServerMessage = " Zombie Escape " ;
}
else if ( g_cvServerType . IntValue = = 2 )
{
g_cServerMessage = " Minigames " ;
}
else if ( g_cvServerType . IntValue = = 3 )
{
g_cServerMessage = " Zombie Riot " ;
}
else
{
g_cServerMessage = " " ;
}
}
public void ConVarChange ( ConVar convar , char [ ] oldValue , char [ ] newValue )
{
GetConVars ( ) ;
2019-05-27 02:11:27 +02:00
}
2019-05-30 15:29:54 +02:00
public bool Filter_NewPlayers ( const char [ ] sPattern , Handle hClients )
{
for ( int i = 1 ; i < = MaxClients ; i + + )
{
if ( IsClientInGame ( i ) & & ! IsFakeClient ( i ) )
{
if ( g_bNewPlayer [ i ] )
PushArrayCell ( hClients , i ) ;
}
}
return true ;
}
public Action Command_DisplayNewPlayers ( int client , int args )
{
char aBuf [ 1024 ] ;
char aBuf2 [ MAX_NAME_LENGTH ] ;
for ( int i = 1 ; i < = MaxClients ; i + + )
{
if ( IsClientInGame ( i ) & & ! IsFakeClient ( i ) )
{
if ( g_bNewPlayer [ i ] )
{
GetClientName ( i , aBuf2 , sizeof ( aBuf2 ) ) ;
StrCat ( aBuf , sizeof ( aBuf ) , aBuf2 ) ;
StrCat ( aBuf , sizeof ( aBuf ) , " , " ) ;
}
}
}
if ( strlen ( aBuf ) )
{
aBuf [ strlen ( aBuf ) - 2 ] = 0 ;
ReplyToCommand ( client , " [SM] New Players online: %s " , aBuf ) ;
}
else
ReplyToCommand ( client , " [SM] New Players online: none " ) ;
return Plugin_Handled ;
}
2019-05-27 02:11:27 +02:00
public void OnClientPostAdminCheck ( int client )
{
if ( IsFakeClient ( client ) | | IsClientSourceTV ( client ) )
return ;
char sAuthID [ 32 ] ;
GetClientAuthId ( client , AuthId_Steam2 , sAuthID , sizeof ( sAuthID ) ) ;
char sQuery [ 512 ] ;
Format ( sQuery , sizeof ( sQuery ) , " SELECT * FROM connections WHERE auth='%s' " , sAuthID ) ;
g_hDatabase . Query ( SQL_OnQueryCompleted , sQuery , GetClientSerial ( client ) , DBPrio_Low ) ;
}
public void SQL_OnDatabaseConnect ( Database db , const char [ ] error , any data )
{
if ( ! db | | strlen ( error ) )
{
LogError ( " Database error: %s " , error ) ;
return ;
}
g_hDatabase = db ;
char sQuery [ 512 ] ;
Format ( sQuery , sizeof ( sQuery ) , " CREATE TABLE IF NOT EXISTS connections (`auth` varchar(32)) " ) ;
g_hDatabase . Query ( SQL_OnQueryCompleted , sQuery , _ , DBPrio_Low ) ;
}
public void SQL_OnQueryCompleted ( Database db , DBResultSet results , const char [ ] error , any data )
{
if ( ! db | | strlen ( error ) )
{
LogError ( " Query error: %s " , error ) ;
return ;
}
int client ;
if ( ( client = GetClientFromSerial ( data ) ) = = 0 )
return ;
char sAuthID [ 32 ] ;
GetClientAuthId ( client , AuthId_Steam2 , sAuthID , sizeof ( sAuthID ) ) ;
if ( results . RowCount & & results . FetchRow ( ) )
{
int iFieldNum ;
char sResultAddress [ 32 ] ;
results . FieldNameToNum ( " auth " , iFieldNum ) ;
results . FetchString ( iFieldNum , sResultAddress , sizeof ( sResultAddress ) ) ;
if ( StrEqual ( sAuthID , sResultAddress , true ) )
return ;
}
2019-05-27 12:09:45 +02:00
g_bNewPlayer [ client ] = true ;
2019-07-10 22:55:35 +02:00
g_bNewPlayerChatBlock [ client ] = true ;
2019-05-27 02:11:27 +02:00
NewPlayerMessage ( client ) ;
2019-07-10 23:15:23 +02:00
CreateTimer ( 10.0 , BlockChat , GetClientSerial ( client ) , TIMER_FLAG_NO_MAPCHANGE ) ;
2019-05-27 02:11:27 +02:00
char sQuery [ 512 ] ;
Format ( sQuery , sizeof ( sQuery ) , " INSERT INTO connections (auth) VALUES ('%s') " , sAuthID ) ;
g_hDatabase . Query ( SQL_OnQueryCompleted , sQuery , _ , DBPrio_Low ) ;
}
public Action NewPlayerMessage ( int client )
{
2019-07-10 22:55:35 +02:00
CPrintToChatAll ( " {cyan}Player {lightgreen}%N {cyan}has just connected to an UNLOZE Server for the first time! Welcome! " , client ) ;
2019-05-27 19:17:13 +02:00
if ( g_cvServerType . IntValue > = 1 & & g_cvServerType . IntValue < = 3 )
{
2019-07-10 22:55:35 +02:00
CPrintToChat ( client , " {purple}**************************************************** " ) ;
CPrintToChat ( client , " {purple}**************************************************** " ) ;
CPrintToChat ( client , " {cyan}Hi {lightgreen}%N{cyan}. Welcome to the {blueviolet}Unloze %s Server{cyan}! We hope you enjoy your stay here and add our server to your favorites. Make sure to check out our website at {blueviolet}www.unloze.com{cyan}. " , client , g_cServerMessage ) ;
CPrintToChat ( client , " {purple}**************************************************** " ) ;
CPrintToChat ( client , " {purple}**************************************************** " ) ;
2019-05-27 19:17:13 +02:00
}
else
{
2019-07-10 22:55:35 +02:00
CPrintToChat ( client , " {purple}**************************************************** " ) ;
CPrintToChat ( client , " {purple}**************************************************** " ) ;
CPrintToChat ( client , " {cyan}Hi {lightgreen}%N. Welcome to this {blueviolet}Unloze Server{cyan}! We hope you enjoy your stay here and add our server to your favorites. Make sure to check out our website at {blueviolet}www.unloze.com{cyan}. " , client ) ;
CPrintToChat ( client , " {purple}**************************************************** " ) ;
CPrintToChat ( client , " {purple}**************************************************** " ) ;
2019-05-27 19:17:13 +02:00
}
2019-05-27 12:09:45 +02:00
}
public void OnClientDisconnect ( int client )
{
g_bNewPlayer [ client ] = false ;
2019-07-10 22:55:35 +02:00
g_bNewPlayerChatBlock [ client ] = false ;
}
2019-07-10 23:11:18 +02:00
public Action BlockChat ( Handle timer , int clientid )
2019-07-10 22:55:35 +02:00
{
2019-07-10 23:15:23 +02:00
if ( ( client = GetClientFromSerial ( clientid ) ) = = 0 )
2019-07-10 23:11:18 +02:00
return ;
2019-07-10 22:55:35 +02:00
g_bNewPlayerChatBlock [ client ] = false ;
}
public Action CCC_OnChatMessage ( int client , int author , const char [ ] message )
{
if ( g_bNewPlayerChatBlock [ client ] )
return Plugin_Handled ;
return Plugin_Continue ;
2019-05-27 02:11:27 +02:00
}