Half-Life Icon HL Script

[AMXX] Protect Names

Attention Gamer! We are one of the oldest mod sites on the Interwebs. Sign up and maximize your browsing experience.

  • Subscribe: Get notified of new submissions like this.
  • Say Thanks: Show your appreciation by sending Rj. points.
  • Post: Give Rj. your thoughts on this Script.
  • Vote: Help Rj. win the Monthly Awards.
  • Rate: Give this Script a rating out of 10.
  • Flag: Alert moderators and warn members of a problem with this Script.
  • Watch: Get notified when this Script is updated.
Mascot

Interested?

Join GameBanana

Already a Bananite? Login

476 lines | 12 kb | Raw Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#include < amxmodx >
#include < amxmisc >
#include < regex >
#include < fakemeta >

enum ( <<= 1 )
{
        MATCH_EQUAL = 1,
        MATCH_CONTAIN,
        MATCH_CASESENSITIVE,
        MATCH_REGEX
};

enum
{
        RESTRICT_IP = 1,
        RESTRICT_STEAMID,
        RESTRICT_FLAGS
};

enum _:name_t
{
        m_szName[ 32 ],
        m_iMatchFlags,
        m_iszPattern,
        m_pPattern,
        m_szRestricted[ 64 ],
        m_iRestrictFlags,
        m_szReplacement[ 32 ]
};

// Note:
// If m_iRestrictFlags & RESTRICT_FLAGS
//      iAccessFlags = iRestrictFlags >> 2

new Array:g_aNameDatas;
new g_iNumNames;

new bool:g_bIsDedicatedServer;

new g_pCvarPunish;
new g_pCvarCommand;
new g_pCvarReason;

new g_pCvarMode;
new g_pCvarPasswordField;
new g_pCvarDefaultAccess;

public plugin_init( )
{
        register_plugin( "Protect Names", "0.0.2", "Exolent" );
       
        register_forward( FM_ClientUserInfoChanged, "FwdClientUserInfoChanged" );
       
        g_pCvarPunish  = register_cvar( "protect_name_punish" , "0" );
        g_pCvarCommand = register_cvar( "protect_name_command", "kick %userid% \'%reason%\'" );
        g_pCvarReason  = register_cvar( "protect_name_reason" , "%name% is protected and you are not allowed to use it!" );
       
        g_pCvarMode = register_cvar( "amx_mode", "1" );
        g_pCvarPasswordField = register_cvar( "amx_password_field", "_pw" );
        g_pCvarDefaultAccess = register_cvar( "amx_default_access", "" );
       
        g_aNameDatas = ArrayCreate( name_t );
       
        LoadNames( );
       
        g_bIsDedicatedServer = bool:is_dedicated_server( );
}

public plugin_end( )
{
        new eNameData[ name_t ];
       
        for( new i = 0; i < g_iNumNames; i++ )
        {
                ArrayGetArray( g_aNameDatas, i, eNameData );
               
                if( eNameData[ m_iMatchFlags ] & MATCH_REGEX )
                {
                        regex_free( Regex:eNameData[ m_pPattern ] );
                }
        }
       
        ArrayDestroy( g_aNameDatas );
}

public client_authorized( iPlayer )
{
        CheckName( iPlayer );
}

public client_putinserver( iPlayer )
{
        if( !g_bIsDedicatedServer && iPlayer == 1 )
        {
                CheckName( iPlayer );
        }
}

public FwdClientUserInfoChanged( iPlayer )
{
        new szOldName[ 32 ], szNewName[ 32 ];
        pev( iPlayer, pev_netname, szOldName, charsmax( szOldName ) );
       
        if( szOldName[ 0 ] )
        {
                get_user_info( iPlayer, "name", szNewName, charsmax( szNewName ) )
               
                if( !equal( szOldName, szNewName ) )
                {
                        return CheckName( iPlayer, szNewName );
                }
        }
        else if( get_user_info( iPlayer, "name", szNewName, charsmax( szNewName ) ) )
        {
                return CheckName( iPlayer, szNewName );
        }
       
        return FMRES_IGNORED;
}

