AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   nVault data switching (https://forums.alliedmods.net/showthread.php?t=324645)

Shadows Adi 05-22-2020 13:58

nVault data switching
 
Hello,
I have a problem with nVault loading.
Code:
PHP Code:


public client_authorizedid )
{
    if(
g_bMapBanned)
        return 
PLUGIN_HANDLED

    
if ( !( g_BotOrHLTVid ] = bool:( is_user_botid ) || is_user_hltvid ) ) ) )
    {
        
get_user_authidid g_AuthIDid ] , charsmaxg_AuthID[ ] ) );
        
        
nvault_get_arrayg_Vault g_AuthIDid ] , pdDataid ][ PlayerData:] , sizeofpdData[  ] ) );
    }
    return 
PLUGIN_HANDLED
}

public 
client_disconnectedid )
{
    if(
g_bMapBanned)
        return 
PLUGIN_HANDLED

    
if ( !g_BotOrHLTVid ] )
    {
        
get_user_nameid pdDataid ][ PlayerName ] , charsmaxpdData[][ PlayerName ] ) );
        
        
nvault_set_arrayg_Vault g_AuthIDid ] , pdDataid ][ PlayerData:] , sizeofpdData[  ] ) );
    }
    return 
PLUGIN_HANDLED
}

public 
DeathMsg()
{
    if(
g_bMapBanned || !is_user_connected(id))
        return 
PLUGIN_HANDLED
    
    
new iKiller read_data);
    new 
iVictim read_data);

    
pdData[iVictim][Deaths]++;
    
pdData[iKiller][Kills]++;
    
pdData[iKiller][Headshot] += read_data);
    
    return 
PLUGIN_HANDLED


The problem is when a new player is joining the server, he receive +1 Death.
It worked for 3 maps, then it stored as I said above.

Registered events:
PHP Code:

register_event"DeathMsg" "DeathMsg" "a" "4=knife" "1>0" ); 

.
Anyone, any idea?

Natsheh 05-22-2020 15:40

Re: nVault array switching
 
PHP Code:

public DeathMsg()
{
    if(
g_bMapBanned)
        return 
PLUGIN_HANDLED
    
    
new iKiller read_data);
    new 
iVictim read_data);
    
    
pdData[iVictim][Deaths]++;

    if(!(
iKiller != iVictim && (32 >= iKiller 0))) return PLUGIN_HANDLED;
    
pdData[iKiller][Kills]++;
    
pdData[iKiller][Headshot] += read_data);
    
    return 
PLUGIN_HANDLED


Param id is not presented in the function.

Bugsy 05-22-2020 18:40

Re: nVault data switching
 
There's a possibility that the death(s) remain there from the previous player on that slot. nvault_get_array() only fills the array if the player has data stored. So the below sequence of events would cause a connecting player to have data from the previous player.

1. Player A on slot 1 had 4 deaths. They disconnect.
2. Player B connects on slot 1. They have no data stored in the vault so nvault_get_array() essentially does nothing.
3. Player B has Player A's data leftover in pdData array.

I would clear out the pdData[ SLOT ] on disconnect.
Code:
public client_disconnected( id ) {     if(g_bMapBanned)         return PLUGIN_HANDLED     if ( !g_BotOrHLTV[ id ] )     {         get_user_name( id , pdData[ id ][ PlayerName ] , charsmax( pdData[][ PlayerName ] ) );                 nvault_set_array( g_Vault , g_AuthID[ id ] , pdData[ id ][ PlayerData:0 ] , sizeof( pdData[  ] ) );         arrayset( pdData[ id ] , 0 , sizeof( pdData[] ) );     }     return PLUGIN_HANDLED }

Shadows Adi 05-22-2020 18:51

Re: nVault data switching
 
Quote:

Originally Posted by Bugsy (Post 2701687)
There's a possibility that the death(s) remain there from the previous player on that slot. nvault_get_array() only fills the array if the player has data stored. So the below sequence of events would cause a connecting player to have data from the previous player.

1. Player A on slot 1 had 4 deaths. They disconnect.
2. Player B connects on slot 1. They have no data stored in the vault so nvault_get_array() essentially does nothing.
3. Player B has Player A's data leftover in pdData array.

I had the same theory.
I will test your way.
You should apply this update at this tutorial:
https://forums.alliedmods.net/showthread.php?t=307518

Bugsy 05-22-2020 19:42

Re: nVault data switching
 
I just tested the nvault module, nvault_get() clears the string variable if no record exists., I think a correction to the nVault Array include would be better for consistency. This should be fine from a backwards compatibility perspective.


All times are GMT -4. The time now is 17:14.

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