Better UPNP logging. Also fixes a compile error
This commit is contained in:
committed by
Matthias Mailänder
parent
989c23e632
commit
083d59613a
@@ -26,7 +26,7 @@ namespace OpenRA
|
||||
public static class Log
|
||||
{
|
||||
static string LogPathPrefix = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + Path.DirectorySeparatorChar;
|
||||
static Dictionary<string, ChannelInfo> channels = new Dictionary<string,ChannelInfo>();
|
||||
public static readonly Dictionary<string, ChannelInfo> Channels = new Dictionary<string, ChannelInfo>();
|
||||
|
||||
public static string LogPath
|
||||
{
|
||||
@@ -47,7 +47,7 @@ namespace OpenRA
|
||||
|
||||
public static void AddChannel(string channelName, string baseFilename)
|
||||
{
|
||||
if (channels.ContainsKey(channelName)) return;
|
||||
if (Channels.ContainsKey(channelName)) return;
|
||||
|
||||
foreach (var filename in FilenamesForChannel(channelName, baseFilename))
|
||||
try
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA
|
||||
var writer = File.CreateText(filename);
|
||||
writer.AutoFlush = true;
|
||||
|
||||
channels.Add(channelName,
|
||||
Channels.Add(channelName,
|
||||
new ChannelInfo()
|
||||
{
|
||||
Filename = filename,
|
||||
@@ -70,7 +70,7 @@ namespace OpenRA
|
||||
public static void Write(string channel, string format, params object[] args)
|
||||
{
|
||||
ChannelInfo info;
|
||||
if (!channels.TryGetValue(channel, out info))
|
||||
if (!Channels.TryGetValue(channel, out info))
|
||||
throw new Exception("Tried logging to non-existant channel " + channel);
|
||||
|
||||
info.Writer.WriteLine(format, args);
|
||||
|
||||
@@ -264,14 +264,18 @@ namespace OpenRA
|
||||
Log.AddChannel("sync", "syncreport.log");
|
||||
Log.AddChannel("server", "server.log");
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
NatUtility.Logger = Log.Channels["server"].Writer;
|
||||
NatUtility.Verbose = true;
|
||||
NatUtility.DeviceFound += DeviceFound;
|
||||
NatUtility.DeviceLost += DeviceLost;
|
||||
|
||||
NatUtility.StartDiscovery();
|
||||
OpenRA.Log.Write("server", "NAT discovery started.");
|
||||
} catch (Exception e) {
|
||||
OpenRA.Log.Write("server", "Can't discover UPnP-enabled device: {0}", e);
|
||||
Log.Write("server", "NAT discovery started.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Write("server", "Can't discover UPnP-enabled device: {0}", e);
|
||||
Settings.Server.AllowUPnP = false;
|
||||
}
|
||||
|
||||
@@ -287,27 +291,26 @@ namespace OpenRA
|
||||
InitializeWithMods(Settings.Game.Mods);
|
||||
}
|
||||
|
||||
public static void DeviceFound (object sender, DeviceEventArgs args)
|
||||
public static void DeviceFound(object sender, DeviceEventArgs args)
|
||||
{
|
||||
natDevice = args.Device;
|
||||
|
||||
Log.Write ("server", "NAT device discovered.");
|
||||
Log.Write ("server", "Type: {0}", natDevice.GetType ().Name);
|
||||
Log.Write ("server", "Your external IP is: {0}", natDevice.GetExternalIP ());
|
||||
Log.Write("server", "NAT device discovered.");
|
||||
Log.Write("server", "Type: {0}", natDevice.GetType());
|
||||
Log.Write("server", "Your external IP is: {0}", natDevice.GetExternalIP());
|
||||
|
||||
foreach (Mapping mp in natDevice.GetAllMappings()) {
|
||||
Log.Write ("server", "Existing port mapping: protocol={0}, public={1}, private={2}", mp.Protocol, mp.PublicPort, mp.PrivatePort);
|
||||
}
|
||||
foreach (var mp in natDevice.GetAllMappings())
|
||||
Log.Write("server", "Existing port mapping: protocol={0}, public={1}, private={2}", mp.Protocol, mp.PublicPort, mp.PrivatePort);
|
||||
|
||||
Settings.Server.AllowUPnP = true;
|
||||
}
|
||||
|
||||
public static void DeviceLost (object sender, DeviceEventArgs args)
|
||||
public static void DeviceLost(object sender, DeviceEventArgs args)
|
||||
{
|
||||
natDevice = args.Device;
|
||||
|
||||
Log.Write("server", "NAT device Lost");
|
||||
Log.Write("server", "Type: {0}", natDevice.GetType().Name);
|
||||
Log.Write("server", "Type: {0}", natDevice.GetType());
|
||||
|
||||
Settings.Server.AllowUPnP = false;
|
||||
}
|
||||
|
||||
@@ -68,13 +68,13 @@
|
||||
<Reference Include="SharpFont">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\thirdparty\SharpFont.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Mono.Nat, Version=1.1.0.0, Culture=neutral">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<Private>False</Private>
|
||||
<Package>mono.nat</Package>
|
||||
<HintPath>..\thirdparty\Mono.Nat.dll</HintPath>
|
||||
</Reference>
|
||||
</Reference>
|
||||
<Reference Include="Tao.OpenAl, Version=1.1.0.1, Culture=neutral, PublicKeyToken=a7579dda88828311">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\thirdparty\Tao\Tao.OpenAl.dll</HintPath>
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace OpenRA.Server
|
||||
var timeout = ServerTraits.WithInterface<ITick>().Min(t => t.TickTimeout);
|
||||
for( ; ; )
|
||||
{
|
||||
var checkRead = new ArrayList();
|
||||
var checkRead = new List<Socket>();
|
||||
checkRead.Add( listener.Server );
|
||||
foreach( var c in conns ) checkRead.Add( c.socket );
|
||||
foreach( var c in preConns ) checkRead.Add( c.socket );
|
||||
@@ -140,7 +140,7 @@ namespace OpenRA.Server
|
||||
break;
|
||||
}
|
||||
|
||||
foreach( Socket s in checkRead )
|
||||
foreach( var s in checkRead )
|
||||
if( s == listener.Server ) AcceptConnection();
|
||||
else if (preConns.Count > 0)
|
||||
{
|
||||
@@ -181,13 +181,13 @@ namespace OpenRA.Server
|
||||
{
|
||||
try
|
||||
{
|
||||
Mapping mapping = new Mapping (Protocol.Tcp, Settings.ExternalPort, Settings.ListenPort);
|
||||
var mapping = new Mapping(Protocol.Tcp, Settings.ExternalPort, Settings.ListenPort);
|
||||
NatDevice.CreatePortMap(mapping);
|
||||
Log.Write("server", "Create port mapping: protocol={0}, public={1}, private={2}", mapping.Protocol, mapping.PublicPort, mapping.PrivatePort);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
OpenRA.Log.Write("server", "Can not forward ports via UPnP: {0}", e);
|
||||
Log.Write("server", "Can not forward ports via UPnP: {0}", e);
|
||||
Settings.AllowUPnP = false;
|
||||
}
|
||||
}
|
||||
@@ -196,13 +196,13 @@ namespace OpenRA.Server
|
||||
{
|
||||
try
|
||||
{
|
||||
Mapping mapping = new Mapping (Protocol.Tcp, Settings.ExternalPort, Settings.ListenPort);
|
||||
NatDevice.DeletePortMap (mapping);
|
||||
var mapping = new Mapping(Protocol.Tcp, Settings.ExternalPort, Settings.ListenPort);
|
||||
NatDevice.DeletePortMap(mapping);
|
||||
Log.Write("server", "Remove port mapping: protocol={0}, public={1}, private={2}", mapping.Protocol, mapping.PublicPort, mapping.PrivatePort);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
OpenRA.Log.Write("server", "Can not remove UPnP portforwarding rules: {0}", e);
|
||||
Log.Write("server", "Can not remove UPnP portforwarding rules: {0}", e);
|
||||
Settings.AllowUPnP = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user