Author Topic: [Patch] Multiple players behind a NAT router  (Read 3299 times)

0 Members and 1 Guest are viewing this topic.

[Patch] Multiple players behind a NAT router
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 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]
« Last Edit: January 09, 2015, 10:09:37 pm by Vestigare »

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: [Patch] Multiple players behind a NAT router
 :yes: A late Merry Christmas to us!  Thank you!
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: [Patch] Multiple players behind a NAT router
I'm taking a look at this now. Looks good so far but I want to do a bit more testing.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 
Re: [Patch] Multiple players behind a NAT router
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.
« Last Edit: January 11, 2015, 07:14:02 pm by Vestigare »

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: [Patch] Multiple players behind a NAT router
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 on Github.  And I bet you thought we'd forgotten about you ;)
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: [Patch] Multiple players behind a NAT router
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.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline jr2

  • The Mail Man
  • 212
  • It's prounounced jayartoo 0x6A7232
    • Steam
Re: [Patch] Multiple players behind a NAT router
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?

 
Re: [Patch] Multiple players behind a NAT router
And I bet you thought we'd forgotten about you ;)

I must admit, I had started to wonder.  Especially after pirates stole the attachment.    ;)

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: [Patch] Multiple players behind a NAT router
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.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: [Patch] Multiple players behind a NAT router
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. :p
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline jr2

  • The Mail Man
  • 212
  • It's prounounced jayartoo 0x6A7232
    • Steam
Re: [Patch] Multiple players behind a NAT router
: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.

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: [Patch] Multiple players behind a NAT router
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.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline Echelon9

  • 210
Re: [Patch] Multiple players behind a NAT router
Great to hear.