AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Other way to block changing name (https://forums.alliedmods.net/showthread.php?t=171309)

m0skVi4a 11-04-2011 13:59

Other way to block changing name
 
Hello
I am making a Register System plugin and the beta version is almost reаdy. My problem is that when player change his name and hi is logged to block the name change. I found that and works properly
PHP Code:

public client_infochanged(id
{
        if(!
is_user_connected(id))
            return 
PLUGIN_HANDLED

        
new newname[32]
        
get_user_info(id,"name",newname,31)

        new 
oldname[32]
        
get_user_name(id,oldname,31)

        if(!
equal(newname,oldname))
        {
            
set_user_info(id,"name",oldname)
            return 
PLUGIN_HANDLED
        
}
            return 
PLUGIN_CONTINUE


and i change it to
PHP Code:

public client_infochanged(id
{
    if(
is_logged[id])
    {
        if(!
is_user_connected(id))
            return 
PLUGIN_HANDLED

        
new newname[32]
        
get_user_info(id,"name",newname,31)

        new 
oldname[32]
        
get_user_name(id,oldname,31)

        if(!
equal(newname,oldname))
        {
            
set_user_info(id,"name",oldname)
            return 
PLUGIN_HANDLED
        
}
    }
    else if(
is_registerd[id])
    {
        
is_registerd[id] = false
    
    
}
    

    return 
PLUGIN_CONTINUE


The problem is that when player putinserver the plugin makes the checks and if his name is in the file is_registered makes true. But when player connect (i suppose) client_infochanged makes is_registered to false and the player can't log in.

My question:
Is there any other way to block name changing, except client_infochanged and the fakemeta way with FM_ClientUserInfoChanged. Or how to do my code to work properly?

fysiks 11-05-2011 01:17

Re: Other way to block changing name
 
The Fakemeta way is the best way that I've seen.

m0skVi4a 11-05-2011 04:10

Re: Other way to block changing name
 
OK
here is it
PHP Code:

register_forward(FM_ClientUserInfoChanged"NoNameChange")

...

public 
NoNameChange(idbuffer)
{
    if(
is_logged[id])
    {
        if(!
is_user_connected(id))
            return 
FMRES_IGNORED
    
        
static name[32], val[32];
    
        
get_user_name(idnamesizeof name 1)
        
engfunc(EngFunc_InfoKeyValuebuffer"name"valsizeof val 1)
    
        if(
equal(valname))
            return 
FMRES_IGNORED
    
        engfunc
(EngFunc_SetClientKeyValueidbuffer"name"name)
        
client_printcolor(id"%L"LANG_SERVER"NAME_CHANGE"prefix)
    }
    else if(
is_registerd[id])
    {
        
is_registerd[id] = false
    
}
    
    return 
FMRES_SUPERCEDE


The problem is the same:
From client_putinserver is_registered makes true, but that code makes it false and user can't login.

fysiks 11-05-2011 04:49

Re: Other way to block changing name
 
You need to realize that this function is called several times before the user is connected completely so you can't supercede in those cases and you also will not have a proper/relevant value for is_logged[id] either.

In laymans terms, move the is_user_connected check so that when they aren't connected then no code gets executed and you return ignored.

m0skVi4a 11-05-2011 14:42

Re: Other way to block changing name
 
Both methods don't work with is_user_connected in the start of the function..
Here is it the fakemeta method
PHP Code:

public NoNameChange(idbuffer
{
    if(!
is_user_connected(id))
        return 
FMRES_IGNORED
        
    
if(is_logged[id])
    {
        static 
name[32], val[32];
    
        
get_user_name(idnamesizeof name 1)
        
engfunc(EngFunc_InfoKeyValuebuffer"name"valsizeof val 1)
    
        if(
equal(valname))
            return 
FMRES_IGNORED
    
        engfunc
(EngFunc_SetClientKeyValueidbuffer"name"name)
        
client_printcolor(id"%L"LANG_SERVER"NAME_CHANGE"prefix)
    }
    else if(
is_registerd[id])
    {
        
is_registerd[id] = false
    
}
    
    return 
FMRES_SUPERCEDE


Is there any other way to find when player is changing his name except client_infochanged and the fakemeta userinfo changed but only for name change?

ConnorMcLeod 11-05-2011 15:10

Re: Other way to block changing name
 
PHP Code:

public plugin_init()
{
    
register_forward(FM_ClientUserInfoChanged"ClientUserInfoChanged")
}

public 
ClientUserInfoChanged(id)
{
    static const 
name[] = "name"
    
new szOldName[32], szNewName[32]
    
pev(idpev_netnameszOldNamecharsmax(szOldName))
    if( 
szOldName[0] )
    {
        
get_user_info(idnameszNewNamecharsmax(szNewName))
        if( !
equal(szOldNameszNewName) )
        {
            
// name change, to block or change use set_user_info and return FMRES_HANDLED (don't need to superceede)
        
}
    }
    else if( 
get_user_info(idnameszNewNamecharsmax(szNewName)) )
    {
        
// first time client name is taken in account
        // to change, use set_user_info and return FMRES_HANDLED (don't need to superceede)
    
}
    return 
FMRES_IGNORED



m0skVi4a 11-05-2011 15:33

Re: Other way to block changing name
 
Thanks
I changed it to
PHP Code:

public NoNameChange(id
{
    static const 
name[] = "name"
    
new szOldName[32], szNewName[32]
    
pev(idpev_netnameszOldNamecharsmax(szOldName))
    if(
szOldName[0])
    {
        
get_user_info(idnameszNewNamecharsmax(szNewName))
        if(!
equal(szOldNameszNewName))
        {
            if(
is_logged[id])
            {
                
set_user_info(idnameszOldName)
                
client_printcolor(id"%L"LANG_SERVER"NAME_CHANGE"prefix)
                return 
FMRES_HANDLED
            
}
            else if(
is_registerd[id])
            {
                
is_registerd[id] = false
                remove_task
(id)
                return 
FMRES_HANDLED
            
}            
        }
    }
    return 
FMRES_IGNORED


Tomorrow i will write the description and i will post the plugin in the forum :)

ConnorMcLeod 11-05-2011 15:37

Re: Other way to block changing name
 
PHP Code:

            else if(is_registerd[id])
            {
                
is_registerd[id] = false
                remove_task
(id)
                return 
FMRES_HANDLED
            


You don't need to return HANDLED there since you changed nothing except plugin internal datas.


All times are GMT -4. The time now is 01:30.

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