You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-19 00:26:30 +09:00
UPnP now also tests for WANPPPConnection; see issue #138
This commit is contained in:
@@ -22,6 +22,7 @@ namespace Lidgren.Network
|
|||||||
private const int c_discoveryTimeOutMillis = 1000;
|
private const int c_discoveryTimeOutMillis = 1000;
|
||||||
|
|
||||||
private string m_serviceUrl;
|
private string m_serviceUrl;
|
||||||
|
private string m_serviceName = "";
|
||||||
private NetPeer m_peer;
|
private NetPeer m_peer;
|
||||||
private ManualResetEvent m_discoveryComplete = new ManualResetEvent(false);
|
private ManualResetEvent m_discoveryComplete = new ManualResetEvent(false);
|
||||||
|
|
||||||
@@ -78,9 +79,18 @@ namespace Lidgren.Network
|
|||||||
XmlNode typen = desc.SelectSingleNode("//tns:device/tns:deviceType/text()", nsMgr);
|
XmlNode typen = desc.SelectSingleNode("//tns:device/tns:deviceType/text()", nsMgr);
|
||||||
if (!typen.Value.Contains("InternetGatewayDevice"))
|
if (!typen.Value.Contains("InternetGatewayDevice"))
|
||||||
return;
|
return;
|
||||||
XmlNode node = desc.SelectSingleNode("//tns:service[tns:serviceType=\"urn:schemas-upnp-org:service:WANIPConnection:1\"]/tns:controlURL/text()", nsMgr);
|
|
||||||
|
m_serviceName = "WANIPConnection";
|
||||||
|
XmlNode node = desc.SelectSingleNode("//tns:service[tns:serviceType=\"urn:schemas-upnp-org:service:" + m_serviceName + ":1\"]/tns:controlURL/text()", nsMgr);
|
||||||
|
if (node == null)
|
||||||
|
{
|
||||||
|
//try another service name
|
||||||
|
m_serviceName = "WANPPPConnection";
|
||||||
|
node = desc.SelectSingleNode("//tns:service[tns:serviceType=\"urn:schemas-upnp-org:service:" + m_serviceName + ":1\"]/tns:controlURL/text()", nsMgr);
|
||||||
if (node == null)
|
if (node == null)
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_serviceUrl = CombineUrls(resp, node.Value);
|
m_serviceUrl = CombineUrls(resp, node.Value);
|
||||||
m_peer.LogDebug("UPnP service ready");
|
m_peer.LogDebug("UPnP service ready");
|
||||||
m_status = UPnPStatus.Available;
|
m_status = UPnPStatus.Available;
|
||||||
@@ -138,8 +148,9 @@ namespace Lidgren.Network
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
XmlDocument xdoc = SOAPRequest(m_serviceUrl,
|
XmlDocument xdoc = SOAPRequest(m_serviceUrl,
|
||||||
"<u:AddPortMapping xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">" +
|
"<u:AddPortMapping xmlns:u=\"urn:schemas-upnp-org:service:" + m_serviceName + ":1\">" +
|
||||||
"<NewRemoteHost></NewRemoteHost><NewExternalPort>" + port.ToString() + "</NewExternalPort>" +
|
"<NewRemoteHost></NewRemoteHost>" +
|
||||||
|
"<NewExternalPort>" + port.ToString() + "</NewExternalPort>" +
|
||||||
"<NewProtocol>" + ProtocolType.Udp.ToString().ToUpper() + "</NewProtocol>" +
|
"<NewProtocol>" + ProtocolType.Udp.ToString().ToUpper() + "</NewProtocol>" +
|
||||||
"<NewInternalPort>" + port.ToString() + "</NewInternalPort>" +
|
"<NewInternalPort>" + port.ToString() + "</NewInternalPort>" +
|
||||||
"<NewInternalClient>" + client.ToString() + "</NewInternalClient>" +
|
"<NewInternalClient>" + client.ToString() + "</NewInternalClient>" +
|
||||||
@@ -171,7 +182,7 @@ namespace Lidgren.Network
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
XmlDocument xdoc = SOAPRequest(m_serviceUrl,
|
XmlDocument xdoc = SOAPRequest(m_serviceUrl,
|
||||||
"<u:DeletePortMapping xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">" +
|
"<u:DeletePortMapping xmlns:u=\"urn:schemas-upnp-org:service:" + m_serviceName + ":1\">" +
|
||||||
"<NewRemoteHost>" +
|
"<NewRemoteHost>" +
|
||||||
"</NewRemoteHost>" +
|
"</NewRemoteHost>" +
|
||||||
"<NewExternalPort>" + port + "</NewExternalPort>" +
|
"<NewExternalPort>" + port + "</NewExternalPort>" +
|
||||||
@@ -195,7 +206,7 @@ namespace Lidgren.Network
|
|||||||
return null;
|
return null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
XmlDocument xdoc = SOAPRequest(m_serviceUrl, "<u:GetExternalIPAddress xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">" +
|
XmlDocument xdoc = SOAPRequest(m_serviceUrl, "<u:GetExternalIPAddress xmlns:u=\"urn:schemas-upnp-org:service:" + m_serviceName + ":1\">" +
|
||||||
"</u:GetExternalIPAddress>", "GetExternalIPAddress");
|
"</u:GetExternalIPAddress>", "GetExternalIPAddress");
|
||||||
XmlNamespaceManager nsMgr = new XmlNamespaceManager(xdoc.NameTable);
|
XmlNamespaceManager nsMgr = new XmlNamespaceManager(xdoc.NameTable);
|
||||||
nsMgr.AddNamespace("tns", "urn:schemas-upnp-org:device-1-0");
|
nsMgr.AddNamespace("tns", "urn:schemas-upnp-org:device-1-0");
|
||||||
@@ -220,7 +231,7 @@ namespace Lidgren.Network
|
|||||||
WebRequest r = HttpWebRequest.Create(url);
|
WebRequest r = HttpWebRequest.Create(url);
|
||||||
r.Method = "POST";
|
r.Method = "POST";
|
||||||
byte[] b = System.Text.Encoding.UTF8.GetBytes(req);
|
byte[] b = System.Text.Encoding.UTF8.GetBytes(req);
|
||||||
r.Headers.Add("SOAPACTION", "\"urn:schemas-upnp-org:service:WANIPConnection:1#" + function + "\"");
|
r.Headers.Add("SOAPACTION", "\"urn:schemas-upnp-org:service:" + m_serviceName + ":1#" + function + "\"");
|
||||||
r.ContentType = "text/xml; charset=\"utf-8\"";
|
r.ContentType = "text/xml; charset=\"utf-8\"";
|
||||||
r.ContentLength = b.Length;
|
r.ContentLength = b.Length;
|
||||||
r.GetRequestStream().Write(b, 0, b.Length);
|
r.GetRequestStream().Write(b, 0, b.Length);
|
||||||
|
|||||||
Reference in New Issue
Block a user