Merge branch 'network-play' into 'master'

Network play fixes

Closes #396

See merge request core-developers/forge!333
This commit is contained in:
austinio7116
2018-03-30 21:06:05 +00:00
4 changed files with 78 additions and 38 deletions

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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");