slight upnp improvements/rewrite

This commit is contained in:
Bitl 2020-07-01 15:48:13 -07:00
parent 6ae445a9e0
commit 9ef1586150
3 changed files with 27 additions and 14 deletions

View File

@ -15,7 +15,8 @@ public static class UPnP
{
public static void InitUPnP(EventHandler<DeviceEventArgs> DeviceFound, EventHandler<DeviceEventArgs> DeviceLost)
{
if (GlobalVars.UPnP == true) {
if (GlobalVars.UPnP == true)
{
NatUtility.DeviceFound += DeviceFound;
NatUtility.DeviceLost += DeviceLost;
NatUtility.StartDiscovery();
@ -24,22 +25,34 @@ public static class UPnP
public static void StartUPnP(INatDevice device, Protocol protocol, int port)
{
if (GlobalVars.UPnP == true) {
int map = device.GetSpecificMapping(protocol, port).PublicPort;
if (map == -1) {
device.CreatePortMap(new Mapping(protocol, port, port));
if (GlobalVars.UPnP == true)
{
Mapping checker = device.GetSpecificMapping(protocol, port);
int mapPublic = checker.PublicPort;
int mapPrivate = checker.PrivatePort;
if (mapPublic == -1 && mapPrivate == -1)
{
Mapping portmap = new Mapping(protocol, port, port);
portmap.Description = "Novetus";
device.CreatePortMap(portmap);
}
}
}
public static void StopUPnP(INatDevice device, Protocol protocol, int port)
{
if (GlobalVars.UPnP == true) {
int map = device.GetSpecificMapping(protocol, port).PublicPort;
if (map != -1) {
device.DeletePortMap(new Mapping(protocol, port, port));
if (GlobalVars.UPnP == true)
{
Mapping checker = device.GetSpecificMapping(protocol, port);
int mapPublic = checker.PublicPort;
int mapPrivate = checker.PrivatePort;
if (mapPublic != -1 && mapPrivate != -1)
{
Mapping portmap = new Mapping(protocol, port, port);
portmap.Description = "Novetus";
device.DeletePortMap(portmap);
}
}
}

View File

@ -1660,7 +1660,7 @@ namespace NovetusLauncher
void CheckBox4Click(object sender, EventArgs e)
{
MessageBox.Show("Please restart the Novetus launcher for this option to take effect.","Novetus - UPnP", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("Please restart the Novetus launcher for this option to take effect." + Environment.NewLine + "Make sure to check if your router has UPnP functionality enabled. Please note that some routers may not support UPnP, and some ISPs will block the UPnP protocol. This may not work for all users.","Novetus - UPnP", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
void Button24Click(object sender, EventArgs e)

View File

@ -1633,9 +1633,9 @@ namespace NovetusLauncher
void CheckBox4Click(object sender, EventArgs e)
{
MessageBox.Show("Please restart the Novetus launcher for this option to take effect.","Novetus - UPnP", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("Please restart the Novetus launcher for this option to take effect." + Environment.NewLine + "Make sure to check if your router has UPnP functionality enabled. Please note that some routers may not support UPnP, and some ISPs will block the UPnP protocol. This may not work for all users.", "Novetus - UPnP", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
void Button24Click(object sender, EventArgs e)
{
treeView1.Nodes.Clear();