Author Topic: NetHelper 1.5.2 - UPnP auto port forwarding and binding to all net adapters  (Read 1496 times)

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1111
NetHelper is now included in Outpost 2 1.3.6 or later.

I made a mod for OP2 that adds automatic port forwarding via UPnP or NAT-PMP/PCP for direct TCP/IP play. It also makes the game's net code bind to all adapters, which makes the "Hamachi fix" (steps 4-6 of the Hamachi setup guide) no longer necessary for use with Hamachi or other VPNs, and resolves issues with multiplayer in WINE. Your router must have UPnP or NAT-PMP/PCP enabled for the port forwarding to work; one is by default for most routers. NetHelper is compatible with NetFix, but may be used as a substitute for it. You may even see NetFix's reliability improve with the port forwarding.

Download link: NetHelper.zip (current version: 1.5.2, last updated 11/10/2016)

To install, extract NetHelper.dll to [Outpost 2 folder]\NetHelper\NetHelper.dll. Then, open [Outpost 2 folder]\outpost2.ini, and change the line under [Game] that says:
Quote
LoadAddons = "NetFix"
to
Quote
LoadAddons = "NetFix, NetHelper"
Then add to the bottom of the .ini:
Quote
[NetHelper]
Dll = "NetHelper\NetHelper.dll"
BindAll = 1
ForwardMode = 1
LeaseSec = 86400
(Note: if port forwarding isn't working, try setting LeaseSec to 0 if your router uses UPnP, or add "AllowPMPReset = 1" if your router uses NAT-PMP/PCP)

For more information, see the included readme.txt.
Source code is included as well, and is licensed under the LGPL.
« Last Edit: November 10, 2016, 12:27:17 PM by Arklon »

Offline Betaray

  • Administrator
  • Hero Member
  • *****
  • Posts: 2902
    • http://
Re: NetHelper - UPnP auto port forwarding and binding to all net adapters
« Reply #1 on: September 05, 2016, 07:09:06 PM »
Confirmed it works, one less hassle to deal with. 

Good job Arklon
I am the nincompoop, I eat atomic bombs for breakfest, fusion bombs for lunch, and anti-matter bombs for dinner

I just hope they don't explode

Offline zanco

  • Full Member
  • ***
  • Posts: 242
    • http://zanco.f2g.net/
Re: NetHelper - UPnP auto port forwarding and binding to all net adapters
« Reply #2 on: September 05, 2016, 07:43:36 PM »
Okay, good.

Good job Arklon. He was just talk about it, but then he actually did it. Let this be an example for all of us who want to help. Let's just do it.
if anyone finds and communicate to us that which thus far has eluded our efforts, great will be our gratitude.
          Jakob Bernouilli

"Zanco`, n00b o' The Flares"

Offline Drakmar

  • Full Member
  • ***
  • Posts: 244
  • NTCS Administrator
    • New Terran Command Site
Re: NetHelper - UPnP auto port forwarding and binding to all net adapters
« Reply #3 on: September 05, 2016, 08:23:27 PM »
Awesome work Arklon! Very exciting! I've gone ahead and integrated NetHelper into the macOS version. I'll let you know how well it works as soon as I get a chance to test it. :)

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 3752
Re: NetHelper - UPnP auto port forwarding and binding to all net adapters
« Reply #4 on: September 06, 2016, 01:19:06 AM »
Good job. I'm quite impressed that you just went ahead and did this.

Offline Leviathan

  • Hero Member
  • *****
  • Posts: 4114
Re: NetHelper - UPnP auto port forwarding and binding to all net adapters
« Reply #5 on: September 07, 2016, 03:12:28 AM »
Hey!

Great work, really impressed and this will really help, great and needed improvement that the game needs for sure.

Thanks for shearing the source, will you upload it to the SVN?

Hopefully get some time to test this out property soon.

Thanks

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1111
Re: NetHelper - UPnP auto port forwarding and binding to all net adapters
« Reply #6 on: September 07, 2016, 09:57:58 PM »
I made an update to it. I replaced the local IP address auto detection code, and patched OP2's "your local IP address is" message to display your external IP address instead (requires UPnP).

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1111
Re: NetHelper - UPnP auto port forwarding and binding to all net adapters
« Reply #7 on: September 10, 2016, 10:42:44 AM »
I made another small update to it yesterday, but it's pretty much just making code simpler, it's not likely to affect anything.

