New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vpn/proxy issues when creating new mp game #6715
Conversation
replaced redundant ping with opening a connection to dropbox to fix the proxy issue
firstly, I think I suggested that you use |
I suggest this changes!!! |
I'll change it now but
not sure how to check for that |
Did you check my pr in your fork? |
check multiplayerServer url if the user is playing on it
I did and merged it, thanks ! |
Looks good from my I-don't-know-anything-about-Kotlin point of view. |
Lol. I used https://play.kotlinlang.org & https://www.google.com to test some assumed lines of kotlin code and checked if those worked before doing these commits. I know I used to say that. I will change 'anything' to 'much' from now on maybe. 🤣 I saw a YouTube video on Kotlin basics months ago. Maybe I should add that too. |
yeah I never wrote Kotlin before committing to this repo, I just assumed its somewhat similar to java and so far it seems to be. (more like python variables combined with java but yeah) :)) |
Kotlin is an Island and a language. Java is an Island and a language. Intentional. The Kotlin compiler emits Java VM bytecode - unless a different backend is used. |
if connected to proxy but no internet access it will freeze for a couple seconds (until it finishes the for loop) but it works
This new code looks a lot of sus to me. How does it work? |
Also if internet is not working shouldn’t the previous changes be enough to check it? Or is the previous version is not enough to detect proxy? |
well its the code that runs on desktop, but I'm not sure why it freezes.
No, the previous version was not working when connected to proxy |
So I could remove the SDK code. That would make the function identical to the desktop one so It could be moved back to NewGameScreen to avoid duplicate code? Or leave it in PlatformSpecificHelpers? I kept it there in case that fails, so that it continues to the SDK code, but I probably should have added another try-catch inside that one. Might be redundant though, so what do you think? Keep the android SDK code or get rid of it? And if the latter should I move isInternetConnected() out of the platform specific stuff and move it in NewGameScreen where its being used? |
Probably something that runs on both is better. Android Specific codes are a problem. Also if the previous changes then Unciv shouldn’t work on proxy in the first place. URL comes directly from Java so i don't get why it wouldn’t work. |
Maybe check Dropbox codes and use the network utilities used there? They should work regardless of platform a they are already working properly currently right? |
@@ -34,13 +36,23 @@ Sources for Info about current orientation in case need: | |||
} | |||
|
|||
override fun isInternetConnected(): Boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're changing this to not only check internet connectivity, there are actually 2 fail states and so A. the function name should be changed (checkConnectionToMultiplayerServer or something) and B. we should tell the user if it's a problem with his internet or the server itself, so either return a fail string or an enum or something.
This also means we can keep the already-translated line of "No internet connection!" and just add another translation line of "The server is unreachable" or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I'm gonna split the 2 in 2 separate functions
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 | ||
} | ||
|
||
true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And obviously this should be first.
First check if we even have internet, if no - failure A.
Then check if we can reach server - if no, failure B.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried with that first but the code fails (the freeze is back)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And obviously this should be first.
First check if we even have internet, if no - failure A.
Then check if we can reach server - if no, failure B.
I think alex said that even after doing a connection check to the server, if the client is connected to the a proxy / vpn URL.connect doesn't work (?)
So, if B always fails ob Proxy, doing it before A is pointless.
ignore my last commit :) |
Sorry, in its current state I'd call this a no-go, wrong design.
Ah, parallel comments & commits, OK pick what's still relevant. |
removed frunctions from PlatformSpecificHelpers__
so I guess its good where it is now (next to the invalid ID code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simplify and redo it!!
@@ -73,7 +73,7 @@ class NewGameScreen( | |||
if (gameSetupInfo.gameParameters.isOnlineMultiplayer) { | |||
if (UncivGame.Current.platformSpecificHelper?.isInternetConnected() != true) { | |||
val noInternetConnectionPopup = Popup(this) | |||
noInternetConnectionPopup.addGoodSizedLabel("No internet connection!".tr()).row() | |||
noInternetConnectionPopup.addGoodSizedLabel("No connection to internet or dropbox!".tr()).row() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe Just Couldn't connect to the Server
would do?
noInternetConnectionPopup.addGoodSizedLabel("No connection to internet or dropbox!".tr()).row() | |
noInternetConnectionPopup.addGoodSizedLabel("Couldn't connect to the Server!".tr()).row() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SomeTroglodyte what do you think?
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 | ||
} | ||
|
||
true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And obviously this should be first.
First check if we even have internet, if no - failure A.
Then check if we can reach server - if no, failure B.
I think alex said that even after doing a connection check to the server, if the client is connected to the a proxy / vpn URL.connect doesn't work (?)
So, if B always fails ob Proxy, doing it before A is pointless.
return try { | ||
val u = URL(UncivGame.Current.settings.multiplayerServer) | ||
val conn = u.openConnection() | ||
conn.connect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to java docs, openConnection()
and connect()
is used like this:
- The connection object is created by invoking the openConnection method on a URL.
- The setup parameters and general request properties are manipulated.
- The actual connection to the remote object is made, using the connect method.
- The remote object becomes available. The header fields and the contents of the remote object can be accessed.
So basically openConnection()
makes a connection object and connect()
connects to the server and makes the remote resouces available for further requests?
So basically java allows you to make a URLConnection
object, modify it and then do actual network operations with connect()
. There also seems to a property called connected
that stores boolean values of a connection.
So, I guess proper way to do this would be something like
URL().openConnection().setTimeout(5000).connect()
Also it's unnecessary to ping any specific url since we are only checking the connection. But isalive
would be better I guess since it sends less data.
@alexban011 I think I have found the correct way to do this. See this:
So, I think something like this would do: import java.net.URL
import com.unciv.Constants
import com.unciv.UncivGame
private fun isConnectionToServerPossible(): Boolean {
return try {
val multiplayerServer = UncivGame.Current.settings.multiplayerServer
val isDropbox = multiplayerServer == Constants.dropboxMultiplayerServer
val u = URL(if (isDropbox) "https://content.dropboxapi.com" else multiplayerServer)
val con = u.openConnection()
con.setConnectTimeout(5000)
con.connect()
true
} catch(ex: Throwable) {
val noInternetConnectionPopup = Popup(this)
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
false
}
} |
Just tried it on android and it seems to work did you tested it on the Pi? |
I can't compile the source for reasons. Give me a jar to test. |
I'm trying. I'm getting this: I'll try reinstalling the JDK as people on forums said this should solve this Sending it now |
Sorry for mediafire link, I have no clue how else to send it: |
You're lucky (or maybe unlucky) there seems to be no actual user with that name around, or you would have spammed them. And the jar location is in the wiki not far under the |
otnolatrnup.com, doubleclick.net and aaxads.com are all quite malicious. do not visit without a good blocker. |
I made sure I'm not pinging anyone when I sent that :)) |
So now it works on Windows and Android even with proxy (both Mobile Hotspot and 1.1.1.1 vpn). Now the "Couldn't connect to Dropbox!" makes more sense than the old "No internet connection!", but should I change it back to the old one to keep the translation or keep the new one as its more informative of what the issue is? |
Last commit is just cleanup and I replaced the setConnectionTimeout because it was giving a warning. Also I set the timeout to 3000 instead of 5000 since if the server doesn't respond in 3 seconds I really doubt it will in 5. |
Never pull updates in a branch!!! But only in master / main. |
|
||
override fun isInternetConnected(): Boolean { | ||
return try { | ||
InetAddress.getByName("8.8.8.8").isReachable(500) // Parameter timeout in milliseconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sigh could it be that this is the reason why my checks always failed on Pi?
Proxy increases latency by a good margin and 500 is really not enough.
It is not enough even without proxy. And will fail 5-10% of times.
Who even sets timeout to only 0.5 seconds, I am astonished that nobody pointed this out.
Noted. |
Sorry or not I can't even download it. |
@alexban011 use this https://www.file.io/ |
@alexban011 I tested your jar and it works fine on raspberry pi This pr got too big, maybe open a new one with clear & concise changes? |
yeah I was thinking about that. I'll do it now |
Disagree. There are some very valid reasons to do so. Own work in two+ studio installations, or testing someone's branch and they pushed, or mixing features to see if they work together....... .. or maybe you meant "from yairm210/master"? That I don't do but even that could work if you know what you're doing - it'll start a merge. |
Merge branch 'yairm210:master' into master-proxyIssues I said that cause I don't like this kind of commits.
Yeah that also. For starters you would like them to start clean. After a while they would understand these things anyways. |
Then a wording like "Never" gives a misleading impression, the sentence was an imperative. With three Char(0x21) to boot. Simply "I never..." would have hit the mark, right? Online, culture barriers and so on, be careful.. |
resolves #6709, resolves #6649 by opening a connection to dropbox when starting a new mp game
Tested on windows and linux (Zorin OS). Seems to be working now.
I removed the redundant ping and replaced it with opening a connection to dropbox
I've also fixed the unnecessary commits and will close the other PR