Can't /report yourself?
#1

I have this code for a /report command:
pawn Code:
dcmd_report(playerid, params[])
{
    new tmp[256], idx;
    tmp = strtok(params, idx);
    if(!strlen(tmp)){
        SendClientMessage(playerid, 0x555252AA, "Syntax Error: /report [player] [reason]");
        return 1;
    }else{
        new pid = strval(tmp);
        tmp = strrest(params, idx);
        if(!IsPlayerConnected(pid)){
            SendClientMessage(playerid, 0x555252AA, "ERROR: Invalid Player");
            return 1;
        }else{
            if(!strlen(tmp)){
                SendClientMessage(playerid, 0x555252AA, "Syntax Error: /report [player] [reason]");
                return 1;
            }else{
                new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME], string[200];
                GetPlayerName(playerid, name, sizeof(name));
                GetPlayerName(pid, name2, sizeof(name2));
                format(string, sizeof(string), "[REPORT]%s [ID:%d] reported %s [ID:%d] for: %s", name, playerid, name2, pid, tmp);
                SendClientMessage(playerid,grey,"Thank you for your report. It has been sent to online admins.");
                SendMessageToAdmins(string);
            }
        }
    }
    return 1;
}
But the problem is, you can /report yourself, which makes it easy to abuse this command. What would I have to do to make sure you can't report yourself?
Reply
#2

Add this line under this line: "pid = strval(tmp);"
pawn Code:
if(pid == playerid) return SendClientMessage(playerid, 0x555252AA, "Error: You can't report your self!");
Reply
#3

pawn Code:
dcmd_report(playerid, params[])
{
    new tmp[256], idx;
    tmp = strtok(params, idx);
    if(!strlen(tmp)){
        SendClientMessage(playerid, 0x555252AA, "Syntax Error: /report [player] [reason]");
        return 1;
    }else{
        new pid = strval(tmp);
        tmp = strrest(params, idx);
        if(!IsPlayerConnected(pid) || playerid == pid){
            SendClientMessage(playerid, 0x555252AA, "ERROR: Invalid Player");
            return 1;
        }else{
            if(!strlen(tmp)){
                SendClientMessage(playerid, 0x555252AA, "Syntax Error: /report [player] [reason]");
                return 1;
            }else{
                new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME], string[200];
                GetPlayerName(playerid, name, sizeof(name));
                GetPlayerName(pid, name2, sizeof(name2));
                format(string, sizeof(string), "[REPORT]%s [ID:%d] reported %s [ID:%d] for: %s", name, playerid, name2, pid, tmp);
                SendClientMessage(playerid,grey,"Thank you for your report. It has been sent to online admins.");
                SendMessageToAdmins(string);
            }
        }
    }
    return 1;
}
Reply
#4

Thanks! Have a +rep!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)