Raised This Month: $12 Target: $400
 3% 

Solved Loop order


Post New Thread Reply   
 
Thread Tools Display Modes
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 01-15-2018 , 13:58   Re: Loop order
Reply With Quote #11

Update your code to something like this, with removing g_iItems from global scope and add parse condition to be sure that all fields are parsed and stored into array:
PHP Code:
ReadFile( )
{
    
ArrayClearg_aDatabase );

    new 
g_iItemsPlayerData ] );

    new 
szConfigs32 ], szFormat64 ], szPlayerData512 ];
    
get_configsdirszConfigscharsmaxszConfigs ) );
    
    
formatexszFormatcharsmaxszFormat ), "%s/%s"szConfigsg_szFile );
    
    new 
iFile fopenszFormat"rt" );
    
    if( 
iFile )
    {
        while( ! 
feofiFile ) )
        {    
            
fgetsiFileszPlayerDatacharsmaxszPlayerData ) );
            
trimszPlayerData );
            
            if( 
szPlayerData] == ';' || strlen(szPlayerData) < 10 || ( szPlayerData] == '/' && szPlayerData] == '/' ) )
            continue;
            
            if(
parseszPlayerDatag_iItems[Player_Name], charsmaxg_iItems[Player_Name] ), g_iItems[Player_Password], charsmaxg_iItems[Player_Password]), g_iItems[Player_AccessFlags], charsmaxg_iItems[Player_AccessFlags] ), g_iItems[Player_Prefix], charsmaxg_iItems[Player_Prefix] ) ) < 4)
             continue;
            
            
ArrayPushArrayg_aDatabaseg_iItems );
        }
        
fcloseiFile );
    }

After that you will have all data stored in array g_aDatabase on wich you will be later iterate read etc.
On the next ReadFile function call, g_aDatabase array will be emptied and filled with new data from file.
Clauu is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-15-2018 , 14:04   Re: Loop order
Reply With Quote #12

Quote:
Originally Posted by Clauu View Post
Update your code to something like this, with removing g_iItems from global scope and add parse condition to be sure that all fields are parsed and stored into array:
PHP Code:
ReadFile( )
{
    
ArrayClearg_aDatabase );

    new 
g_iItemsPlayerData ] );

    new 
szConfigs32 ], szFormat64 ], szPlayerData512 ];
    
get_configsdirszConfigscharsmaxszConfigs ) );
    
    
formatexszFormatcharsmaxszFormat ), "%s/%s"szConfigsg_szFile );
    
    new 
iFile fopenszFormat"rt" );
    
    if( 
iFile )
    {
        while( ! 
feofiFile ) )
        {    
            
fgetsiFileszPlayerDatacharsmaxszPlayerData ) );
            
trimszPlayerData );
            
            if( 
szPlayerData] == ';' || strlen(szPlayerData) < 10 || ( szPlayerData] == '/' && szPlayerData] == '/' ) )
            continue;
            
            if(
parseszPlayerDatag_iItems[Player_Name], charsmaxg_iItems[Player_Name] ), g_iItems[Player_Password], charsmaxg_iItems[Player_Password]), g_iItems[Player_AccessFlags], charsmaxg_iItems[Player_AccessFlags] ), g_iItems[Player_Prefix], charsmaxg_iItems[Player_Prefix] ) ) < 4)
             continue;
            
            
ArrayPushArrayg_aDatabaseg_iItems );
        }
        
fcloseiFile );
    }

After that you will have all data stored in array g_aDatabase on wich you will be later iterate read etc.
On the next ReadFile function call, g_aDatabase array will be emptied and filled with new data from file.
If I make g_iItems a local variable inside ReadFile, I'll have to re-create it every time I need to use it, so every 0.1 second, that doesn't sound like a reasonable idea, I'll stick with what I have now. I'll have some use from your code, anyway, thanks!

By the way, I managed to fix the code, if you haven't checked my last post.
__________________

Last edited by edon1337; 01-15-2018 at 14:04.
edon1337 is offline
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 01-15-2018 , 14:22   Re: Loop order
Reply With Quote #13

Well you don't have do to that, all data is stored into global array g_aDatabase so whenever you want just parse that array and get necessary data from it.
After posting i saw your last message :-)

Last edited by Clauu; 01-15-2018 at 14:24.
Clauu is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-15-2018 , 16:35   Re: Loop order
Reply With Quote #14

Quote:
Originally Posted by Clauu View Post
Well you don't have do to that, all data is stored into global array g_aDatabase so whenever you want just parse that array and get necessary data from it.
After posting i saw your last message :-)
I actually tried doing that, and I got 'undefined symbol g_iItems' error, just as I expected.
I'm trying to make an option to suspend (disable) someone's admin by adding a semi-colon (;) at the beginning of the line, but it never returns true in one of my checks.

