mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
Merge branch 'network-play' into 'master'
Network play fixes Closes #396 See merge request core-developers/forge!333
This commit is contained in:
@@ -610,7 +610,14 @@ public final class CMatchUI
|
|||||||
public void updatePhase() {
|
public void updatePhase() {
|
||||||
final PlayerView p = getGameView().getPlayerTurn();
|
final PlayerView p = getGameView().getPlayerTurn();
|
||||||
final PhaseType ph = getGameView().getPhase();
|
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();
|
resetAllPhaseButtons();
|
||||||
if (lbl != null) {
|
if (lbl != null) {
|
||||||
|
|||||||
@@ -79,32 +79,32 @@ public class PhaseIndicator extends JPanel {
|
|||||||
//========== Custom class handling
|
//========== Custom class handling
|
||||||
public PhaseLabel getLabelFor(final PhaseType s) {
|
public PhaseLabel getLabelFor(final PhaseType s) {
|
||||||
switch (s) {
|
switch (s) {
|
||||||
case UPKEEP:
|
case UPKEEP:
|
||||||
return this.getLblUpkeep();
|
return this.getLblUpkeep();
|
||||||
case DRAW:
|
case DRAW:
|
||||||
return this.getLblDraw();
|
return this.getLblDraw();
|
||||||
case MAIN1:
|
case MAIN1:
|
||||||
return this.getLblMain1();
|
return this.getLblMain1();
|
||||||
case COMBAT_BEGIN:
|
case COMBAT_BEGIN:
|
||||||
return this.getLblBeginCombat();
|
return this.getLblBeginCombat();
|
||||||
case COMBAT_DECLARE_ATTACKERS:
|
case COMBAT_DECLARE_ATTACKERS:
|
||||||
return this.getLblDeclareAttackers();
|
return this.getLblDeclareAttackers();
|
||||||
case COMBAT_DECLARE_BLOCKERS:
|
case COMBAT_DECLARE_BLOCKERS:
|
||||||
return this.getLblDeclareBlockers();
|
return this.getLblDeclareBlockers();
|
||||||
case COMBAT_DAMAGE:
|
case COMBAT_DAMAGE:
|
||||||
return this.getLblCombatDamage();
|
return this.getLblCombatDamage();
|
||||||
case COMBAT_FIRST_STRIKE_DAMAGE:
|
case COMBAT_FIRST_STRIKE_DAMAGE:
|
||||||
return this.getLblFirstStrike();
|
return this.getLblFirstStrike();
|
||||||
case COMBAT_END:
|
case COMBAT_END:
|
||||||
return this.getLblEndCombat();
|
return this.getLblEndCombat();
|
||||||
case MAIN2:
|
case MAIN2:
|
||||||
return this.getLblMain2();
|
return this.getLblMain2();
|
||||||
case END_OF_TURN:
|
case END_OF_TURN:
|
||||||
return this.getLblEndTurn();
|
return this.getLblEndTurn();
|
||||||
case CLEANUP:
|
case CLEANUP:
|
||||||
return this.getLblCleanup();
|
return this.getLblCleanup();
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,10 +106,24 @@ public class NetConnectUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void copyHostedServerUrl() {
|
public static void copyHostedServerUrl() {
|
||||||
String hostname = FServerManager.getInstance().getLocalAddress();
|
String internalAddress = FServerManager.getInstance().getLocalAddress();
|
||||||
String url = hostname + ":" + ForgeProfileProperties.getServerPort();
|
String externalAddress = FServerManager.getInstance().getExternalAddress();
|
||||||
GuiBase.getInterface().copyToClipboard(url);
|
String internalUrl = internalAddress + ":" + ForgeProfileProperties.getServerPort();
|
||||||
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 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) {
|
public static ChatMessage join(final String url, final IOnlineLobby onlineLobby, final IOnlineChatInterface chatInterface) {
|
||||||
|
|||||||
@@ -30,13 +30,10 @@ import io.netty.handler.codec.serialization.ObjectEncoder;
|
|||||||
import io.netty.handler.logging.LogLevel;
|
import io.netty.handler.logging.LogLevel;
|
||||||
import io.netty.handler.logging.LoggingHandler;
|
import io.netty.handler.logging.LoggingHandler;
|
||||||
|
|
||||||
import java.net.DatagramSocket;
|
import java.io.BufferedReader;
|
||||||
import java.net.Inet4Address;
|
import java.io.IOException;
|
||||||
import java.net.Inet6Address;
|
import java.io.InputStreamReader;
|
||||||
import java.net.InetAddress;
|
import java.net.*;
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.net.SocketException;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
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) {
|
private void mapNatPort(final int port) {
|
||||||
final String localAddress = getLocalAddress();
|
final String localAddress = getLocalAddress();
|
||||||
final PortMapping portMapping = new PortMapping(port, localAddress, PortMapping.Protocol.TCP, "Forge");
|
final PortMapping portMapping = new PortMapping(port, localAddress, PortMapping.Protocol.TCP, "Forge");
|
||||||
|
|||||||
Reference in New Issue
Block a user