AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Trouble using Tries (https://forums.alliedmods.net/showthread.php?t=320675)

edon1337 01-03-2020 10:52

Trouble using Tries
 
1 Attachment(s)
I tried optimizing my Elite Admin System plugin by using Tries instead of Arrays for storing player information. The problem is some Admins/Vips in my server aren't getting their flags, I also noticed that only those that are around the middle/end of the file are having this issue, if I copy-paste their data to the top of the users file, they get their flags, which is confusing me. It feels like some lines are being skipped when reading.

To avoid confusion: I'm checking TrieKeyExists in 2 ways, steamid and name, because in Elite Admin System you're able to set admins by name and steamid.

Part which sets flags:
PHP Code:

CheckPlayerAdminid )
{    
    new 
szPasswordMAX_PASSWORD_LENGTH ], eDataPlayerData ];
    
get_user_infoid"_pw"szPasswordcharsmaxszPassword ) );
    
    if( 
TrieKeyExistsg_tDatabaseg_szAuthIdid ] ) ) // key exists?
    
{
        
TrieGetArrayg_tDatabaseg_szAuthIdid ], eDatasizeof eData ); // get the data from the key
        
        
if( ( eDataPlayer_Password ][ ] && equaleDataPlayer_Password ], szPassword ) ) || !eDataPlayer_Password ][ ] ) // password correct or no password at all
        
{
            if( 
eDataPlayer_Suspended ] || ( eDataPlayer_Expired ] && !eDataPlayer_KeepPrivileges ] ) ) // player suspended or date expired
            
{
                
remove_user_flagsid );
                
set_user_flagsidADMIN_USER );
            }
            
            else if( 
eDataPlayer_Expired ] && eDataPlayer_KeepPrivileges ] ) // expired but keeps his flags
            
{
                
remove_user_flagsid );
                
                if( ! 
eDataPlayer_AccessFlags ][ ] ) // no flags specified?
                
{
                    
set_user_flagsidADMIN_USER );
                } 
                
                new 
iFlags read_flagseDataPlayer_AccessFlags ] );
                
iFlags &= ~read_flagseDataPlayer_FlagsExpire ] ); // remove expire flags from default flags
                
                
if( ! iFlags // no flags left
                
{
                    
set_user_flagsidADMIN_USER ); // set 'z' flag
                
}
                
                else
                {
                    
set_user_flagsidiFlags ); // set flags
                
}
            }
            
            else
            {
                
remove_user_flagsid );
                
                if( ! 
eDataPlayer_AccessFlags ][ ] ) // no flags
                
{
                    
set_user_flagsidADMIN_USER );
                }
                
                else
                {
                    
set_user_flagsidread_flagseDataPlayer_AccessFlags ] ) );
                }
            }
        }
        
        else if( 
eDataPlayer_Password ][ ] && !equaleDataPlayer_Password ], szPassword ) )
        {
            
server_cmd"kick #%d ^"%L^""get_user_useridid ), LANG_PLAYER"INCORRECT_PASSWORD" );
        }
    }
    
    else if( 
TrieKeyExistsg_tDatabaseg_szNameid ] ) )
    {
        
TrieGetArrayg_tDatabaseg_szNameid ], eDatasizeof eData );
        
        if( ( 
eDataPlayer_Password ][ ] && equaleDataPlayer_Password ], szPassword ) ) || !eDataPlayer_Password ][ ] )
        {
            if( 
eDataPlayer_Suspended ] || ( eDataPlayer_Expired ] && !eDataPlayer_KeepPrivileges ] ) )
            {
                
remove_user_flagsid );
                
set_user_flagsidADMIN_USER );
            }
            
            else if( 
eDataPlayer_Expired ] && eDataPlayer_KeepPrivileges ] )
            {
                
remove_user_flagsid );
                
                if( ! 
eDataPlayer_AccessFlags ][ ] )
                {
                    
set_user_flagsidADMIN_USER );
                } 
                
                new 
iFlags read_flagseDataPlayer_AccessFlags ] );
                
iFlags &= ~read_flagseDataPlayer_FlagsExpire ] );
                
                if( ! 
iFlags )
                {
                    
set_user_flagsidADMIN_USER );
                }
                
                else
                {
                    
set_user_flagsidiFlags );
                }
            }
            
            else
            {
                
remove_user_flagsid );
                
                if( ! 
eDataPlayer_AccessFlags ][ ] )
                {
                    
set_user_flagsidADMIN_USER );
                }
                
                else
                {
                    
set_user_flagsidread_flagseDataPlayer_AccessFlags ] ) );
                }
            }
        }
        
        else if( 
eDataPlayer_Password ][ ] && !equaleDataPlayer_Password ], szPassword ) )
        {
            
server_cmd"kick #%d ^"%L^""get_user_useridid ), LANG_PLAYER"INCORRECT_PASSWORD" );
        }
    }


