MySQL tempban [Help]
#1

Hey guys, I'm doing my tempban system for my server project and when i send the command /tempban with the parameters it doesn't insert into the database

pawn Код:
CMD:tempban(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        new id, reason[20], hours, string[126], query[126], pIpAddress[15];
        if(sscanf(params, "us[20]d", id, reason, hours))
            return SendClientMessage(playerid, -1, "Syntax: /tempban [playerid] [reason] [hours]");

        format(string, sizeof(string), "Ban: %s has been banned by %s for %d hours. Reason: %s", GetPName(id), GetPName(playerid), hours, reason);
        SendClientMessageToAll(0xFF7373FF, string);

        GetPlayerIp(id, pIpAddress, sizeof(pIpAddress));

        format(query, sizeof(query), "INSERT INTO `bans` (Name, Reason, BannedBy, IpAddress, Date, Status, Expiration) bans VALUES ('%s', '%s', '%s', '%s', '%s', '1', '%d')", GetPName(id), reason, GetPName(playerid), pIpAddress, gettime(), gettime() + (3600*hours));
        mysql_query(query);

        Kick(id);
    }
    return 1;
}
Just incase (Check ban)

pawn Код:
stock Checkban(playerid)
{
    new query[126], pIpAddress[126], bExpiration, bID;

    GetPlayerIp(playerid, pIpAddress, sizeof(pIpAddress));

    format(query, sizeof(query), "SELECT * FROM bans WHERE (Name = '%s' OR IpAddress = '%s') AND status = 1", GetPName(playerid), pIpAddress);
    mysql_query(query);

    mysql_store_result();
    if(mysql_num_rows() >= 1)
    {
        new bReason[126], bannedBy[MAX_PLAYER_NAME], dialogText[126];
        while(mysql_fetch_row_format(query,"|"))
        {
            mysql_fetch_field_row(query, "BanID"); bID = strval(query);
            mysql_fetch_field_row(bReason, "Reason");
            mysql_fetch_field_row(bannedBy, "BannedBy");
            mysql_fetch_field_row(query, "Expiration"); bExpiration = strval(query);

            if(bExpiration > 0)
            {
                if(gettime() >= bExpiration)
                {
                    format(query, sizeof(query), "UPDATE bans SET Status = 0 WHERE BanID = %d", bID);
                    mysql_query(query);
                    SendClientMessage(playerid, -1, "You have been unbanned!");
                }
                else
                {
                    format(dialogText, sizeof(dialogText), "You are banned from this server\n\n{0094BD}Reason: {FFFFFF}%s\n\n{0094BD}Banned By: {FFFFFF}%s\n{0094BD}Unbanned in: {FFFFFF}%d hours", bReason, bannedBy, (bExpiration-gettime())/3600);
                    ShowPlayerDialog(playerid, DIALOG_BANNED, DIALOG_STYLE_MSGBOX, "Banned", dialogText, "Close", "");
                }
            }
            else
            {
                format(dialogText, sizeof(dialogText), "You are banned from this server\n\n{0094BD}Reason: {FFFFFF}%s\n\n{0094BD}Banned By: {FFFFFF}%s", bReason, bannedBy);
                ShowPlayerDialog(playerid, DIALOG_BANNED, DIALOG_STYLE_MSGBOX, "Banned", dialogText, "Close", "");
            }
        }
        return 1;
    }
    mysql_free_result();

    return 0;
}
Reply
#2

Logs?

Though the problem might just be with the order of parameters. I'm not sure if sscanf can reliably determine where it needs to split things if there is a string in the middle. For example:

Код:
/tempban 42 spamming 42 all the time 10
How should sscanf know where it needs to split?
Reply
#3

I removed the command, Any chance you could make a tutorial for MySQL R5 (BlueG)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)