24.02.2015, 10:34
There is no need for a timer. Not in your script, and not in the database itself.
When you use a database, you can simply save the unix timestamp as an integer value in the player's account.
When you want to ban a player for a week for example, you can calculate the amount of seconds for one week.
One week equals to 7 * 24 * 60 * 60 = 604800 seconds.
In your ban command, you can use "gettime()" to get the current unix timestamp.
Add 604800 to the value returned by gettime() and save that value in the database.
When a player tries to login, load the bantime you saved and compare it to the current timestamp.
If the stored value is still larger than the current time, kick the player again because his ban-time isn't over yet.
If the stored value is smaller than the current time, allow him to login as his ban-time has expired.
There even is no need to clear that value in the database.
If your code is always checking this bantime value, it won't matter if the value is cleared (set to 0) or kept at a value lower than the current time.
It also allows admins to check the database and see at a glance who was banned at least once (bantime > 0).
When you use a database, you can simply save the unix timestamp as an integer value in the player's account.
When you want to ban a player for a week for example, you can calculate the amount of seconds for one week.
One week equals to 7 * 24 * 60 * 60 = 604800 seconds.
In your ban command, you can use "gettime()" to get the current unix timestamp.
Add 604800 to the value returned by gettime() and save that value in the database.
When a player tries to login, load the bantime you saved and compare it to the current timestamp.
If the stored value is still larger than the current time, kick the player again because his ban-time isn't over yet.
If the stored value is smaller than the current time, allow him to login as his ban-time has expired.
There even is no need to clear that value in the database.
If your code is always checking this bantime value, it won't matter if the value is cleared (set to 0) or kept at a value lower than the current time.
It also allows admins to check the database and see at a glance who was banned at least once (bantime > 0).