[AYUDA] sobre el fwrite y fread
#1

Hola quisiera que me ayuden:
tengo un problema con el uso de un sistema de Login Register
una parte de register:
pawn Код:
new player[MAX_PLAYER_NAME];
GetPlayerName(playerid, player, 50);
new string3[32];
new playername3[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername3, sizeof(playername3));
format(string3, sizeof(string3), ACCOUNTS_FOLDER, playername3);
new ip[20];
GetPlayerIp(playerid,ip,sizeof(ip));
new File: hFile = fopen(string3, io_write);
AccountInfo[playerid][aMuertes] = 0;
AccountInfo[playerid][aAsesinatos] = 0;
if (hFile)
{
strmid(AccountInfo[playerid][aPassword], inputtext, 0, strlen(inputtext), 255);
new var[128];
format(var, 128, "Password=%s ", AccountInfo[playerid][aPassword]);fwrite(hFile, var);
format(var, 128, "IP=%s ",ip);fwrite(hFile, var);
format(var, 128, "Admin=%d ", AccountInfo[playerid][aAdmin]);fwrite(hFile, var);
format(var, 128, "Muertes=%d ", AccountInfo[playerid][aMuertes]);fwrite(hFile, var);
format(var, 128, "Asesinatos=%d ", AccountInfo[playerid][aAsesinatos]);fwrite(hFile, var);
format(var, 128, "Dinero=%d ", AccountInfo[playerid][aDinero]);fwrite(hFile, var);
format(var, 128, "Carcel=%d ", AccountInfo[playerid][aCarcel]);fwrite(hFile, var);
format(var, 128, "TiempoCarcel=%d ", AccountInfo[playerid][aTiempoCarcel]);fwrite(hFile, var);
format(var, 128, "Bloqueado=%d ", AccountInfo[playerid][aBloqueado]);fwrite(hFile, var);
format(var, 128, "Silencio=%d ", AccountInfo[playerid][aSilencio]);fwrite(hFile, var);
fclose(hFile);
}
y esta es de Login:
pawn Код:
new string2[128];
new playername2[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername2, sizeof(playername2));
format(string2, sizeof(string2), ACCOUNTS_FOLDER, playername2);
new File: UserFile = fopen(string2, io_read);
if ( UserFile )
{
new PassData[256];
new keytmp[256], valtmp[256];
fread( UserFile , PassData , sizeof( PassData ) );
keytmp = ini_GetKey( PassData );
if( strcmp( keytmp , "Password" , true ) == 0 )
{//AQUI ES DONDE CREO QUE ESTA EL PROBLEMA
valtmp = ini_GetValue( PassData );
strmid(AccountInfo[playerid][aPassword], valtmp, 0, strlen(valtmp)-1, 255);
}
if(strcmp(AccountInfo[playerid][aPassword],inputtext, true ) == 0)
{
if(strlen(inputtext))
{
for(new p = 0; p < strlen(AccountInfo[playerid][aPassword]); p++)
{
inputtext[p] = '?';
}
AccountInfo[playerid][aLogged] = 1;
register[playerid] = 0;
login[playerid] = 0;
printf("%s Ha logeado.",playername2);
format(string2, sizeof(string2), "%s Se ha unido al servidor", playername2);
SendClientMessageToAll(COLOR_WHITE, string2);
new key[ 256 ] , val[ 256 ];
new Data[256];
while ( fread( UserFile , Data , sizeof( Data ) ) )
{
key = ini_GetKey( Data );
if( strcmp( key , "Admin" , true ) == 0 ) { val = ini_GetValue( Data ); AccountInfo[playerid][aAdmin] = strval( val ); }
if( strcmp( key , "Muertes" , true ) == 0 ) { val = ini_GetValue( Data ); AccountInfo[playerid][aMuertes] = strval( val ); }
if( strcmp( key , "Asesinatos" , true ) == 0 ) { val = ini_GetValue( Data ); AccountInfo[playerid][aAsesinatos] = strval( val ); }
if( strcmp( key , "Dinero" , true ) == 0 ) { val = ini_GetValue( Data ); AccountInfo[playerid][aDinero] = strval( val ); }
if( strcmp( key , "Carcel" , true ) == 0 ) { val = ini_GetValue( Data ); AccountInfo[playerid][aCarcel] = strval( val ); }
if( strcmp( key , "TiempoCarcel" , true ) == 0 ) { val = ini_GetValue( Data ); AccountInfo[playerid][aTiempoCarcel] = strval( val ); }
if( strcmp( key , "Bloqueado" , true ) == 0 ) { val = ini_GetValue( Data ); AccountInfo[playerid][aBloqueado] = strval( val ); }
if( strcmp( key , "Silencio" , true ) == 0 ) { val = ini_GetValue( Data ); AccountInfo[playerid][aSilencio] = strval( val ); }
}
fclose(UserFile);
como veran al principio en register puse esto al final de cada linea "\r\n" para cuando me cree el archivo txt, me salga ordenado Osea:

Password=****
IP=127.0.0.1
Admin=5
Muertes=2
etc, etc


Bueno ahora cuando me registro y pongo mi pass me dice contraseсa incorrecta
Antes estaba al final de cada linea "\r" y funcionaba bien, yo probe y le quite esa "\r" por "\n" y tambien trabajaba BIEN, pero lo malo que en el txt era asi:

Password=****@IP=127.0.0.1@Admin=5@Muertes=2@etc@e tc

en ves de los "@" que puse era como un rectangulos parados XD, pero para mi esop no tiene orden XD.

Pero cuando puse "\r\n" que lo saque de a wiki del samp, me lo ponia en orden como dije, pero no reconoce la contraseсa, me dice contrasela incorrecta, yo pienso que en el code del login se debe agregar algo para que lea "\r\n" o no se.
Espero no molestarlos y Ayudenme pls
Grax
Reply
#2

Y si pruebas poniendolo al reves? "\n" pasa espacio, "\r" No lo sй.

Pruebalo inverso, "\n\r"
Reply
#3

Hola lo probe pero me aparacerio asi:
Password=****@@IP=127.0.0.1@@Admin=5@@Muertes=2@@e tc@@etc
me aparece el doble de esos cuadrados q dije.
pero el login si FUNKA, + ayuda .... thx
Reply
#4

Prueba sуlo con \n ya que eso indica que va a brincar espacio
Reply
#5

Windows necesita \r\n para hacer un salto de lнnea, si abrнs un archivo que usa \n en otro sistema operativo te lo va a mostrar normal.
Reply
#6

Bueno supongo que me resignare, yo lo vi q lo hacia en orden el FS gadmin, pero usaba dini, dubs etc XD, Bueno ese codigo es del EsAdmin.
Cuando lo abro con el Wordpad lo habre en orden pero en block, lo habre como dije.
de todas formas GRACIAS POR TODO
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)