From 3efbbc716ed218f122cfcff2d951936dd1632712 Mon Sep 17 00:00:00 2001 From: GGGuenni Date: Tue, 13 Apr 2021 21:57:39 +0200 Subject: [PATCH] Fixed Multiplayer bugs (#3781) * Removed save feature from TurnChecker * Hopefully fixed not correctly updating multiplayer games? * Fixed "refresh list" not updating the savegame correctly * Fixed game update when upload fails * Revert "Fixed game update when upload fails" This reverts commit cc9f1cf589f4dacd97d1e2a31c0cfb66f5e48198. --- android/src/com/unciv/app/MultiplayerTurnCheckWorker.kt | 8 +++++++- core/src/com/unciv/ui/multiplayer/MultiplayerScreen.kt | 9 +++++---- core/src/com/unciv/ui/worldscreen/WorldScreen.kt | 4 +--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/android/src/com/unciv/app/MultiplayerTurnCheckWorker.kt b/android/src/com/unciv/app/MultiplayerTurnCheckWorker.kt index d20fa42f3d..89dd78b9a4 100644 --- a/android/src/com/unciv/app/MultiplayerTurnCheckWorker.kt +++ b/android/src/com/unciv/app/MultiplayerTurnCheckWorker.kt @@ -242,7 +242,13 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame val currentTurnPlayer = game.getCivilization(game.currentPlayer) //Save game so MultiplayerScreen gets updated - GameSaver.saveGame(game, gameNames[arrayIndex], true) + /* + I received multiple reports regarding broken save games. + All of them where missing a few thousand chars at the end of the save game. + I assume this happened because the TurnCheckerWorker gets canceled by the AndroidLauncher + while saves are getting saved right here. + */ + //GameSaver.saveGame(game, gameNames[arrayIndex], true) if (currentTurnPlayer.playerId == inputData.getString(USER_ID)!!) { foundGame = true diff --git a/core/src/com/unciv/ui/multiplayer/MultiplayerScreen.kt b/core/src/com/unciv/ui/multiplayer/MultiplayerScreen.kt index 3e26f6bdb8..1d05a39549 100644 --- a/core/src/com/unciv/ui/multiplayer/MultiplayerScreen.kt +++ b/core/src/com/unciv/ui/multiplayer/MultiplayerScreen.kt @@ -295,15 +295,16 @@ class MultiplayerScreen(previousScreen: CameraStageBaseScreen) : PickerScreen() //One thread for all downloads thread(name = "multiplayerGameDownload") { - for (entry in multiplayerGames) { + for ((fileHandle, gameInfo) in multiplayerGames) { try { - val game = OnlineMultiplayer().tryDownloadGame(entry.value.gameId) - GameSaver.saveGame(game, entry.key.name(), true) + val game = OnlineMultiplayer().tryDownloadGame(gameInfo.gameId) + GameSaver.saveGame(game, fileHandle.name(), true) + multiplayerGames[fileHandle] = game } catch (ex: Exception) { //skipping one is not fatal //Trying to use as many prev. used strings as possible Gdx.app.postRunnable { - ToastPopup("Could not download game!" + " ${entry.key.name()}", this) + ToastPopup("Could not download game!" + " ${fileHandle.name()}", this) } continue } diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index 82b4a63e0f..24dd57e91f 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -242,10 +242,8 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Cam val latestGame = OnlineMultiplayer().tryDownloadGame(gameInfo.gameId) // if we find it still isn't player's turn...nothing changed - if (gameInfo.currentPlayer == latestGame.currentPlayer) { + if (viewingCiv.civName != latestGame.currentPlayer) { Gdx.app.postRunnable { loadingGamePopup.close() } - // edge case - if there's only one player in a multiplayer game, we still check online, but it could be that we were correct and it is our turn - isPlayersTurn = latestGame.currentPlayer == viewingCiv.civName shouldUpdate = true return } else { //else we found it is the player's turn again, turn off polling and load turn