diff --git a/android/src/com/unciv/app/PlatformSpecificHelpersAndroid.kt b/android/src/com/unciv/app/PlatformSpecificHelpersAndroid.kt index e91431d72d..8746b845b6 100644 --- a/android/src/com/unciv/app/PlatformSpecificHelpersAndroid.kt +++ b/android/src/com/unciv/app/PlatformSpecificHelpersAndroid.kt @@ -1,10 +1,7 @@ package com.unciv.app import android.app.Activity -import android.content.Context import android.content.pm.ActivityInfo -import android.net.ConnectivityManager -import android.net.NetworkCapabilities import com.unciv.ui.utils.GeneralPlatformSpecificHelpers /** See also interface [GeneralPlatformSpecificHelpers]. @@ -32,15 +29,4 @@ Sources for Info about current orientation in case need: // Comparison ensures ActivityTaskManager.getService().setRequestedOrientation isn't called unless necessary if (activity.requestedOrientation != orientation) activity.requestedOrientation = orientation } - - override fun isInternetConnected(): Boolean { - val connectivityManager = activity.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager - for (network in connectivityManager.allNetworks) { - val networkCapabilities = connectivityManager.getNetworkCapabilities(network) ?: continue - val isInternet = networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) - val info = connectivityManager.getNetworkInfo(network) ?: continue - if (isInternet && info.isConnected) return true - } - return false - } } diff --git a/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt b/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt index feefc5033d..cbf0b7338a 100644 --- a/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt +++ b/core/src/com/unciv/ui/newgamescreen/NewGameScreen.kt @@ -11,18 +11,19 @@ import com.unciv.UncivGame import com.unciv.logic.* import com.unciv.logic.civilization.PlayerType import com.unciv.logic.map.MapType +import com.unciv.logic.multiplayer.OnlineMultiplayer import com.unciv.models.metadata.GameSetupInfo import com.unciv.models.ruleset.RulesetCache import com.unciv.models.translations.tr -import com.unciv.ui.pickerscreens.PickerScreen -import com.unciv.ui.utils.* -import com.unciv.logic.multiplayer.OnlineMultiplayer import com.unciv.ui.crashhandling.crashHandlingThread import com.unciv.ui.crashhandling.postCrashHandlingRunnable import com.unciv.ui.images.ImageGetter +import com.unciv.ui.pickerscreens.PickerScreen import com.unciv.ui.popup.Popup import com.unciv.ui.popup.ToastPopup import com.unciv.ui.popup.YesNoPopup +import com.unciv.ui.utils.* +import java.net.URL import java.util.* import com.unciv.ui.utils.AutoScrollPane as ScrollPane @@ -71,13 +72,16 @@ class NewGameScreen( rightSideButton.setText("Start game!".tr()) rightSideButton.onClick { if (gameSetupInfo.gameParameters.isOnlineMultiplayer) { - if (UncivGame.Current.platformSpecificHelper?.isInternetConnected() != true) { + val isDropbox = UncivGame.Current.settings.multiplayerServer == Constants.dropboxMultiplayerServer + if (!checkConnectionToMultiplayerServer()) { val noInternetConnectionPopup = Popup(this) - noInternetConnectionPopup.addGoodSizedLabel("No internet connection!".tr()).row() + val label = if (isDropbox) "Couldn't connect to Dropbox!" else "Couldn't connect to Multiplayer Server!" + noInternetConnectionPopup.addGoodSizedLabel(label.tr()).row() noInternetConnectionPopup.addCloseButton() noInternetConnectionPopup.open() return@onClick } + for (player in gameSetupInfo.gameParameters.players.filter { it.playerType == PlayerType.Human }) { try { UUID.fromString(IdChecker.checkAndReturnPlayerUuid(player.playerId)) @@ -206,6 +210,21 @@ class NewGameScreen( }).expandX().fillX().row() } + private fun checkConnectionToMultiplayerServer(): Boolean { + val isDropbox = UncivGame.Current.settings.multiplayerServer == Constants.dropboxMultiplayerServer + return try { + val multiplayerServer = UncivGame.Current.settings.multiplayerServer + val u = URL(if (isDropbox) "https://content.dropboxapi.com" else multiplayerServer) + val con = u.openConnection() + con.connectTimeout = 3000 + con.connect() + + true + } catch(ex: Throwable) { + false + } + } + private fun newGameThread() { val newGame:GameInfo try { diff --git a/core/src/com/unciv/ui/utils/GeneralPlatformSpecificHelpers.kt b/core/src/com/unciv/ui/utils/GeneralPlatformSpecificHelpers.kt index 0680ab4bb4..acc2a3d493 100644 --- a/core/src/com/unciv/ui/utils/GeneralPlatformSpecificHelpers.kt +++ b/core/src/com/unciv/ui/utils/GeneralPlatformSpecificHelpers.kt @@ -13,8 +13,6 @@ interface GeneralPlatformSpecificHelpers { */ fun allowPortrait(allow: Boolean) {} - fun isInternetConnected(): Boolean - /** * Notifies the user that it's their turn while the game is running */ diff --git a/desktop/src/com/unciv/app/desktop/PlatformSpecificHelpersDesktop.kt b/desktop/src/com/unciv/app/desktop/PlatformSpecificHelpersDesktop.kt index 8e4da875cd..490487e32b 100644 --- a/desktop/src/com/unciv/app/desktop/PlatformSpecificHelpersDesktop.kt +++ b/desktop/src/com/unciv/app/desktop/PlatformSpecificHelpersDesktop.kt @@ -2,20 +2,11 @@ package com.unciv.app.desktop import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration import com.unciv.ui.utils.GeneralPlatformSpecificHelpers -import java.net.InetAddress class PlatformSpecificHelpersDesktop(config: Lwjgl3ApplicationConfiguration) : GeneralPlatformSpecificHelpers { val turnNotifier = MultiplayerTurnNotifierDesktop() init { - config.setWindowListener(turnNotifier); - } - - override fun isInternetConnected(): Boolean { - return try { - InetAddress.getByName("8.8.8.8").isReachable(500) // Parameter timeout in milliseconds - } catch (ex: Throwable) { - false - } + config.setWindowListener(turnNotifier) } override fun notifyTurnStarted() {