#include <sourcemod>
#include <sdktools>
new String: RestrictedNamesFile[ PLATFORM_MAX_PATH ]
new Handle: RestrictedNames = INVALID_HANDLE
Handle: HandleMethod
Handle: BackupName
Handle: KickReason
Handle: MinNameLen
public Plugin:myinfo = {
name = "Restricted Names: Basic",
author = "tre3fla",
description = "Filtreaza numele jucatorilor",
version = "1.0",
url = "http://extreamcs.com/forum"
}
public OnPluginStart( ) {
HandleMethod = CreateConVar( "sm_restricted_names_action", "3", "0=dezactivat, 1=kick, 2=schimba numele, 3=sterge partea interzisa din nume" )
BackupName = CreateConVar( "sm_default_name", "CSGO Player", "Numele in care sa fie redenumiti jucatorii cu nume interzise" )
KickReason = CreateConVar( "sm_kick_reason", "Your name is not allowed", "Mesajul care sa ii apara daca primeste kick pentur ca are nume interzis" )
MinNameLen = CreateConVar( "sm_min_name_lenght", "3", "Minim cate caractere sa aiba numele pentru a putea fi folosit" )
HookUserMessage( GetUserMessageId( "SayText2" ), SayText2, true )
HookEvent( "player_changename", OnNameChange )
}
public void OnMapStart( ) {
LoadRestrictedNames( )
}
public OnClientPutInServer( client ) {
CheckClientName( client )
}
public Action:OnNameChange( Handle:event, const String:name[ ], bool:dontBroadcast ) {
new UserID = GetEventInt( event, "userid" )
new client = GetClientOfUserId( UserID )
if( IsClientInGame( client ) && !IsFakeClient( client ) ) {
decl String:NewName[ MAX_NAME_LENGTH ]
decl String:OldName[ MAX_NAME_LENGTH ]
GetEventString( event, "oldname", OldName, sizeof( OldName ) )
GetEventString( event, "newname", NewName, sizeof( NewName ) )
decl String: LargeBuffer[ 1024 ]
for( new i = 0; i < GetArraySize( RestrictedNames ); i++ ) {
GetArrayString( RestrictedNames, i, LargeBuffer, sizeof( LargeBuffer ) )
if( StrContains( NewName, LargeBuffer, false ) != -1 ) {
SetClientName( client, OldName )
PrintToChat( client, "* Name change attempt failed!\x02 Your choosen name is not allowed!" )
return Plugin_Changed
}
if( GetConVarInt( MinNameLen ) > 0 && strlen( NewName ) < GetConVarInt( MinNameLen ) ) {
SetClientName( client, OldName )
PrintToChat( client, "*\x02 Name change attempt failed!" )
PrintToChat( client, "* Your\x04 name\x01 must have at least\x05 %d\x01 characters!", GetConVarInt( MinNameLen ) )
return Plugin_Stop
}
}
}
return Plugin_Continue
}
public CheckClientName( client ) {
if( IsClientInGame( client ) && client > 0 && client < MaxClients ) {
decl String: LargeBuffer[ 1024 ]
decl String: Name[ 32 ]
GetClientName( client, Name, sizeof( Name ) )
for( new i = 0; i < GetArraySize( RestrictedNames ); i++ ) {
GetArrayString( RestrictedNames, i, LargeBuffer, sizeof( LargeBuffer ) )
if( StrContains( Name, LargeBuffer, false ) != -1 ) {
switch( GetConVarInt( HandleMethod ) ) {
case 1: {
decl String: ReasonBuffer[ 128 ]
GetConVarString( KickReason, ReasonBuffer, sizeof( ReasonBuffer ) )
KickClient( client, "%s", ReasonBuffer )
}
case 2: {
decl String: NameBuffer[ 32 ]
GetConVarString( BackupName, NameBuffer, sizeof( NameBuffer ) )
SetClientName( client, NameBuffer )
}
case 3: {
ReplaceString( Name, sizeof( Name ), LargeBuffer, "" )
SetClientName( client, Name )
if( TrimString( Name ) && StrEqual( Name, "" ) ) {
decl String: NameBuffer[ 32 ]
GetConVarString( BackupName, NameBuffer, sizeof( NameBuffer ) )
SetClientName( client, NameBuffer )
}
}
}
}
if( GetConVarInt( MinNameLen ) > 0 && strlen( Name ) < GetConVarInt( MinNameLen ) ) {
decl String: NameBuffer[ 32 ]
GetConVarString( BackupName, NameBuffer, sizeof( NameBuffer ) )
SetClientName( client, NameBuffer )
}
}
}
}
public Action:SayText2( UserMsg:msg_id, Handle:bf, players[ ], playersNum, bool:reliable, bool:init ) {
new String:buffer[ 25 ]
if( GetUserMessageType( ) == UM_Protobuf ) {
PbReadString( bf, "msg_name", buffer, sizeof( buffer ) )
if( StrEqual( buffer, "#Cstrike_Name_Change" ) ) {
return Plugin_Handled
}
}
return Plugin_Continue
}
public LoadRestrictedNames( ) {
RestrictedNames = CreateArray( 1024 )
BuildPath( Path_SM, RestrictedNamesFile, sizeof( RestrictedNamesFile ), "configs/RestrictedNames.txt" )
new Handle: RestrictedNamesText = OpenFile( RestrictedNamesFile, "r" )
new String: ResultsBuffer[ 1024 ]
while( !IsEndOfFile( RestrictedNamesText ) && ReadFileLine( RestrictedNamesText, ResultsBuffer, sizeof( ResultsBuffer ) ) ) {
ReplaceString( ResultsBuffer, sizeof( ResultsBuffer ), "\n", "", false )
PushArrayString( RestrictedNames, ResultsBuffer )
}
}