ID:155690
 
Well, I was wondering how you did that.
I had a rough idea on how to start, tried it out, but failed:
client/New()
..()
for(var/client/M in world)
if(M.computer_id==src.computer_id)
world<<"[M] and [src] are multikeying. (Computer_id: [src.computer_id])"


Can anyone give me some hints, what I have to lookup in the reference perhaps, or just some steps to get started?

Sincerely,
Raimo H.
To simply modify what you have there, I don't think you can loop through clients like that(though I could be wrong), this works though:

client/New()
..()
for(var/mob/M in world)
if(M.client && (M.client != src))
if(M.client.computer_id==src.computer_id)
world<<"[M] and [src] are multikeying. (Computer_id: [src.computer_id])"



There's a few other ways you could do it as well, for example, you could add the clients computer id to a global list when they log in, and check new logins against that list, it would be a lot faster, especially if your game has a lot of mobs that don't have clients.
Remove the 'in world' - clients aren't in the world, they simply exist.
No doubt this'll fire off for anyone who logs in, because their computer_id will be the same as their client's already in the list. Ensure that M ain't src.
In response to Jotdaniel
He definitely shouldn't loop through all the mobs in the world to accomplish this - for(var/client/C) is the way to go, it's just a shame more people don't know about it.
In response to Murrawhip
Thanks Murrawhip and Jotdaniel for the answers, this definitely helped me a lot.
In response to Murrawhip
Good to know, I've never tried that before.
In response to Jotdaniel
for(var/mob/M in world)
if(M.client)
if(M!=src)
if(M.client.address==src.client.address)
if(M.client.computer_id == src.client.computer_id)
if(Multikey)
world<<"<B><font color=yellow size=3>[M]([M.key]) and [src]([src.key]) are connected on one PC with the same shared IP address [M.client.address]."
else
world<<"<B><font color=yellow>[M]([M.key]) and [src]([src.key]) are connected on one PC with the same shared IP address [M.client.address] and have been booted because multikeying is disabled."
src<<"<font face='Arial Black'><font color=blue>You and [M]([M.key]) have been booted for multikeying because it's disabled."
M<<"<font face='Arial Black'><font color=blue>You and [src]([src.key]) have been booted for multikeying because it's disabled."
spawn()
del M
del src
else
world<<"<B><font color=yellow size=2>[M]([M.key]) and [src]([src.key]) are probably connected via a router with the same shared IP address [M.client.address]."


Code I used to check when people where multikeying or not and if they are not on the same PC. I have never considered Client/C and just used mob and search for clients, but what the rest is saying is more efficient. There are also messages in the code for debugging cause back then.
In response to Sokkiejjj
Sokkiejjj wrote:
for(var/mob/M in world)
> if(M.client)
> if(M!=src)
> if(M.client.address==src.client.address)
> if(M.client.computer_id == src.client.computer_id)
> if(Multikey)
> world<<"<B><font color=yellow size=3>[M]([M.key]) and [src]([src.key]) are connected on one PC with the same shared IP address [M.client.address]."
> else
> world<<"<B><font color=yellow>[M]([M.key]) and [src]([src.key]) are connected on one PC with the same shared IP address [M.client.address] and have been booted because multikeying is disabled."
> src<<"<font face='Arial Black'><font color=blue>You and [M]([M.key]) have been booted for multikeying because it's disabled."
> M<<"<font face='Arial Black'><font color=blue>You and [src]([src.key]) have been booted for multikeying because it's disabled."
> spawn()
> del M
> del src
> else
> world<<"<B><font color=yellow size=2>[M]([M.key]) and [src]([src.key]) are probably connected via a router with the same shared IP address [M.client.address]."

Code I used to check when people where multikeying or not and if they are not on the same PC. I have never considered Client/C and just used mob and search for clients, but what the rest is saying is more efficient. There are also messages in the code for debugging cause back then.

Can you please explain what makes your work more efficient?
In response to Murrawhip
client/New()
..()
for(var/client/C)
if(C != src)
if(C.computer_id==src.computer_id)
world<<"[C] and [src] are multikeying. (Computer_id: [src.computer_id])"
.=..()//If I don't place this here, the second client will have a black screen.
else
.=..()

Well, this is what I have now and it seems to work perfectly. But I was wondering if this was the best way to go about it. Does anything need to be cleaned up or something like that?

Sincerely,
Raimo H.
In response to Raimo
Couldn't you simply just store the online computer ids in a list and compare any new id that logs in to it, disconnecting it if found?

var/list/ids = new/list

client
New()
. = ..()
if(src.computer_id in ids) del(src)

ids += src.computer_id

Del()
. = ..()
ids -= src.computer_id


I'm not sure off hand, but you could probably go one better and perform the check in world/IsBanned().
In response to Tiberath

var/list/ids = new/list
>
> client

>
> Del()
> . = ..()
> ids -= src.computer_id



Wouldn't the proc terminate before it removed the computer_id with .=..() going first?
In response to Jotdaniel
Jotdaniel wrote:
Wouldn't the proc terminate before it removed the computer_id with .=..() going first?

IIRC, . is the value the proc will return after it's execution unless it's execution is stopped with a return statement. Outputting a debug statement into the snippet Del() above displayed a message to the world.
In response to Murrawhip
I meant what the rest of the people are saying here (thus the Client/C method) is much more efficient then my method, but it does the trick.

Probably said it wrong (English is not my main language).
In response to Tiberath
Thank you, I've always been confused by that.
In response to Tiberath
Actually that method won't work. When a person trying to multi-key and their second key is kicked, their computer_id will be removed from the list, and then they can connect again with their second key.
In response to Raimo
bump.
In response to Spunky_Girl
How about this one?
var/list/ids = new/list
client
New()
ids[computer_id]++
if(ids[computer_id]>1)del(src)
.=..()
Del()
ids[computer_id]--
if(ids[computer_id]<=0)
ids[computer_id]=null
. = ..()


Heres a fix for his.

var/list/ids = new/list

client
New()
if(src.computer_id in ids)
spawn(0)
del(src)
ids += src.computer_id
. = ..()
Del()
ids -= src.computer_id
. = ..()


This method works too, and it's probably more reliable.

client
New()
for(var/client/C)
if(C.computer_id!=src.computer_id) continue
if(C==src) continue
del(src)
.=..()
In response to Chowder
Your method would work.

Your "fix" is another fail since you will just be disconnected right after connecting.

Your alternate method can subsequently be shortened to...
client/New()
..()
for(var/client/c)
if(c != src && c.computer_id == src.computer_id)
del src
In response to Spunky_Girl
The "fail" has been corrected.

If we must be speed freaks, This should do it.
client
New()
..()
for(var/client/C)
if((C.computer_id!=computer_id)|(src.key==C.key)) continue
mob.key=null

The alternate method you provided of mine is slightly slower, because the (c!=src) is being checked before the computer id.
In response to Chowder
That wont do it. You're using the | operator in place of || and there's not much need for a continue statement if you can just check and kill on the go.

client
New()
. = ..()
for(var/client/C)
if(C.computer_id == src.computer_id && src.ckey != C.ckey) del(src)


The above will work to OP's specifications. (And is essentially what Spunky Girl posted in [link])
Page: 1 2