mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-15 02:09:21 +07:00
Fix multiplayer turn check worker writing game data to wrong locations (#6976)
The fix in #6901 caused `arrayIndex` to go out of sync, because the `continue` happened before `arrayIndex` was incremented. This caused a later game preview to be saved to the previous game name, overwriting and duplicating it.
This commit is contained in:
@ -281,13 +281,13 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame
|
|||||||
try {
|
try {
|
||||||
val gameIds = inputData.getStringArray(GAME_ID)!!
|
val gameIds = inputData.getStringArray(GAME_ID)!!
|
||||||
val gameNames = inputData.getStringArray(GAME_NAME)!!
|
val gameNames = inputData.getStringArray(GAME_NAME)!!
|
||||||
var arrayIndex = 0
|
|
||||||
Log.d(LOG_TAG, "doWork gameNames: ${Arrays.toString(gameNames)}")
|
Log.d(LOG_TAG, "doWork gameNames: ${Arrays.toString(gameNames)}")
|
||||||
// We only want to notify the user or update persisted notification once but still want
|
// We only want to notify the user or update persisted notification once but still want
|
||||||
// to download all games to update the files so we save the first one we find
|
// to download all games to update the files so we save the first one we find
|
||||||
var foundGame: Pair<String, String>? = null
|
var foundGame: Pair<String, String>? = null
|
||||||
|
|
||||||
for (gameId in gameIds){
|
for (idx in 0 until gameIds.size){
|
||||||
|
val gameId = gameIds[idx]
|
||||||
//gameId could be an empty string if startTurnChecker fails to load all files
|
//gameId could be an empty string if startTurnChecker fails to load all files
|
||||||
if (gameId.isEmpty())
|
if (gameId.isEmpty())
|
||||||
continue
|
continue
|
||||||
@ -311,17 +311,16 @@ class MultiplayerTurnCheckWorker(appContext: Context, workerParams: WorkerParame
|
|||||||
while saves are getting saved right here.
|
while saves are getting saved right here.
|
||||||
Lets hope it works with gamePreview as they are a lot smaller and faster to save
|
Lets hope it works with gamePreview as they are a lot smaller and faster to save
|
||||||
*/
|
*/
|
||||||
Log.i(LOG_TAG, "doWork save gameName: ${gameNames[arrayIndex]}")
|
Log.i(LOG_TAG, "doWork save gameName: ${gameNames[idx]}")
|
||||||
gameSaver.saveGame(gamePreview, gameNames[arrayIndex])
|
gameSaver.saveGame(gamePreview, gameNames[idx])
|
||||||
Log.i(LOG_TAG, "doWork save ${gameNames[arrayIndex]} done")
|
Log.i(LOG_TAG, "doWork save ${gameNames[idx]} done")
|
||||||
|
|
||||||
if (currentTurnPlayer.playerId == inputData.getString(USER_ID)!! && foundGame == null) {
|
if (currentTurnPlayer.playerId == inputData.getString(USER_ID)!! && foundGame == null) {
|
||||||
foundGame = Pair(gameNames[arrayIndex], gameIds[arrayIndex])
|
foundGame = Pair(gameNames[idx], gameIds[idx])
|
||||||
}
|
}
|
||||||
arrayIndex++
|
|
||||||
} catch (ex: FileStorageRateLimitReached) {
|
} catch (ex: FileStorageRateLimitReached) {
|
||||||
Log.i(LOG_TAG, "doWork FileStorageRateLimitReached ${ex.message}")
|
Log.i(LOG_TAG, "doWork FileStorageRateLimitReached ${ex.message}")
|
||||||
// We just break here as configuredDelay is probably enough to wait for the rate limit anyway
|
// We just break here as the configured delay is probably enough to wait for the rate limit anyway
|
||||||
break
|
break
|
||||||
} catch (ex: FileNotFoundException){
|
} catch (ex: FileNotFoundException){
|
||||||
Log.i(LOG_TAG, "doWork FileNotFoundException ${ex.message}")
|
Log.i(LOG_TAG, "doWork FileNotFoundException ${ex.message}")
|
||||||
|
Reference in New Issue
Block a user