PHP Code:
enum _:PlayerData
{
    
Player_Name32 ],
    
Player_Password18 ],
    
Player_AccessFlags32 ],
    
Player_Prefix24 ],
    
Player_Suspended]
}

public 
OnTaskCheckStealAdmin( )
{
    
ReadFile( );

    new 
iArraySize ArraySizeg_aDatabase );

    new 
szPlayers32 ], iNumszName32 ], szAuthID32 ], szPassword18 ], szName232 ], szPassword218 ], szFlags32 ], szSuspended];
    
get_playersszPlayersiNum );
    
    static 
iTempID;
    
copyszName2charsmaxszName2 ), g_iItemsPlayer_Name ] );
    
copyszPassword2charsmaxszPassword2 ), g_iItemsPlayer_Password ] );
    
copyszFlagscharsmaxszFlags ), g_iItemsPlayer_AccessFlags ] );
    
copyszSuspendedcharsmaxszSuspended ), g_iItemsPlayer_Suspended ] );

        
// I debugged this part and both szSuspended and g_iItems[ Player_Suspended ] had ';'

    
for( new iiNumi++ )
    {
        
iTempID szPlayers];

        for( new 
iIndexiIndex iArraySizeiIndex++ )
        {
            
ArrayGetArrayg_aDatabaseiIndexg_iItems );
            
            
get_user_infoiTempID"name"szNamecharsmaxszName ) );
            
get_user_authidiTempIDszAuthIDcharsmaxszAuthID ) );
            
get_user_infoiTempID"_pw"szPasswordcharsmaxszPassword ) );
            
            if( 
equalszName2szName ) || equalszName2szAuthID ) )
            {
                if( ! 
szPassword2] || equalszPassword2szPassword ) )
                {
                    if( 
szSuspended] == ';' || ( containszSuspended";" ) != -) || equalszSuspended], ";" ) ) // even though szSuspended has ';', it still doesn't return true
                    
{
                        
remove_user_flagsiTempID );
                        
log_to_file"DebugTest.txt""#2 Called" );
                    }
                    
                    
remove_user_flagsiTempID );
                    
set_user_flagsiTempIDread_flagsszFlags ) );
                    
                    
log_to_file"DebugTest.txt""#3 Called" );
                }
                
                else if( ! 
equalszPassword2szPassword ) )
                {
                    
remove_user_flagsiTempID );
                    
server_cmd"kick #%d ^"KICKEDyou have no entry to this server^""get_user_useridiTempID ) );        
                }
            }
        }
    }
}

public 
ReadFile( )
{
    
ArrayClearg_aDatabase );
        
    
FreeStringg_iItemsPlayer_Name ] );
    
FreeStringg_iItemsPlayer_Password ] );
    
FreeStringg_iItemsPlayer_AccessFlags ] );
    
FreeStringg_iItemsPlayer_Prefix ] );
    
FreeStringg_iItemsPlayer_Suspended ] );
    
    new 
szConfigs32 ], szFormat64 ], szPlayerData512 ], szName32 ], szPassword18 ], szAccessFlags25 ], szPrefix24 ];
    
get_configsdirszConfigscharsmaxszConfigs ) );
    
    
formatexszFormatcharsmaxszFormat ), "%s/%s"szConfigsg_szFile );
    
    new 
iFile fopenszFormat"r" );
    
    if( 
iFile )
    {
        while( ! 
feofiFile ) )
        {    
            
fgetsiFileszPlayerDatacharsmaxszPlayerData ) );
            
trimszPlayerData );
            
            if( ( 
szPlayerData] == '/' && szPlayerData] == '/' ) )
            continue;
            
            
parseszPlayerDataszNamecharsmaxszName ), szPasswordcharsmaxszPassword ), szAccessFlagscharsmaxszAccessFlags ), szPrefixcharsmaxszPrefix ) )
            
            
g_iItemsPlayer_Name ] = szName;
            
g_iItemsPlayer_Password ] = szPassword;
            
g_iItemsPlayer_AccessFlags ] = szAccessFlags;
            
g_iItemsPlayer_Prefix ] = szPrefix;
            
g_iItemsPlayer_Suspended ][ ] = szPlayerData];
            
            
ArrayPushArrayg_aDatabaseg_iItems );
        }
        
fcloseiFile );
    }

__________________
edon1337 is offline
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 01-15-2018 , 18:17   Re: Loop order
Reply With Quote #15

That's because you have to entirely remove g_iItems from global scope and keep it only local in functions, array g_aDatabase is what you must use.
PHP Code:
copyszName2charsmaxszName2 ), g_iItemsPlayer_Name ] ); 
Since g_iItems it is filled in ReadFile, here you are copying the last value parsed from that function, if it is parsed correctly since you don't have such condition.
In order to make it work your code needs to be refactored..
Clauu is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-16-2018 , 11:12   Re: Loop order
Reply With Quote #16

