1
2
ID:167398
Mar 18 2006, 11:27 am
|
|
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.
|
In response to Flame Sage
|
|
Okay heres the code i've adjusted from yours:
var/list/banlist= list() 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:
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 Then, to load: var/savefile/f=new("Ban.sav") 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 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 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 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: var/list No he didn't. He told it to check the banlist var.Can someone explain to me what I have done wrong? |
In response to Kireis
|
|
Ban(mob/Player/M in world) Unban(mob/M in banlist) mob/Login() |
In response to Jp
|
|
Jp wrote:
Ban(mob/Player/M in world) > Unban(mob/M in banlist) mob/Login() 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" |
In response to SJRDOZER
|
|
Oh wow! I feel stupid. Okay, sorry about that. So here's my new code:
world 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 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// 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. |
1
2
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.