I'm writing a hybrid lobby for the Steam version of my game. For the lobby to fully function, it requires Godot's ENet to connect to an IP address, specifically the hosts'. For now, it only works with a local ip address, but I want this to be worldwide. How do I get the result of a website like https://whatismyipaddress.com/ and then put (at least the ipv4) result as the public ip address to connect to?
Running a command to get a public IP address from a getmyip site.
You need to make a game lobby. This would be code that would run on your server. Servers are cheap, you can get one for a few dollars a month. The game lobby does not run the code for the game, it is just to connect the peers. You can get the WAN IP address from a client using PHP, or various backend technologies, and then store this in some temporary table for other clients to connect to.
For example, you can let one person start a game lobby, they just give it a name, and it connects to the lobby server (which is hard-coded into the game, like my-game-lobby dot com) and then the server adds their IP to the list. Other clients can query the lobbies for the game, which will show a UI table with the available lobbies, and their names and the names of the peers connected. Then they click "Join Lobby" which uploads their IP to the server, and the other peers can probably check every few seconds for new IPs from the server to update their local list. Then once the lobby has enough people, or when someone clicks "Start Game", or whatever, the game starts and uses peer to peer, without any further need for the lobby server.
- Best Answerset by AesynthGrey
I still think using a lobby server is best for a larger multiplayer game. But if you just need to test stuff while you are developing, you can use this code.
func _ready():
var http = HTTPRequest.new()
add_child(http)
http.connect("request_completed", self, "print_ip")
http.request("https://api.ipify.org")
func print_ip(result, response_code, headers, body):
var ip = body.get_string_from_utf8()
print("Internet IP is: ", ip)
Thanks! I'm an indie dev and this really helps.
Glad to help.
I might get a server too. I gotta go over it with some peeps.