ID:167398
 
I'm having problem making a ban code. I tried using libraries but I'd rather stick to my own work. Could someone explain to me the basic principals and features needed in a ban code so that I may make my own? Please don't reccomend me to any libraries or in fact give your own slice of code, because one, I won't completely grasp the concept, and two, I want it to be my own.
Basicly, It's just looking up someone's key (or IP) in a list.

var/list/banned=list()

mob/verb/AddBan()
banned+=input("What is the persons ckey you want to ban?")
mob/verb/RemoveBan()
banned-=input("Who do you want to remove in ban?")in banned

mob/Login()
if(banned.Find(src.ckey))del(src)
</DM>
Untested, but should work.
In response to Flame Sage
Okay heres the code i've adjusted from yours:
var/list/banlist= list()


mob/proc/Ban(mob/Player/M in world)
banlist+=M.client.address
src<< "You have banned [M]!"
del(M)


mob/proc/Unban(mob/M in banlist)
banlist-=M.client.address
src<< "You have unbanned [M]!"

mob/Login()
if(banlist.Find(src.client.address))
del(src)


This works okay until the server shutsdown. How do I make it so that the banlist is not lost when the game is shutdown? Also you'll see that I have adjusted it to ban IPs. As of yet if I were to unban someone it would just show a list of IPs. So how do I make it so it displays their key when the list pops up? Or better yet, how would I make it so that it automatically unbans someone after a designated amount of time? Using sleep to automatically unban would work until the game was shutdown. So how would I do it so it unbans them whether the game is up or not? If their are any other ways to make this ban system more efficient or if you see any problems with it, let me know please.
In response to Teris
You would have to save it. That would require you to look up some saving demos.
In response to Crzylme
Crzylme wrote:
You would have to save it. That would require you to look up some saving demos.

http://www.deadron.com/Games/ByondBasicSavefiles.html
In response to Mecha Destroyer JD
Now after reading that tutorial I'm confused. It is about savefiles, yes, but it pertains nothing to the format of which I need to know to apply it to a ban code. Now here is my freakishly mutated ban code:

    
mob/proc/Ban(mob/Player/M in world)
var/savefile/F= new("banlist.sav")
F+= M.client.address
F.cd= "/[ckey]/[M.client.address]"
del(M)

mob/proc/Unban(mob/Player/M in "banlist.sav")
var/savefile/F= new("banlist.sav")
F.cd = "/[ckey]/[M.client.address]"
var/list/banned = F.dir
var/list/menu = new()
menu += banned
menu+= "cancel"
var/result = input("DELETING a character", null, "Which character do you want to delete?") in menu
if (result)
F.cd = "/[ckey]/[M.client.address]"
F.dir.Remove(result)

Lol sad isn't it? Could someone please show me how to implement a savefile correctly in an IP ban code please?
In response to Teris
I would do something like this:

var/savefile/f=new("Ban.sav") //Load the file 'Ban.sav' into f. If it doesn't exist, this creates it
f["banned"] << banlist //Put 'banlist' into the buffer 'banned' inside 'Ban.sav'


Then, to load:

var/savefile/f=new("Ban.sav")
f["banned"] >> banlist


Simple.
In response to Jp
I tried your suggestion but it appears I've done something wrong. If I ban someone, it still allows them to log in:

var/list
banlist= list()

Ban(mob/Player/M in world)
var/savefile/F=new("Ban.sav")
banlist+=M.client.address
src<< "<font color= white>You have banned [M]!</font>"
F["banned"] << banlist

Unban(mob/M in banlist)
var.savefile/F= new("Bans.sav")
banlist-=M.client.address
src<< "<font color= white>You have unbanned [M]!</font>"
F["banned"]<< banlist

mob/Login()
..()
var/savefile/F= new("Bans.sav")
F["banned"]>> banlist
if(src.client.address in banlist)
src<< "<font color= white> You are banned! You may not enter!</font>"
del(src)


Can someone explain to me what I have done wrong?

In response to Teris
You would want to put the loading of the banlist in the creation of the world instead of as soon as someone logs in:
world
New()
..()
var/savefile/F= new("Bans.sav")
F["banned"]>> banlist


But besides that, I'm still looking it over..
In response to Teris
Teris wrote:
I tried your suggestion but it appears I've done something wrong. If I ban someone, it still allows them to log in:

var/list
> banlist= list()
>
> Ban(mob/Player/M in world)
> var/savefile/F=new("Ban.sav")
> banlist+=M.client.address
> src<< "<font color= white>You have banned [M]!</font>"
> F["banned"] << banlist
>
> Unban(mob/M in banlist)
> var.savefile/F= new("Bans.sav")
> banlist-=M.client.address
> src<< "<font color= white>You have unbanned [M]!</font>"
> F["banned"]<< banlist
>
> mob/Login()
> ..()
> var/savefile/F= new("Bans.sav")
> F["banned"]>> banlist
> if(src.client.address in banlist)
> src<< "<font color= white> You are banned! You may not enter!</font>"
> del(src)

Can someone explain to me what I have done wrong?

WHen you wrote the banned player's address to the savefile you said "ban.sav" then later you told it to read "bans.sav"
In response to SJRDOZER
SJRDOZER wrote:
Teris wrote:
I tried your suggestion but it appears I've done something wrong. If I ban someone, it still allows them to log in:

var/list
> > banlist= list()
> >
> > Ban(mob/Player/M in world)
> > var/savefile/F=new("Ban.sav")
> > banlist+=M.client.address
> > src<< "<font color= white>You have banned [M]!</font>"
> > F["banned"] << banlist
> >
> > Unban(mob/M in banlist)
> > var.savefile/F= new("Bans.sav")
> > banlist-=M.client.address
> > src<< "<font color= white>You have unbanned [M]!</font>"
> > F["banned"]<< banlist
> >
> > mob/Login()
> > ..()
> > var/savefile/F= new("Bans.sav")
> > F["banned"]>> banlist
> > if(src.client.address in banlist)
> > src<< "<font color= white> You are banned! You may not enter!</font>"
> > del(src)

Can someone explain to me what I have done wrong?

WHen you wrote the banned player's address to the savefile you said "ban.sav" then later you told it to read "bans.sav"
No he didn't. He told it to check the banlist var.
In response to Kireis
Ban(mob/Player/M in world)
var/savefile/F=new("Ban.sav")


Unban(mob/M in banlist)
var.savefile/F= new("Bans.sav")


mob/Login()
..()
var/savefile/F= new("Bans.sav")
In response to Jp
Jp wrote:
Ban(mob/Player/M in world)
> var/savefile/F=new("Ban.sav")

> Unban(mob/M in banlist)
> var.savefile/F= new("Bans.sav")

mob/Login()
> ..()
> var/savefile/F= new("Bans.sav")


What is this?
In response to Teris
Those are your mistakes I told you about. You are writing and reading banlist from different savefiles.

try this:
var/savefile/F = ("ban.sav")//now you just refer to F and don't have to keep "creating it"
var/list/L = list() //the banlist, name it whatever.

mob
Player
//stuff
admin
//stuff
verb
Ban(mob/Player/M as mob in world) //input a player
if(M.key != usr.key) //can't ban yourself
L += M.client.address //write the player's ip to the banlist
F["banned"] << L //write the banlist to the savefile

Unban()
var/who //who will it be?
F["banned"] >> L //update the banlist
who = input("Unban who?") in L //ask the admin who to unban
L -= who //delete the ip chosen from the banlist
F["banned"] << L //update the savefile

Login()
F["banned"] >> L //update the banlist
if(L.Find(src.client.address,1,0) == 1) //look for the client's ip in the banlist
src << "You are banned. Have a nice day." //he's there, bye bye sucker.
del(src) //ok now bye bye sucker
else //he's clean
..() //on with the show
In response to SJRDOZER
Oh wow! I feel stupid. Okay, sorry about that. So here's my new code:

world
New()
..()
var/savefile/F= new("Bans.sav")
F["banned"]>> banlist

var/list/banlist= list()

mob/Mod/proc


Ban(mob/Player/M in world)
var/savefile/F=new("Bans.sav")
banlist+=M.client.address
src<< "<font color= white>You have banned [M]!</font>"
F["banned"] << banlist

Unban(mob/M in banlist)
var/savefile/F= new("Bans.sav")
banlist-=M.client.address
src<< "<font color= white>You have unbanned [M]!</font>"
F["banned"]<< banlist

mob/Login()
..()
if(src.client.address in banlist)
src<< "<font color= white> You are banned! You may not enter!</font>"
del(src)


This code still doesn't work though. People are still allowed to log in after they are banned. Are there anymore problems? By the way, I left out del(M) in the ban proc on purpose for now.
In response to Teris
/* You don't have to make a new var/savefile/F = new("bans.sav") at every proc. Just use F and 
it will know it as "bans.sav"*/


var/savefile/F = new("bans.sav") //savefile bans.sav can be referenced using F
var/list/banlist = new/list() //banlist is created for the world with variable length

world/New()
..()
F.cd = "/" //might need this, dunno, worth a try.sets the directory of a savefile to be in
F["banned"] >> banlist //you can write the savefile to the banlist at start if you want

