Fix crash that happens on startup after waking up a Pokémon

This commit is contained in:
kuroppoi 2023-07-16 22:55:57 +02:00
parent 72d5a10ffc
commit 99240e163a
5 changed files with 20 additions and 14 deletions

View File

@ -1,14 +1,14 @@
package entralinked;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
public record Configuration(
@JsonProperty(required = true) String hostName,
@JsonProperty(required = true) boolean clearPlayerDreamInfoOnWake,
@JsonProperty(required = true) boolean allowOverwritingPlayerDreamInfo,
@JsonProperty(required = true) boolean allowWfcRegistrationThroughLogin) {
String hostName,
boolean clearPlayerDreamInfoOnWake,
boolean allowOverwritingPlayerDreamInfo,
boolean allowPlayerGameVersionMismatch,
boolean allowWfcRegistrationThroughLogin) {
public static final Configuration DEFAULT = new Configuration("local", true, false, true);
public static final Configuration DEFAULT = new Configuration("local", true, false, false, true);
}

View File

@ -143,21 +143,25 @@ public class Entralinked {
private Configuration loadConfigFile() {
logger.info("Loading configuration ...");
Configuration configuration = null;
try {
File configFile = new File("config.json");
if(!configFile.exists()) {
logger.info("No configuration file exists - default configuration will be used");
mapper.writeValue(configFile, Configuration.DEFAULT);
return Configuration.DEFAULT;
configuration = Configuration.DEFAULT;
} else {
return mapper.readValue(configFile, Configuration.class);
configuration = mapper.readValue(configFile, Configuration.class);
}
mapper.writeValue(configFile, configuration);
} catch(IOException e) {
logger.error("Could not load configuration - default configuration will be used", e);
return Configuration.DEFAULT;
configuration = Configuration.DEFAULT;
}
return configuration;
}
public Configuration getConfiguration() {

View File

@ -33,7 +33,6 @@ public class Player {
public void resetDreamInfo() {
status = PlayerStatus.AWAKE;
gameVersion = null;
dreamerInfo = null;
encounters.clear();
items.clear();

View File

@ -92,7 +92,7 @@ public class DashboardHandler implements HttpHandler {
// Cache the result
skinPreviewCache.put("%s/%s".formatted(player.getGameSyncId(), version2 ? "CGEAR2" : "CGEAR"), image);
} catch(IOException | IndexOutOfBoundsException e) {
} catch(IOException | IndexOutOfBoundsException | NullPointerException e) {
logger.error("Could not load custom C-Gear skin preview for player {}", player.getGameSyncId(), e);
}
}

View File

@ -425,10 +425,13 @@ public class PglHandler implements HttpHandler {
// Prepare response
LEOutputStream outputStream = new LEOutputStream(ctx.outputStream());
// Check if the player exists and does not already have a Pokémon tucked in
// Check if the player exists, has no Pokémon tucked in already and uses the same game version
Player player = playerManager.getPlayer(request.gameSyncId());
if(player == null || (player.getStatus() != PlayerStatus.AWAKE && !configuration.allowOverwritingPlayerDreamInfo())) {
if(player == null
|| (!configuration.allowOverwritingPlayerDreamInfo() && player.getStatus() != PlayerStatus.AWAKE)
|| (!configuration.allowPlayerGameVersionMismatch() && player.getGameVersion() != null
&& request.gameVersion() != player.getGameVersion())) {
// Skip everything
ServletInputStream inputStream = ctx.req().getInputStream();