PDA

View Full Version : Get unban data (month, day and year)

cellps
08/05/2019, 09:49 AM
Hello everyone, I am creating a ban system and I would like to know how I can get the date of the month, day and year that the player is going to be banned, I use "gettime () + 60 * 60 * 24 * Days" to set the time of banishment.

Example: The player took 10 days ban

Date ban: 05/08/2019
Date unban 05/18/2019 (This is the date I'd like to get)

Vizi10
08/05/2019, 11:28 AM

jasperschellekens
08/05/2019, 04:21 PM
If you are using SQL you can do it like I did.
I wrote this little part and it works for a ban between 1-14 days only.

Calculate the date the player will be unbanned based on the days entered by the administrator.

gettime(hour, minute, second);
getdate(Year,Month,Day);
dbuntill = Day + banDays; // Banned until day.
mbuntill = Month; // Banned until month
ybuntill = Year; // Banned until year
if(Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 || Month == 10 || Month == 11) //Months that have 31 days
{
if(dbuntill >= 31) // When today is 28 and the administrator entered 14 days, the value will be 42
{
dbuntill -= 31; // 42 - 31 = 11 so the player will be banned untill the 11th of next month
mbuntill += 1; // Since there are more then 31 days, the banned until month goes up by one.
}
}
else if(Month == 4 || Month == 6 || Month == 9 || Month == 11) //Months that have 30 days
{
if(dbuntill >= 30)
{
dbuntill -= 30;
mbuntill += 1;
}
}
else if(Month == 2) //Month that has 28 days
{
if(dbuntill >= 28)
{
dbuntill -= 28;
mbuntill += 1;
}
}
if(mbuntill >= 13) { mbuntill = 1; ybuntill += 1; } // If banmonth is 13 or higher, set month to 1 and year +1
printf("Player will be banned untill: %d/%d/%d (m-d-y)", mbuntill ,dbuntill ,ybuntill );

For unbanning I do this: There's a server timer that's get called from now and then and update's the time etc. It also calls for this function:

UnbanPlayers()
{
new DBResult:M_RESULT, szQuery[128], Year, Month, Day;
getdate(Year,Month,Day);
format(szQuery, sizeof(szQuery), "SELECT * FROM `BANS` WHERE `UDAY` = '%d' AND `UMONTH` = '%d'", Day,Month);
M_RESULT = db_query(ZARP_DATABASE, szQuery);
if(db_num_rows(M_RESULT)) // An banned player that will be unbanned today was found.
{
new uyear = db_get_field_assoc_int(M_RESULT, "UYEAR"), id = db_get_field_assoc_int(M_RESULT, "ID"), permed = db_get_field_assoc_int(M_RESULT, "PERMED");
if(uyear == Year && permed == 0) // If player is not permed and if unban year is the same as the current year.
{
format(szQuery, sizeof(szQuery), "delete from `BANS` where `ID` = '%d'",id);
M_RESULT = db_query(ZARP_DATABASE, szQuery);
}
}
db_free_result(M_RESULT);
return 1;
}