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