diff --git a/Launcher/source/client/PlayerProfile.java b/Launcher/source/client/PlayerProfile.java index 8976265..89dea4f 100644 --- a/Launcher/source/client/PlayerProfile.java +++ b/Launcher/source/client/PlayerProfile.java @@ -1,7 +1,6 @@ package launcher.client; import java.io.IOException; -import java.io.InputStream; import java.net.URL; import java.util.Objects; import java.util.UUID; @@ -15,11 +14,6 @@ import launcher.serialize.stream.StreamObject; public final class PlayerProfile extends StreamObject { - @LauncherAPI public static final int TEXTURE_TIMEOUT = VerifyHelper.verifyInt( - Integer.parseUnsignedInt(System.getProperty("launcher.textureTimeout", Integer.toString(5000))), - VerifyHelper.POSITIVE, "launcher.textureTimeout can't be <= 0"); - - // Instance @LauncherAPI public final UUID uuid; @LauncherAPI public final String username; @LauncherAPI public final Texture skin, cloak; @@ -79,9 +73,7 @@ @LauncherAPI public Texture(String url) throws IOException { this.url = IOHelper.verifyURL(url); - try (InputStream input = IOHelper.newInput(new URL(url), TEXTURE_TIMEOUT)) { - digest = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, input); - } + digest = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, new URL(url)); } @LauncherAPI diff --git a/Launcher/source/client/ServerPinger.java b/Launcher/source/client/ServerPinger.java index 40dae08..514a70b 100644 --- a/Launcher/source/client/ServerPinger.java +++ b/Launcher/source/client/ServerPinger.java @@ -52,7 +52,7 @@ private Result doPing() throws IOException { try (Socket socket = IOHelper.newSocket()) { - socket.connect(IOHelper.resolve(address), IOHelper.TIMEOUT); + socket.connect(IOHelper.resolve(address), IOHelper.SOCKET_TIMEOUT); try (HInput input = new HInput(socket.getInputStream()); HOutput output = new HOutput(socket.getOutputStream())) { return version.compareTo(ClientProfile.Version.MC172) >= 0 ? diff --git a/Launcher/source/helper/IOHelper.java b/Launcher/source/helper/IOHelper.java index a756d3b..b002a1e 100644 --- a/Launcher/source/helper/IOHelper.java +++ b/Launcher/source/helper/IOHelper.java @@ -60,8 +60,17 @@ @LauncherAPI public static final Charset ASCII_CHARSET = StandardCharsets.US_ASCII; // Constants - @LauncherAPI public static final int TIMEOUT = 30000; - @LauncherAPI public static final int BUFFER_SIZE = 0x10000; + @LauncherAPI public static final int SOCKET_TIMEOUT = VerifyHelper.verifyInt( + Integer.parseUnsignedInt(System.getProperty("launcher.socketTimeout", Integer.toString(30000))), + VerifyHelper.POSITIVE, "launcher.socketTimeout can't be <= 0"); + @LauncherAPI public static final int HTTP_TIMEOUT = VerifyHelper.verifyInt( + Integer.parseUnsignedInt(System.getProperty("launcher.httpTimeout", Integer.toString(5000))), + VerifyHelper.POSITIVE, "launcher.httpTimeout can't be <= 0"); + @LauncherAPI public static final int BUFFER_SIZE = VerifyHelper.verifyInt( + Integer.parseUnsignedInt(System.getProperty("launcher.bufferSize", Integer.toString(0x10000))), + VerifyHelper.POSITIVE, "launcher.bufferSize can't be <= 0"); + + // Platform-dependent @LauncherAPI public static final String CROSS_SEPARATOR = "/"; @LauncherAPI public static final FileSystem FS = FileSystems.getDefault(); @LauncherAPI public static final String PLATFORM_SEPARATOR = FS.getSeparator(); @@ -230,11 +239,11 @@ } @LauncherAPI - public static InputStream newInput(URL url, int timeout) throws IOException { + public static InputStream newInput(URL url) throws IOException { URLConnection connection = url.openConnection(); if (connection instanceof HttpURLConnection) { - connection.setReadTimeout(timeout); - connection.setConnectTimeout(timeout); + connection.setReadTimeout(HTTP_TIMEOUT); + connection.setConnectTimeout(HTTP_TIMEOUT); } connection.setDoInput(true); connection.setDoOutput(false); @@ -242,11 +251,6 @@ } @LauncherAPI - public static InputStream newInput(URL url) throws IOException { - return newInput(url, TIMEOUT); - } - - @LauncherAPI public static InputStream newInput(Path file) throws IOException { return Files.newInputStream(file, READ_OPTIONS); } @@ -475,7 +479,7 @@ socket.setReuseAddress(true); // Set socket options - socket.setSoTimeout(TIMEOUT); + socket.setSoTimeout(SOCKET_TIMEOUT); socket.setTrafficClass(0b11100); socket.setSendBufferSize(BUFFER_SIZE); socket.setReceiveBufferSize(BUFFER_SIZE);