Copy IP address if possible instead of localhost

This commit is contained in:
drdev
2015-06-06 16:02:14 +00:00
parent fd2b7639c3
commit c876abba66
2 changed files with 10 additions and 7 deletions

View File

@@ -101,7 +101,7 @@ public class NetConnectUtil {
}
public static void copyHostedServerUrl() {
String hostname = "localhost";
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);

View File

@@ -31,7 +31,6 @@ import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@@ -196,14 +195,18 @@ public final class FServerManager {
return null;
}
private void mapNatPort(final int port) {
final String localAddress;
public String getLocalAddress() {
try {
localAddress = InetAddress.getLocalHost().getHostAddress();
} catch (final UnknownHostException e) {
throw new RuntimeException(e);
return InetAddress.getLocalHost().getHostAddress();
}
catch (final Exception e) {
e.printStackTrace();
return "localhost";
}
}
private void mapNatPort(final int port) {
final String localAddress = getLocalAddress();
final PortMapping portMapping = new PortMapping(port, localAddress, PortMapping.Protocol.TCP, "Forge");
if (upnpService != null) {
// Safeguard shutdown call, to prevent lingering port mappings