AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Invalid Character in Name (https://forums.alliedmods.net/showthread.php?t=64794)

owned 12-24-2007 17:45

Invalid Character in Name
 
What i'm trying to do is, if the user has ` or ~ in their name it kicks them with a message.

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Bad Name Kicker"
#define VERSION "1.0"
#define AUTHOR "owned"

new const bad_names[][] = {"`","~"};


public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public 
client_connect(id){
    new 
name[32];
    
get_user_name(id,name,31);
    
    
checkname(id);
    return 
PLUGIN_CONTINUE;
}

public 
client_infochanged(id){
    new 
name[32];
    
get_user_name(id,name,31);
    
    
checkname(id);
    return 
PLUGIN_CONTINUE;
}

public 
checkname(id){
    new 
name[32];
    
get_user_name(id,name,31);
    new 
uid get_user_userid(id);
    
    if(
is_user_admin(id)){
        return 
PLUGIN_CONTINUE;
    }else {
        for(new 
0sizeof bad_namesi++){
            if(
contain(name,bad_names[i]) > 0){
                
kickuser(uid);
                return 
PLUGIN_CONTINUE;
            }
        }
    }
    return 
PLUGIN_CONTINUE;
}

public 
kickuser(id){
    new 
name[32];
    
get_user_name(id,name,31);
    
    
server_cmd("banid 1 #%d"id);
    
client_cmd(id"echo ^"[BNKYour name contained invalid characters!^"; disconnect");
    return 
PLUGIN_CONTINUE;


Well I guess it doesn't want to kick me. Can I get some help?

[ --<-@ ] Black Rose 12-24-2007 17:47

Re: Invalid Character in Name
 
To start with...
Code:
new const bad_names[][] = {"`","~"};
-->
Code:
new const bad_names[] = {'`','~'};

Then...
Code:
public checkname(id){     new name[32];     get_user_name(id, name, 31);     new uid = get_user_userid(id);     new len = strlen(name);         if ( is_user_admin(id) )         return PLUGIN_CONTINUE;         for ( new i = 0 ; i < sizeof bad_names - 1 ; i++ ) {         for ( new j = 0 ; j < len ; j++ ) {             if ( name[j] == bad_names[i] ) {                 kickuser(uid);                 return PLUGIN_CONTINUE;             }         }     }     return PLUGIN_CONTINUE; }

YamiKaitou 12-24-2007 17:59

Re: Invalid Character in Name
 
Also, there is no point in getting the client's name in connect and infochanged if you don't use it


All times are GMT -4. The time now is 11:05.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.