Godot UPNP doesnt work and no errors?

Godot Version

3.5.1

Question

I am trying to use UPNP with my multiplayer game but UPNP doesnt works and not giving any error.

My code:

var upn = UPNP.new()
func upnp():
	var discorver_result = upn.discover(2000, 2, "InternetGatewayDevice")
	if discorver_result == UPNP.UPNP_RESULT_SUCCESS:
		print(upn.get_gateway())
		if upn.get_gateway() and upn.get_gateway().is_valid_gateway():
			var map_res_udp = upn.add_port_mapping(port,0,"game_udp","UDP",0)
			var map_res_tcp = upn.add_port_mapping(port,0,"game_udp","TCP",0)
			if !map_res_udp == UPNP.UPNP_RESULT_SUCCESS:
				upn.add_port_mapping(port,0,"","UDP",0)
			if !map_res_tcp == UPNP.UPNP_RESULT_SUCCESS:
				upn.add_port_mapping(port,0,"","TCP",0)
	ip_adress.append([tr("a_intern"),upn.query_external_address()])
	print(upn.query_external_address())

what is wrong? and how can I use UPNP?

Not all routers support UPNP or maybe it’s disabled (bearing in mind that you are testing with your home router.)

but if not supperting why its not giving any errors?

It wont error if its disabled on the router, you are only opening the port on the local machine. If that failed then you would get an error.

uPnP should be banned anyway, hell of a security risk.

but what I can do for make my local online game to peer-to-peer online over internet?

is there is a way for it like UPNP that user doesnt need to do something? Or any tutorial for solution?

Manual port forwarding is the only other way.

but telling player to make manuel port forwarding is not good solution. I think there is another solution. How other games do it?

Normally they use some server, with known IP or HostName ,like:
STUN - to let peers connect to each other. Might not work with all firewalls and on dual NAT. There are a lot of free STUN servers. Just knows the public IP and Port of the peers.
TURN or TURNS - A message relay that peers can connect to. TURN servers relay all information, so it require a lot of bandwidth. If free then often with limitations.

2 Likes

so we cant do it without server? isnt it?

Yes, as UPnP is being increasingly disabled by default in modern router configurations. This is why relying on external STUN/TURN servers (or simply dedicated game servers) has become the norm in multiplayer gaming over the last 10 years.

You can check whether your router supports UPnP by visiting its web interface. This address depends on your internet service provider (or router), but it’s usually something of the form http://192.168.1.1 or http://192.168.0.1.

There’s plenty of games and services that require port forwarding if you dont want to use uPnP. Thats why it was invented in the first place. The issue is that it opens the door to hackers as if someone has managed to download malicious code that opens a port uPnP does not check this.

As others have said routers are coming with them disabled by default at this point. And many more MP games use dedicated servers instead.

The other issue with peer to peer is someone has to be the host, which gives them ‘host advantage’ if the game is competitive.

1 Like

what do you mean with this? I am begining on multiplayer and I just heard this term.
And anyway I like to make peer-to-peer if there is a good solution. and easy for players

‘Host Advantage’ occurs when a peer-to-peer game has more than 2 players, one of the lot is deemed the authority, hosts the game logic locally (acting as a server) and has zero ping. Other players are still connected through STUN/TURN but it follows a pretty standard server-client model with a new client becoming a server if the last authority dropped out.

Gears of War pvp followed this model, with the horrible combination of console hardware not fit to be a server, majority wi-fi connections, and peer-to-peer the server authority player would just clear house. That player would have zero ping, and all shots taken were before any other players actions. I am sure it was fine testing in-office with LAN ethernet and devkits, but the real world exacerbates peer to peer problems.

Fighting games (usually) consist of two players duking it out. Instead of server-client each client must agree on the next simulation. Before rollback this would consist of hatling the frame waiting for input state: more ping, more delay on each input. There isn’t an advantage for either player, but there is a lot of delay, especially for wi-fi players. While rollback has less delay because it lets clients assume the next input will be the same as the last, if it was wrong the character would jump into the correct state. Learn more about it from Core-A and the GGPO developer on youtube

1 Like

yes I learned this thing and I am also going on it. Hey do you have a idea for how to make peer-to-peer over internet?

And IPV6, from 1998, was designed to solve most of those problems, all devices have a unique public IP and it’s the same as the local IP, but implementation are “slow” :frowning:

can I use IPV6 for making my game online over internet?
is there is a tutorial for it?

You could include IPV6 as an option (which most MP services do now).

However IPV6 / rollout/ implemenation / routing hardware (home routing hardware) all have issues currently. When it works its fine, but adoption is not high.

IPv6 routers almost have a firewall enabled by default, and UPNPv6 is typically disabled by default. The situation ends up just as dire as IPv4 when it comes to easy self-hosting, unfortunately.

1 Like

thats too bad. But I think there is a way to do it no?