CheckName( iPlayer, szCurrentName[ 32 ] = "" )
{
        if( !szCurrentName[ 0 ] )
        {
                get_user_name( iPlayer, szCurrentName, charsmax( szCurrentName ) );
        }
       
        new szIP[ 16 ], szSteamID[ 35 ];
        get_user_ip( iPlayer, szIP, charsmax( szIP ), 1 );
        get_user_authid( iPlayer, szSteamID, charsmax( szSteamID ) );
       
        new iFlags = PredictNewFlags( iPlayer, szCurrentName, szSteamID, szIP );
       
        new eNameData[ name_t ];
        new bCaseSensitive;
       
        for( new i = 0; i < g_iNumNames; i++ )
        {
                ArrayGetArray( g_aNameDatas, i, eNameData );
               
                if( eNameData[ m_iMatchFlags ] & MATCH_REGEX )
                {
                        // Using bCaseSensitive as a temporary return value to not use another variable
                       
                        if( regex_match_c( szCurrentName, Regex:eNameData[ m_pPattern ], bCaseSensitive ) <= 0 )
                        {
                                continue;
                        }
                }
                else
                {
                        bCaseSensitive = !!( eNameData[ m_iMatchFlags ] & MATCH_CASESENSITIVE );
                       
                        if( ( eNameData[ m_iMatchFlags ] & MATCH_EQUAL )
                                ? strcmp( szCurrentName, eNameData[ m_szName ], !bCaseSensitive ) != 0
                                : strfind( szCurrentName, eNameData[ m_szName ], !bCaseSensitive ) == -1 )
                        {
                                continue;
                        }
                }
               
                // Name matched this restriction if made it this far
               
                if( ( eNameData[ m_iRestrictFlags ] & 3 ) == RESTRICT_FLAGS )
                {
                        // Using bCaseSensitive as a temporary return value to not use another variable
                       
                        bCaseSensitive = eNameData[ m_iRestrictFlags ] >> 2;
                       
                        if( ( iFlags & bCaseSensitive ) == bCaseSensitive )
                        {
                                continue;
                        }
                }
                else
                {
                        if( equal( eNameData[ m_szRestricted ], ( eNameData[ m_iRestrictFlags ] == RESTRICT_IP ) ? szIP : szSteamID ) )
                        {
                                continue;
                        }
                }
               
                // Player does not have access to name if made it this far
               
                new szUserID[ 13 ];
                formatex( szUserID, charsmax( szUserID ), "#%d", get_user_userid( iPlayer ) );
               
                if( eNameData[ m_iMatchFlags ] & MATCH_REGEX )
                {
                        static szPattern[ 512 ];
                        global_get( glb_pStringBase, eNameData[ m_iszPattern ], szPattern, charsmax( szPattern ) );
                       
                        log_amx( "%s<%s><%s><%s> used a restricted name, which matched RegEx pattern %s", szCurrentName, szUserID, szSteamID, szIP, szPattern );
                }
                else
                {
                        log_amx( "%s<%s><%s><%s> used a restricted name, which matched %s", szCurrentName, szUserID, szSteamID, szIP, eNameData[ m_szName ] );
                }
               
                new szReason[ 192 ];
                get_pcvar_string( g_pCvarReason, szReason, charsmax( szReason ) );
               
                FixFormatting( szReason, charsmax( szReason ), szCurrentName, szSteamID, szUserID, szIP );
               
                if( get_pcvar_num( g_pCvarPunish ) )
                {
                        new szCommand[ 192 ];
                        get_pcvar_string( g_pCvarCommand, szCommand, charsmax( szCommand ) );
                       
                        FixFormatting( szCommand, charsmax( szCommand ), szCurrentName, szSteamID, szUserID, szIP, szReason );
                       
                        server_cmd( "%s", szCommand );
                        server_exec( );
                }
                else
                {
                        set_user_info( iPlayer, "name", eNameData[ m_szReplacement ] );
                       
                        if( szReason[ 0 ] )
                        {
                                client_print( iPlayer, print_chat, "* %s", szReason );
                        }
                }
               
                return FMRES_HANDLED;
        }
       
        return FMRES_IGNORED;
}