mob/Mod/verb //you want it to be verb, not proc or else you can't use it from the commands panel
Ban(mob/Player/M in world) //input a player
if(M.key != usr.key) //checks if the mobs key isn't yours so you aren't banned
banlist += M.client.address //add the client's address
F.cd = "/"
F["banned"] << banlist //update the savefile

Unban()
var/who
F.cd = "/"
F["banned"] >> banlist //update the banlist
banlist.Add("cancel")//if you changed your mind
who = input("Unban who?") in banlist //select an ip address
if(who != "cancel") //selected an ip
banlist -= who //allow that ip
F["banned"] << banlist //update the savefile

mob/Login() //a player logs in
F.cd = "/"
F["banned"] >> banlist //update the banlist
if(banlist.Find(src.client.address) == 1) //the search for the address is true, he's naughty
src << "You are banned. Bye"
del(src)
else
..()


I don't think src.client.address in banlist will work. I just use a boolean to be safe.
if(banlist.Find(src.client.address) == 1) The find proc will look through the banlist for that value. If it's there, it will return 1. If not, it will return 0. If you want to look for someone who isn't banned, you'd do
banlist.Find(src.client.address) == 0 will see if the search returned false. That player was not banned then.
Hope you see how it works.
In response to SJRDOZER
BAD!

Of COURSE 'if(client.address in banlist)' will work. That's good programming practice.

What isn't good programming practice is this:

if((client.address in banlist)==1)


That is unstable, unrobust, and brittle. Not good. Don't do it.

if(var) is similar to if(var==1), but better. It does the same thing.

if(!var) is similar to if(var==0), but much, much better.

Finally, don't use Find(). Find() crashes if the list is empty - not what you want here.
In response to SJRDOZER
Yes that makes sense. But I was always told to avoid boolean when comparing a value to one. Either way, with or without the boolean I still get a runtime error saying unable to execute null.Find. So there is probably something wrong with the if statement, but I don't see anything. Here is the code I have now. I've included more code in case there is something else conflicting with it that I haven't put up before:

//Checking Procs//
mob/proc
Alpha_Check()
if(key in Alpha_Testers)
src<< "<i><font color= green>You are an Alpha Tester!</font></i>"


else
src<< "<i><font color= red>Sorry but you have not been appointed as one of the closed Alpha testers. Please, try again when the game has been finished.</font></i>"
del(src)

Ban_Check()
Banfile.cd = "/"//I have changed F to Banfile because F is a horrible name for a global variable
Banfile["banned"] >> banlist
if(banlist.Find(src.client.address))
src << "You are banned. Bye"
del(src)
else
..()

Mod_Check()
if(key== "UmbrousSoul")
client.mob= new/mob/Player/Mod/GM

if(key== "Teris")
client.mob= new/mob/Player/Mod/WW

if(key== "Randonius")
client.mob= new/mob/Player/Mod/Admin

if(!key== "UmbrousSoul"&&"Teris"&&"Randonius")
client.mob= new/mob/Player

//This is a list of mob variables in the Global scope.//
mob/var
adminlevel=0

//This is a list of global variable lists.//
var/list
banlist= new/list()
Alpha_Testers= list("UmbrousSoul", "Kireis", "Randonius")

//This is a list of various savefiles//
var/savefile
Banfile = new("bans.sav")


world

hub="UmbrousSoul.SyntheticDreamsVoiceOfAnIllusion"
name = "Synthetic Dreams: Desu Koe No Ni Maboroshii"
view= 6
mob= /mob/Checks

New()
..()
Banfile.cd = "/"
Banfile["banned"]>> banlist



mob/Checks/Login()
..()
Alpha_Check()
Ban_Check()
Mod_Check()

//Defines GM mob//
mob/Player/Mod/GM/Login()
..()
adminlevel= 5
name= key
src<< "<i><font color= green>Welcome to \"Synthetic Dreams\"! You are currently a Level [adminlevel] Game Manager!</font></i>"
verbs+= /mob/Mod/proc/Boot
verbs+= /mob/Mod/proc/Teleport
verbs+= /mob/Mod/proc/Mute



//Defines Worldweaver mob//
mob/Player/Mod/WW/Login()
..()
adminlevel= 4
name= key
src<< "<i><font color= green>Welcome to \"Synthetic Dreams\"! You are currently a Level [adminlevel] Worldweaver!</font></i>"
verbs+= /mob/Mod/proc/Boot
verbs+= /mob/Mod/proc/Teleport
verbs+= /mob/Mod/proc/Mute
verbs+= /mob/Mod/proc/Announce
verbs+= /mob/Mod/proc/Ban
verbs+= /mob/Mod/proc/Unban


