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;
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Action onExit;
|
||||
MapPreview preview = MapCache.UnknownMap;
|
||||
bool advertiseOnline;
|
||||
bool allowPortForward;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ServerCreationLogic(Widget widget, ModData modData, Action onExit, Action openLobby)
|
||||
@@ -84,20 +83,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
advertiseCheckbox.IsChecked = () => advertiseOnline;
|
||||
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");
|
||||
if (passwordField != null)
|
||||
passwordField.Text = Game.Settings.Server.Password;
|
||||
@@ -121,7 +106,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Game.Settings.Server.ListenPort = listenPort;
|
||||
Game.Settings.Server.ExternalPort = externalPort;
|
||||
Game.Settings.Server.AdvertiseOnline = advertiseOnline;
|
||||
Game.Settings.Server.AllowPortForward = allowPortForward;
|
||||
Game.Settings.Server.Map = preview.Uid;
|
||||
Game.Settings.Server.Password = password;
|
||||
Game.Settings.Save();
|
||||
|
||||
@@ -85,31 +85,6 @@ Container@MULTIPLAYER_CREATESERVER_PANEL:
|
||||
Height: 20
|
||||
Font: Regular
|
||||
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:
|
||||
X: PARENT_RIGHT - WIDTH
|
||||
Y: 30
|
||||
|
||||
@@ -13,7 +13,7 @@ Container@MULTIPLAYER_CREATESERVER_PANEL:
|
||||
ScrollPanel:
|
||||
Y: 30
|
||||
Width: 583
|
||||
Height: 279
|
||||
Height: PARENT_BOTTOM - 30
|
||||
Children:
|
||||
Container:
|
||||
X: 185
|
||||
@@ -85,31 +85,6 @@ Container@MULTIPLAYER_CREATESERVER_PANEL:
|
||||
Height: 20
|
||||
Font: Regular
|
||||
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:
|
||||
X: PARENT_RIGHT - WIDTH
|
||||
Y: 30
|
||||
@@ -134,7 +109,7 @@ Container@MULTIPLAYER_CREATESERVER_PANEL:
|
||||
Align: Center
|
||||
Button@MAP_BUTTON:
|
||||
X: PARENT_RIGHT - WIDTH
|
||||
Y: 284 - 30
|
||||
Y: 240
|
||||
Width: 174
|
||||
Height: 25
|
||||
Text: Choose Map
|
||||
@@ -142,7 +117,7 @@ Container@MULTIPLAYER_CREATESERVER_PANEL:
|
||||
Button@CREATE_BUTTON:
|
||||
Key: return
|
||||
X: PARENT_RIGHT - WIDTH
|
||||
Y: 284
|
||||
Y: PARENT_BOTTOM - 25
|
||||
Width: 174
|
||||
Height: 25
|
||||
Text: Create
|
||||
|
||||
Reference in New Issue
Block a user