Remove secondary AllowPortForward setting.

The global setting is fine, and this simplifies
both the code and the UI.
This commit is contained in:
Paul Chote
2017-12-22 13:13:50 +00:00
committed by abcdefg30
parent 38cb3dea05
commit 205c45198c
7 changed files with 14 additions and 84 deletions

View File

@@ -327,13 +327,8 @@ namespace OpenRA
GeoIP.Initialize(); GeoIP.Initialize();
if (!Settings.Server.DiscoverNatDevices) if (Settings.Server.DiscoverNatDevices)
Settings.Server.AllowPortForward = false;
else
{
discoverNat = UPnP.DiscoverNatDevices(Settings.Server.NatDiscoveryTimeout); discoverNat = UPnP.DiscoverNatDevices(Settings.Server.NatDiscoveryTimeout);
Settings.Server.AllowPortForward = true;
}
var modSearchArg = args.GetValue("Engine.ModSearchPaths", null); var modSearchArg = args.GetValue("Engine.ModSearchPaths", null);
var modSearchPaths = modSearchArg != null ? var modSearchPaths = modSearchArg != null ?
@@ -461,7 +456,6 @@ namespace OpenRA
{ {
Console.WriteLine("NAT discovery failed: {0}", e.Message); Console.WriteLine("NAT discovery failed: {0}", e.Message);
Log.Write("nat", e.ToString()); Log.Write("nat", e.ToString());
Settings.Server.AllowPortForward = false;
} }
ModData.LoadScreen.StartGame(args); ModData.LoadScreen.StartGame(args);
@@ -871,8 +865,7 @@ namespace OpenRA
{ {
Name = "Skirmish Game", Name = "Skirmish Game",
Map = map, Map = map,
AdvertiseOnline = false, AdvertiseOnline = false
AllowPortForward = false
}; };
server = new Server.Server(new IPEndPoint(IPAddress.Loopback, 0), settings, ModData, false); server = new Server.Server(new IPEndPoint(IPAddress.Loopback, 0), settings, ModData, false);

View File

