ID:263792
 
Ive seen a few bits of code, and all fail to properly stop multikeying... They rely on players logging in first...
I wanna stop more than 2 clients from same IP address logging in..

client/New()
..()
for(var/client/C)
if(C.address==src.address)
if(C.key!=src.key)
src<<"<font color=red>Multiple keys are disabled. -Management.</font>"; spawn(2)del(src)

Thats what I came up with, but it doesnt work...
Get that for() outta there.
In response to Kaiochao2536
oh i forgot the in world?
EDIT: naw didnt help


remove for()..? that makes no sense if you dont replace it with anything
In response to Saucepan Man
There doesn't have to be anything there in the first place.
var/list/clientip[] = new()             // multiple connections
var/const/max_ip_allowed=2 // maximum number of connection from the same IP address.

client
New()
if(address)
if(clientip.Find("[address]") && clientip["[address]"]>0)
clientip["[address]"]++
if(clientip["[address]"] > max_ip_allowed)
src<<"<font color=red>Connection refused: Too many connections from your IP address."
del(src)
else clientip["[address]"] = 1
..()
Del()
if(address && clientip.Find("[address]"))
clientip["[address]"]--
if(clientip["[address]"]<=0)
clientip -= "[address]"
..()


Try that...
In response to Kaiochao2536
Kaiochao2536 wrote:
There doesn't have to be anything there in the first place.

Are you seriously suggesting i do this?:
client/New()
..()
if(src.key)
if(src.address)
src<<"<font color=red>Multiple keys are disabled. -Management.</font>"; spawn(2)del(src)


Thats banning anyone that has BYOND o_O
In response to Darker Emerald
Whoo thanks zombie boy.
It looks right... and I cant find fault with it (although it IS 8am, and im yet to go to bed)
client
New()
if(address)
if(clientip.Find("[address]") && clientip["[address]"]>0)
clientip["[address]"]++
if(clientip["[address]"] > max_ip_allowed)
src<<"<font color=red>Connection refused: Too many connections from your IP address.</font>"
del(src)
else clientip["[address]"] = 1
..()
if(src.key=="Guest")
src<<"<font color=red>The Guest key is disabled. -Management.</font>"; spawn(2)del(src)

Del()
Save()
if(address && clientip.Find("[address]"))
clientip["[address]"]--
if(clientip["[address]"]<=0)
clientip -= "[address]"
sleep(20)//<--- just incase?
return ..()
.=..()


That is exactly how I have it...
Could it just be failing because Im the host?
In response to Saucepan Man
mob/Login()
for(var/mob/M in world)
if(!M.client) return
if(M.address == src.address)
src<<"<font color=red>Multiple keys are disabled. -Management.</font>";spawn(2) del(src)

You may want to make spaces tabs >>
In response to Inuyashaisbest
:S
This is in login, thus they have logged in.. Creating unecessary lag (allbeit a rare/small amount)...
I really wanna leave it in client()

But thanks..
In response to Saucepan Man
Replace the first one's Cs with src. Remove the for()s.

You're messing it up even more, not me.
In response to Kaiochao2536
There's nothing bad about for() if there as it wouldnt be there
try this:
client/New()
..()
for(var/mob/M in world)
if(M.client.address==src.address)
if(M.key!=src.key)
src<<"<font color=red>Multiple keys are disabled. -Management.</font>"; spawn(2)del(src)Z
In response to Kaiochao2536
for() actually DOES have a use you know <_< And in this scenario it is doing exactly what it was made for.
world/IsBanned(key,address)
for(var/client/C)
if(C.address == address)
.["Login"] = 0
.["desc"] = "You can't multikey."
return .
return ..()


<code>IsBanned()</code> is called before the client object is created, so it's a better option than <code>client.New()</code>.
In response to Saucepan Man
Dunno if your using client side-save it wont save :L but if its server saved than it should save try using it like this...

client
New()
if(key == "Guest")
src<<"<font color=red>Connection refused: The 'Guest key' is disabled.</font>"
del(src)
if(address)
if(clientip.Find("[address]") && clientip["[address]"] > 0)
clientip["[address]"]++
if(clientip["[address]"] > max_ip_allowed)
src<<"<font color=red>Connection refused: Too many connections from your IP address.</font>"
del(src)
else clientip["[address]"] = 1
..()
Del()
if(address && clientip.Find("[address]"))
clientip["[address]"]--
if(clientip["[address]"] <= 0)
clientip -= "[address]"
Save()
..()
Well, first, if you don't want somebody to log in, then you should never call ..() in client/New() unless if they're allowed to login. That means that instead of <code>spawn(2)del(src)</code>, just have <code>return</code>. Then, put ..() at the end of client/New(), so it's only reached if there hasn't been a violation.

Otherwise, what you have seems to be correct. However, I'd remove the key check. Instead, in the first line of the for loop, put
if(C == src) continue
which will keep it from drawing a false positive on everybody.