PDA

View Full Version : Automatic unban after some time


JaskaranSingh
31/01/2018, 05:26 PM
I made a /tempban system that bans a player based on IP or account for a duration of time. How do I run something that automatically changes the ban status to 0 in the database after the ban expires?

This is the function that checks for ban:

public checkaccban(playerid)
{
new query[128], pIpAddress[128], pName[128];

GetPlayerName(playerid, pName, sizeof(pName));

mysql_format(g_SQL, query, sizeof(query), "SELECT * FROM `accbans` WHERE `pName` = '%e' AND pBanned = 1", pName, pIpAddress);
mysql_tquery(g_SQL, query, "bancheckcb", "i", playerid);

return 1;
}


This is the callback function

public bancheckcb(playerid)
{
new rows, dest;

cache_get_row_count(rows);

if(rows > 0)
{
cache_get_value_name_int(0, "bExpiration", dest);

dest = (dest - gettime())/3600;

if(dest > 0)
{
new string[128];
format(string, sizeof(string), "You are banned from this server. Hours left: %d", dest);
SendClientMessage(playerid, COLOR_RED, string);

SetTimerEx("DelayedKick", 1000, false, "i", playerid);
}
}
return 1;
}