From 9ef1586150cfc31fb1b09b399af94ffaa1fc3e65 Mon Sep 17 00:00:00 2001 From: Bitl Date: Wed, 1 Jul 2020 15:48:13 -0700 Subject: [PATCH] slight upnp improvements/rewrite --- NovetusLauncher/NovetusFuncs/NetFuncs.cs | 35 +++++++++++++------ .../NovetusLauncher/MainForm/MainForm.cs | 2 +- .../MainForm/MainForm_legacy.cs | 4 +-- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/NovetusLauncher/NovetusFuncs/NetFuncs.cs b/NovetusLauncher/NovetusFuncs/NetFuncs.cs index 956138c..50d615e 100644 --- a/NovetusLauncher/NovetusFuncs/NetFuncs.cs +++ b/NovetusLauncher/NovetusFuncs/NetFuncs.cs @@ -15,7 +15,8 @@ public static class UPnP { public static void InitUPnP(EventHandler DeviceFound, EventHandler 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); } } } diff --git a/NovetusLauncher/NovetusLauncher/MainForm/MainForm.cs b/NovetusLauncher/NovetusLauncher/MainForm/MainForm.cs index b689698..4f5dd12 100644 --- a/NovetusLauncher/NovetusLauncher/MainForm/MainForm.cs +++ b/NovetusLauncher/NovetusLauncher/MainForm/MainForm.cs @@ -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) diff --git a/NovetusLauncher/NovetusLauncher/MainForm/MainForm_legacy.cs b/NovetusLauncher/NovetusLauncher/MainForm/MainForm_legacy.cs index 4b2c14d..d350e38 100644 --- a/NovetusLauncher/NovetusLauncher/MainForm/MainForm_legacy.cs +++ b/NovetusLauncher/NovetusLauncher/MainForm/MainForm_legacy.cs @@ -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();