clean file
#1

I'm making a system that saves the day, month, year, hour, minute and ip logged to the player who signed to appear in next to him:

His last login was on 02/12/2010 at 16:15 by ip: 11111111111

It works almost 100%
the only problem is that when he logs a second time, to save over envez doque had it just continues.
I'm doing the following:

To save the data:

pawn Код:
new giveplayer[MAX_PLAYER_NAME];
               GetPlayerName(playerid, giveplayer, sizeof(giveplayer));
               new stringaa[128];
               new stringgg[128];
               GetPlayerIp(playerid,ip,15);
               format(stringaa, sizeof(stringaa), "/LogPlayer/%s.ini", giveplayer);
                if(!dini_Exists(stringaa))
                    {
                        dini_Create(stringaa);
                    }
                new File:logadmin = fopen(stringaa, io_append);
                if(logadmin)
                {
                new Ano, Mes,Dia;
                getdate(Ano, Mes,Dia);
                getdate(Anologp[playerid], Meslogp[playerid],Dialogp[playerid]);
                new Hora, Minuto, Segundo;
                gettime(Hora, Minuto, Segundo);
                gettime(Horalogp[playerid], Minutologp[playerid], Segundologp[playerid]);
                format(stringgg, sizeof stringgg, "%d|%d|%d|%d|%d|%s", Dia, Mes, Ano, Hora, Minuto,ip);
                fwrite(logadmin, stringgg);
                fclose(logadmin);
To read the data from last login:
pawn Код:
new Baname[MAX_PLAYER_NAME];
        GetPlayerName(playerid, Baname, sizeof(Baname));
         new string123[128];
        format(string123, sizeof(string123), "/LogPlayer/%s.ini", Baname);
        if(fexist(string123))
        {
         new load[12][32];
        new str[128];
        new UltimoDia,UltimoMes,UltimoAno,UltimaHora,UltimoMinuto,UltimoIp[15];
        new File:file = fopen(string123,io_read);
        if (file)
        {
            while (fread(file, str, sizeof str))
            {
                split(str, load, '|');

                UltimoDia = strval(load[0]);
                UltimoMes = strval(load[1]);
                UltimoAno = strval(load[2]);
                UltimaHora = strval(load[3]);
                UltimoMinuto = strval(load[4]);
                strmid(UltimoIp, load[5], 0, strlen(load[5])-1, 15);
                format(str, sizeof str, "His last login was on%d/%d/%d бs %d:%d, by ip: %s",UltimoDia,UltimoMes,UltimoAno,UltimaHora,UltimoMinuto,UltimoIp);
               SendClientMessage(playerid, ADMIN_RED, str);
               }
               }
               return 1;
              }]

What's going on is as follows:
The first login will save this:
2 | 12 | 2010 | 16 | 18 | 1111111

and will read it right
already the second will be saved like this:
2 | 12 | 2010 | 16 | 18 | 11111113 | 12 | 2010 | 15 | 11 | 1111111

One after the other.
Causes problems.
What I wanted to do is clean the file before each new bailout, or delete.
So I do not know how.
I tried deleting the file by OnPlayerDisconnect but I can not.
So I can delete the file when the player is off, then I type a cmd to delete and delete.
Can someone help me please, because I have this problem in a tempban I did too ...


sorry for my bad english
Reply
#2

Add a \n to where you need a new line...

eg,
pawn Код:
format(stringgg, sizeof stringgg, "%d|%d|%d|%d|%d|%s\n", Dia, Mes, Ano, Hora, Minuto,ip);
Reply
#3

so that by doing so it will read again and add the second line read first??

edit:

I took the test ..
do not read the second line
only reads the first ..
Reply
#4

Here, now the saving and the loading of data are perfectly



Saving (I did in OnPlayerDisconnect):


pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new giveplayer[MAX_PLAYER_NAME];
    new Anologp[MAX_PLAYERS];
    new Meslogp[MAX_PLAYERS];
    new Dialogp[MAX_PLAYERS];
    new Horalogp[MAX_PLAYERS];
    new Minutologp[MAX_PLAYERS];
    new Segundologp[MAX_PLAYERS];
    new Ano, Mes,Dia;
    new Hora, Minuto, Segundo;
    new ip[128];
    new stringaa[128];
    new stringgg[128];
    new stringbb[128];
    GetPlayerName(playerid, giveplayer, sizeof(giveplayer));
    GetPlayerIp(playerid,ip,15);
    format(stringaa, sizeof(stringaa), "/LogPlayer/%s.ini", giveplayer);
    if(fexist(stringaa))
    {
        fremove(stringaa);
        if (fexist(stringaa)) return false;
        new File:specialvar;
        specialvar=fopen(stringaa,io_write);
        if (specialvar) {
            getdate(Ano, Mes,Dia);
            getdate(Anologp[playerid], Meslogp[playerid],Dialogp[playerid]);
            gettime(Hora, Minuto, Segundo);
            gettime(Horalogp[playerid], Minutologp[playerid], Segundologp[playerid]);
            new File:gogo = fopen(stringaa, io_append);
            format(stringbb, sizeof(stringbb), "%d|%d|%d|%d|%d|%s", Dia, Mes, Ano, Hora, Minuto, ip);
            fwrite(gogo, stringbb);
            fclose(gogo);
            fclose(specialvar);
            return true;
        }
        return false;
    }
    else
    {
        getdate(Ano, Mes,Dia);
        getdate(Anologp[playerid], Meslogp[playerid],Dialogp[playerid]);
        gettime(Hora, Minuto, Segundo);
        gettime(Horalogp[playerid], Minutologp[playerid], Segundologp[playerid]);
        new File:logadmin = fopen(stringaa, io_append);
        format(stringgg, sizeof(stringgg), "%d|%d|%d|%d|%d|%s", Dia, Mes, Ano, Hora, Minuto, ip);
        fwrite(logadmin, stringgg);
        fclose(logadmin);
        return 1;
    }
}

And Loading (i did in OnPlayerSpawn):


pawn Код:
public OnPlayerSpawn(playerid)
{
    new nicklogger[MAX_PLAYER_NAME];
    GetPlayerName(playerid, nicklogger, sizeof(nicklogger));
    new stringlogging[128];
    format(stringlogging, sizeof(stringlogging), "/LogPlayer/%s.ini", nicklogger);
    if(fexist(stringlogging))
    {
        new Baname[MAX_PLAYER_NAME];
        GetPlayerName(playerid, Baname, sizeof(Baname));
        new string123[128];
        format(string123, sizeof(string123), "/LogPlayer/%s.ini", Baname);
        if(fexist(string123))
        {
            new load[12][32];
            new str[128];
            new UltimoDia,UltimoMes,UltimoAno,UltimaHora,UltimoMinuto,UltimoIp[15];
            new File:file = fopen(string123,io_read);
            if (file)
            {
                    while (fread(file, str, sizeof str))
                    {
                        split(str, load, '|');
                        UltimoDia = strval(load[0]);
                        UltimoMes = strval(load[1]);
                        UltimoAno = strval(load[2]);
                        UltimaHora = strval(load[3]);
                        UltimoMinuto = strval(load[4]);
                        strmid(UltimoIp, load[5], 0, strlen(load[5])-1, 15);
                        format(str, sizeof str, "His last login was on%d/%d/%d бs %d:%d, by ip: %s",UltimoDia,UltimoMes,UltimoAno,UltimaHora,UltimoMinuto,UltimoIp);
                        SendClientMessage(playerid, ADMIN_RED, str);
                    }
            }
        }
    }
 }

I want that i have helped
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)