PDA

View Full Version : Why does this crash my server


Scripter12345
03/04/2012, 08:37 PM
Please Help Me Please


#define reportPATH "Logs/ReportLog.txt"


CMD:report(playerid,params[])
{

new Target; //define the target's name
new Reason[128];//the report-reason
if(!sscanf(params, "us[32]",Target, Reason))
{
if(Target == playerid) return SendClientMessage(playerid, COLOR_RED, "SERVER: Cant perform this command on yourself!"); //comment this line if you want to try this cmd on yourself
if(!IsPlayerConnected(Target)) //if the ID is invalid
return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected!"); //send the player a message, that the ID doesn't exist

new tname[MAX_PLAYER_NAME]; //the name of player one (reporting)
new pname[MAX_PLAYER_NAME]; //the name of player two (the reported)
GetPlayerName(Target,tname,sizeof(tname)); //get (receive) the player's name for the first
GetPlayerName(playerid,pname,sizeof(pname)); //get (receive) the player's name for the second

new rstring[256]; //the report-string
format(rstring,sizeof(rstring),"* Player %s(%d) reported %s(%d)! (Reason: %s)", pname,playerid,tname,Target,Reason); //only admins will receive this message! a specific player with a reason got reported, here we'll use all variables created
SendMessageToAdmins(COLOR_WHITE,rstring); //we'll talk about that later

//NOW HERE, we'll open the reportpath and WRITE into it
new File:Log = fopen(reportPATH, io_append); //here you're opening the path defined
new logData[128]; //create the logdata we wanna write in
new name[MAX_PLAYER_NAME]; //define the name again
GetPlayerName(Target,name,sizeof(name)); //receive the name again
new fTime[6]; //create the specific time for the report
getdate(fTime[0], fTime[1], fTime[2]); //get the report's date
gettime(fTime[3], fTime[4], fTime[5]); //get the report's time
format(logData, sizeof logData, "[%02d/%02d/%04d || %02d:%02d:%02d]%s got reported by %s! (Reason: %s)\r\n", fTime[2], fTime[1], fTime[0], fTime[3], fTime[4], fTime[5], tname, pname, Reason); //this will write everything (name,reason,time,date etc.) into the logdata
fwrite(Log, logData); //write it into the path
fclose(Log); //close the log, finished!
}
else return SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /report <playerid> <reason>"); //detects the wrong params from sscanf and send the client this message

return 1;
}


public SendMessageToAdmins(color,const string[]) //create the callback, including color and string
{
for(new i = 0; i < MAX_PLAYERS; i++) //set a for-loop and loop through all the admins
{
if(IsPlayerConnected(i) == 1) //the admin gotta be connected
if(PlayerInfo[i][pAdmin] >= 1) //and his level gotta be at least 1 (or higher)
SendClientMessage(i, color, string); //send this message now to every admin online, with color + string!
}
return 1;
}


Please Help Me

TzAkS.
03/04/2012, 08:45 PM
When is crashing?Check server.log
Do you have folder Logs and the txt file on scriptfiles?

Scripter12345
03/04/2012, 09:43 PM
When is crashing?Check server.log
Do you have folder Logs and the txt file on scriptfiles?


No it just crashed when i do /report 1 Test


Please Help Please

captainjohn
03/04/2012, 09:47 PM
Have you got the crashdetect plugin?
If so, what does the server.log say after it crashes?

Scripter12345
03/04/2012, 09:55 PM
Have you got the crashdetect plugin?
If so, what does the server.log say after it crashes?


I have not got crashdecect can you give me a link please

jamesbond007
03/04/2012, 09:58 PM
YOU HAVE TO HAVE THIS "Logs/ReportLog.txt" IN YOUR SCRIPTFILES FOLDER FOR IT TO WORK

Scripter12345
03/04/2012, 10:00 PM
YOU HAVE TO HAVE THIS "Logs/ReportLog.txt" IN YOUR SCRIPTFILES FOLDER FOR IT TO WORK

So i have to create the file my self ?

TzAkS.
03/04/2012, 10:01 PM
You don`t have that folder in scriptfiles and ReportLog.txt there.
Create it and it should work.

Edit:
Didn`t see that other 2 people post..i said this in first post,to create that folder and file.

Scripter12345
03/04/2012, 10:10 PM
You don`t have that folder in scriptfiles and ReportLog.txt there.
Create it and it should work.

Edit:
Didn`t see that other 2 people post..i said this in first post,to create that folder and file.


I put the folder in scriptfiles and it still did not work

Vince
03/04/2012, 10:11 PM
The io_append filemode should automatically create the file if it doesn't exists, but the folder ('Logs') has to be created manually. A good practice when working with files is to throw an exception if the file is not found or cannot be opened for some other odd reason. This can be as simple as doing:


new File:Log = fopen(reportPATH, io_append);

if(!Log)
return printf("[warning] Failed to open stream: %s", reportPATH);

// Rest of file functions

Scripter12345
03/04/2012, 10:13 PM
The io_append filemode should automatically create the file if it doesn't exists, but the folder ('Logs') has to be created manually. A good practice when working with files is to throw an exception if the file is not found or cannot be opened for some other odd reason. This can be as simple as doing:


new File:Log = fopen(reportPATH, io_append);

if(!Log)
return printf("[warning] Failed to open stream: %s", reportPATH);

// Rest of file functions



So how will this stop my server crashing

TzAkS.
04/04/2012, 07:36 AM
Just put that folder there and will work,don`t bump 3 times and try what other people say`s and then post.

Scripter12345
04/04/2012, 01:00 PM
I have put the folder in scriptfiles and when i do /report the server still freezes and closes but the reports go in the ReportLog.txt


Please Help