Quote:
Originally Posted by Clauu View Post
That's because you have to entirely remove g_iItems from global scope and keep it only local in functions, array g_aDatabase is what you must use..
I removed g_iItems from global scope, and used it only in local functions where ReadFile was called, still got that error, what do you mean with 'g_aDatabase is what you must use' ?

Quote:
Originally Posted by Clauu View Post
PHP Code:
copyszName2charsmaxszName2 ), g_iItemsPlayer_Name ] ); 
Since g_iItems it is filled in ReadFile, here you are copying the last value parsed from that function, if it is parsed correctly since you don't have such condition.
Sorry, what is wrong with that part of the code? It copies the name inside g_iItems[ Player_Name ] into szName2 ?
__________________
edon1337 is offline
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 01-16-2018 , 15:11   Re: Loop order
Reply With Quote #17

Because first you need to declare it locally before using it
new g_iItems[ PlayerData ];
Since all file data was parsed into array g_aDatabase, from this you will retrieve later any data you want.
Yes, it copies the name, but it will be the last name parsed from that file. Is that what you want?
Let me be more specific with some changes in your code, at the logic and structure, your OnTaskCheckStealAdmin function should be like this:
PHP Code:
public OnTaskCheckStealAdmin( )
{
    
ReadFile( );

    new 
iArraySize ArraySizeg_aDatabase );

    new 
g_iItemsPlayerData ];

    new 
szPlayers32 ], iNumszName32 ], szAuthID32 ], szPassword18 ], iTempID;
    
get_playersszPlayersiNum );


    for( new 
iiNumi++ )
    {
        
iTempID szPlayers];

        for( new 
iIndexiIndex iArraySizeiIndex++ )
        {
            
ArrayGetArrayg_aDatabaseiIndexg_iItems );
            
            
get_user_infoiTempID"name"szNamecharsmaxszName ) );
            
get_user_authidiTempIDszAuthIDcharsmaxszAuthID ) );
            
get_user_infoiTempID"_pw"szPasswordcharsmaxszPassword ) );
            
trim(szName);
            
trim(szPassword);

            if( 
equalg_iItems[Player_Name], szName ) || equalg_iItems[Player_Name], szAuthID ) )
            {
                if( 
equalg_iItems[Player_Password], szPassword ) )
                {
                    if( 
g_iItems[Player_Suspended] ) 
                    {
                        
remove_user_flagsiTempID );
                        
log_to_file"DebugTest.txt""#2 Called" );
                    }
                    else {
                           
remove_user_flagsiTempID );
                           
set_user_flagsiTempIDread_flagsg_iItems[Player_AccessFlags]) );
                    
                            
log_to_file"DebugTest.txt""#3 Called" );
                   }
                }
                else
                {
                    
server_cmd"kick #%d ^"KICKEDyou have no entry to this server^""get_user_useridiTempID ) );        
                }
            }
        }
    }

Update your struct like this:
PHP Code:
enum _:PlayerData
{
    
Player_Name32 ],
    
Player_Password18 ],
    
Player_AccessFlags32 ],
    
Player_Prefix24 ],
    
Player_Suspended

And your ReadFile function like this:
PHP Code:
ReadFile( )
{
    
ArrayClearg_aDatabase );

    new 
g_iItemsPlayerData ];

    new 
szConfigs32 ], szFormat64 ], szPlayerData512 ];
    
get_configsdirszConfigscharsmaxszConfigs ) );
    
    
formatexszFormatcharsmaxszFormat ), "%s/%s"szConfigsg_szFile );
    
    new 
iFile fopenszFormat"rt" );
    
    if( 
iFile )
    {
        while( ! 
feofiFile ) )
        {    
            
fgetsiFileszPlayerDatacharsmaxszPlayerData ) );
            
trimszPlayerData );
            
            if( 
strlen(szPlayerData) < 10 || ( szPlayerData] == '/' && szPlayerData] == '/' ) )
            continue;
            
            if(
parseszPlayerDatag_iItems[Player_Name], charsmaxg_iItems[Player_Name] ), g_iItems[Player_Password], charsmaxg_iItems[Player_Password]), g_iItems[Player_AccessFlags], charsmaxg_iItems[Player_AccessFlags] ), g_iItems[Player_Prefix], charsmaxg_iItems[Player_Prefix] ) ) < 4)
             continue;
            
             
g_iItems[Player_Suspended]=(szPlayerData] == ';');
            
ArrayPushArrayg_aDatabaseg_iItems );
        }
        
fcloseiFile );
    }

