SA-MP Forums Archive
[HELP] Server crash on linux - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP] Server crash on linux (/showthread.php?tid=297646)



[HELP] Server crash on linux - telmo_ferreira - 16.11.2011

This commands are working on windows loaded pc, but doesn't on linux . It gives crash. anyone knows How to fix?

Code:
#define FILE_NAME "log/gravardata.txt"







public actualizardata(playerid)
{
  if(PlayerInfo[playerid][pPhousekey] == 255)
	{
	return 1;
    }
  if(PlayerInfo[playerid][pPhousekey] <11 )
	{
	return 1;
    }
  new chave;
  new str[128];
  new File:gstats;
  new day,month,year;
  getdate(day,month,year);
  chave = PlayerInfo[playerid][pPhousekey];
  format(str, sizeof(str), "Casa Nє%d",chave);
  fdeleteline(FILE_NAME,str);
  new sstr[128];
  format(sstr, sizeof(sstr), "Casa Nє%d Data: %d.%d.%d \r<br>\n",chave,day,month,year);
  gstats=fopen(FILE_NAME, io_append);
  fwrite(gstats, sstr);
  fclose(gstats);
  return 1;
}


stock fdeleteline(filename[], removed[])
{
    new string[64], str[32], File:handle, File:ftmp;
    handle = fopen(filename,io_read);
    format(str,sizeof(str),"%s.part",filename);
    ftmp = fopen(str,io_write);
    while(fread(handle,string))
        if(strfind(string,removed) == -1)
            fwrite(ftmp,string);
    fclose(handle);
    fclose(ftmp);
    handle = fopen(filename,io_write);
    ftmp = fopen(str,io_read);
    while(fread(ftmp,string))
        fwrite(handle,string);
    fclose(handle);
    fclose(ftmp);
    return fremove(str);
}



Re: [HELP] Server crash on linux - Calgon - 17.11.2011

If you use io_read and the file doesn't exist, the server will crash.

Add a check to confirm the file you're trying to open with fopen()'s io_read parameters actually exists.

Not sure if this crash is exclusive to Linux.

pawn Code:
stock fdeleteline(filename[], removed[])
{
    new string[64], str[32], File:handle, File:ftmp;
    if(fexist(filename)) handle = fopen(filename,io_read); else return 0;
    format(str,sizeof(str),"%s.part",filename);
    if(fexist(str)) ftmp = fopen(str,io_write); else return 0;
    while(fread(handle,string))
        if(strfind(string,removed) == -1)
            fwrite(ftmp,string);
    fclose(handle);
    fclose(ftmp);
    handle = fopen(filename,io_write);
    if(fexist(str)) ftmp = fopen(str,io_read); else return 0;
    while(fread(ftmp,string))
        fwrite(handle,string);
    fclose(handle);
    fclose(ftmp);
    return fremove(str);
}



Re: [HELP] Server crash on linux - MP2 - 17.11.2011

Files are cASe sEnSiTiVe. If you need to, look at this tutorial written by me: http:/wiki.sa-mp.com/wiki/Debugging


Re: [HELP] Server crash on linux - telmo_ferreira - 17.11.2011

im try only with the actualizardata(playerid) just for testing, and add if(!gstats) { fcreate(FILE_NAME); }
and the linux crashe again.




Code:
public actualizardata(playerid)
{
  if(PlayerInfo[playerid][pPhousekey] == 255)
	{
	return 1;
    }
  if(PlayerInfo[playerid][pPhousekey] <11 )
	{
	return 1;
    }
  new chave;
  new str[128];
  new File:gstats;
  new day,month,year;
  getdate(day,month,year);
  chave = PlayerInfo[playerid][pPhousekey];
  format(str, sizeof(str), "Casa Nє%d",chave);
  new sstr[128];
  format(sstr, sizeof(sstr), "Casa Nє%d Data: %d.%d.%d \r<br>\n",chave,day,month,year);
  gstats=fopen(FILE_NAME, io_append);
  if(!gstats) { fcreate(FILE_NAME); }
//  fdeleteline(FILE_NAME,str);
  fwrite(gstats, sstr);
  fclose(gstats);
  return 1;
}



Re: [HELP] Server crash on linux - telmo_ferreira - 17.11.2011

this simple code is crashing the server only in linux

Code:
if(strcmp(cmdtext, "/actualizardata", true) == 0)
	{

    actualizardata(playerid);
    SendClientMessage(playerid, COLOR_YELLOW, "actualizar");
    return 1;
	}




public actualizardata(playerid)
{
    new File:gstats;
    new pname[24];
    new str[256];
    new ccurdate = getdate();
    GetPlayerName(playerid, pname, 24);
    format(str, 30, "%s %d",pname,ccurdate);
    gstats=fopen(FILE_NAME, io_append);
    fwrite(gstats, str);
    fclose(gstats);
    return 1;
}



Re: [HELP] Server crash on linux - teste - 06.12.2011

Files are case sensitive