ID:158308
 
I want to make a ban system where I can view who is banned, for example:

Key - IP Address - Computer id - ban date - Unban Date
Howey - 124.345.24.12 - 4646436446 - 22:31 21/09/2009 - 22:31 22/09/2009

(HH/MM DD/MM/YYYY)

I also want to know how I would go around getting it to auto unban a player when it reaches the unban date. The rest of how I want my ban system to be I know I to do.

Any help please?
I like this idea, though I cannot do it, I would like to see and know how to do it too.. :D
Howey wrote:
I want to make a ban system where I can view who is banned

Then store this data using a format of your choice... and add a method of your choice (e.g. verb) for your admins to have it displayed to them... in the form of your choice (window popup, statpanel, output, grid...).
You could just dump all bans info (and data about the players in question, when available) into one fat log file that the admins can view, but you may want something tidier.
You could use a datum to represent each ban (or identity of a person for that matter, since almost all of the data you want to keep track of is properties of that - and you might have a complex identity system where you even link identities of different keys and as such because overlapping of computer_ids etc), though you could also just use lists (associative or not) to represent each ban's data as well. Either way you'll want a global list(s) of all bans for easy access. Here's one way a ban datum-based structure I just came up could look like (where when a person is banned his key, IP as well as computer_id are all banned together):
ban
var/ckey //you could make this var potentially a list to support banning multiple ckeys of the person in the same ban
var/ip
var/c_id
var/ban_date //numerical, world.realtime format
var/expire_date //same
New(...)
... //initialize vars here
bans += src
#define has_expired(date) (world.realtime >= date)
var/list/bans //global list holding all ban datums created

//only a simple verb example included
mob/admin/verb/deliver_the_punishment()
var/client/C = input("Ban who?") as null|anything in players
if(C) add_ban(C)
proc/add_ban(client/ckey,ip,c_id,expire_date)
//ckey can either be a ckey, or a client object
if(istype(ckey)) //if a client was given
ip = C.address
c_id = C.computer_id
ckey = C.ckey
for(var/ban/B in bans)
if((B.ckey == ckey || B.c_id == c_id) && !has_expired(B.expire_date))
//person is already banned
return 0
new /ban(ckey,ip,c_id,expire_date)
//you can add booting the player if he's logged in here

//ban checking
world/IsBanned(key,addr,cid)
key = ckey(key)
for(var/ban/B in bans)
if(B.ckey == key || B.ip == addr || B.c_id == cid)
//a matching ban found
if(has_expired(B.expire_date))
bans -= B //this will cause the ban object to be garbage collected and deleted afterwards
//we don't return here to continue checking other bans as there might be more that match this player
else return list("desc" = "You're banned!\nYour ban will expire on [time2text(B.expire_date)].")

/* Displaying bans to admins and saving/loading them
is not included: that should be easy and obvious to do
in the shown system. */