@@ -20,15 +20,22 @@ using Open.Nat;
namespace OpenRA.Network namespace OpenRA.Network
{ {
public enum UPnPStatus { Enabled, Disabled, NotSupported }
public class UPnP public class UPnP
{ {
static NatDevice natDevice; static NatDevice natDevice;
static Mapping mapping; static Mapping mapping;
static bool initialized;
public static IPAddress ExternalIP { get; private set; } 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) public static async Task DiscoverNatDevices(int timeout)
{ {
initialized = true;
NatDiscoverer.TraceSource.Switch.Level = SourceLevels.Verbose; NatDiscoverer.TraceSource.Switch.Level = SourceLevels.Verbose;
var logChannel = Log.Channel("nat"); var logChannel = Log.Channel("nat");
NatDiscoverer.TraceSource.Listeners.Add(new TextWriterTraceListener(logChannel.Writer)); NatDiscoverer.TraceSource.Listeners.Add(new TextWriterTraceListener(logChannel.Writer));

View File

@@ -134,8 +134,7 @@ namespace OpenRA.Server
randomSeed = (int)DateTime.Now.ToBinary(); randomSeed = (int)DateTime.Now.ToBinary();
// UPnP is only supported for servers created by the game client. if (UPnP.Status == UPnPStatus.Enabled)
if (!dedicated && Settings.AllowPortForward)
UPnP.ForwardPort(Settings.ListenPort, Settings.ExternalPort).Wait(); UPnP.ForwardPort(Settings.ListenPort, Settings.ExternalPort).Wait();
foreach (var trait in modData.Manifest.ServerTraits) foreach (var trait in modData.Manifest.ServerTraits)
@@ -206,7 +205,7 @@ namespace OpenRA.Server
if (State == ServerState.ShuttingDown) if (State == ServerState.ShuttingDown)
{ {
EndGame(); EndGame();
if (!dedicated && Settings.AllowPortForward) if (UPnP.Status == UPnPStatus.Enabled)
UPnP.RemovePortForward().Wait(); UPnP.RemovePortForward().Wait();
break; break;
} }

View File

@@ -54,9 +54,6 @@ namespace OpenRA
[Desc("Allow users to enable NAT discovery for external IP detection and automatic port forwarding.")] [Desc("Allow users to enable NAT discovery for external IP detection and automatic port forwarding.")]
public bool DiscoverNatDevices = false; 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.")] [Desc("Time in milliseconds to search for UPnP enabled NAT devices.")]
public int NatDiscoveryTimeout = 1000; public int NatDiscoveryTimeout = 1000;

View File

@@ -22,7 +22,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Action onExit; Action onExit;
MapPreview preview = MapCache.UnknownMap; MapPreview preview = MapCache.UnknownMap;
bool advertiseOnline; bool advertiseOnline;
bool allowPortForward;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public ServerCreationLogic(Widget widget, ModData modData, Action onExit, Action openLobby) public ServerCreationLogic(Widget widget, ModData modData, Action onExit, Action openLobby)
@@ -84,20 +83,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
advertiseCheckbox.IsChecked = () => advertiseOnline; advertiseCheckbox.IsChecked = () => advertiseOnline;
advertiseCheckbox.OnClick = () => advertiseOnline ^= true; advertiseCheckbox.OnClick = () => advertiseOnline ^= true;
allowPortForward = Game.Settings.Server.AllowPortForward;
var checkboxUPnP = panel.Get<CheckboxWidget>("UPNP_CHECKBOX");
checkboxUPnP.IsChecked = () => allowPortForward;
checkboxUPnP.OnClick = () => allowPortForward ^= true;
checkboxUPnP.IsDisabled = () => !Game.Settings.Server.AllowPortForward;
var labelUPnP = panel.GetOrNull<LabelWidget>("UPNP_NOTICE");
if (labelUPnP != null)
labelUPnP.IsVisible = () => !Game.Settings.Server.DiscoverNatDevices;
var labelUPnPUnsupported = panel.GetOrNull<LabelWidget>("UPNP_UNSUPPORTED_NOTICE");
if (labelUPnPUnsupported != null)
labelUPnPUnsupported.IsVisible = () => Game.Settings.Server.DiscoverNatDevices && !Game.Settings.Server.AllowPortForward;
var passwordField = panel.GetOrNull<PasswordFieldWidget>("PASSWORD"); var passwordField = panel.GetOrNull<PasswordFieldWidget>("PASSWORD");
if (passwordField != null) if (passwordField != null)
passwordField.Text = Game.Settings.Server.Password; passwordField.Text = Game.Settings.Server.Password;
@@ -121,7 +106,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Game.Settings.Server.ListenPort = listenPort; Game.Settings.Server.ListenPort = listenPort;
Game.Settings.Server.ExternalPort = externalPort; Game.Settings.Server.ExternalPort = externalPort;
Game.Settings.Server.AdvertiseOnline = advertiseOnline; Game.Settings.Server.AdvertiseOnline = advertiseOnline;
Game.Settings.Server.AllowPortForward = allowPortForward;
Game.Settings.Server.Map = preview.Uid; Game.Settings.Server.Map = preview.Uid;
Game.Settings.Server.Password = password; Game.Settings.Server.Password = password;
Game.Settings.Save(); Game.Settings.Save();

View File

@@ -85,31 +85,6 @@ Container@MULTIPLAYER_CREATESERVER_PANEL:
Height: 20 Height: 20
Font: Regular Font: Regular
Text: Advertise Online Text: Advertise Online
Checkbox@UPNP_CHECKBOX:
X: 100
Y: 165
Width: 300
Height: 20
Font: Regular
Text: Automatic port forwarding
Label@UPNP_NOTICE:
X: 130
Y: 180
Width: 200
Height: 25
Font: Tiny
Align: Left
WordWrap: True
Text: Requires Network Discovery (UPnP). Enable in Settings - Advanced.
Label@UPNP_UNSUPPORTED_NOTICE:
X: 130
Y: 180
Width: 220
Height: 25
Font: Tiny
Align: Left
WordWrap: True
Text: Your router does not seem to support UPnP. Please consult your router's manual.
Container@SIDEBAR: Container@SIDEBAR:
X: PARENT_RIGHT - WIDTH X: PARENT_RIGHT - WIDTH
Y: 30 Y: 30

View File

@@ -13,7 +13,7 @@ Container@MULTIPLAYER_CREATESERVER_PANEL:
ScrollPanel: ScrollPanel:
Y: 30 Y: 30
Width: 583 Width: 583
Height: 279 Height: PARENT_BOTTOM - 30
Children: Children:
Container: Container:
X: 185 X: 185
@@ -85,31 +85,6 @@ Container@MULTIPLAYER_CREATESERVER_PANEL:
Height: 20 Height: 20
Font: Regular Font: Regular
Text: Advertise Online Text: Advertise Online
Checkbox@UPNP_CHECKBOX:
X: 100
Y: 165
Width: 300
Height: 20
Font: Regular
Text: Automatic port forwarding
Label@UPNP_NOTICE:
X: 130
Y: 180
Width: 200
Height: 25
Font: Tiny
Align: Left
WordWrap: True
Text: Requires Network Discovery (UPnP). Enable in Settings - Advanced.
Label@UPNP_UNSUPPORTED_NOTICE:
X: 130
Y: 180
Width: 220
Height: 25
Font: Tiny
Align: Left
WordWrap: True
Text: Your router does not seem to support UPnP. Please consult your router's manual.
Container@SIDEBAR: Container@SIDEBAR:
X: PARENT_RIGHT - WIDTH X: PARENT_RIGHT - WIDTH
Y: 30 Y: 30
@@ -134,7 +109,7 @@ Container@MULTIPLAYER_CREATESERVER_PANEL:
Align: Center Align: Center
Button@MAP_BUTTON: Button@MAP_BUTTON:
X: PARENT_RIGHT - WIDTH X: PARENT_RIGHT - WIDTH
Y: 284 - 30 Y: 240
Width: 174 Width: 174
Height: 25 Height: 25
Text: Choose Map Text: Choose Map
@@ -142,7 +117,7 @@ Container@MULTIPLAYER_CREATESERVER_PANEL:
Button@CREATE_BUTTON: Button@CREATE_BUTTON:
Key: return Key: return
X: PARENT_RIGHT - WIDTH X: PARENT_RIGHT - WIDTH
Y: 284 Y: PARENT_BOTTOM - 25
Width: 174 Width: 174
Height: 25 Height: 25
Text: Create Text: Create