xyz there are dyslexic people on the godot official forums aswell
var ip_adress :String
if OS.has_feature("windows"):
if OS.has_environment("COMPUTERNAME"):
ip_adress = IP.resolve_hostname(str(OS.get_environment("COMPUTERNAME")),1)
elif OS.has_feature("x11"):
if OS.has_environment("HOSTNAME"):
ip_adress = IP.resolve_hostname(str(OS.get_environment("HOSTNAME")),1)
elif OS.has_feature("OSX"):
if OS.has_environment("HOSTNAME"):
ip_adress = IP.resolve_hostname(str(OS.get_environment("HOSTNAME")),1)
This works, but... im not sure how to use this to determine... the problem im facing is how to cross reference the server that is hosted on your machine with a server list that gets sent to you on the request from masterlist server.
The masterlist records the IP from which the valid packet was received from and uses that to add to serverlist. Then serves this list to anyone that requests it.
So if i create game, i make req to master list to update th elist with my game. Masterlist see my public IP and add it to list then from the same host machine i make req to masterlist as client and i get a serverlist with a server that has my public IP, but the host has no idea what public IP it has 😃.
For a local game sure, resolve hostname and bobs your unkie.
EDIT:
Ok so a quick maths lead me to make a http request to a well-known IP API.
var http_request = HTTPRequest.new()
func _ready():
add_child(http_request)
http_request.request_completed.connect(_on_http_completed)
var error = http_request.request("https://api.ipify.org")
if error:
print("Http error: ", error)
func _on_http_completed(result, response_code, headers, body):
var json = JSON.new()
var lol = body.get_string_from_utf8()
var response = json.parse_string(lol)
pass
But im not sure if this is the best way to determine if im connected to the server that im hosting when served the server list from masterlist