For some reason my code gets duplicated, so if the original line that we have is like this
PHP Code:
;"Name" "Pw" "AccessFlags" "Prefix"
It becomes
PHP Code:
"Name" "Pw" "AccessFlags" "Prefix"
"Name" "Pw" "AccessFlags" "Prefix"
// blank line
Instead of just (removed ;)
PHP Code:
"Name" "Pw" "AccessFlags" "Prefix"
Basically #1 log gets called twice while it should be called once, and I have no idea what makes the file read the same line twice.
PHP Code:
UnSuspendPlayer( const id )
{
new const szTempFileName[ ] = "tempfile.ini";
new szConfigs[ 32 ], szFormat[ 64 ], szData[ 128 ], szDataName[ 32 ], szDataPw[ 32 ], szDataFlags[ 32 ], szDataPrefix[ 32 ], szPlayerName[ 32 ];
get_configsdir( szConfigs, charsmax( szConfigs ) );
new szTempFilePath[ 256 ];
formatex( szTempFilePath, charsmax( szTempFilePath ), "%s/%s", szConfigs, szTempFileName );
get_user_name( id, szPlayerName, charsmax( szPlayerName ) );
formatex( szFormat, charsmax( szFormat ), "%s/%s", szConfigs, g_szFile );
new iFilePointer = fopen( szFormat, "rt" );
if( iFilePointer )
{
new iInputFilePointer = fopen( szTempFilePath, "wt" );
if( iInputFilePointer )
{
while( ! feof( iFilePointer ) )
{
fgets( iFilePointer, szData, charsmax( szData ) );
trim( szData );
parse( szData, szDataName, charsmax( szDataName ), szDataPw, charsmax( szDataPw ), szDataFlags, charsmax( szDataFlags ), szDataPrefix, charsmax( szDataPrefix ) );
log_to_file( "unsusp.txt", "#1 Called" );
if( szDataName[ 0 ] == ';' ) // check if name has ; in it (;"DoNii" becomes ";DoNii")
{
if( equal( szDataName[ 1 ], szPlayerName ) ) // found the admin that we're searching for
{
fprintf( iInputFilePointer, "^"%s^" ^"%s^" ^"%s^" ^"%s^"^n", szDataName[ 1 ], szDataPw, szDataFlags, szDataPrefix ); // write to new file without ;
log_to_file( "unsusp.txt", "#3 %s", szDataName );
}
else // not the person we're looking for
{
fprintf( iInputFilePointer, ";^"%s^" ^"%s^" ^"%s^" ^"%s^"^n", szDataName, szDataPw, szDataFlags, szDataPrefix ); // write as it was before
log_to_file( "unsusp.txt", "#3 %s", szDataName );
}
}
else // doesnt contain ;
{
fprintf( iInputFilePointer, "^"%s^" ^"%s^" ^"%s^" ^"%s^"^n", szDataName, szDataPw, szDataFlags, szDataPrefix ); // unknown admin, write as is
log_to_file( "unsusp.txt", "#2 %s", szDataName );
}
}
fclose( iInputFilePointer );
fclose( iFilePointer );
delete_file( szFormat );
rename_file( szTempFilePath, szFormat, 1 );
}
}
return 0;
}
Code:
L 08/18/2018 - 15:29:04: #1 Called
L 08/18/2018 - 15:29:04: #3 DoNii
L 08/18/2018 - 15:29:04: #1 Called
L 08/18/2018 - 15:29:04: #2 DoNii
__________________