So i made a simple ban system using steamid64.
Banning players and unbanning functions work fine but how would i time the unban?
First i thought of using timers but then i realized how unreliable they are, incase of a server crash.
Next i thought about using UTime, but i have no idea how to capture time correctly, if anyone could help i would appriciate it alot!!
Save the unban time to a db, check the db unban time against current time, isBanned = currentTime < unbanTime.
os.time() returns the current unix time (Amount of seconds elapsed since Jan 01 1970 to the current system time), so you can use this to check how long has elapsed between two points in time.
One way would be to simply store the unban time, say current os.time() is 1545341889 and you ban someone for 1 day (86400 seconds), you could store os.time() + 86400 then when they try to join you just need to check if the current value of os.time() is more than the unban time you stored.
Why not just save the ban time and the ban length? (isbanned = os.time() < bantime + banlength)
Not really any difference between the two other than the way I said you are calculating the unban time once and storing it and the other you are doing the calculation every time they join or this needs to be checked. It's probably negligible in terms of performance so I guess it's down to preference or what fits best with your system.
The way I mentioned you could also just store the ban length separately for the purpose of displaying this somewhere if needed.
What a waste of time......
just work out the time the ban expires and store that............
have a DATABASE function to remove the records in the background....... each time a player joins.
no penalty on the game server.
just do a simple query when they try to join..... If they are IN the database, they cannot join... .then fire up a trigger to remove all expired records in the database execution thread.
select all where player id_onlie = databaseid, if the database returns zero they aint banned.
this can be applied to each player as they join.
anything else can be CALCULATED if needed.
DO NOT rely on the os time unless it is validated first against an external clock.
So let me explain how im saving the data. Currently when i ban someone i svae their steamid64 in a file so i could do 888472847 lets say and then the ban length?
Ban time and ban length
If you're using a file to store the bans, I guess you're using JSON to store the data and read it? If so then it won't be difficult to store when the user was banned and how long the ban is, or the time it will be unbanned. Have in mind tho, you can either put two more fields which are when it was banned and the ban length, OR one more which is the time when it will be unbanned, you can choose from either of those two as the people above have mentioned.
And then, when the player enters what you just have to do is check if the current time is past the ban time.
as i said in the post i made a very simple thing. the simplest ban system. it currently writes the steamid64 of the banned player. and with some modifications i made it write {SteamID} {BanExparation}
so it looks like 76561198097203962 1545393699
{STEAM ID 64} {os.time + banlength}
now my only issue is splitting the values which i get from one file. in the same line
Using string.Split with " " as the separator would return a table with the steamid as the first entry and time as the second.
I edited my post above but I based my first response on the fact that this seems like a simple learning project so I gave a simple answer. It's good to keep things simple and learn what tools you have to work with before exploring and thinking about how you can do what you are doing more elegantly or faster/safer.
Sorry, you need to Log In to post a reply to this thread.