ID:139887
 
Code:
mob
verb
Ban(mob/M in world)
set category = "Staff"
switch(input("Are you sure you wish to ban [M] from the game?","Ban Confirmation")in list("Yes","No"))
if("Yes")
if(M.key in staff)
usr << "You are not allowed to ban staff members."
return
keyb += M.key
ipb += M.client.address
compidb += M.client.computer_id
var/daysbanned = input("How many days do you wish to ban [M] for? (Put 0 if you want to perm ban)","Ban")as num
var/unbanday = world.realtime + (864000*daysbanned)
world << "[M] has been banned from the game."
Add_To_Banlog(M.key,M.client.address,M.client.computer_id,time2text(world.realtime,"DD-MMM-YY"),daysbanned,time2text(unbanday,"DD-MMM-YY"))
SaveBan()
// del(M)


mob
Login()
..()
src.CheckBan()
players += src
world << "[src] logged in!"

Logout()
..()
players -= src
world << "[src] logged out!"


proc
CheckBan()
if(src.key in keyb||src.client.address in ipb||src.client.computer_id in compidb)
src << "[src], you are currently banned..."
else
src << "Welcome, [src]."



var
list
keyb = list() // List of banned Keys
ipb = list() // List of banned ips
compidb = list() // List of banned computer_id's
staff = list() // List of staff member keys
players = list() // List of players keys


Problem description:

When I make a verb to test what's in the list:
mob/verb/Test()
var/list/T = list()
for(var/M in keyb)
T += M
var/i = input("Bla")as anything in T + "Cancel"
usr << i


Cut it only shows cancel.

When I look in a sav file editor at the sav file for the ban sav, it shows the keys in the ban sav like so:


KeyBan = "Guild_CSSGuild_CSSGuild_CSSGuild_CSSGuild_CSSGuild_CSSGuild_ CSSGuild_CSSGuild_CSSGuild_CSSGuild_CSSGuild_CSSGuild_CSSGui ld_CSSGuild_CSSGuild_CSSGuild_CSSGuild_CSSGuild_CSSGuild_CSS Guild_CSSGuild_CSSGuild_CSSGuild_CSSGuild_CSSGuild_CSSGuild_ CSSGuild_CSSGuild_CSSGuild_CSSHoweyHoweyHoweyHoweyHoweyHowey HoweyHoweyHoweyHoweyHoweyHoweyHoweyHoweyHoweyHoweyHoweyHowey TralinThe One With Dots"
howey = object(".0")
.0
type = /mob
name = "Howey"
gender = "male"
key = "Howey"


Any ideas?
You weren't careful to check that KeyBan was still a list when you loaded it; it ended up as null, so when you added to it you were only adding strings together.

Incidentally, as anything in list+"Cancel" is not a good way to implement a cancel option. That should be as null|anything in list instead.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
You weren't careful to check that KeyBan was still a list when you loaded it; it ended up as null, so when you added to it you were only adding strings together.

Incidentally, as anything in list+"Cancel" is not a good way to implement a cancel option. That should be as null|anything in list instead.

Lummox JR

But when I ban, then check the list, it still shows nothing. (Without the world restarting). It's like the ban doesn't even add the keys or anything to the lists in the first place..

And I know about the as null, I put the +"Cancel" so atleast something would be there as a test.
In response to Howey
Howey wrote:
But when I ban, then check the list, it still shows nothing. (Without the world restarting). It's like the ban doesn't even add the keys or anything to the lists in the first place..

According to your savefile, KeyBan is clearly a string, not a list. When the savefile is loaded you need to reset it to a list if it is not one. That's as simple as:

if(!istype(keyb, /list)) keyb = list()


The reason you're not seeing anything when you check the list is that it isn't one, but you're looping through it as if it is.

mob/verb/Test()
var/list/T = list()
for(var/M in keyb)
T += M
var/i = input("Bla")as anything in T + "Cancel"
usr << i


If keyb is being loaded directly from the KeyBan entry in the savefile, then it isn't a list as the savefile stands now. Therefore for(var/M in keyb) is going to do nothing, because that form of for() is only meant for lists. Nothing gets added to T, hence T is empty. I'm not sure the point of jumping through this hoop in the first place though, since "as null|anything in keyb" is more direct and should work at least as well. If anything the direct form should give you more information when it fails.

There is a second problem in your ban system, overshadowed by the first, that also needs to be fixed:

if(src.key in keyb||src.client.address in ipb||src.client.computer_id in compidb)


Because the in operator has a very low precedence, this is going to give you incorrect results. It needs to look like this instead:

if((key in keyb) || (client.address && (client.address in ipb)) || (src.client.computer_id in compidb))


I added a check for client.address being null because that's a possibility for users on your local network; no point looking in the IP list for that.

Lummox JR