30.08.2016, 14:03
Hello,
I have made a small temp ban system, what it actually dies is ask admin the number of days.
and i am taking those days like this:
hours= 24/days;
secs = hours*3600;
unbants = gettime() + secs;
In unban_time field i set it the value to unbants(and we're ok until here).
but when the player tries to join while banned, i want to show him how many days are left until he'll stay banned...
and this is what i do:
but those days are showed like a huge number... so what did i do wrong in maths... ?
for example a 3 days ban is: 1472088830
I have made a small temp ban system, what it actually dies is ask admin the number of days.
and i am taking those days like this:
hours= 24/days;
secs = hours*3600;
unbants = gettime() + secs;
In unban_time field i set it the value to unbants(and we're ok until here).
but when the player tries to join while banned, i want to show him how many days are left until he'll stay banned...
and this is what i do:
PHP код:
public TempBanChecking(playerid)
{
new banquery[180], days, time, ip[16];
GetPlayerIp(playerid, ip, 16);
mysql_format(1, banquery, sizeof(banquery), "SELECT `unban_time` FROM `TBanData` WHERE `ip` = '%s'", ip);
new Cache:cacheid = mysql_query(1, banquery);
if(cache_num_rows() != 0) //if an unban time was found with their ip address
{
new unbantimestamp = cache_get_field_content_int(0, "unban_time");// = mysql_fetch_int(); //get the timestamp from the database
new string[128];
mins =(unbantimestamp - gettime())/60;
hours = mins/60;
days = hours/24;
//format(string, sizeof(string), "[DEBUG]An unban timer was found! %d > %d",unbantimestamp, time);
//SendClientMessageToAll(COLOR_WHITE, string);
if(unbantimestamp > time) //if the unban time hasn't been reached yet
{
format(string, sizeof(string), "You're banned from this server... for %d days", days);
SendClientMessage(playerid, -1, string);
}
}
cache_delete(cacheid);
}
for example a 3 days ban is: 1472088830