From 434573a5f8c72b05fd8674c681cc65f9d6e7f801 Mon Sep 17 00:00:00 2001 From: "Jamin W. Collins" Date: Fri, 30 Mar 2018 08:11:50 -0600 Subject: [PATCH 1/3] reflow the PhaseIndicator switch statement Signed-off-by: Jamin W. Collins --- .../forge/toolbox/special/PhaseIndicator.java | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/forge-gui-desktop/src/main/java/forge/toolbox/special/PhaseIndicator.java b/forge-gui-desktop/src/main/java/forge/toolbox/special/PhaseIndicator.java index fbbb46361a2..35122903d81 100644 --- a/forge-gui-desktop/src/main/java/forge/toolbox/special/PhaseIndicator.java +++ b/forge-gui-desktop/src/main/java/forge/toolbox/special/PhaseIndicator.java @@ -79,32 +79,32 @@ public class PhaseIndicator extends JPanel { //========== Custom class handling public PhaseLabel getLabelFor(final PhaseType s) { switch (s) { - case UPKEEP: - return this.getLblUpkeep(); - case DRAW: - return this.getLblDraw(); - case MAIN1: - return this.getLblMain1(); - case COMBAT_BEGIN: - return this.getLblBeginCombat(); - case COMBAT_DECLARE_ATTACKERS: - return this.getLblDeclareAttackers(); - case COMBAT_DECLARE_BLOCKERS: - return this.getLblDeclareBlockers(); - case COMBAT_DAMAGE: - return this.getLblCombatDamage(); - case COMBAT_FIRST_STRIKE_DAMAGE: - return this.getLblFirstStrike(); - case COMBAT_END: - return this.getLblEndCombat(); - case MAIN2: - return this.getLblMain2(); - case END_OF_TURN: - return this.getLblEndTurn(); - case CLEANUP: - return this.getLblCleanup(); - default: - return null; + case UPKEEP: + return this.getLblUpkeep(); + case DRAW: + return this.getLblDraw(); + case MAIN1: + return this.getLblMain1(); + case COMBAT_BEGIN: + return this.getLblBeginCombat(); + case COMBAT_DECLARE_ATTACKERS: + return this.getLblDeclareAttackers(); + case COMBAT_DECLARE_BLOCKERS: + return this.getLblDeclareBlockers(); + case COMBAT_DAMAGE: + return this.getLblCombatDamage(); + case COMBAT_FIRST_STRIKE_DAMAGE: + return this.getLblFirstStrike(); + case COMBAT_END: + return this.getLblEndCombat(); + case MAIN2: + return this.getLblMain2(); + case END_OF_TURN: + return this.getLblEndTurn(); + case CLEANUP: + return this.getLblCleanup(); + default: + return null; } } From 35d0e73901e6204bf6e7c52f1168259229e598c8 Mon Sep 17 00:00:00 2001 From: "Jamin W. Collins" Date: Fri, 30 Mar 2018 08:20:34 -0600 Subject: [PATCH 2/3] handle null response from getPhase() Signed-off-by: Jamin W. Collins --- .../src/main/java/forge/screens/match/CMatchUI.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java b/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java index a002d398f28..79c88aa75fb 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java +++ b/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java @@ -610,7 +610,14 @@ public final class CMatchUI public void updatePhase() { final PlayerView p = getGameView().getPlayerTurn(); final PhaseType ph = getGameView().getPhase(); - final PhaseLabel lbl = p == null ? null : getFieldViewFor(p).getPhaseIndicator().getLabelFor(ph); + // this should never happen, but I've seen it periodically... so, need to get to the bottom of it + PhaseLabel lbl = null; + if (ph != null ) { + lbl = p == null ? null : getFieldViewFor(p).getPhaseIndicator().getLabelFor(ph); + } else { + // not sure what debugging information would help here, log for now + System.err.println("getGameView().getPhase() returned 'null'"); + } resetAllPhaseButtons(); if (lbl != null) { From 2f5a83e171f567fb27f5ead1dbc7d5b7e0916efc Mon Sep 17 00:00:00 2001 From: "Jamin W. Collins" Date: Fri, 30 Mar 2018 08:37:17 -0600 Subject: [PATCH 3/3] Show external IP when hosting, if possible Fixes: core-developers/forge#396 Signed-off-by: Jamin W. Collins --- .../main/java/forge/net/NetConnectUtil.java | 22 ++++++++++--- .../java/forge/net/server/FServerManager.java | 33 +++++++++++++++---- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/forge-gui/src/main/java/forge/net/NetConnectUtil.java b/forge-gui/src/main/java/forge/net/NetConnectUtil.java index cf1e624a423..3e3cdf8e28b 100644 --- a/forge-gui/src/main/java/forge/net/NetConnectUtil.java +++ b/forge-gui/src/main/java/forge/net/NetConnectUtil.java @@ -106,10 +106,24 @@ public class NetConnectUtil { } public static void copyHostedServerUrl() { - String hostname = FServerManager.getInstance().getLocalAddress(); - String url = hostname + ":" + ForgeProfileProperties.getServerPort(); - GuiBase.getInterface().copyToClipboard(url); - SOptionPane.showMessageDialog("Share the following URL with anyone who wishes to join your server. It has been copied to your clipboard for convenience.\n\n" + url, "Server URL", SOptionPane.INFORMATION_ICON); + String internalAddress = FServerManager.getInstance().getLocalAddress(); + String externalAddress = FServerManager.getInstance().getExternalAddress(); + String internalUrl = internalAddress + ":" + ForgeProfileProperties.getServerPort(); + String externalUrl = null; + if (externalAddress != null) { + externalUrl = externalAddress + ":" + ForgeProfileProperties.getServerPort(); + GuiBase.getInterface().copyToClipboard(externalUrl); + } else { + GuiBase.getInterface().copyToClipboard(internalAddress); + } + + String message = "Share the following URL with anyone who wishes to join your server. It has been copied to your clipboard for convenience.\n\n"; + if (externalUrl != null) { + message += externalUrl + "\n\nFor internal games, use the following URL: " + internalUrl; + } else { + message = "Forge was unable to determine your external IP!\n\n" + message + internalUrl; + } + SOptionPane.showMessageDialog(message, "Server URL", SOptionPane.INFORMATION_ICON); } public static ChatMessage join(final String url, final IOnlineLobby onlineLobby, final IOnlineChatInterface chatInterface) { diff --git a/forge-gui/src/main/java/forge/net/server/FServerManager.java b/forge-gui/src/main/java/forge/net/server/FServerManager.java index c5af180361c..fad16bfb982 100644 --- a/forge-gui/src/main/java/forge/net/server/FServerManager.java +++ b/forge-gui/src/main/java/forge/net/server/FServerManager.java @@ -30,13 +30,10 @@ import io.netty.handler.codec.serialization.ObjectEncoder; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import java.net.DatagramSocket; -import java.net.Inet4Address; -import java.net.Inet6Address; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.net.UnknownHostException; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.*; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; @@ -253,6 +250,28 @@ public final class FServerManager { } } + public static String getExternalAddress() { + BufferedReader in = null; + try { + URL whatismyip = new URL("http://checkip.amazonaws.com"); + in = new BufferedReader(new InputStreamReader( + whatismyip.openStream())); + String ip = in.readLine(); + return ip; + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return null; + } + private void mapNatPort(final int port) { final String localAddress = getLocalAddress(); final PortMapping portMapping = new PortMapping(port, localAddress, PortMapping.Protocol.TCP, "Forge");