ID:168955
 
Hey, I was wondering..how would you go about grabbing the current client's ( src.client's ) external IP? I just need some way to connect the world to the client, but I can't do that because client.address returns the client's internal IP ( if they're on a router ) where as world.address returns the world's external IP (I'm on a router. ). How could you go about doing this? ( If not grabbing external IP, is there another way to connect 'em? )

EDIT:

And yes, I know comparing client.address and world.address won't work.

I tried this:

world/New()
..()
OpenPort()

mob/Login()
..()
world << "[client.address == world.address ? "True" : "False"]"

output: "False"

Edit2:
I swear, they changed the tags around on me. ^_^
There are three ways you can tell if the person is the host.

1.) Their IP is "127.0.0.1", which is pretty much localhost
2.) Their IP is the same as the world.address, which happens when you are in a LAN, or you join using your external IP
3.) Their IP is null

Do just do those three checks. If one of them are true, they are the host.

if(client.address == "127.0.0.1" || !client.address || client.address == world.address)
src << "You are the host!"


~~> Dragon Lord
In response to Unknown Person
Unknown Person wrote:
There are three ways you can tell if the person is the host.

1.) Their IP is "127.0.0.1", which is pretty much localhost
2.) Their IP is the same as the world.address, which happens when you are in a LAN, or you join using your external IP
3.) Their IP is null

Do just do those three checks. If one of them are true, they are the host.

> if(client.address == "127.0.0.1" || !client.address || client.address == world.address)
> src << "You are the host!"
>

~~> Dragon Lord

In mob/Login(), none of those return true. ( I tested it myself ) I'm doing this for an admin library I'm writing ( probably for personal use ). It has four access levels: Moderator, Administrator, Creator, Host. In case I do release it, I don't want the user to have to determine the host themselves, so I just need to finish this, throw in the verbs and then I'm done. ( Throw in being create, lol )

Thanks for trying, though.
In response to Audeuro
Directly taking this from my game:
if(!host && (client.address==world.address | client.address==null | client.address==world.address | client.address=="127.0.0.1")){host = "[client.key]";host2 = "[src.name]";src.verbs += typesof(/Host/verb);}


If that doesn't work, than you're crazy :P
In response to GhostAnime
You should be setting the host to the mob, not the key/name.
In response to GhostAnime
GhostAnime wrote:
Directly taking this from my game:
if(!host && (client.address==world.address | client.address==null | client.address==world.address | client.address=="127.0.0.1")){host = "[client.key]";host2 = "[src.name]";src.verbs += typesof(/Host/verb);}

If that doesn't work, than you're crazy :P

It worked, and I thank you for that, but I don't see why this worked and the previous one didn't. It's also weird because you have some redundancy in there, you do if( client.address == world.address ) twice. Oh wait, I thought client.address would always equal 127.0.0.1 since that's the same as "localhost" or "myself?" Well, that's not why it's returning true. It's returning true because of the !client.address.

Thanks for the help everyone.

( btw, I'm not actuallly setting a host var, I'm just giving the host some verbs if these return true. )
In response to Audeuro
Acutally. If the person is the host (or sharing the same router)
There client.address would be equal to "" (or null)
If memory serves me right.
In response to Ol' Yeller
Like I said it before, I took it from my game... the host var is used for the status to show the people who's hosting... messy I know but meah to you :P
In response to Ol' Yeller
Ol' Yeller wrote:
You should be setting the host to the mob, not the key/name.

Set the host to the mob? That's a bad idea. Mobs can change easily. They may not do so in all games, but it happens in lots of them. The key or ckey is a better idea than the mob. Dealing with the client would work too.