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

View File

@ -1633,7 +1633,7 @@ namespace NovetusLauncher
void CheckBox4Click(object sender, EventArgs e) 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) void Button24Click(object sender, EventArgs e)