Part which reads data from users file and fills the trie:
PHP Code:

ReloadFile( )
{
    
TrieClearg_tDatabase );
    
ArrayClearg_aPlayers );

    new 
szFormat64 ], szPlayerData512 ], eDataPlayerData ];
    
formatexszFormatcharsmaxszFormat ), "%s/%s"g_szConfigsDirg_iConfigUSERS_FILE ] );
    
    new 
iFile fopenszFormat"rt" );
    
    if( 
iFile )
    {
        while( 
fgetsiFileszPlayerDatacharsmaxszPlayerData ) ) )
        {
            
trimszPlayerData );
            
            switch( 
szPlayerData] )
            {
            case 
EOS'#''/''\':
                {
                    continue;
                }
                
            default:
                {
                    new szImmunity[ 8 ], szKeepPrivileges[ 3 ];
                    if( parse( szPlayerData, eData[ Player_Name ], charsmax( eData[ Player_Name ] ), eData[ Player_SteamID ], charsmax( eData[ Player_SteamID ] ), eData[ Player_Password ], charsmax( eData[ Player_Password ] ), eData[ Player_AccessFlags ], charsmax( eData[ Player_AccessFlags ] ),
                                eData[ Player_Prefix ], charsmax( eData[ Player_Prefix ] ), eData[ Player_Model_T ], charsmax( eData[ Player_Model_T ] ), eData[ Player_Model_CT ], charsmax( eData[ Player_Model_CT ] ), szImmunity, charsmax( szImmunity ),
                                eData[ Player_Expire_Date ], charsmax( eData[ Player_Expire_Date ] ), eData[ Player_FlagsExpire ], charsmax( eData[ Player_FlagsExpire ] ), szKeepPrivileges, charsmax( szKeepPrivileges ) ) < 11 )
                    {
                        continue;
                    }
                    
                    if( szPlayerData[ 0 ] == '
;' )
                    {
                        eData[ Player_Suspended ] = true;
                        replace( eData[ Player_Name ], charsmax( eData[ Player_Name ] ), ";", "" );
                    }
                    
                    if( eData[ Player_Expire_Date ][ 0 ] )
                    {
                        if( HasAdminExpired( eData[ Player_Expire_Date ] ) )
                        {
                            eData[ Player_Expired ] = true;
                        }
                    }
                    
                    // we don'
t want to use models that don't exist
                    if( eData[ Player_Model_T ][ 0 ] )
                    {
                        if( ! ModelExists( eData[ Player_Model_T ] ) )
                        {
                            eData[ Player_Model_T ][ 0 ] = EOS;
                        }
                    }
                    
                    if( eData[ Player_Model_CT ][ 0 ] )
                    {
                        if( ! ModelExists( eData[ Player_Model_CT ] ) )
                        {
                            eData[ Player_Model_CT ][ 0 ] = EOS;
                        }
                    }
                    
                    new iImmunity = str_to_num( szImmunity );
                    eData[ Player_Immunity ] = ( ! is_str_num( szImmunity ) || iImmunity < 0 ) ? 0 : iImmunity;
                    
                    new iKeepPrivileges = str_to_num( szKeepPrivileges );
                    eData[ Player_KeepPrivileges ] = bool:( ( ! is_str_num( szKeepPrivileges ) || !( 0 <= iKeepPrivileges <= 1 ) ) ? 0 : iKeepPrivileges );
                    
                    if( eData[ Player_SteamID ][ 0 ] )
                    {
                        TrieSetArray( g_tDatabase, eData[ Player_SteamID ], eData, sizeof eData );
                        ArrayPushString( g_aPlayers, eData[ Player_SteamID ] );
                    }
                    
                    else if( eData[ Player_Name ][ 0 ] )
                    {
                        TrieSetArray( g_tDatabase, eData[ Player_Name ], eData, sizeof eData );
                        ArrayPushString( g_aPlayers, eData[ Player_Name ] );
                    }
                }
            }
        }
        fclose( iFile );
    }


Full code attached!


All times are GMT -4. The time now is 03:42.

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