Loading Reports and deleting them -
Marven - 23.10.2016
Hello there so i have made a report system it saves the reports so admins can check later on when they are online but i dont know how to open the stored reports and then later on how can i delete them?
here is the report cmd
Код:
CMD:report(playerid,params[])
{
new Target,reason[50],rstring[128];
if(IsJailedOrMuted(playerid))return 1;
if(sscanf(params,"us[50]",Target,reason))return SendClientMessage(playerid,GREY,"USAGE: /report [playerid] [reason]");
if(!IsPlayerConnectedEx(Target)) return SendClientMessage(playerid,GREY,"Invalid player ID");
if(strlen(reason) > 50) return SendClientMessage(playerid,GREY,"Reason can't be longer than 50 characters");
format(rstring,sizeof(rstring),"SERVER: {FFFFFF}%s reported %s(Reason: %s)",PlayerName(playerid),PlayerName(Target),reason);
SendMessageToAdmins(RED,rstring);
SendClientMessage(playerid,YELLOW,"Your report has been sucessfully sent to the online admins");
LogReport(rstring); //Log the string
return 1;
}
here is the stock used to store report.
Код:
stock LogReport(event[])
{
new File:log = fopen("report_log.txt", io_append);
fwrite(log, event);
fwrite(log, "/n");
fclose(log);
}
Help would be appreciated.
Re: Loading Reports and deleting them -
Micko123 - 23.10.2016
Does it makes report_log.txt file?
Re: Loading Reports and deleting them -
Vince - 23.10.2016
Sequential files are really not suited for this kind of thing. You have no way to identify the line to remove other than some string comparison (slow). Also sequential files can only be read from and written to sequentially (hence their name). If a line is to be deleted the whole file needs to be rewritten. This process naturally becomes slower as the file grows larger.
Either create a separate folder and store the reports there - one per file - in ini format, or create a simple SQLite database.
And oh, the "newline" char is \n, not /n.
Re: Loading Reports and deleting them -
Marven - 23.10.2016
@Micko yes it does create report file
@Vince oh alright any way i can make one report per file? not talking about SQlite just in ini format.
Re: Loading Reports and deleting them -
Marven - 24.10.2016
Bump
Re: Loading Reports and deleting them -
IceBilizard - 24.10.2016
PHP код:
CMD:report(playerid,params[])
{
new Target,reason[50],rstring[128];
if(IsJailedOrMuted(playerid))return 1;
if(sscanf(params,"us[50]",Target,reason))return SendClientMessage(playerid,GREY,"USAGE: /report [playerid] [reason]");
if(!IsPlayerConnectedEx(Target)) return SendClientMessage(playerid,GREY,"Invalid player ID");
if(strlen(reason) > 50) return SendClientMessage(playerid,GREY,"Reason can't be longer than 50 characters");
format(rstring,sizeof(rstring),"SERVER: {FFFFFF}%s reported %s(Reason: %s)\r\n",PlayerName(playerid),PlayerName(Target),reason);
SendMessageToAdmins(RED,rstring);
SendClientMessage(playerid,YELLOW,"Your report has been sucessfully sent to the online admins");
new File: file = fopen("report_log.txt", io_append);
fwrite(file, rstring);
fclose(file);
return 1;
}
CMD:reports(playerid, params[])
{
if (adlvl[playerid] < 1) return 0;
new string[256];
new strings[128], File: file = fopen("report_log.txt", io_read), idxx=1;
SendClientMessage(playerid, COLOR_ORANGE, "[Server Reports]:");
while(fread(file, strings))
{
format(strings, sizeof(strings), "%d) %s", idxx, strings);
SendClientMessage(playerid, COLOR_ORANGE, strings);
AddAdminCmdLog(playerid, string);
idxx ++;
}
fclose(file);
return 1;
}