godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.13k stars 21.19k forks source link

UPNP invalid gateway #79857

Closed BurningFluffer closed 1 year ago

BurningFluffer commented 1 year ago

Godot version

4.1.stable

System information

Godot v4.1.stable - Windows 10.0.19044 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3050 (NVIDIA; 31.0.15.2824) - Intel(R) Core(TM) i5-4690K CPU @ 3.50GHz (4 Threads)

Issue description

I'm trying to enable UPNP in my game (create IP adress others would be able to connect to for online multiplayer; setting up the server) and UPNP does get discovered, but the gateway is invalid. I followed a tutorial and they seem to have it working.

Steps to reproduce

Code so far:

func upnp_setup():
    var upnp = UPNP.new()
    var discover_result = upnp.discover() 
    assert(discover_result == UPNP.UPNP_RESULT_SUCCESS, "UPNP Discover Failed! Error %s" % discover_result)
    assert(upnp.get_gateway() and upnp.get_gateway().is_valid_gateway(), "UPNP Invalid Gateway!")# <- here is a fail point
    var map_result = upnp.add_port_mapping(PORT)
    assert(map_result == UPNP.UPNP_RESULT_SUCCESS, "UPNP Port Mapping Failed! Error %s" % map_result)
    print("Sucess! Join Address: %s" % upnp.query_external_address())
    $"../../MultiplayerMenu/MPMenu/TextureRect/OwnIP".text = "%s" % upnp.query_external_address()

Might be router-specific. Both my PC and my router have UPNP enabled. Model below, but judging by its shell, it's a rebrand of Huawei Echolife HG8245H or the similar. Here are router stats: image image image image

Minimal reproduction project

N/A

BurningFluffer commented 1 year ago

OK, nevermind. To all who discovers the same issue later: check with your provider. Mine disables UPNP while having it "Enabled" on router, to have "static IP" as a separate payable service. That truly sucks for all (devs with similar providers) and players, because this severs people from creating servers/hosting games. Is there any way to work around it using only a dynamic IP? I'm sorry, I'm not an expert with how networking works.

Calinou commented 1 year ago

Is there any way to work around it using only a dynamic IP? I'm sorry, I'm not an expert with how networking works.

No, other than using dedicated servers and making players create virtual "rooms" on them (or spawning instances on demand). This is also required for players behind CGNAT or players that can't enable UPnP on their router for other reasons (such as not knowing how to do it, or having forgotten login credentials).

This is why UPnP is pretty much dead nowadays in general.

Closing, as this is an issue we can't fix.