You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-18 16:16:35 +09:00
Merge pull request #108 from SimonHartfield/Feature/separate-portforwarding-internal-external-ports
Allow different internal and external ports on port forwarding
This commit is contained in:
@@ -165,7 +165,10 @@ namespace Lidgren.Network
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a forwarding rule to the router using UPnP
|
/// Add a forwarding rule to the router using UPnP
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool ForwardPort(int port, string description)
|
/// <param name="externalPort">The external, WAN facing, port</param>
|
||||||
|
/// <param name="description">A description for the port forwarding rule</param>
|
||||||
|
/// <param name="internalPort">The port on the client machine to send traffic to</param>
|
||||||
|
public bool ForwardPort(int externalPort, string description, int internalPort = 0)
|
||||||
{
|
{
|
||||||
if (!CheckAvailability())
|
if (!CheckAvailability())
|
||||||
return false;
|
return false;
|
||||||
@@ -175,14 +178,17 @@ namespace Lidgren.Network
|
|||||||
if (client == null)
|
if (client == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (internalPort == 0)
|
||||||
|
internalPort = externalPort;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SOAPRequest(m_serviceUrl,
|
SOAPRequest(m_serviceUrl,
|
||||||
"<u:AddPortMapping xmlns:u=\"urn:schemas-upnp-org:service:" + m_serviceName + ":1\">" +
|
"<u:AddPortMapping xmlns:u=\"urn:schemas-upnp-org:service:" + m_serviceName + ":1\">" +
|
||||||
"<NewRemoteHost></NewRemoteHost>" +
|
"<NewRemoteHost></NewRemoteHost>" +
|
||||||
"<NewExternalPort>" + port.ToString() + "</NewExternalPort>" +
|
"<NewExternalPort>" + externalPort.ToString() + "</NewExternalPort>" +
|
||||||
"<NewProtocol>" + ProtocolType.Udp.ToString().ToUpper(System.Globalization.CultureInfo.InvariantCulture) + "</NewProtocol>" +
|
"<NewProtocol>" + ProtocolType.Udp.ToString().ToUpper(System.Globalization.CultureInfo.InvariantCulture) + "</NewProtocol>" +
|
||||||
"<NewInternalPort>" + port.ToString() + "</NewInternalPort>" +
|
"<NewInternalPort>" + internalPort.ToString() + "</NewInternalPort>" +
|
||||||
"<NewInternalClient>" + client.ToString() + "</NewInternalClient>" +
|
"<NewInternalClient>" + client.ToString() + "</NewInternalClient>" +
|
||||||
"<NewEnabled>1</NewEnabled>" +
|
"<NewEnabled>1</NewEnabled>" +
|
||||||
"<NewPortMappingDescription>" + description + "</NewPortMappingDescription>" +
|
"<NewPortMappingDescription>" + description + "</NewPortMappingDescription>" +
|
||||||
@@ -204,7 +210,8 @@ namespace Lidgren.Network
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete a forwarding rule from the router using UPnP
|
/// Delete a forwarding rule from the router using UPnP
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool DeleteForwardingRule(int port)
|
/// <param name="externalPort">The external, 'internet facing', port</param>
|
||||||
|
public bool DeleteForwardingRule(int externalPort)
|
||||||
{
|
{
|
||||||
if (!CheckAvailability())
|
if (!CheckAvailability())
|
||||||
return false;
|
return false;
|
||||||
@@ -215,7 +222,7 @@ namespace Lidgren.Network
|
|||||||
"<u:DeletePortMapping xmlns:u=\"urn:schemas-upnp-org:service:" + m_serviceName + ":1\">" +
|
"<u:DeletePortMapping xmlns:u=\"urn:schemas-upnp-org:service:" + m_serviceName + ":1\">" +
|
||||||
"<NewRemoteHost>" +
|
"<NewRemoteHost>" +
|
||||||
"</NewRemoteHost>" +
|
"</NewRemoteHost>" +
|
||||||
"<NewExternalPort>" + port + "</NewExternalPort>" +
|
"<NewExternalPort>" + externalPort + "</NewExternalPort>" +
|
||||||
"<NewProtocol>" + ProtocolType.Udp.ToString().ToUpper(System.Globalization.CultureInfo.InvariantCulture) + "</NewProtocol>" +
|
"<NewProtocol>" + ProtocolType.Udp.ToString().ToUpper(System.Globalization.CultureInfo.InvariantCulture) + "</NewProtocol>" +
|
||||||
"</u:DeletePortMapping>", "DeletePortMapping");
|
"</u:DeletePortMapping>", "DeletePortMapping");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user