CoD4x_Server icon indicating copy to clipboard operation
CoD4x_Server copied to clipboard

Implement NAT Hole punching

Open Kingwolf123 opened this issue 1 year ago • 7 comments

Is it possible? Will make port forwarding and other stuff not necessary

Kingwolf123 avatar Jun 30 '23 23:06 Kingwolf123

Currently no, but it is possible to do so, not sure if it's really necessary tho, as the servers never use random ports. And port forwarding is literally a 2 minute job, I don't think it's needed in the code.

AlexanderCurl avatar Jul 01 '23 19:07 AlexanderCurl

Vast numbers of people behind CGNAT will benefit tremendously. Creation of spontaneous servers is always easier.

Kingwolf123 avatar Jul 01 '23 19:07 Kingwolf123

If people behind CGNAT, they don't have public IP address anyway, so even port forward doesn't help in that situation.

AlexanderCurl avatar Jul 02 '23 05:07 AlexanderCurl

Hole punching is optimal for such users

Kingwolf123 avatar Jul 02 '23 09:07 Kingwolf123

People behind CGNAT do benefit from hole punching fyi

Kingwolf123 avatar Jul 20 '23 02:07 Kingwolf123

@Kingwolf123 How exactly would that work? The concept sounds pretty simple, but it seems like it's more suitable for P2P communication and wouldn't really make sense for a game server, correct? Though I've never implemented it myself so I might be missing something. And if I'm not mistaken, it would also require implementing this on the client side as well.

proxict avatar Sep 04 '23 16:09 proxict

Hello , So i have gathered some information and implementation features that will help this move forward

Open source stun and turn servers are already available and ready to use . This is a very advanced S&T server. Cod4 doesnt need all these features hence they can be stripped down to exactly fit the usage.

The library is integrated into the server, client and the cod4x masterserver.

The system works as follows.

The main server is implemented in the cod4master server where all servers and clients can communicate to get holepunched. Anyone can host their own cod4x holepunch server. [Optional] 3rd party people can apply for their hole punch server to be broadcasted via the cod4x server after applying for it . This ensures that the system never goes down, because even if the master server goes down, the clients still have holepunch server addresses that are working The holepunching feature is implemented in the client, and the client ships with the default dvar of the holepunching addresses so it can communicated with the master server. IPV6 punching can also be implemented for ipv6 hosts behind firewall for example, which are alot.

Behaviour suggestions The client should always prefer direct connection, and if that fails lets say within 3 seconds then the client switches to holepunching. Stun servers should ensure privacy and keep no logs. Custom stun servers should be easy to setup, as easy as click and run with a few cmd options.

stun is directly shipped with both server and all clients in a patch to enable mass use .

The server clients .adds some cvars such as "sv_stun_sv_list" "add_stun_sv" . One use case that cannot work is a custom stun server and a custom server.The client cannot connect without stun server knowledge, and server cannot provide that in a p2p way or can it? The client will have to manually add the stun server in .shoudnt be that difficult. A format for the connect command on the client implemented to give both the server ip and the stun server ip such as /connect 192.168.5.2:28964 -s 65.543.34.123:5436 -s is an abbreviation for stun .

In conclusion, stun server is ready to be integrated into cod4x with the vast majority of average users benefitting from automated NAT and firewall punch .The argument of for and against stun server implementation clear and a majority average cg-natted users can host and play cod4 with their friends seamlessly.

Appreciate feedback Regards

Kingwolf123 avatar Jun 28 '24 02:06 Kingwolf123