From 00c9da2167f25e85cdac960a1213f2a9e87d6b31 Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 29 Jul 2015 19:54:14 +1000 Subject: Add option to check for hash of Vanilla server jar. --- src/main/java/org/spigotmc/builder/Builder.java | 25 +++++++++++++++++++--- .../java/org/spigotmc/builder/VersionInfo.java | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/spigotmc/builder/Builder.java b/src/main/java/org/spigotmc/builder/Builder.java index 54da43d..dfdc551 100644 --- a/src/main/java/org/spigotmc/builder/Builder.java +++ b/src/main/java/org/spigotmc/builder/Builder.java @@ -173,7 +173,7 @@ public class Builder File maven; String m2Home = System.getenv( "M2_HOME" ); - if ( m2Home == null || !(maven = new File(m2Home)).exists() ) + if ( m2Home == null || !( maven = new File( m2Home ) ).exists() ) { maven = new File( "apache-maven-3.2.5" ); @@ -240,15 +240,20 @@ public class Builder // Default to 1.8 builds. if ( versionInfo == null ) { - versionInfo = new VersionInfo( "1.8", "bukkit-1.8.at", "bukkit-1.8-cl.csrg", "bukkit-1.8-members.csrg", "package.srg" ); + versionInfo = new VersionInfo( "1.8", "bukkit-1.8.at", "bukkit-1.8-cl.csrg", "bukkit-1.8-members.csrg", "package.srg", null ); } System.out.println( "Attempting to build Minecraft with details: " + versionInfo ); File vanillaJar = new File( workDir, "minecraft_server." + versionInfo.getMinecraftVersion() + ".jar" ); - if ( !vanillaJar.exists() ) + if ( !vanillaJar.exists() || !checkHash( vanillaJar, versionInfo ) ) { download( String.format( "https://s3.amazonaws.com/Minecraft.Download/versions/%1$s/minecraft_server.%1$s.jar", versionInfo.getMinecraftVersion() ), vanillaJar ); } + if ( !checkHash( vanillaJar, versionInfo ) ) + { + System.err.println( "**** Could not download clean Minecraft jar, giving up." ); + return; + } Iterable mappings = buildGit.log() .addPath( "mappings/" + versionInfo.getAccessTransforms() ) @@ -420,6 +425,20 @@ public class Builder } } + private static boolean checkHash(File vanillaJar, VersionInfo versionInfo) throws IOException + { + String hash = Files.hash( vanillaJar, Hashing.md5() ).toString(); + if ( !dev && versionInfo.getMinecraftHash() != null && !hash.equals( versionInfo.getMinecraftHash() ) ) + { + System.err.println( "**** Warning, Minecraft jar hash of " + hash + " does not match stored hash of " + versionInfo.getMinecraftHash() ); + return false; + } else + { + System.out.println( "Found good Minecraft hash (" + hash + ")" ); + return true; + } + } + public static final String get(String url) throws IOException { URLConnection con = new URL( url ).openConnection(); diff --git a/src/main/java/org/spigotmc/builder/VersionInfo.java b/src/main/java/org/spigotmc/builder/VersionInfo.java index 9ab97f2..e3a4f34 100644 --- a/src/main/java/org/spigotmc/builder/VersionInfo.java +++ b/src/main/java/org/spigotmc/builder/VersionInfo.java @@ -13,4 +13,5 @@ public class VersionInfo private String classMappings; private String memberMappings; private String packageMappings; + private String minecraftHash; } -- cgit v1.2.3