Remove secondary AllowPortForward setting.
The global setting is fine, and this simplifies both the code and the UI.
This commit is contained in:
@@ -327,13 +327,8 @@ namespace OpenRA
|
||||
|
||||
GeoIP.Initialize();
|
||||
|
||||
if (!Settings.Server.DiscoverNatDevices)
|
||||
Settings.Server.AllowPortForward = false;
|
||||
else
|
||||
{
|
||||
if (Settings.Server.DiscoverNatDevices)
|
||||
discoverNat = UPnP.DiscoverNatDevices(Settings.Server.NatDiscoveryTimeout);
|
||||
Settings.Server.AllowPortForward = true;
|
||||
}
|
||||
|
||||
var modSearchArg = args.GetValue("Engine.ModSearchPaths", null);
|
||||
var modSearchPaths = modSearchArg != null ?
|
||||
@@ -461,7 +456,6 @@ namespace OpenRA
|
||||
{
|
||||
Console.WriteLine("NAT discovery failed: {0}", e.Message);
|
||||
Log.Write("nat", e.ToString());
|
||||
Settings.Server.AllowPortForward = false;
|
||||
}
|
||||
|
||||
ModData.LoadScreen.StartGame(args);
|
||||
@@ -871,8 +865,7 @@ namespace OpenRA
|
||||
{
|
||||
Name = "Skirmish Game",
|
||||
Map = map,
|
||||
AdvertiseOnline = false,
|
||||
AllowPortForward = false
|
||||
AdvertiseOnline = false
|
||||
};
|
||||
|
||||
server = new Server.Server(new IPEndPoint(IPAddress.Loopback, 0), settings, ModData, false);
|
||||
|
||||
@@ -20,15 +20,22 @@ using Open.Nat;
|
||||
|
||||
namespace OpenRA.Network
|
||||
{
|
||||
public enum UPnPStatus { Enabled, Disabled, NotSupported }
|
||||
|
||||
public class UPnP
|
||||
{
|
||||
static NatDevice natDevice;
|
||||
static Mapping mapping;
|
||||
static bool initialized;
|
||||
|
||||
public static IPAddress ExternalIP { get; private set; }
|
||||
public static UPnPStatus Status { get { return initialized ? natDevice != null ?
|
||||
UPnPStatus.Enabled : UPnPStatus.NotSupported : UPnPStatus.Disabled; } }
|
||||
|
||||
public static async Task DiscoverNatDevices(int timeout)
|
||||
{
|
||||
initialized = true;
|
||||
|
||||
NatDiscoverer.TraceSource.Switch.Level = SourceLevels.Verbose;
|
||||
var logChannel = Log.Channel("nat");
|
||||
NatDiscoverer.TraceSource.Listeners.Add(new TextWriterTraceListener(logChannel.Writer));
|
||||
|
||||
@@ -134,8 +134,7 @@ namespace OpenRA.Server
|
||||
|
||||
randomSeed = (int)DateTime.Now.ToBinary();
|
||||
|
||||
// UPnP is only supported for servers created by the game client.
|
||||
if (!dedicated && Settings.AllowPortForward)
|
||||
if (UPnP.Status == UPnPStatus.Enabled)
|
||||
UPnP.ForwardPort(Settings.ListenPort, Settings.ExternalPort).Wait();
|
||||
|
||||
foreach (var trait in modData.Manifest.ServerTraits)
|
||||
@@ -206,7 +205,7 @@ namespace OpenRA.Server
|
||||
if (State == ServerState.ShuttingDown)
|
||||
{
|
||||
EndGame();
|
||||
if (!dedicated && Settings.AllowPortForward)
|
||||
if (UPnP.Status == UPnPStatus.Enabled)
|
||||
UPnP.RemovePortForward().Wait();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -54,9 +54,6 @@ namespace OpenRA
|
||||
[Desc("Allow users to enable NAT discovery for external IP detection and automatic port forwarding.")]
|
||||
public bool DiscoverNatDevices = false;
|
||||
|
||||
[Desc("Set this to false to disable UPnP even if compatible devices are found.")]
|
||||
public bool AllowPortForward = true;
|
||||
|
||||
[Desc("Time in milliseconds to search for UPnP enabled NAT devices.")]
|
||||
public int NatDiscoveryTimeout = 1000;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user