16.05.2013, 18:35
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
Just incase (Check ban)
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;
}
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;
}