PredictNewFlags( iPlayer, const szName[ ], const szSteamID[ ], const szIP[ ] )
{
        // Code here mimics admin.sma's method of accessing admins
        // This is done since some name checking is done before admin.sma gives access
       
        new iMode = get_pcvar_num( g_pCvarMode );
       
        if( !iMode )
        {
                return 0;
        }
       
        new iNumAdmins = admins_num( );
        new iIndex = -1;
        new iFlags;
        new szAuth[ 44 ]; // Size from admin.sma
        new iLen;
       
        for( new i = 0; i < iNumAdmins; i++ )
        {
                iFlags = admins_lookup( i, AdminProp_Flags );
               
                admins_lookup( i, AdminProp_Auth, szAuth, charsmax( szAuth ) );
               
                if( iFlags & FLAG_AUTHID )
                {
                        if( equal( szAuth, szSteamID ) )
                        {
                                iIndex = i;
                                break;
                        }
                }
                else if( iFlags & FLAG_IP )
                {
                        iLen = strlen( szAuth ) - 1;
                       
                        if( szAuth[ iLen ] != '.' )
                        {
                                iLen = 0;
                        }
                       
                        if( equal( szAuth, szIP, iLen ) )
                        {
                                iIndex = i;
                                break;
                        }
                }
                else
                {
                        if( ( iFlags & FLAG_TAG )
                                ? ( strfind( szName, szAuth, _:( !( iFlags & FLAG_CASE_SENSITIVE ) ) ) != -1 )
                                : ( strcmp( szName, szAuth,  _:( !( iFlags & FLAG_CASE_SENSITIVE ) ) ) !=  0 ) )
                        {
                                iIndex = i;
                                break;
                        }
                }
        }
       
        new iAccess;
       
        if( iIndex >= 0 )
        {
                if( ~iFlags & FLAG_NOPASS )
                {
                        new szPasswordField[ 32 ]; // Size from admin.sma
                        get_pcvar_string( g_pCvarPasswordField, szPasswordField, charsmax( szPasswordField ) );
                       
                        new szPassword[ 32 ]; // Size from admin.sma
                        get_user_info( iPlayer, szPasswordField, szPassword, charsmax( szPassword ) );
                       
                        new szAccessPassword[ sizeof( szPassword ) ];
                        admins_lookup( iIndex, AdminProp_Password, szAccessPassword, charsmax( szAccessPassword ) );
                       
                        if( !equal( szPassword, szAccessPassword ) )
                        {
                                return 0;
                        }
                }
               
                iAccess = admins_lookup( iIndex, AdminProp_Access );
        }
        else if( iMode != 2 )
        {
                new szFlags[ 27 ];
                get_pcvar_string( g_pCvarDefaultAccess, szFlags, charsmax( szFlags ) );
               
                iAccess = read_flags( szFlags );
               
                if( !iAccess )
                {
                        iAccess = ADMIN_USER;
                }
        }
       
        return iAccess;
}