If you're not familiar with how world/IsBanned() is handled, look it up. At any case you don't strictly have to do the banchecking there, of course.
Note: the above is not complete code of course, demonstration-only - lacking support for some features (e.g. permanent bans, in which you'd just flag the expiration date with a special value like -1 and account for it). You could also expand the system to take multiple IP addresses and keys per ban, so if you ban 2 different keys (or IPs) of the same person and it is possible to detect this by overlap of another identifying piece of data, the system will only use one ban object for the person instead of multiple.
Also note you could actually pull off the same without a global bans list since you can just loop through all ban datums in existence with for(var/bans/B) instead, though you'd need of course to change the code a bit to keep the bans datum from being garbage collected and making sure they're still deleted when they're supposed to.

I also want to know how I would go around getting it to auto unban a player when it reaches the unban date. The rest of how I want my ban system to be I know I to do.

If you really want the ban to be completely clear from the system after it expires, you could check for expired bans in a loop that's reprocessed every few minutes (or even longer). However, you don't need to check for expired bans periodically at all if you're so inclined - simply when a person logs in and you check if he's banned, also check if his ban has expired in the process, and if it has, remove it altogether. It could also be useful for admins to still see expired bans (until the person first logs in after the ban is expired) in the bans list as a sort of keeping track of things (you'd mark the ban as expired, of course).

By the way, most of the things discussed in this post could of course also be done similarly with other forms of punishments like mutes and as such (and those should always be linked to the identity or at the very least the client of player, by the way, rather than the mob which is a common design mistake).
In response to Kaioken
God I always love seeing Kaioken program :)
In response to Kaioken
Kaioken wrote:
Howey wrote:
I want to make a ban system where I can view who is banned

Then store this data using a format of your choice... and add a method of your choice (e.g. verb) for your admins to have it displayed to them... in the form of your choice (window popup, statpanel, output, grid...).
You could just dump all bans info (and data about the players in question, when available) into one fat log file that the admins can view, but you may want something tidier.
You could use a datum to represent each ban (or identity of a person for that matter, since almost all of the data you want to keep track of is properties of that - and you might have a complex identity system where you even link identities of different keys and as such because overlapping of computer_ids etc), though you could also just use lists (associative or not) to represent each ban's data as well. Either way you'll want a global list(s) of all bans for easy access. Here's one way a ban datum-based structure I just came up could look like (where when a person is banned his key, IP as well as computer_id are all banned together):
> ban
> var/ckey //you could make this var potentially a list to support banning multiple ckeys of the person in the same ban
> var/ip
> var/c_id
> var/ban_date //numerical, world.realtime format
> var/expire_date //same
> New(...)
> ... //initialize vars here
> bans += src
> #define has_expired(date) (world.realtime >= date)
> var/list/bans //global list holding all ban datums created
>
> //only a simple verb example included
> mob/admin/verb/deliver_the_punishment()
> var/client/C = input("Ban who?") as null|anything in players
> if(C) add_ban(C)
> proc/add_ban(client/ckey,ip,c_id,expire_date)
> //ckey can either be a ckey, or a client object
> if(istype(ckey)) //if a client was given
> ip = C.address
> c_id = C.computer_id
> ckey = C.ckey
> for(var/ban/B in bans)
> if((B.ckey == ckey || B.c_id == c_id) && !has_expired(B.expire_date))
> //person is already banned
> return 0
> new /ban(ckey,ip,c_id,expire_date)
> //you can add booting the player if he's logged in here
>
> //ban checking
> world/IsBanned(key,addr,cid)
> key = ckey(key)
> for(var/ban/B in bans)
> if(B.ckey == key || B.ip == addr || B.c_id == cid)
> //a matching ban found
> if(has_expired(B.expire_date))
> bans -= B //this will cause the ban object to be garbage collected and deleted afterwards
> //we don't return here to continue checking other bans as there might be more that match this player
> else return list("desc" = "You're banned!\nYour ban will expire on [time2text(B.expire_date)].")
>
> /* Displaying bans to admins and saving/loading them
> is not included: that should be easy and obvious to do
> in the shown system. */

If you're not familiar with how world/IsBanned() is handled, look it up. At any case you don't strictly have to do the banchecking there, of course.
Note: the above is not complete code of course, demonstration-only - lacking support for some features (e.g. permanent bans, in which you'd just flag the expiration date with a special value like -1 and account for it). You could also expand the system to take multiple IP addresses and keys per ban, so if you ban 2 different keys (or IPs) of the same person and it is possible to detect this by overlap of another identifying piece of data, the system will only use one ban object for the person instead of multiple.
Also note you could actually pull off the same without a global bans list since you can just loop through all ban datums in existence with for(var/bans/B) instead, though you'd need of course to change the code a bit to keep the bans datum from being garbage collected and making sure they're still deleted when they're supposed to.

I also want to know how I would go around getting it to auto unban a player when it reaches the unban date. The rest of how I want my ban system to be I know I to do.

If you really want the ban to be completely clear from the system after it expires, you could check for expired bans in a loop that's reprocessed every few minutes (or even longer). However, you don't need to check for expired bans periodically at all if you're so inclined - simply when a person logs in and you check if he's banned, also check if his ban has expired in the process, and if it has, remove it altogether. It could also be useful for admins to still see expired bans (until the person first logs in after the ban is expired) in the bans list as a sort of keeping track of things (you'd mark the ban as expired, of course).

By the way, most of the things discussed in this post could of course also be done similarly with other forms of punishments like mutes and as such (and those should always be linked to the identity or at the very least the client of player, by the way, rather than the mob which is a common design mistake).

i know i am late but i was lookin a this code the add ban proc has stuff like C.address, etc... Were does C get defined?

ip = C.address
c_id = C.computer_id
ckey = C.ckey

also how would you make it so you can set the amount of days the person was banned as this seems like a good ban system i would like to use :O
In response to Darkness_Prince
It seems I renamed the argument but forgot to do so in all places. C would be the first argument, which is meant to be either a ckey or a client to grab all the info from.
You may want to also look at this post of mine. [link]

And yeah... don't quote huge amounts of text. Especially without good reason. Especially while making a huge bump, even if it can be justified. :P