enhanced UPnP discovery usability
- don't search for NATs forever, 5 seconds seem to be enough - disable the UPnP checkbox if discovery failed - no computer industry acronyms in user GUI - don't remove port-forwarding twice, just once on shutdown - user-configurable settings for debugging
This commit is contained in:
@@ -267,15 +267,17 @@ namespace OpenRA
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
NatUtility.Logger = Log.Channels["server"].Writer;
|
NatUtility.Logger = Log.Channels["server"].Writer;
|
||||||
NatUtility.Verbose = true;
|
NatUtility.Verbose = Settings.Server.VerboseNatDiscovery;
|
||||||
NatUtility.DeviceFound += DeviceFound;
|
NatUtility.DeviceFound += DeviceFound;
|
||||||
NatUtility.DeviceLost += DeviceLost;
|
NatUtility.DeviceLost += DeviceLost;
|
||||||
|
Settings.Server.NatDeviceAvailable = false;
|
||||||
NatUtility.StartDiscovery();
|
NatUtility.StartDiscovery();
|
||||||
Log.Write("server", "NAT discovery started.");
|
Log.Write("server", "NAT discovery started.");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Write("server", "Can't discover UPnP-enabled device: {0}", e);
|
Log.Write("server", "Can't discover UPnP-enabled device: {0}", e);
|
||||||
|
Settings.Server.NatDeviceAvailable = false;
|
||||||
Settings.Server.AllowUPnP = false;
|
Settings.Server.AllowUPnP = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,6 +291,18 @@ namespace OpenRA
|
|||||||
|
|
||||||
Sound.Create(Settings.Sound.Engine);
|
Sound.Create(Settings.Sound.Engine);
|
||||||
InitializeWithMods(Settings.Game.Mods);
|
InitializeWithMods(Settings.Game.Mods);
|
||||||
|
|
||||||
|
RunAfterDelay(Settings.Server.NatDiscoveryTimeout, () =>
|
||||||
|
{
|
||||||
|
NatUtility.StopDiscovery();
|
||||||
|
Log.Write("server", "NAT discovery stopped.");
|
||||||
|
if (natDevice == null)
|
||||||
|
{
|
||||||
|
Log.Write("server", "No NAT devices with UPnP enabled found within {0} ms deadline. Disabling automatic port forwarding.".F(Settings.Server.NatDiscoveryTimeout));
|
||||||
|
Settings.Server.NatDeviceAvailable = false;
|
||||||
|
Settings.Server.AllowUPnP = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DeviceFound(object sender, DeviceEventArgs args)
|
public static void DeviceFound(object sender, DeviceEventArgs args)
|
||||||
@@ -302,6 +316,7 @@ namespace OpenRA
|
|||||||
foreach (var mp in natDevice.GetAllMappings())
|
foreach (var mp in natDevice.GetAllMappings())
|
||||||
Log.Write("server", "Existing port mapping: protocol={0}, public={1}, private={2}", mp.Protocol, mp.PublicPort, mp.PrivatePort);
|
Log.Write("server", "Existing port mapping: protocol={0}, public={1}, private={2}", mp.Protocol, mp.PublicPort, mp.PrivatePort);
|
||||||
|
|
||||||
|
Settings.Server.NatDeviceAvailable = true;
|
||||||
Settings.Server.AllowUPnP = true;
|
Settings.Server.AllowUPnP = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,9 +324,10 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
natDevice = args.Device;
|
natDevice = args.Device;
|
||||||
|
|
||||||
Log.Write("server", "NAT device Lost");
|
Log.Write("server", "NAT device lost.");
|
||||||
Log.Write("server", "Type: {0}", natDevice.GetType());
|
Log.Write("server", "Type: {0}", natDevice.GetType());
|
||||||
|
|
||||||
|
Settings.Server.NatDeviceAvailable = false;
|
||||||
Settings.Server.AllowUPnP = false;
|
Settings.Server.AllowUPnP = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,10 @@ namespace OpenRA.GameRules
|
|||||||
public int ExternalPort = 1234;
|
public int ExternalPort = 1234;
|
||||||
public bool AdvertiseOnline = true;
|
public bool AdvertiseOnline = true;
|
||||||
public string MasterServer = "http://master.open-ra.org/";
|
public string MasterServer = "http://master.open-ra.org/";
|
||||||
public bool AllowUPnP = true;
|
public bool AllowUPnP = true; // let the user disable it
|
||||||
|
public bool NatDeviceAvailable = false; // internal check if discovery succeeded
|
||||||
|
public int NatDiscoveryTimeout = 1000; // ms to search for UPnP enabled NATs
|
||||||
|
public bool VerboseNatDiscovery = false; // print very detailed logs for debugging
|
||||||
public bool AllowCheats = false;
|
public bool AllowCheats = false;
|
||||||
public string Map = null;
|
public string Map = null;
|
||||||
public string[] Ban = null;
|
public string[] Ban = null;
|
||||||
@@ -49,6 +52,9 @@ namespace OpenRA.GameRules
|
|||||||
AdvertiseOnline = other.AdvertiseOnline;
|
AdvertiseOnline = other.AdvertiseOnline;
|
||||||
MasterServer = other.MasterServer;
|
MasterServer = other.MasterServer;
|
||||||
AllowUPnP = other.AllowUPnP;
|
AllowUPnP = other.AllowUPnP;
|
||||||
|
NatDeviceAvailable = other.NatDeviceAvailable;
|
||||||
|
NatDiscoveryTimeout = other.NatDiscoveryTimeout;
|
||||||
|
VerboseNatDiscovery = other.VerboseNatDiscovery;
|
||||||
AllowCheats = other.AllowCheats;
|
AllowCheats = other.AllowCheats;
|
||||||
Map = other.Map;
|
Map = other.Map;
|
||||||
Ban = other.Ban;
|
Ban = other.Ban;
|
||||||
|
|||||||
@@ -80,8 +80,6 @@ namespace OpenRA.Server
|
|||||||
{
|
{
|
||||||
foreach (var t in ServerTraits.WithInterface<IEndGame>())
|
foreach (var t in ServerTraits.WithInterface<IEndGame>())
|
||||||
t.GameEnded(this);
|
t.GameEnded(this);
|
||||||
if (Settings.AllowUPnP)
|
|
||||||
RemovePortforward();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Server(IPEndPoint endpoint, string[] mods, ServerSettings settings, ModData modData, INatDevice natDevice)
|
public Server(IPEndPoint endpoint, string[] mods, ServerSettings settings, ModData modData, INatDevice natDevice)
|
||||||
@@ -159,6 +157,8 @@ namespace OpenRA.Server
|
|||||||
if (State == ServerState.ShuttingDown)
|
if (State == ServerState.ShuttingDown)
|
||||||
{
|
{
|
||||||
EndGame();
|
EndGame();
|
||||||
|
if (Settings.AllowUPnP)
|
||||||
|
RemovePortforward();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,9 +166,6 @@ namespace OpenRA.Server
|
|||||||
foreach (var t in ServerTraits.WithInterface<INotifyServerShutdown>())
|
foreach (var t in ServerTraits.WithInterface<INotifyServerShutdown>())
|
||||||
t.ServerShutdown(this);
|
t.ServerShutdown(this);
|
||||||
|
|
||||||
if (Settings.AllowUPnP)
|
|
||||||
RemovePortforward();
|
|
||||||
|
|
||||||
preConns.Clear();
|
preConns.Clear();
|
||||||
conns.Clear();
|
conns.Clear();
|
||||||
try { listener.Stop(); }
|
try { listener.Stop(); }
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
var UPnPCheckbox = panel.Get<CheckboxWidget>("UPNP_CHECKBOX");
|
var UPnPCheckbox = panel.Get<CheckboxWidget>("UPNP_CHECKBOX");
|
||||||
UPnPCheckbox.IsChecked = () => allowUPnP;
|
UPnPCheckbox.IsChecked = () => allowUPnP;
|
||||||
UPnPCheckbox.OnClick = () => allowUPnP ^= true;
|
UPnPCheckbox.OnClick = () => allowUPnP ^= true;
|
||||||
|
UPnPCheckbox.IsDisabled = () => !Game.Settings.Server.NatDeviceAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateAndJoin()
|
void CreateAndJoin()
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ Container@CREATESERVER_PANEL:
|
|||||||
Y:180
|
Y:180
|
||||||
Width:300
|
Width:300
|
||||||
Height:20
|
Height:20
|
||||||
Text:Allow UPnP port forwarding
|
Text:Automatic port forwarding
|
||||||
Label@EXTERNAL_PORT_LABEL:
|
Label@EXTERNAL_PORT_LABEL:
|
||||||
X:15
|
X:15
|
||||||
Y:219
|
Y:219
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ Background@CREATESERVER_BG:
|
|||||||
Y:165
|
Y:165
|
||||||
Width:300
|
Width:300
|
||||||
Height:20
|
Height:20
|
||||||
Text:Allow UPnP port forwarding
|
Text:Automatic port forwarding
|
||||||
Button@CREATE_BUTTON:
|
Button@CREATE_BUTTON:
|
||||||
X:130
|
X:130
|
||||||
Y:PARENT_BOTTOM - 45
|
Y:PARENT_BOTTOM - 45
|
||||||
|
|||||||
Reference in New Issue
Block a user