Changed server connection to URL-based to allow connection to uncivserver.xyz

This commit is contained in:
Yair Morgenstern
2022-03-31 23:03:14 +03:00
parent 279178f103
commit 6315a16d98
6 changed files with 15 additions and 35 deletions

View File

@ -1251,8 +1251,7 @@ Invalid ID! =
# Multiplayer options menu
Current IP address =
Server's IP address =
Server address =
Reset to Dropbox =
Check connection to server =
Awaiting response... =

View File

@ -6,7 +6,6 @@ import com.unciv.UncivGame
import com.unciv.logic.GameInfo
import com.unciv.logic.GameInfoPreview
import com.unciv.logic.GameSaver
import com.unciv.models.metadata.checkMultiplayerServerWithPort
import com.unciv.ui.saves.Gzip
import com.unciv.ui.worldscreen.mainmenu.OptionsPopup
import java.util.*
@ -24,8 +23,7 @@ interface IFileMetaData {
class UncivServerFileStorage(serverIpWithPort:String):IFileStorage {
val serverUrl = "http://$serverIpWithPort"
class UncivServerFileStorage(val serverUrl:String):IFileStorage {
override fun saveFileData(fileName: String, data: String) {
OptionsPopup.SimpleHttp.sendRequest(Net.HttpMethods.PUT, "$serverUrl/files/$fileName", data){
success: Boolean, result: String ->
@ -70,10 +68,7 @@ class OnlineMultiplayer {
val settings = UncivGame.Current.settings
if (settings.multiplayerServer == Constants.dropboxMultiplayerServer)
fileStorage = DropboxFileStorage()
else {
val serverIpWithPort = settings.multiplayerServer.checkMultiplayerServerWithPort()
fileStorage = UncivServerFileStorage(serverIpWithPort)
}
else fileStorage = UncivServerFileStorage(settings.multiplayerServer)
}
fun tryUploadGame(gameInfo: GameInfo, withPreview: Boolean) {

View File

@ -1,7 +0,0 @@
package com.unciv.models.metadata
/** Check the url, if no port, add [defaultPort], then return the url. */
fun String.checkMultiplayerServerWithPort(defaultPort: Int = 8080): String {
return if (contains(":")) this
else "$this:$defaultPort"
}

View File

@ -16,7 +16,6 @@ import com.unciv.UncivGame
import com.unciv.logic.MapSaver
import com.unciv.logic.civilization.PlayerType
import com.unciv.models.UncivSound
import com.unciv.models.metadata.checkMultiplayerServerWithPort
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.Ruleset.RulesetError
import com.unciv.models.ruleset.Ruleset.RulesetErrorSeverity
@ -260,18 +259,17 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
val connectionToServerButton = "Check connection to server".toTextButton()
val ipAddress = getIpAddress()
add("{Current IP address}: $ipAddress".toTextButton().onClick {
Gdx.app.clipboard.contents = ipAddress.toString()
}).row()
val multiplayerServerTextField = TextField(settings.multiplayerServer, BaseScreen.skin)
val textToShowForMultiplayerAddress =
if (settings.multiplayerServer != Constants.dropboxMultiplayerServer) settings.multiplayerServer
else "https://..."
val multiplayerServerTextField = TextField(textToShowForMultiplayerAddress, BaseScreen.skin)
multiplayerServerTextField.programmaticChangeEvents = true
multiplayerServerTextField.width = screen.stage.width / 2
val serverIpTable = Table()
serverIpTable.add("Server's IP address".toLabel().onClick {
serverIpTable.add("Server address".toLabel().onClick {
multiplayerServerTextField.text = Gdx.app.clipboard.contents
}).padRight(10f)
}).row()
multiplayerServerTextField.onChange {
settings.multiplayerServer = multiplayerServerTextField.text
settings.save()
@ -345,7 +343,7 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
}
fun successfullyConnectedToServer(action: (Boolean, String)->Unit){
SimpleHttp.sendGetRequest("http://${settings.multiplayerServer.checkMultiplayerServerWithPort()}/isalive", action)
SimpleHttp.sendGetRequest("${settings.multiplayerServer}/isalive", action)
}
private fun getAdvancedTab() = Table(BaseScreen.skin).apply {

View File

@ -26,7 +26,7 @@ private class UncivServerRunner : CliktCommand() {
"-p", "-port",
envvar = "UncivServerPort",
help = "Server port"
).int().restrictTo(1024..49151).default(8080)
).int().restrictTo(1024..49151).default(80)
private val folder by option(
"-f", "-folder",

View File

@ -22,17 +22,12 @@ Your server has now started!
In Unciv itself, from the same computer, enter Options > Multiplayer.
Click the first text (Current IP address) to copy the IP to the clipboard.
Then, click the second the second (Server IP address) to put your computer's IP in the "Server IP" slot.
Enter the URL of the computer you ran the server on (or http://localhost)
If you click "check connection to server" you should now get "Return result: true", which means it's working!
So far you ran the server and connected yourself to it, but now for the interesting part - connecting other people!
For other devices, you'll need an external IP, which is out of scope for this documentation since there are many ways of achieving it.
The IP should still be in your clipboard - if not, just click the 'copy to clipboard' button again.
Send the IP to the other device, there - copy it, and click 'copy from clipboard'.
You can of course enter the IP manually if that's easier for you.
Click 'check connection' from the new device, and if you got the same result - congratulations, you're both connected to the same server and can start a multiplayer game on the server!
On the other device, do the same - enter the URL, click 'check connection' from the new device, and if you got the same result - congratulations, you're both connected to the same server and can start a multiplayer game on the server!
Please note that devices NOT connected to the same server will NOT be able to participate in multiplayer games together!