Support copying url to clipboard when hosting

This commit is contained in:
drdev
2015-06-01 00:54:43 +00:00
parent a2ba32d5fd
commit cceee98a0d
3 changed files with 17 additions and 1 deletions

View File

@@ -65,6 +65,7 @@ public enum CSubmenuOnlineLobby implements ICDoc, IMenuProvider {
if (CHomeUI.SINGLETON_INSTANCE.getCurrentDocID() == EDocID.HOME_NETWORK) { if (CHomeUI.SINGLETON_INSTANCE.getCurrentDocID() == EDocID.HOME_NETWORK) {
VSubmenuOnlineLobby.SINGLETON_INSTANCE.populate(); VSubmenuOnlineLobby.SINGLETON_INSTANCE.populate();
} }
NetConnectUtil.copyHostedServerUrl();
} }
}); });
} }

View File

@@ -60,6 +60,14 @@ public class OnlineLobbyScreen extends LobbyScreen implements IOnlineLobby {
result = NetConnectUtil.host(OnlineLobbyScreen.this, chatInterface); result = NetConnectUtil.host(OnlineLobbyScreen.this, chatInterface);
} }
chatInterface.addMessage(result); chatInterface.addMessage(result);
if (!joinServer) {
FThreads.invokeInBackgroundThread(new Runnable() {
@Override
public void run() {
NetConnectUtil.copyHostedServerUrl();
}
});
}
} }
}); });
} }

View File

@@ -97,7 +97,14 @@ public class NetConnectUtil {
view.update(true); view.update(true);
return String.format("Hosting on port %d", port); return String.format("Hosting on port %d.", port);
}
public static void copyHostedServerUrl() {
String hostname = "localhost";
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);
} }
public static String join(final String url, final IOnlineLobby onlineLobby, final IOnlineChatInterface chatInterface) { public static String join(final String url, final IOnlineLobby onlineLobby, final IOnlineChatInterface chatInterface) {