Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Vestigare on January 09, 2015, 06:24:43 pm

Title: [Patch] Multiple players behind a NAT router
Post by: Vestigare on January 09, 2015, 06:24:43 pm
Hello everyone,

I'm new to FreeSpace Open, but took the time to set up a standalone server on Linux for play with friends and family.

During my testing I noticed that only one person in my household could connect at a time.  Looking around the forums I ran across this post http://www.hard-light.net/forums/index.php?topic=81685.msg1629696#msg1629696 (http://www.hard-light.net/forums/index.php?topic=81685.msg1629696#msg1629696) and it said to try forcing the port.  Like the OP of that thread, it didn't work for me either.   :banghead:

Digging into the source for 3.7.2 RC4, I managed to track down a couple of places where the net code checks the incoming connections for duplicates and it is only checking against the IP address.  The port (forced or otherwise) is ignored and therefore the duplicate player rejection for those passing through NAT to get to game server.

My testing has been limited to accessing an external (to my home network) Linux machine running my modified 3.7.2 RC4 as a standalone server, but I have been able to get two machines to connect and play simultaneously from behind the same router.  One machine has to have a forced port set in wxLauncher, the other has been tested both with the default and a different forced port.  No opening or forwarding of ports on the firewall was required.

Attached is the diff file from the stock 3.7.2 RC4 source and my modifications.  I took the time to look at the SVN source and it appears it'd be equally applicable to that as well if anyone is interested.  It's my first go at a patch, but should be created correctly, I believe.

A big thank you to all the people who've made FreeSpace Open possible.  I hope this little contribution helps at least a few people out there.   :)

[attachment kidnapped by pirates]
Title: Re: [Patch] Multiple players behind a NAT router
Post by: chief1983 on January 10, 2015, 09:47:15 am
 :yes: A late Merry Christmas to us!  Thank you!
Title: Re: [Patch] Multiple players behind a NAT router
Post by: karajorma on January 10, 2015, 10:29:00 pm
I'm taking a look at this now. Looks good so far but I want to do a bit more testing.
Title: Re: [Patch] Multiple players behind a NAT router
Post by: Vestigare on January 11, 2015, 06:59:04 pm
The code base is huge so while I may have missed something, the only other similar piece of code I noticed was in code/network/psnet2.cpp, function psnet_rel_work(), line ~1504:

Code: [Select]
if(memcmp(&d3_rcv_addr, &Reliable_sockets[i].m_net_addr, sizeof(net_addr)) == 0){

This compares one address to another as well, but since it compares the entire structure and not just the IP address, the port should be taken in to account so I didn't alter it.  The old "if it ain't broke, don't fix it" motto.
Title: Re: [Patch] Multiple players behind a NAT router
Post by: chief1983 on May 06, 2015, 03:49:46 pm
I didn't want this to be forgotten.  I had the patch sitting on my desktop for after 3.7.2 if Karajorma hadn't looked at it by then.  Now that 3.7.2 is out I think we can move forward with this as long as someone looks at it, so I opened PR #77 (https://github.com/scp-fs2open/fs2open.github.com/pull/77) on Github.  And I bet you thought we'd forgotten about you ;)
Title: Re: [Patch] Multiple players behind a NAT router
Post by: karajorma on May 06, 2015, 08:16:44 pm
I hadn't forgotten about this either, I just had no computer to test it on. Hopefully next week I'll get my laptop repaired and then I can actually run tests and get it working.
Title: Re: [Patch] Multiple players behind a NAT router
Post by: jr2 on May 07, 2015, 08:38:08 am
I hadn't forgotten about this either, I just had no computer to test it on. Hopefully next week I'll get my laptop repaired and then I can actually run tests and get it working.

Out of curiousity, what went wrong with it?
Title: Re: [Patch] Multiple players behind a NAT router
Post by: Vestigare on May 07, 2015, 12:39:43 pm
And I bet you thought we'd forgotten about you ;)

I must admit, I had started to wonder.  Especially after pirates stole the attachment.    ;)
Title: Re: [Patch] Multiple players behind a NAT router
Post by: chief1983 on May 07, 2015, 01:03:26 pm
This is why I save pretty much any patch that gets posted to my computer, never know when a link will go down before something gets resolved.
Title: Re: [Patch] Multiple players behind a NAT router
Post by: karajorma on May 07, 2015, 08:37:16 pm
I hadn't forgotten about this either, I just had no computer to test it on. Hopefully next week I'll get my laptop repaired and then I can actually run tests and get it working.

Out of curiousity, what went wrong with it?

I already told you once (http://www.hard-light.net/forums/index.php?topic=88613.msg1783483#msg1783483). :p
Title: Re: [Patch] Multiple players behind a NAT router
Post by: jr2 on May 08, 2015, 04:24:19 pm
:wtf: I thought I remembered asking you.  Didn't remember reading the response; I wonder if I forgot or if I accidentally marked that thread as read without reading it.
Title: Re: [Patch] Multiple players behind a NAT router
Post by: chief1983 on June 17, 2015, 05:31:44 pm
I've built a standalone using this patch and connected to it with two Macbooks behind my office NAT.  It crashed without having the patch applied to the clients as well, but when I rebuilt with the same hash and patch applied, everything was smooth and stable.
Title: Re: [Patch] Multiple players behind a NAT router
Post by: Echelon9 on June 17, 2015, 11:29:53 pm
Great to hear.