ban command problem
#1

I got 2 problems with this command. First:



Check "duration of ban" message. Is supposed to show the duration in days of the ban, not the whole time.

Second problem, when i ban someone the command doesn't execute the query to add ban details in the "Bans" table:

pawn Код:
CMD:ban(playerid, params[])
{
    new reason[200], Reason[200], targetid, Days, Query[450], String[200];
    if(PlayerInfo[playerid][Admin] >= 2)
    {
    if(sscanf(params, "uiS[200]", targetid, Days, reason)) return SendClientMessage(playerid, -1, "{F70505}Usage: {FFFFFF}/ban (playerid) (days) (reason - optional)");
    {
    if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "Player offline/invalid.");
    {
    if(strlen(reason) > 200) return SendClientMessage(playerid, COLOR_RED, "Type a 'ban reason' within 200 characters.");
    {
    PlayerInfo[targetid][Banned] = 1;
    new aName[24];
    GetPlayerName(playerid,aName,24);
    new pName[24];
    GetPlayerName(targetid,pName,24);
    new CTS = (gettime() + (86400*Days));
    mysql_real_escape_string(reason, Reason);
    new IP[16];
    GetPlayerIp(targetid, IP, sizeof(IP));
    format(Query, sizeof(Query), "INSERT INTO `Bans` (Username, Admin, IP, Reason, Days, Banned, Time) VALUES ('%s', '%s', '%s', '%s', '%d', 1, '%s')", pName, aName, IP, Reason, (CTS+gettime()), InsertTimeStamp());
    mysql_function_query(mysqlc, Query, false, "", "");
   
    format(String, sizeof(String), "[BAN] ** %s (%d) has been banned by %s (%d): %s.", pName, targetid, aName, playerid, Reason);
    SendClientMessageToAll(pink, String);
   
    new echo[200];
    format(echo, sizeof(echo), "0,4[BAN] ** %s (%d) has been banned by %s (%d): %s.",pName, targetid, aName, playerid, Reason);
    IRC_GroupSay(gGroupID, IRC_CHANNEL, echo);
   
    PlayerInfo[playerid][PlayersBanned] ++;
   
    new stats[128];
    format(stats, sizeof(stats), "UPDATE ServerStats SET TotalAdminBans = TotalAdminBans + 1");
    mysql_function_query(mysqlc, stats, false, "", "");
   
    SetPlayerPos(targetid,193.5177,176.2223,1003.0234);
    SetPlayerInterior(targetid,3);
   
    //Ban Message
    new metin[128];
    format(metin, sizeof(metin), "* {FF0000}You have been banned from the server *");
    SCM(targetid, -1, metin);
    format(metin, sizeof(metin), "* Admin: {FF0000}%s (%d)", aName, playerid);
    SCM(targetid, -1, metin);
    format(metin, sizeof(metin), "* Date and Time: {FF0000}%s",InsertTimeStamp());
    SCM(targetid, -1, metin);
    format(metin, sizeof(metin), "* Reason: {FF0000}%s", Reason);
    SCM(targetid, -1, metin);
    format(metin, sizeof(metin), "* Duration of ban: {FF0000}%s Days", (CTS+gettime()));
    SCM(targetid, -1, metin);
    format(metin, sizeof(metin), "* If you have been banned wrongfully, visit our forums http://www.bwhsamp.com and appeal at this ban");
    SCM(targetid, -1, metin);
    SCM(targetid,0xFF0000FF, "* You can screen this ban message (F8) and post it on forum. *");

    BanTimer[targetid] = SetTimerEx("BanPlayer",200,false,"d",targetid);
    //
    }
    }
    }
    }
    return 1;
}
Reply
#2

Change:
pawn Код:
format(metin, sizeof(metin), "* Duration of ban: {FF0000}%s Days", (CTS+gettime()));
to:
pawn Код:
format(metin, sizeof(metin), "* Duration of ban: {FF0000}%i Days", Days);
Since it's integer, it should have %i or %d placeholder and you already got days from the command.
Reply
#3

Ok thanks, what about the query to insert ban details not working?
Reply
#4

There could be two issues -
1) You are inserting 'Days' as '%d' - remove the single quotes around %d.
2) You insert 'time' as a '%s' whereas it probably is an integer, or am I wrong?
Reply
#5

The size is probably too small to store the whole query and it fails. Debug it:
pawn Код:
format(Query, sizeof(Query), "INSERT INTO `Bans` (Username, Admin, IP, Reason, Days, Banned, Time) VALUES ('%s', '%s', '%s', '%s', '%d', 1, '%s')", pName, aName, IP, Reason, (CTS+gettime()), InsertTimeStamp());
mysql_function_query(mysqlc, Query, false, "", "");
print(Query);
Reply
#6

mysql_log.txt:

Quote:

[13:03:05] [DEBUG] mysql_escape_string - source: "boobs", connection: 1, max_len: 200
[13:03:05] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO `Bans` (Username, Admin, IP, Reason, Days, Banned, T", callback: "(null)", format: "(null)"
[13:03:05] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[13:03:05] [DEBUG] mysql_tquery - scheduling query "INSERT INTO `Bans` (Username, Admin, IP, Reason, Days, Banned, Time) VALUES ('Face9000', 'Face9000', '192.168.1.2', 'boobs', '-1511331726', 1, '5/2/2014 13:3:5')"..

server_log.txt

Quote:

[13:03:05] sscanf warning: No default value found.
[13:03:06] [part] Face9000 has left the server (0:2)

Reply
#7

If you use (CTS+gettime()) to insert on `Days` you'll get:

(The current timestamp + (Amount of days in seconds)) + The Current timestamp; because you already had defined CTS as the current timestamp + amount of days in seconds. This will always return a negative integer as it will surprass the max integer limit and will return weird data. (Current timestamp is 1.39B~).

pawn Код:
format(Query, sizeof(Query), "INSERT INTO `Bans` (Username, Admin, IP, Reason, Days, Banned, Time) VALUES ('%s', '%s', '%s', '%s', '%d', 1, '%s')", pName, aName, IP, Reason, CTS, InsertTimeStamp());
    mysql_function_query(mysqlc, Query, false, "", "");
Should do.

Also you can use the indicator NOW() on the SQL query to insert current date and time without having to process it anywhere before.
Reply
#8

Same problem, doesn't work.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)