Why does this crash my server
#1

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
Reply
#2

When is crashing?Check server.log
Do you have folder Logs and the txt file on scriptfiles?
Reply
#3

Quote:
Originally Posted by TzAkS.
Посмотреть сообщение
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
Reply
#4

Have you got the crashdetect plugin?
If so, what does the server.log say after it crashes?
Reply
#5

Quote:
Originally Posted by captainjohn
Посмотреть сообщение
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
Reply
#6

YOU HAVE TO HAVE THIS "Logs/ReportLog.txt" IN YOUR SCRIPTFILES FOLDER FOR IT TO WORK
Reply
#7

Quote:
Originally Posted by jamesbond007
Посмотреть сообщение
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 ?
Reply
#8

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.
Reply
#9

Quote:
Originally Posted by TzAkS.
Посмотреть сообщение
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
Reply
#10

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:

pawn Код:
new File:Log = fopen(reportPATH, io_append);

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

// Rest of file functions
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)