From ccff935f7130476421ec1fa6681a89a36f5db427 Mon Sep 17 00:00:00 2001 From: Kenneth VanderLinde Date: Thu, 5 Sep 2024 08:25:06 -0700 Subject: [PATCH 1/3] Use a glass pane instead of dialogs to communicate UPnP scan The dialogs were unstylish and intrusive, constantly stealing focus for no reason. While the glass pane does not mention the specific interfaces being scanned, they will be located in the logs in case it ever matters. Cherry-pick of c58a0654a from release-1.15 branch. --- .../rptools/maptool/server/MapToolServer.java | 10 ++++- .../net/rptools/maptool/util/UPnPUtil.java | 45 ++----------------- .../rptools/maptool/language/i18n.properties | 1 + 3 files changed, 14 insertions(+), 42 deletions(-) diff --git a/src/main/java/net/rptools/maptool/server/MapToolServer.java b/src/main/java/net/rptools/maptool/server/MapToolServer.java index aeac1666e2..c0ed28dc3a 100644 --- a/src/main/java/net/rptools/maptool/server/MapToolServer.java +++ b/src/main/java/net/rptools/maptool/server/MapToolServer.java @@ -32,6 +32,7 @@ import net.rptools.maptool.client.AppConstants; import net.rptools.maptool.client.MapTool; import net.rptools.maptool.client.MapToolRegistry; +import net.rptools.maptool.client.ui.StaticMessageDialog; import net.rptools.maptool.client.ui.connectioninfodialog.ConnectionInfoDialog; import net.rptools.maptool.common.MapToolConstants; import net.rptools.maptool.language.I18N; @@ -388,7 +389,14 @@ public void start() throws IOException { // Use UPnP to open port in router if (useUPnP && config != null) { - UPnPUtil.openPort(config.getPort()); + MapTool.getFrame() + .showFilledGlassPane( + new StaticMessageDialog(I18N.getText("msg.info.server.upnp.discovering"))); + try { + UPnPUtil.openPort(config.getPort()); + } finally { + MapTool.getFrame().hideGlassPane(); + } } // Registered ? diff --git a/src/main/java/net/rptools/maptool/util/UPnPUtil.java b/src/main/java/net/rptools/maptool/util/UPnPUtil.java index c42da3b36c..f4811f30d5 100644 --- a/src/main/java/net/rptools/maptool/util/UPnPUtil.java +++ b/src/main/java/net/rptools/maptool/util/UPnPUtil.java @@ -14,9 +14,6 @@ */ package net.rptools.maptool.util; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.Font; import java.io.IOException; import java.net.Inet4Address; import java.net.InterfaceAddress; @@ -27,13 +24,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.SwingConstants; import net.rptools.maptool.client.AppPreferences; import net.rptools.maptool.client.MapTool; -import net.rptools.maptool.client.swing.SwingUtil; import net.sbbi.upnp.Discovery; import net.sbbi.upnp.impls.InternetGatewayDevice; import net.sbbi.upnp.messages.ActionResponse; @@ -48,34 +40,6 @@ public class UPnPUtil { private static final Logger log = LogManager.getLogger(UPnPUtil.class); private static Map igds; private static List mappings; - private static JDialog dialog = null; - private static JPanel panel = new JPanel(new BorderLayout()); - private static Font labelFont = new Font("Dialog", Font.BOLD, 14); - private static JLabel label = new JLabel("", SwingConstants.CENTER); - - private static void showMessage(String device, String msg) { - if (dialog == null) { - dialog = new JDialog(MapTool.getFrame()); - dialog.setContentPane(panel); - panel.add(label, BorderLayout.CENTER); - label.setFont(labelFont); - } - if (device == null) { - dialog.setVisible(false); - } else { - dialog.setTitle("Scanning device " + device); - label.setText(msg); - - Dimension d = label.getMinimumSize(); - d.width += 50; - d.height += 50; - label.setPreferredSize(d); - - dialog.pack(); - SwingUtil.centerOver(dialog, MapTool.getFrame()); - dialog.setVisible(true); - } - } public static boolean findIGDs() { igds = new HashMap(); @@ -87,17 +51,17 @@ public static boolean findIGDs() { if (ni.isUp() && !ni.isLoopback() && !ni.isVirtual()) { int found = 0; try { - log.info("UPnP: Trying interface {}", ni.getDisplayName()); + log.info( + "UPnP: Looking for gateway devices on interface '{}' [{}]", + ni.getDisplayName(), + addresses); InternetGatewayDevice[] thisNI; - showMessage( - ni.getDisplayName(), "Looking for gateway devices on " + ni.getDisplayName()); thisNI = InternetGatewayDevice.getDevices( AppPreferences.getUpnpDiscoveryTimeout(), Discovery.DEFAULT_TTL, Discovery.DEFAULT_MX, ni); - showMessage(null, null); if (thisNI != null) { for (InternetGatewayDevice igd : thisNI) { found++; @@ -116,7 +80,6 @@ public static boolean findIGDs() { } } } catch (IOException ex) { - showMessage(null, null); // some IO Exception occurred during communication with device log.warn("While searching for internet gateway devices", ex); } diff --git a/src/main/resources/net/rptools/maptool/language/i18n.properties b/src/main/resources/net/rptools/maptool/language/i18n.properties index 4ebff9e42d..9ec4597f3c 100644 --- a/src/main/resources/net/rptools/maptool/language/i18n.properties +++ b/src/main/resources/net/rptools/maptool/language/i18n.properties @@ -2404,6 +2404,7 @@ msg.info.stopWebEndWebPoint = Stopping web end point. # code adds that, if appropriate, based on the situation. msg.info.versionFile = CAN'T FIND VERSION FILE msg.info.assetsDisabled = The GM has disabled insertion of player assets. +msg.info.server.upnp.discovering = Discovering UPnP gateways... msg.title.exportMacro = Export Macro From eb6de1a51868a9625a1a3f87fece19c74e44ec79 Mon Sep 17 00:00:00 2001 From: Kenneth VanderLinde Date: Wed, 11 Sep 2024 23:13:47 -0700 Subject: [PATCH 2/3] Log specific reasons that interfaces may be skipped during UPnP scan Cherry-pick of 4a3d5ade9 from release-1.15 branch. --- .../net/rptools/maptool/util/UPnPUtil.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/rptools/maptool/util/UPnPUtil.java b/src/main/java/net/rptools/maptool/util/UPnPUtil.java index f4811f30d5..9303db187e 100644 --- a/src/main/java/net/rptools/maptool/util/UPnPUtil.java +++ b/src/main/java/net/rptools/maptool/util/UPnPUtil.java @@ -20,6 +20,7 @@ import java.net.NetworkInterface; import java.net.SocketException; import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.List; @@ -48,7 +49,23 @@ public static boolean findIGDs() { while (e.hasMoreElements()) { NetworkInterface ni = e.nextElement(); try { - if (ni.isUp() && !ni.isLoopback() && !ni.isVirtual()) { + var addresses = Collections.list(ni.getInetAddresses()); + if (ni.isLoopback()) { + log.info( + "UPnP: Rejecting interface '{}' [{}] as it is a loopback", + ni.getDisplayName(), + addresses); + } else if (ni.isVirtual()) { + log.info( + "UPnP: Rejecting interface '{}' [{}] as it is virtual", + ni.getDisplayName(), + addresses); + } else if (!ni.isUp()) { + log.info( + "UPnP: Rejecting interface '{}' [{}] as it is not up", + ni.getDisplayName(), + addresses); + } else { int found = 0; try { log.info( From baa89cda93a97bfa7d3a7ab34e27222c77cd6e5d Mon Sep 17 00:00:00 2001 From: Kenneth VanderLinde Date: Wed, 11 Sep 2024 23:14:30 -0700 Subject: [PATCH 3/3] Reject interfaces that have no addresses Cherry-pick of 0ccc67329 from release-1.15 branch. --- src/main/java/net/rptools/maptool/util/UPnPUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/rptools/maptool/util/UPnPUtil.java b/src/main/java/net/rptools/maptool/util/UPnPUtil.java index 9303db187e..984c53cf5f 100644 --- a/src/main/java/net/rptools/maptool/util/UPnPUtil.java +++ b/src/main/java/net/rptools/maptool/util/UPnPUtil.java @@ -50,7 +50,9 @@ public static boolean findIGDs() { NetworkInterface ni = e.nextElement(); try { var addresses = Collections.list(ni.getInetAddresses()); - if (ni.isLoopback()) { + if (addresses.isEmpty()) { + log.info("UPnP: Rejecting interface '{}' as it has no addresses", ni.getDisplayName()); + } else if (ni.isLoopback()) { log.info( "UPnP: Rejecting interface '{}' [{}] as it is a loopback", ni.getDisplayName(),