mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 14:24:43 -04:00
Fix multiplayer turn checker potentially stopping turn checks for everyone that plays that game if a file was not found remotely (#6901)
This commit is contained in:
parent
244f9477df
commit
f34b97a421
@ -190,11 +190,9 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame
|
|||||||
for (gameFile in gameFiles) {
|
for (gameFile in gameFiles) {
|
||||||
try {
|
try {
|
||||||
val gamePreview = gameSaver.loadGamePreviewFromFile(gameFile)
|
val gamePreview = gameSaver.loadGamePreviewFromFile(gameFile)
|
||||||
if (gamePreview.turnNotification) {
|
gameIds[count] = gamePreview.gameId
|
||||||
gameIds[count] = gamePreview.gameId
|
gameNames[count] = gameFile.name()
|
||||||
gameNames[count] = gameFile.name()
|
count++
|
||||||
count++
|
|
||||||
}
|
|
||||||
} catch (ex: Throwable) {
|
} catch (ex: Throwable) {
|
||||||
//only loadGamePreviewFromFile can throw an exception
|
//only loadGamePreviewFromFile can throw an exception
|
||||||
//nothing will be added to the arrays if it fails
|
//nothing will be added to the arrays if it fails
|
||||||
@ -207,9 +205,8 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame
|
|||||||
if (currentGameInfo.currentPlayerCiv.playerId == settings.userId) {
|
if (currentGameInfo.currentPlayerCiv.playerId == settings.userId) {
|
||||||
// May be useful to remind a player that he forgot to complete his turn.
|
// May be useful to remind a player that he forgot to complete his turn.
|
||||||
val gameIndex = gameIds.indexOf(currentGameInfo.gameId)
|
val gameIndex = gameIds.indexOf(currentGameInfo.gameId)
|
||||||
// Of the turnNotification is OFF, this will be -1 since we never saved this game in the array
|
// If reading the preview file threw an exception, gameIndex will be -1
|
||||||
// Or possibly reading the preview file returned an exception
|
if (gameIndex != -1) {
|
||||||
if (gameIndex!=-1) {
|
|
||||||
notifyUserAboutTurn(applicationContext, Pair(gameNames[gameIndex], gameIds[gameIndex]))
|
notifyUserAboutTurn(applicationContext, Pair(gameNames[gameIndex], gameIds[gameIndex]))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -252,6 +249,12 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains gameIds that, if true is set for them, we will not check for updates again. The data here only lives until the user enters Unciv again,
|
||||||
|
* so if the user changes their remote server, this will be reset and we will check for turns again.
|
||||||
|
*/
|
||||||
|
private val notFoundRemotely = mutableMapOf<String, Boolean>()
|
||||||
|
|
||||||
private val gameSaver = GameSaver
|
private val gameSaver = GameSaver
|
||||||
init {
|
init {
|
||||||
// We can't use Gdx.files since that is only initialized within a com.badlogic.gdx.backends.android.AndroidApplication.
|
// We can't use Gdx.files since that is only initialized within a com.badlogic.gdx.backends.android.AndroidApplication.
|
||||||
@ -282,6 +285,11 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame
|
|||||||
if (gameId.isEmpty())
|
if (gameId.isEmpty())
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if (notFoundRemotely[gameId] == true) {
|
||||||
|
// Since the save was not found on the remote server, we do not need to check again, it'll only fail again.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Log.d(LOG_TAG, "doWork download ${gameId}")
|
Log.d(LOG_TAG, "doWork download ${gameId}")
|
||||||
val gamePreview = OnlineMultiplayerGameSaver(fileStorage).tryDownloadGamePreview(gameId)
|
val gamePreview = OnlineMultiplayerGameSaver(fileStorage).tryDownloadGamePreview(gameId)
|
||||||
@ -313,9 +321,7 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame
|
|||||||
// FileNotFoundException is thrown by OnlineMultiplayer().tryDownloadGamePreview(gameId)
|
// FileNotFoundException is thrown by OnlineMultiplayer().tryDownloadGamePreview(gameId)
|
||||||
// and indicates that there is no game preview present for this game
|
// and indicates that there is no game preview present for this game
|
||||||
// in the dropbox so we should not check for this game in the future anymore
|
// in the dropbox so we should not check for this game in the future anymore
|
||||||
val currentGamePreview = gameSaver.loadGamePreviewByName(gameNames[arrayIndex])
|
notFoundRemotely[gameId] = true
|
||||||
currentGamePreview.turnNotification = false
|
|
||||||
gameSaver.saveGame(currentGamePreview, gameNames[arrayIndex])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,7 +502,6 @@ class GameInfoPreview() {
|
|||||||
var gameId = ""
|
var gameId = ""
|
||||||
var currentPlayer = ""
|
var currentPlayer = ""
|
||||||
var currentTurnStartTime = 0L
|
var currentTurnStartTime = 0L
|
||||||
var turnNotification = true //used as setting in the MultiplayerScreen
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a GameInfo object (can be uninitialized) into a GameInfoPreview object.
|
* Converts a GameInfo object (can be uninitialized) into a GameInfoPreview object.
|
||||||
@ -519,32 +518,4 @@ class GameInfoPreview() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getCivilization(civName: String) = civilizations.first { it.civName == civName }
|
fun getCivilization(civName: String) = civilizations.first { it.civName == civName }
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the current player and turn information in the GameInfoPreview object with the help of a
|
|
||||||
* GameInfo object (can be uninitialized).
|
|
||||||
*/
|
|
||||||
fun updateCurrentTurn(gameInfo: GameInfo) : GameInfoPreview {
|
|
||||||
currentPlayer = gameInfo.currentPlayer
|
|
||||||
turns = gameInfo.turns
|
|
||||||
currentTurnStartTime = gameInfo.currentTurnStartTime
|
|
||||||
//We update the civilizations in case someone is removed from the game (resign/kick)
|
|
||||||
civilizations = gameInfo.getCivilizationsAsPreviews()
|
|
||||||
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the current player and turn information in the GameInfoPreview object with the
|
|
||||||
* help of another GameInfoPreview object.
|
|
||||||
*/
|
|
||||||
fun updateCurrentTurn(gameInfo: GameInfoPreview) : GameInfoPreview {
|
|
||||||
currentPlayer = gameInfo.currentPlayer
|
|
||||||
turns = gameInfo.turns
|
|
||||||
currentTurnStartTime = gameInfo.currentTurnStartTime
|
|
||||||
//We update the civilizations in case someone is removed from the game (resign/kick)
|
|
||||||
civilizations = gameInfo.civilizations
|
|
||||||
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user