diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 8e395fe..12e74e5 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -16,6 +16,7 @@ import org.bukkit.potion.PotionType; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.security.InvalidKeyException; import java.security.SecureRandom; import java.util.ArrayList; import java.util.HashMap; @@ -752,6 +753,9 @@ public class Brew { } catch (IOException e) { P.p.errorLog("IO Error while loading Brew"); e.printStackTrace(); + } catch (InvalidKeyException e) { + P.p.errorLog("Failed to load Brew, has the data key 'BrewDataSeed' in the data.yml been changed?"); + e.printStackTrace(); } return null; } @@ -836,12 +840,12 @@ public class Brew { } public static void writeSeed(ConfigurationSection section) { - section.set("seed", saveSeed); + section.set("BrewDataSeed", saveSeed); } public static void loadSeed(ConfigurationSection section) { - if (section.contains("seed")) { - saveSeed = section.getLong("seed"); + if (section.contains("BrewDataSeed")) { + saveSeed = section.getLong("BrewDataSeed"); } else { while (saveSeed == 0) { saveSeed = new SecureRandom().nextLong(); diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 6f07ec5..7ac1cf4 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -179,6 +179,8 @@ public class P extends JavaPlugin { } catch (IOException e) { e.printStackTrace(); + } catch (InvalidKeyException e) { + e.printStackTrace(); } finally { try { data.close(); diff --git a/src/com/dre/brewery/lore/XORScrambleStream.java b/src/com/dre/brewery/lore/XORScrambleStream.java index da669c5..c573b84 100644 --- a/src/com/dre/brewery/lore/XORScrambleStream.java +++ b/src/com/dre/brewery/lore/XORScrambleStream.java @@ -1,6 +1,5 @@ package com.dre.brewery.lore; - import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -27,6 +26,7 @@ public class XORScrambleStream extends FilterOutputStream { xorStream = new SeedInputStream(seed ^ id); out.write((byte) (id >> 8)); out.write((byte) id); + write(209); // parity/sanity } } diff --git a/src/com/dre/brewery/lore/XORUnscrambleStream.java b/src/com/dre/brewery/lore/XORUnscrambleStream.java index 44e49a6..a7a6ed5 100644 --- a/src/com/dre/brewery/lore/XORUnscrambleStream.java +++ b/src/com/dre/brewery/lore/XORUnscrambleStream.java @@ -3,6 +3,7 @@ package com.dre.brewery.lore; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; +import java.security.InvalidKeyException; public class XORUnscrambleStream extends FilterInputStream { @@ -17,7 +18,7 @@ public class XORUnscrambleStream extends FilterInputStream { this.seed = seed; } - public void start() throws IOException { + public void start() throws IOException, InvalidKeyException { running = true; if (xorStream == null) { short id = (short) (in.read() << 8 | in.read()); @@ -26,6 +27,9 @@ public class XORUnscrambleStream extends FilterInputStream { return; } xorStream = new SeedInputStream(seed ^ id); + if (read() != 209) { // Parity/Sanity + throw new InvalidKeyException("Could not read scrambled data, is the seed wrong?"); + } } }