Protect against cross-session overwrites
This commit is contained in:
parent
c6f395d63a
commit
3d9f5fb157
|
@ -3420,6 +3420,8 @@ export class GameOverPhase extends BattlePhase {
|
|||
|
||||
handleClearSession(): void {
|
||||
this.scene.gameData.tryClearSession(this.scene, this.scene.sessionSlotId).then((success: boolean | [boolean, boolean]) => {
|
||||
if (!success[0])
|
||||
return this.scene.reset(true);
|
||||
this.scene.time.delayedCall(1000, () => {
|
||||
let firstClear = false;
|
||||
if (this.victory && success[1]) {
|
||||
|
@ -4327,7 +4329,7 @@ export class EggLapsePhase extends Phase {
|
|||
|
||||
const eggsToHatch: Egg[] = this.scene.gameData.eggs.filter((egg: Egg) => {
|
||||
return --egg.hatchWaves < 1
|
||||
})
|
||||
});
|
||||
|
||||
if (eggsToHatch.length) {
|
||||
this.scene.queueMessage('Oh?');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import BattleScene, { PokeballCounts, bypassLogin } from "../battle-scene";
|
||||
import Pokemon, { EnemyPokemon, PlayerPokemon } from "../field/pokemon";
|
||||
import { pokemonEvolutions, pokemonPrevolutions } from "../data/pokemon-evolutions";
|
||||
import PokemonSpecies, { SpeciesFormKey, allSpecies, getPokemonSpecies, noStarterFormKeys, speciesStarters } from "../data/pokemon-species";
|
||||
import PokemonSpecies, { allSpecies, getPokemonSpecies, noStarterFormKeys, speciesStarters } from "../data/pokemon-species";
|
||||
import { Species, defaultStarterSpecies } from "../data/enums/species";
|
||||
import * as Utils from "../utils";
|
||||
import PokemonData from "./pokemon-data";
|
||||
|
@ -27,7 +27,7 @@ import { Moves } from "../data/enums/moves";
|
|||
import { speciesEggMoves } from "../data/egg-moves";
|
||||
import { allMoves } from "../data/move";
|
||||
import { TrainerVariant } from "../field/trainer";
|
||||
import { OutdatedPhase, ReloadSessionPhase, UnavailablePhase } from "#app/phases";
|
||||
import { OutdatedPhase, ReloadSessionPhase } from "#app/phases";
|
||||
import { Variant, variantData } from "#app/data/variant";
|
||||
|
||||
const saveKey = 'x0i2O7WRiANTqPmZ'; // Temporary; secure encryption is not yet necessary
|
||||
|
@ -722,9 +722,19 @@ export class GameData {
|
|||
Utils.apiFetch(`savedata/delete?datatype=${GameDataType.SESSION}&slot=${slotId}`, true).then(response => {
|
||||
if (response.ok) {
|
||||
loggedInUser.lastSessionSlot = -1;
|
||||
return resolve(true);
|
||||
resolve(true);
|
||||
}
|
||||
resolve(false);
|
||||
return response.text();
|
||||
}).then(error => {
|
||||
if (error) {
|
||||
if (error.startsWith('session out of date')) {
|
||||
this.scene.clearPhaseQueue();
|
||||
this.scene.unshiftPhase(new ReloadSessionPhase(this.scene));
|
||||
}
|
||||
console.error(error);
|
||||
resolve(false);
|
||||
}
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -742,12 +752,19 @@ export class GameData {
|
|||
return resolve([false, false]);
|
||||
const sessionData = this.getSessionSaveData(scene);
|
||||
Utils.apiPost(`savedata/clear?slot=${slotId}`, JSON.stringify(sessionData)).then(response => {
|
||||
if (response.ok) {
|
||||
if (response.ok)
|
||||
loggedInUser.lastSessionSlot = -1;
|
||||
return response.json();
|
||||
return response.json();
|
||||
}).then(jsonResponse => {
|
||||
if (!jsonResponse.error)
|
||||
return resolve([true, jsonResponse.success as boolean]);
|
||||
if (jsonResponse && jsonResponse.error.startsWith('session out of date')) {
|
||||
this.scene.clearPhaseQueue();
|
||||
this.scene.unshiftPhase(new ReloadSessionPhase(this.scene));
|
||||
}
|
||||
console.error(jsonResponse);
|
||||
resolve([false, false]);
|
||||
}).then(jsonResponse => resolve([true, jsonResponse.success as boolean]));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue