diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java index 720393a4..241787dc 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java @@ -7,12 +7,17 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.UUID; public final class RequestTextureProvider extends TextureProvider { // Instance - private String skinURL; - private String cloakURL; + public String skinURL; + public String cloakURL; + + public String skinLocalPath; + public String cloakLocalPath; public RequestTextureProvider() { } @@ -30,6 +35,14 @@ private static Texture getTexture(String url, boolean cloak) throws IOException } } + private static Texture getTexture(String url, Path local, boolean cloak) throws IOException { + try { + return new Texture(url, local, cloak); + } catch (FileNotFoundException ignored) { + return null; // Simply not found + } + } + private static String getTextureURL(String url, UUID uuid, String username, String client) { return CommonHelper.replace(url, "username", IOHelper.urlEncode(username), "uuid", IOHelper.urlEncode(uuid.toString()), "hash", IOHelper.urlEncode(Launcher.toHash(uuid)), @@ -43,11 +56,21 @@ public void close() { @Override public Texture getCloakTexture(UUID uuid, String username, String client) throws IOException { - return getTexture(getTextureURL(cloakURL, uuid, username, client), true); + String textureUrl = getTextureURL(cloakURL, uuid, username, client); + if (cloakLocalPath == null) { + return getTexture(textureUrl, true); + } else { + return getTexture(textureUrl, Paths.get(cloakLocalPath), true); + } } @Override public Texture getSkinTexture(UUID uuid, String username, String client) throws IOException { - return getTexture(getTextureURL(skinURL, uuid, username, client), false); + String textureUrl = getTextureURL(skinURL, uuid, username, client); + if (skinLocalPath == null) { + return getTexture(textureUrl, false); + } else { + return getTexture(textureUrl, Paths.get(skinLocalPath), false); + } } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java index 69483eac..dea6e001 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java @@ -17,6 +17,7 @@ public final class PlayerProfile extends StreamObject { public final Texture skin, cloak; + @Deprecated public PlayerProfile(HInput input) throws IOException { uuid = input.readUUID(); username = VerifyHelper.verifyUsername(input.readString(64)); @@ -41,6 +42,7 @@ public static UUID offlineUUID(String username) { } @Override + @Deprecated public void write(HOutput output) throws IOException { output.writeUUID(uuid); output.writeString(username, 64); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java index e836b661..6d9be5c0 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.nio.file.Path; import java.util.Objects; public final class Texture extends StreamObject { @@ -22,12 +23,12 @@ public final class Texture extends StreamObject { public final byte[] digest; + @Deprecated public Texture(HInput input) throws IOException { url = IOHelper.verifyURL(input.readASCII(2048)); digest = input.readByteArray(-DIGEST_ALGO.bytes); } - public Texture(String url, boolean cloak) throws IOException { this.url = IOHelper.verifyURL(url); @@ -44,6 +45,14 @@ public Texture(String url, boolean cloak) throws IOException { digest = SecurityHelper.digest(DIGEST_ALGO, new URL(url)); } + public Texture(String url, Path local, boolean cloak) throws IOException { + this.url = IOHelper.verifyURL(url); + try (InputStream input = IOHelper.newInput(local)) { + IOHelper.readTexture(input, cloak); // Verify texture + } + this.digest = Objects.requireNonNull(SecurityHelper.digest(DIGEST_ALGO, local), "digest"); + } + public Texture(String url, byte[] digest) { this.url = IOHelper.verifyURL(url);