time limit the port forwarding if possible
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
* available to you under the terms of the GNU General Public License
|
* available to you under the terms of the GNU General Public License
|
||||||
* as published by the Free Software Foundation. For more information,
|
* as published by the Free Software Foundation. For more information,
|
||||||
@@ -76,18 +76,27 @@ namespace OpenRA.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ForwardPort()
|
public static void ForwardPort(int lifetime)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var mapping = new Mapping(Protocol.Tcp, Game.Settings.Server.ExternalPort, Game.Settings.Server.ListenPort);
|
var mapping = new Mapping(Protocol.Tcp, Game.Settings.Server.ExternalPort, Game.Settings.Server.ListenPort, lifetime);
|
||||||
NatDevice.CreatePortMap(mapping);
|
NatDevice.CreatePortMap(mapping);
|
||||||
Log.Write("server", "Create port mapping: protocol={0}, public={1}, private={2}", mapping.Protocol, mapping.PublicPort, mapping.PrivatePort);
|
Log.Write("server", "Create port mapping: protocol = {0}, public = {1}, private = {2}, lifetime = {3} s",
|
||||||
|
mapping.Protocol, mapping.PublicPort, mapping.PrivatePort, mapping.Lifetime);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (MappingException e)
|
||||||
{
|
{
|
||||||
Log.Write("server", "Can not forward ports via UPnP: {0}", e);
|
if (e.ErrorCode == 725 && lifetime != 0)
|
||||||
Game.Settings.Server.AllowPortForward = false;
|
{
|
||||||
|
Log.Write("server", "NAT device answered with OnlyPermanentLeasesSupported. Retrying...");
|
||||||
|
ForwardPort(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Write("server", "Can not forward ports via UPnP: {0}", e);
|
||||||
|
Game.Settings.Server.AllowPortForward = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +106,8 @@ namespace OpenRA.Network
|
|||||||
{
|
{
|
||||||
var mapping = new Mapping(Protocol.Tcp, Game.Settings.Server.ExternalPort, Game.Settings.Server.ListenPort);
|
var mapping = new Mapping(Protocol.Tcp, Game.Settings.Server.ExternalPort, Game.Settings.Server.ListenPort);
|
||||||
NatDevice.DeletePortMap(mapping);
|
NatDevice.DeletePortMap(mapping);
|
||||||
Log.Write("server", "Remove port mapping: protocol={0}, public={1}, private={2}", mapping.Protocol, mapping.PublicPort, mapping.PrivatePort);
|
Log.Write("server", "Remove port mapping: protocol = {0}, public = {1}, private = {2}, expiration = {3}",
|
||||||
|
mapping.Protocol, mapping.PublicPort, mapping.PrivatePort, mapping.Expiration);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ namespace OpenRA.Server
|
|||||||
randomSeed = (int)DateTime.Now.ToBinary();
|
randomSeed = (int)DateTime.Now.ToBinary();
|
||||||
|
|
||||||
if (Settings.AllowPortForward)
|
if (Settings.AllowPortForward)
|
||||||
UPnP.ForwardPort();
|
UPnP.ForwardPort(3600);
|
||||||
|
|
||||||
foreach (var trait in modData.Manifest.ServerTraits)
|
foreach (var trait in modData.Manifest.ServerTraits)
|
||||||
serverTraits.Add(modData.ObjectCreator.CreateObject<ServerTrait>(trait));
|
serverTraits.Add(modData.ObjectCreator.CreateObject<ServerTrait>(trait));
|
||||||
|
|||||||
Reference in New Issue
Block a user