Also, some bad news: I found out that WINE doesn't implement Microsoft's UPnPNAT API. I'm gonna look into using a different UPnP library, probably MiniUPnP (and add NAT-PMP support as well).
« Last Edit: September 10, 2016, 10:46:18 AM by Arklon »

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1111
Re: NetHelper - UPnP auto port forwarding and binding to all net adapters
« Reply #8 on: September 10, 2016, 07:54:40 PM »
Updated to 1.3. It now uses MiniUPnP instead of Microsoft's API, so it should hopefully work in WINE now.

I wrote a code path for NAT-PMP, but realized that I cannot really control the external ports my requests get mapped to with it, making it pretty much useless unless I can figure out how to deal with that, so I disabled it (for now at least).
« Last Edit: September 10, 2016, 08:01:29 PM by Arklon »

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 3752
Re: NetHelper - UPnP auto port forwarding and binding to all net adapters
« Reply #9 on: September 10, 2016, 08:36:55 PM »
You also said something about Microsoft not offering dynamic port forwarding yet, and had already deprecated static port forwarding. Does the library change affect this?

Happy to hear this will work under Wine.

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1111
Re: NetHelper - UPnP auto port forwarding and binding to all net adapters
« Reply #10 on: September 10, 2016, 09:22:21 PM »
You also said something about Microsoft not offering dynamic port forwarding yet, and had already deprecated static port forwarding. Does the library change affect this?
Yes, dynamic port forwarding is supported by MiniUPnP.

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1111
Re: NetHelper 1.3 - UPnP auto port forwarding and binding to all net adapters
« Reply #11 on: September 16, 2016, 06:27:01 PM »
Uploaded version 1.4 which adds support for NAT-PMP/PCP. Note that the ini setting UPnPMode was renamed to ForwardMode, but it doesn't hurt if you forget to change it because the default value is 1 anyway. ForwardMode = 1 means use either NAT-PMP/PCP or UPnP (in that order), 2 = use only UPnP, 3 = use only NAT-PMP/PCP.

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1111
Re: NetHelper 1.4 - UPnP auto port forwarding and binding to all net adapters
« Reply #12 on: September 16, 2016, 10:37:29 PM »
Oops, I forgot to remove some test code. I've uploaded a version with it removed.

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1111
Re: NetHelper 1.4.1 - UPnP auto port forwarding and binding to all net adapters
« Reply #13 on: September 18, 2016, 12:44:38 AM »
Updated to 1.4.1. If ForwardMode is set to 1 (use either NAT-PMP/PCP or UPnP), and it detects NAT-PMP/PCP is supported by the router but is unable to map the ports correctly, it will now attempt to fall back to UPnP. Most routers only support one or the other (usually UPnP), but I have seen third-party router firmwares that support both.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 3752
Re: NetHelper 1.4.1 - UPnP auto port forwarding and binding to all net adapters
« Reply #14 on: September 19, 2016, 01:22:28 AM »
I like the automatic nature of what you're doing here.

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 1426
    • LairWorks Entertainment
Having a bit of difficulty getting it to work but this is amidst the hectic nature of work while I have customers asking me questions and I'm balls deep in their very expensive devices. I can see the games but join requests are failing. I know some of our newer members who have been attempting to play have had some issues too but I have a sneaking suspicion about how to get it working.

Will test out options and update our multiplayer guides with some basic troubleshooting steps for net helper.

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1111
- Try switching around which player is the host of the game.
- UPnP or NAT-PMP/PCP needs to be enabled on your router.
- For UPnP to work, make sure UDP port 1900 and TCP ports 2869 and 5000 are not being blocked by your computer's firewall. For NAT-PMP/PCP, UDP ports 5350 and 5351 need to not be blocked by your computer's firewall. (Note that I am not talking about forwarding ports here, just your computer's firewall software.)
- DMZ or manual port forwards of UDP ports 47776-47807 must not be enabled on your router, as UPnP and NAT-PMP/PCP cannot override them.
- If your network is a multiple router/repeater/etc. setup, ensure that only the root router (i.e. the one that directly connects to the internet) has UPnP or NAT-PMP/PCP enabled; if it's enabled on an intermediate router, it may try to request the forwarding rules to be set on the wrong device, which will cause it to not work.
- Only one device on the network can have ports forwarded to it at one time. If you start another OP2 client on another device, if using UPnP it will overwrite the rules set by the previous client, or if using NAT-PMP/PCP it will fail to override the rules set by the first client.

The first one is probably going to be the most relevant here. I'm not entirely sure how to explain why certain people hosting doesn't work even though the ports are forwarded, but then if you swap which player is hosting all of a sudden things work fine; that's always been an issue that would sometimes show up even with manual port forwarding back in the day.

I should update the readme file with these troubleshooting tips.
« Last Edit: October 13, 2016, 05:32:10 PM by Arklon »