//Defines Admin mob//
mob/Player/Mod/Admin/Login()
..()
adminlevel= 4
name= key
src<< "<i><font color= green>Welcome to \"Synthetic Dreams\"! You are currently a Level [adminlevel] Admin!</font></i>"
verbs+= /mob/Mod/proc/Boot
verbs+= /mob/Mod/proc/Teleport
verbs+= /mob/Mod/proc/Mute

//Moderator Verbs//
mob/Mod/proc

Boot(mob/Player/M in world)
set category= "Admin"
if(src.adminlevel== M.adminlevel)
usr<<"<font color= red>You cannot boot [M]! They have the same Admin level as you!</font>"

if(src.adminlevel< M.adminlevel)
usr<<"<font color= red>You cannot boot [M]! They have a higher Admin level than you!</font>"

if(src.adminlevel> M.adminlevel)
world<< "<i><font color= gray>[M] has been booted by [usr]!</font></i>"
M<< "<font color= red size=+1>You have been booted!</font>"
del(M)


Teleport(mob/M in world)
set category= "Admin"
src.x= M.x
src.y= M.y-1
src.z= M.z
M<< "<i><font color= white>In a flash of white light, [src] appears before you!</font></i>"
src<< "<i><font color= white>You appear before [M].</font></i>"


Mute(mob/Player/M in world)
var/length
set category= "Admin"
if(src.adminlevel== M.adminlevel)
src<<"<font color= red>You cannot mute [M]! They have the same Admin level as you!</font>"

if(src.adminlevel< M.adminlevel)
src<<"<font color= red>You cannot boot [M]! They have a higher Admin level than you!</font>"

if(src.adminlevel> M.adminlevel)
length= input("How many minutes should this person be muted?")as num
if(length< 2)
M<< "<center><font color= red size=+1>You have been muted for [length] minute!</font></center>"
world<< "<i><font color= gray size=+1>[M] has been muted for [length] minute!</font></i>"
M.verbs-= /mob/Player/verb/World_Say
M.verbs-= /mob/Player/verb/Say
sleep(600*length)
M<< "<center><font color= green size=+1>You have been unmuted!</font></center>"
M.verbs+= /mob/Player/verb/World_Say
M.verbs+= /mob/Player/verb/Say

if(length>30)
src<< "<font color= red>That's too long. If it's that bad than just ban the person.</font>"

else
M<< "<center><font color= red size=+1>You have been muted for [length] minutes!</font></center>"
world<< "<i><font color= gray size=+1>[M] has been muted for [length] minutes!</font></i>"
M.verbs-= /mob/Player/verb/World_Say
M.verbs-= /mob/Player/verb/Say
sleep(600*length)
M<< "<center><font color= green size=+1>You have been unmuted!</font></center>"
M.verbs+= /mob/Player/verb/World_Say
M.verbs+= /mob/Player/verb/Say


Announce(msg as message)
set category= "Admin"
world<< "<center><font color= blue size=+3>[src] announces:[msg]</font></center>"



Ban(mob/Player/M in world)
set category= "Admin"
banlist+=M.client.address
Banfile.cd = "/"
src<< "<font color= white>You have banned [M]!</font>"
Banfile["banned"] << banlist



Unban()
set category= "Admin"
var/who
Banfile.cd = "/"
Banfile["banned"] >> banlist
banlist.Add("Cancel")
who = input("Unban who?") in banlist
if(who != "cancel")
banlist -= who
Banfile["banned"] << banlist


So that's basically my Login/Mob code. And here is the runtime error I get when I login:

runtime error: Cannot execute null.Find().
proc name: Ban Check (/mob/proc/Ban_Check)
usr: Kireis (/mob/Checks)
src: Kireis (/mob/Checks)
call stack:
Kireis (/mob/Checks): Ban Check()
Kireis (/mob/Checks): Login()

And here is another runtime error I get when I try to unban:

runtime error: Cannot execute null.Add().
proc name: Unban (/mob/Mod/proc/Unban)
usr: Kireis (/mob/Player/Mod/WW)
src: Kireis (/mob/Player/Mod/WW)
call stack:
Kireis (/mob/Player/Mod/WW): Unban()

Let me know if you see something wrong with this. Also, while it's up here, might as well put up any other suggestions you have for my system.
In response to Jp
Nevermind. Alright changing the if statement got rid of the runtime error, but banned people can still log in. Also I still have a runtime error when I click unban.
In response to Teris
The list is null because it's empty so do += "Cancel" instead of .Add

Jeez this is a ton. I just ban keys. Any multikeys learn their lesson because they lose their characters.
Page: 1 2