And also overall for your needs it's better to use Tries with the name as an index, in this way you will get rid of the loop on every player in OnTaskCheckStealAdmin
Hope that this helps.
PS. there are some later editings, so please recheck the code

Last edited by Clauu; 01-17-2018 at 03:22.
Clauu is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-16-2018 , 17:05   Re: Loop order
Reply With Quote #18

Quote:
Originally Posted by Clauu View Post
Because first you need to declare it locally before using it
new g_iItems[ PlayerData ];
Since all file data was parsed into array g_aDatabase, from this you will retrieve later any data you want.
Yes, it copies the name, but it will be the last name parsed from that file. Is that what you want?
Let me be more specific with some changes in your code, at the logic and structure, your OnTaskCheckStealAdmin function should be like this:
..
Thanks for the code, but it still never executes this part of the code, maybe making Player_Suspended a string in the enum and then later using str_to_num would work?
PHP Code:
if( g_iItemsPlayer_Suspended ] ) 
{
    
remove_user_flagsiTempID );
    
log_to_file"DebugTest.txt""#2 Called" );

__________________

Last edited by edon1337; 01-16-2018 at 17:05.
edon1337 is offline
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 01-17-2018 , 03:21   Re: Loop order
Reply With Quote #19

No, the problem is that we forget to remove ; from the player name, if has it. Sorry for that
PHP Code:
ReadFile( )
{
    
ArrayClearg_aDatabase );

    new 
g_iItemsPlayerData ];

    new 
szConfigs32 ], szFormat64 ], szPlayerData512 ];
    
get_configsdirszConfigscharsmaxszConfigs ) );
    
    
formatexszFormatcharsmaxszFormat ), "%s/%s"szConfigsg_szFile );
    
    new 
iFile fopenszFormat"rt" );
    
    if( 
iFile )
    {
        while( ! 
feofiFile ) )
        {    
            
fgetsiFileszPlayerDatacharsmaxszPlayerData ) );
            
trimszPlayerData );
            
            if( 
strlen(szPlayerData) < 10 || ( szPlayerData] == '/' && szPlayerData] == '/' ) )
            continue;
            
            if(
parseszPlayerDatag_iItems[Player_Name], charsmaxg_iItems[Player_Name] ), g_iItems[Player_Password], charsmaxg_iItems[Player_Password]), g_iItems[Player_AccessFlags], charsmaxg_iItems[Player_AccessFlags] ), g_iItems[Player_Prefix], charsmaxg_iItems[Player_Prefix] ) ) < 4)
             continue;
            
             if(
szPlayerData] == ';') {
                   
g_iItems[Player_Suspended]=1;
                   
replace(g_iItems[Player_Name],charsmax(g_iItems[Player_Name]),";","");
             }
            
ArrayPushArrayg_aDatabaseg_iItems );
        }
        
fcloseiFile );
    }

Now it will be fine.

Last edited by Clauu; 01-17-2018 at 03:23.
Clauu is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-17-2018 , 09:04   Re: Loop order
Reply With Quote #20

Quote:
Originally Posted by Clauu View Post
No, the problem is that we forget to remove ; from the player name, if has it. Sorry for that
PHP Code:
ReadFile( )
{
    
ArrayClearg_aDatabase );

    new 
g_iItemsPlayerData ];

    new 
szConfigs32 ], szFormat64 ], szPlayerData512 ];
    
get_configsdirszConfigscharsmaxszConfigs ) );
    
    
formatexszFormatcharsmaxszFormat ), "%s/%s"szConfigsg_szFile );
    
    new 
iFile fopenszFormat"rt" );
    
    if( 
iFile )
    {
        while( ! 
feofiFile ) )
        {    
            
fgetsiFileszPlayerDatacharsmaxszPlayerData ) );
            
trimszPlayerData );
            
            if( 
strlen(szPlayerData) < 10 || ( szPlayerData] == '/' && szPlayerData] == '/' ) )
            continue;
            
            if(
parseszPlayerDatag_iItems[Player_Name], charsmaxg_iItems[Player_Name] ), g_iItems[Player_Password], charsmaxg_iItems[Player_Password]), g_iItems[Player_AccessFlags], charsmaxg_iItems[Player_AccessFlags] ), g_iItems[Player_Prefix], charsmaxg_iItems[Player_Prefix] ) ) < 4)
             continue;
            
             if(
szPlayerData] == ';') {
                   
g_iItems[Player_Suspended]=1;
                   
replace(g_iItems[Player_Name],charsmax(g_iItems[Player_Name]),";","");
             }
            
ArrayPushArrayg_aDatabaseg_iItems );
        }
        
fcloseiFile );
    }

Now it will be fine.
Thanks a lot, it's working!
__________________
edon1337 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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