Salut!
Alors voilà, j'aimerai sauvegarder des infos dans un fichier et les récupérer. Les récupérer, c'est bon (étrangement) alors qu’enregistrer, ça marche, mais ça donne des trucs comme ça:
Code:
"STEAM_0:1:25648437" "0" "~iG`Rakuraii [Co]-[L]dr ^^"
"STEAM_0:1:25648437" "0" "~iG`Rakuraii [Co]-[L]dr ^^"
" "Kid"
"STEAM_0:1:38423710" "0" "sMOKY* #LE"
"STEAM_0:1:38423710" "0" "sMOKY* #LE"
0:0:22492608" "0" "Kid"
"STEAM_0:1:36850164" "0" ".~#SAW#~. Showw [ElectrO]"
"STEAM_0:1:36850164" "0" ".~#SAW#~. Showw [ElectrO]"
6" "0" "Pouette"
"STEAM_0:0:22492608" "0" "Kid"
"STEAM_0:0:22492608" "0" "Kid"
"" "0" "e2k - Drinker"
"STEAM_0:0:20505546" "0" "Pouette"
"STEAM_0:0:20505546" "0" "RaVeN"
Les information sont correctement enregistrée, mais il y a plusieurs STEAM_ID pour un seul joueur alors que rien ne change. Mon problème est que je ne trouve pas de méthode pour remplacer une ligne...
Voici mes fonctions:
PHP Code:
public bb_set_user_level( id, exp, startlevel )
{
new n;
if( is_user_connected( id ) )
{
while ( exp > ( ( n + 1 ) * 10 ) )
{
n++;
}
}
iLevel[ id ] = n + 1;
client_print( 0, print_chat, "bb_set_user_level : level returned: %i", iLevel[ id ] );
return ( startlevel == iLevel[ id ] ? 0 : 1 );
}
public betaUpdate( id )
{
updateExp( id, iExp[ id ] );
}
public betaGet( id )
{
getUserExp( id );
}
public betaGetLevel( id )
{
bb_set_user_level( id, iExp[ id ], iLevel[ id ] );
}
public getUserExp( id )
{
new iSteamId[ 35 ];
new xp, found;
get_user_authid( id, iSteamId, charsmax( iSteamId ) );
new fp = fopen( szLevelsFile, "rt" );
if ( !fp )
{
return -1;
}
new szLineData[ 364 ], szLineKey[ 96 ], szLineValue[ 264 ], szName[ 35 ];
while ( !feof( fp ) )
{
fgets( fp, szLineData, charsmax( szLineData ) );
trim( szLineData );
if ( szLineData[ 0 ] == ';' || szLineData[ 0 ] == '#' || ( szLineData[ 0 ] == '/' && szLineData[ 1 ] == '/' ) || !szLineData[ 0 ] )
{
continue;
}
parse( szLineData, szLineKey, charsmax( szLineKey ), szLineValue, charsmax( szLineValue ), szName, charsmax( szName ) );
remove_quotes( szLineKey );
remove_quotes( szLineValue );
remove_quotes( szName );
if ( equal( szLineKey, iSteamId ) )
{
client_print( 0, print_chat, "getUserExp: %s %s has %s xp", szLineKey, szName, szLineValue );
xp = str_to_num( szLineValue );
found = 1;
break;
}
}
fclose( fp );
if ( !found )
{
client_print( 0, print_chat, "getUserExp: NOT FOUND! %s. Launch updateExp", iSteamId );
xp = 0;
updateExp( id, xp );
}
return xp;
}
public updateExp( id, xp )
{
new iSteamId[ 35 ], iName[ 35 ];
new done = -1;
get_user_authid( id, iSteamId, charsmax( iSteamId ) );
get_user_name( id, iName, charsmax( iName ) );
new fp = fopen( szLevelsFile, "r+wt" );
if ( !fp )
{
return done;
}
done = 0;
new szLineData[ 364 ], szLineKey[ 96 ], szLineValue[ 264 ], szName[ 35 ];
while ( !feof( fp ) )
{
fgets( fp, szLineData, charsmax( szLineData ) );
trim( szLineData );
if ( szLineData[ 0 ] == ';' || szLineData[ 0 ] == '#' || ( szLineData[ 0 ] == '/' && szLineData[ 1 ] == '/' ) || !szLineData[ 0 ] )
{
continue;
}
parse( szLineData, szLineKey, charsmax( szLineKey ), szLineValue, charsmax( szLineValue ), szName, charsmax( szName ) );
remove_quotes( szLineKey );
remove_quotes( szLineValue );
remove_quotes( szName );
client_print( 0, print_chat, "updateExp: %s %s %s", szLineKey, szLineValue, szName );
if ( equal( szLineKey, iSteamId ) )
{
fseek( fp, 0, SEEK_CUR );
fprintf( fp, "^"%s^" ^"%i^" ^"%s^" ^n", iSteamId, xp, iName );
done = 1;
client_print( 0, print_chat, "updateExp: FOUND! %s = %s. puts %s %i %s", szLineKey, iSteamId, iSteamId, xp, iName );
break;
}
}
if ( !done )
{
fseek( fp, 0, SEEK_END );
fprintf( fp, "^"%s^" ^"%i^" ^"%s^" ^n", iSteamId, xp, iName );
client_print( 0, print_chat, "updateExp: NEW! puts %s %i %s", iSteamId, xp, iName );
done = 1;
}
fclose( fp );
return done;
}
PS: Les 3 petites fonction servent à tester.
PS2: J'ai mis beaucoup d'espaces pour empêcher que la réécriture n'écrase pas toute la ligne.
Voilà voilà, j'espère qu'il y a une solution ^^
__________________