FixFormatting( szString[ ], iMaxLen, const szName[ ], const szSteamID[ ], const szUserID[ ], const szIP[ ], const szReason[ ] = "" )
{
        replace_all( szString, iMaxLen, "\'", "^"" );
        replace_all( szString, iMaxLen, "
%name%", szName );
        replace_all( szString, iMaxLen, "
%steamid%", szSteamID );
        replace_all( szString, iMaxLen, "
%userid%", szUserID );
        replace_all( szString, iMaxLen, "
%ip%", szIP );
        replace_all( szString, iMaxLen, "
%reason%", szReason );
}

LoadNames( )
{
        new szFile[ 64 ];
        get_configsdir( szFile, charsmax( szFile ) );
        add( szFile, charsmax( szFile ), "
/protect_names.ini" );
       
        new pFile = fopen( szFile, "
rt" );
       
        if( pFile )
        {
                new iLine;
               
                new szMatchType[ 16 ];
                new szMatchString[ 512 ];
                new szRestrictType[ 16 ];
                new szRestrictedString[ 64 ];
                new szReplacement[ 32 ];
                new szLine[ sizeof( szMatchType ) + sizeof( szMatchString ) + sizeof( szRestrictType ) + sizeof( szRestrictedString ) + sizeof( szReplacement ) + 10 ];
               
                new eNameData[ name_t ];
                new szError[ 128 ], iReturn;
               
                while( !feof( pFile ) )
                {
                        iLine++;
                       
                        fgets( pFile, szLine, charsmax( szLine ) );
                        trim( szLine );
                       
                        if( !szLine[ 0 ] || szLine[ 0 ] == ';'
                        ||  szLine[ 0 ] == '/' && szLine[ 1 ] == '/'
                        ||  parse( szLine,
                                szMatchType, charsmax( szMatchType ),
                                szMatchString, charsmax( szMatchString ),
                                szRestrictType, charsmax( szRestrictType ),
                                szRestrictedString, charsmax( szRestrictedString ),
                                szReplacement, charsmax( szReplacement ) ) < 5 )
                        {
                                continue;
                        }
                       
                        // Default match and restrict flags to none
                       
                        eNameData[ m_iMatchFlags ] = 0;
                        eNameData[ m_iRestrictFlags ] = 0;
                       
                        // Read the match type and string
                       
                        if( equali( szMatchType, "
contain", 7 ) )
                        {
                                eNameData[ m_iMatchFlags ] |= MATCH_CONTAIN;
                               
                                if( szMatchType[ 7 ] != 'I' && szMatchType[ 7 ] != 'i' )
                                {
                                        eNameData[ m_iMatchFlags ] |= MATCH_CASESENSITIVE;
                                }
                               
                                copy( eNameData[ m_szName ], charsmax( eNameData[ m_szName ] ), szMatchString );
                        }
                        else if( equali( szMatchType, "
equal", 5 ) )
                        {
                                eNameData[ m_iMatchFlags ] |= MATCH_EQUAL;
                               
                                if( szMatchType[ 5 ] != 'I' && szMatchType[ 5 ] != 'i' )
                                {
                                        eNameData[ m_iMatchFlags ] |= MATCH_CASESENSITIVE;
                                }
                               
                                copy( eNameData[ m_szName ], charsmax( eNameData[ m_szName ] ), szMatchString );
                        }
                        else if( equali( szMatchType, "
regex", 5 ) )
                        {
                                eNameData[ m_iMatchFlags ] |= MATCH_REGEX;
                               
                                if( szMatchType[ 5 ] == '/' )
                                {
                                        format( szMatchType, charsmax( szMatchType ), "
%s", szMatchType[ 6 ] );
                                }
                                else
                                {
                                        szMatchType[ 0 ] = EOS;
                                }
                               
                                eNameData[ m_pPattern ] = _:regex_compile( szMatchString, iReturn, szError, charsmax( szError ), szMatchType );
                               
                                if( Regex:eNameData[ m_pPattern ] < REGEX_OK )
                                {
                                        log_amx( "
Error on pattern compiling for line #%d: %s", iLine, szError );
                                        continue;
                                }
                               
                                eNameData[ m_iszPattern ] = engfunc( EngFunc_AllocString, szMatchString );
                        }
                        else
                        {
                                continue;
                        }
                       
                        // Read the restricted type
                       
                        if( equali( szRestrictType, "steam", 5 ) )
                        {
                                eNameData[ m_iRestrictFlags ] = RESTRICT_STEAMID;
                               
                                copy( eNameData[ m_szRestricted ], charsmax( eNameData[ m_szRestricted ] ), szRestrictedString );
                        }
                        else if( equali( szRestrictType, "ip", 2 ) || equali( szRestrictType, "address", 7 ) )
                        {
                                eNameData[ m_iRestrictFlags ] = RESTRICT_IP;
                               
                                copy( eNameData[ m_szRestricted ], charsmax( eNameData[ m_szRestricted ] ), szRestrictedString );
                        }
                        else if( equali( szRestrictType, "flag", 4 ) )
                        {
                                eNameData[ m_iRestrictFlags ] = RESTRICT_FLAGS | ( read_flags( szRestrictedString ) << 2 );
                        }
                        else
                        {
                                continue;
                        }
                       
                        copy( eNameData[ m_szReplacement ], charsmax( eNameData[ m_szReplacement ] ), szReplacement );
                       
                        // Everything was parsed, so add to the array
                       
                        ArrayPushArray( g_aNameDatas, eNameData );
                        g_iNumNames++;
                }
               
                fclose( pFile );
        }
       
        if( !g_iNumNames )
        {
                set_fail_state( "No names were loaded to protect" );
        }
}
This plugin allows you to protect player names so that other players cannot fake that name.

Don't get this idea confused with Restrict Names.
That plugin blocks names from being used at all, whereas this one protects names to specified players.

This already exists in the default AMXX, but it requires you to set passwords for players and doesn't allow them to be matched to a SteamID among other options that this plugin offers.
This plugin does not deal with passwords (if you want passwords, just use AMXX's method).

It allows you to restrict a name based on one of the following:
  • SteamID
  • IP
  • admin flags

For matching a name to be restricted, you can match it by:
  • equaling the name
  • containing the name (like a tag for example)
  • or a regular expression

Requirements:
  • AMX Mod X 1.8.0 or higher
  • RegEx module
  • Fakemeta module

Cvars:
  • protect_name_punish 0/1- 0 = Rename player to replacement name from file- 1 = Execute command from protect_name_command cvar (kick or ban).- Default: 0
  • protect_name_command "command"- Command executed on server when player is punished (when protect_name_punish is 1)- Allows formatting with variables:
    • %name% - The name that player tried using
    • %steamid% - The SteamID of the player
    • %userid% - The userid of the player
    • %ip% - The IP of the player
    • %reason% - The reason from protect_name_reason cvar
    - To use double quotes in this cvar, use \' and they will be replaced to "
    Default: "kick %userid% \'%reason%\'"
  • protect_name_reason "reason"- Reason printed to player in chat if no punishment is taken.- Allows formatting with variables:
    • %name% - The name that player tried using
    • %steamid% - The SteamID of the player
    • %userid% - The userid of the player
    • %ip% - The IP of the player
    Default: "%name% is protected and you are not allowed to use it!"
  • Old 07-03-2012 , 13:18   Protect Names
    Reply With Quote #1

    Protect Names
    v0.0.2, by Exolent


    Description:

    This plugin allows you to protect player names so that other players cannot fake that name.

    Don't get this idea confused with Restrict Names.
    That plugin blocks names from being used at all, whereas this one protects names to specified players.

    This already exists in the default AMXX, but it requires you to set passwords for players and doesn't allow them to be matched to a SteamID among other options that this plugin offers.
    This plugin does not deal with passwords (if you want passwords, just use AMXX's method).

    It allows you to restrict a name based on one of the following:
    • SteamID
    • IP
    • admin flags

    For matching a name to be restricted, you can match it by:
    • equaling the name
    • containing the name (like a tag for example)
    • or a regular expression

    Requirements:
    • AMX Mod X 1.8.0 or higher
    • RegEx module
    • Fakemeta module

    Cvars:
    • protect_name_punish 0/1- 0 = Rename player to replacement name from file- 1 = Execute command from protect_name_command cvar (kick or ban).- Default: 0
    • protect_name_command "command"- Command executed on server when player is punished (when protect_name_punish is 1)- Allows formatting with variables:
      • %name% - The name that player tried using
      • %steamid% - The SteamID of the player
      • %userid% - The userid of the player
      • %ip% - The IP of the player
      • %reason% - The reason from protect_name_reason cvar
      - To use double quotes in this cvar, use \' and they will be replaced to "
      Default: "kick %userid% \'%reason%\'"
    • protect_name_reason "reason"- Reason printed to player in chat if no punishment is taken.- Allows formatting with variables:
      • %name% - The name that player tried using
      • %steamid% - The SteamID of the player
      • %userid% - The userid of the player
      • %ip% - The IP of the player
      Default: "%name% is protected and you are not allowed to use it!"

    File Setup:

    File is located at addons/amxmodx/configs/protect_names.ini

    Format of the file is as follows:
    Code:
    // Lines starting with // or ; are comments and are ignored in the file
    
    ; This is a comment, too!
    //
    // File format:
    // "match type" "string to match" "restrict type" "restricted string" "replacement"
    //
    // Available match types:
    // equal
    // equali
    // contain
    // containi
    // regex/flags (eg. regex/i)
    //
    // When using "regex" match type, the pattern goes in the match string.
    //
    // Available restrict types:
    // steam, steamid
    // ip, address, ipaddress
    // flag, flags
    //
    // Remember, match types and restrict types are case insensitive, so RegEx and SteamID will also work.
    //
    "containi" "Exolent" "steamid" "STEAM_0:1:23456" "Imposter alert!"
    "regex/i" "j(uke)?Nr(un)?" "flags" "m" "Fake member"

    Changelog:
    • 0.0.2- Fixed backwards IP/SteamID restriction- Updated name change for new access flags detection
    • 0.0.1- Initial release

Comments

None found

Share

Shareable Image:
Share banner
HTML embed code:
BB embed code:
Markdown embed code:

More embeddable images

Bookmark and Share

Credits

Original Authors
Exolent
amxx coder/script

Submitter

Rj. avatar
Rj. IN PLAYGROUND
Members > ElysiumLeoSK
Member Joined 9 months ago
34 medals 4 legendary 8 rare
  • Submitted 15 Tools Medal icon
  • Submitted 50 Gamefiles Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2016 Medal icon
  • Thanked 500 submitters Medal icon
  • 2nd Place - Game Poetry Contest Medal icon
  • Submitted 5 Tools Medal icon

Rj.
Redistributor
Request Ownership
Send a Private Message to the submitter

Category

Stats

Posts
0
Views
147
Date Added
1 month ago
Feb 18 2017 @ 11:26am UTC
Date Updated
1 month ago
Feb 18 2017 @ 11:26am UTC