mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-01-06 18:47:44 +01:00
Added Parity/Sanity to Scrambling
This commit is contained in:
parent
9bf3268fb4
commit
2121bf5c8a
@ -17,6 +17,7 @@ import org.bukkit.potion.PotionType;
|
|||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -756,6 +757,9 @@ public class Brew {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
P.p.errorLog("IO Error while loading Brew");
|
P.p.errorLog("IO Error while loading Brew");
|
||||||
e.printStackTrace();
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
@ -840,12 +844,12 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void writeSeed(ConfigurationSection section) {
|
public static void writeSeed(ConfigurationSection section) {
|
||||||
section.set("seed", saveSeed);
|
section.set("BrewDataSeed", saveSeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadSeed(ConfigurationSection section) {
|
public static void loadSeed(ConfigurationSection section) {
|
||||||
if (section.contains("seed")) {
|
if (section.contains("BrewDataSeed")) {
|
||||||
saveSeed = section.getLong("seed");
|
saveSeed = section.getLong("BrewDataSeed");
|
||||||
} else {
|
} else {
|
||||||
while (saveSeed == 0) {
|
while (saveSeed == 0) {
|
||||||
saveSeed = new SecureRandom().nextLong();
|
saveSeed = new SecureRandom().nextLong();
|
||||||
|
@ -206,6 +206,8 @@ public class P extends JavaPlugin {
|
|||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} catch (InvalidKeyException e) {
|
||||||
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
data.close();
|
data.close();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.dre.brewery.lore;
|
package com.dre.brewery.lore;
|
||||||
|
|
||||||
|
|
||||||
import java.io.FilterOutputStream;
|
import java.io.FilterOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@ -27,6 +26,7 @@ public class XORScrambleStream extends FilterOutputStream {
|
|||||||
xorStream = new SeedInputStream(seed ^ id);
|
xorStream = new SeedInputStream(seed ^ id);
|
||||||
out.write((byte) (id >> 8));
|
out.write((byte) (id >> 8));
|
||||||
out.write((byte) id);
|
out.write((byte) id);
|
||||||
|
write(209); // parity/sanity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package com.dre.brewery.lore;
|
|||||||
import java.io.FilterInputStream;
|
import java.io.FilterInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
|
|
||||||
public class XORUnscrambleStream extends FilterInputStream {
|
public class XORUnscrambleStream extends FilterInputStream {
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ public class XORUnscrambleStream extends FilterInputStream {
|
|||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() throws IOException {
|
public void start() throws IOException, InvalidKeyException {
|
||||||
running = true;
|
running = true;
|
||||||
if (xorStream == null) {
|
if (xorStream == null) {
|
||||||
short id = (short) (in.read() << 8 | in.read());
|
short id = (short) (in.read() << 8 | in.read());
|
||||||
@ -26,6 +27,9 @@ public class XORUnscrambleStream extends FilterInputStream {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
xorStream = new SeedInputStream(seed ^ id);
|
xorStream = new SeedInputStream(seed ^ id);
|
||||||
|
if (read() != 209) { // Parity/Sanity
|
||||||
|
throw new InvalidKeyException("Could not read scrambled data, is the seed wrong?");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user