From 0524e77e3ebd8c87e2777396e09f6d239f7b4065 Mon Sep 17 00:00:00 2001 From: xDark Date: Tue, 13 Aug 2019 22:11:51 +0300 Subject: [PATCH] =?UTF-8?q?[ANY]=20=D0=A7=D0=B8=D1=81=D1=82=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=B4=D0=B0=20x2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/LauncherAgent.java | 24 +++++----- .../launcher/client/ClientLauncher.java | 46 +++++++++++-------- .../launcher/hwid/OshiHWIDProvider.java | 1 + .../pro/gravit/launcher/utils/DirWatcher.java | 10 ---- .../launcher/downloader/ListDownloader.java | 8 +++- .../YggdrasilGameProfileRepository.java | 11 +++-- .../YggdrasilMinecraftSessionService.java | 18 +++++--- .../pro/gravit/utils/helper/IOHelper.java | 6 ++- .../pro/gravit/utils/helper/LogHelper.java | 11 ++--- .../gravit/launcher/server/ServerWrapper.java | 2 +- 10 files changed, 73 insertions(+), 64 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java index 4a4329a1..c0f855bf 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherAgent.java @@ -22,6 +22,7 @@ import cpw.mods.fml.SafeExitJVMLegacy; import net.minecraftforge.fml.SafeExitJVM; import pro.gravit.launcher.utils.NativeJVMHalt; +import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; @LauncherAPI @@ -46,19 +47,20 @@ public static void premain(String agentArgument, Instrumentation instrumentation NativeJVMHalt.class.getName(); NativeJVMHalt.initFunc(); isAgentStarted = true; - boolean pb = true; - boolean rt = true; - if (agentArgument != null) { - String trimmedArg = agentArgument.trim(); - if (!trimmedArg.isEmpty()) { - if (trimmedArg.contains("p")) pb = false; - if (trimmedArg.contains("r")) rt = false; - } - } if (System.getProperty("java.vm.name").toUpperCase(Locale.US).contains("HOTSPOT")) try { - if (ManagementFactory.getOperatingSystemMXBean().getName().startsWith("Windows")) replaceClasses(pb, rt); - else replaceClasses(false, false); + if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { + boolean pb = true; + boolean rt = true; + if (agentArgument != null) { + String trimmedArg = agentArgument.trim(); + if (!trimmedArg.isEmpty()) { + if (trimmedArg.contains("p")) pb = false; + if (trimmedArg.contains("r")) rt = false; + } + } + replaceClasses(pb, rt); + } else replaceClasses(false, false); } catch (Error e) { NativeJVMHalt.haltA(294); throw e; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index c22033e7..9d066ce3 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -14,11 +14,15 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.PosixFilePermission; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.EnumSet; import java.util.LinkedList; +import java.util.List; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.swing.JOptionPane; @@ -55,16 +59,16 @@ public final class ClientLauncher { private static final class ClassPathFileVisitor extends SimpleFileVisitor { - private final Collection result; + private final Stream.Builder result; - private ClassPathFileVisitor(Collection result) { + private ClassPathFileVisitor(Stream.Builder result) { this.result = result; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (IOHelper.hasExtension(file, "jar") || IOHelper.hasExtension(file, "zip")) - result.add(file); + result.accept(file); return super.visitFile(file, attrs); } } @@ -282,10 +286,17 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl System.setProperty("minecraft.applet.TargetDirectory", params.clientDir.toString()); } Collections.addAll(args, profile.getClientArgs()); - LogHelper.debug("Args: " + args); + List copy = new ArrayList<>(args); + for (int i = 0, l = copy.size(); i < l; i++) { + String s = copy.get(i); + if ( i + 1 < l && ("--accessToken".equals(s) || "--session".equals(s))) { + copy.set(i + 1, "censored"); + } + } + LogHelper.debug("Args: " + copy); // Resolve main class and method Class mainClass = classLoader.loadClass(profile.getMainClass()); - MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)).asFixedArity(); + MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)); Launcher.LAUNCHED.set(true); JVMHelper.fullGC(); // Invoke main method @@ -407,7 +418,7 @@ public static Process launch( Thread.sleep(200); } if (!clientStarted) { - LogHelper.error("Write Client Params not successful. Using debug mode for more information"); + LogHelper.error("Client did not start properly. Enable debug mode for more information"); } } clientStarted = false; @@ -515,29 +526,24 @@ public static void main(String... args) throws Throwable { } private static URL[] resolveClassPath(Path clientDir, String... classPath) throws IOException { - Collection result = new LinkedList<>(); - for (String classPathEntry : classPath) { - Path path = clientDir.resolve(IOHelper.toPath(classPathEntry)); - if (IOHelper.isDir(path)) { // Recursive walking and adding - IOHelper.walk(path, new ClassPathFileVisitor(result), false); - continue; - } - result.add(path); - } - return result.stream().map(IOHelper::toURL).toArray(URL[]::new); + return resolveClassPathStream(clientDir, classPath).map(IOHelper::toURL).toArray(URL[]::new); } private static LinkedList resolveClassPathList(Path clientDir, String... classPath) throws IOException { - LinkedList result = new LinkedList<>(); + return resolveClassPathStream(clientDir, classPath).collect(Collectors.toCollection(LinkedList::new)); + } + + private static Stream resolveClassPathStream(Path clientDir, String... classPath) throws IOException { + Stream.Builder builder = Stream.builder(); for (String classPathEntry : classPath) { Path path = clientDir.resolve(IOHelper.toPath(classPathEntry)); if (IOHelper.isDir(path)) { // Recursive walking and adding - IOHelper.walk(path, new ClassPathFileVisitor(result), false); + IOHelper.walk(path, new ClassPathFileVisitor(builder), false); continue; } - result.add(path); + builder.accept(path); } - return result; + return builder.build(); } private static void initGson() { diff --git a/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java b/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java index 2f14a995..e977bf9b 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/hwid/OshiHWIDProvider.java @@ -68,6 +68,7 @@ public String getHWDisk() { public String getMacAddr() { for (NetworkIF networkIF : hardware.getNetworkIFs()) { + if (networkIF.getNetworkInterface().isVirtual()) continue; for (String ipv4 : networkIF.getIPv4addr()) { if (ipv4.startsWith("127.")) continue; if (ipv4.startsWith("10.")) continue; diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java b/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java index 6c3b5146..213b073f 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/DirWatcher.java @@ -27,15 +27,6 @@ public final class DirWatcher implements Runnable, AutoCloseable { private final class RegisterFileVisitor extends SimpleFileVisitor { - private final Deque path = new LinkedList<>(); - - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { - FileVisitResult result = super.postVisitDirectory(dir, exc); - if (!DirWatcher.this.dir.equals(dir)) - path.removeLast(); - return result; - } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { @@ -46,7 +37,6 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th } // Maybe it's unnecessary to go deeper - path.add(IOHelper.getFileName(dir)); //if (matcher != null && !matcher.shouldVerify(path)) { // return FileVisitResult.SKIP_SUBTREE; //} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java index 4633e6f4..1145a507 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java @@ -60,7 +60,9 @@ public void download(String base, List applies, Path dstDirFile, D URI u = new URI(scheme, host, path + apply.apply, "", ""); callback.stateChanged(apply.apply, 0L, apply.size); Path targetPath = dstDirFile.resolve(apply.apply); - LogHelper.debug("Download URL: %s to file %s dir: %s", u.toString(), targetPath.toAbsolutePath().toString(), dstDirFile.toAbsolutePath().toString()); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Download URL: %s to file %s dir: %s", u.toString(), targetPath.toAbsolutePath().toString(), dstDirFile.toAbsolutePath().toString()); + } if (get == null) get = new HttpGet(u); else { get.reset(); @@ -104,7 +106,9 @@ public void downloadOne(String url, Path target) throws IOException, URISyntaxEx HttpGet get; URI u = new URL(url).toURI(); - LogHelper.debug("Download URL: %s", u.toString()); + if (LogHelper.isDebugEnabled()) { + LogHelper.debug("Download URL: %s", u.toString()); + } get = new HttpGet(u); httpclient.execute(get, new FileDownloadResponseHandler(target.toAbsolutePath())); } diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java index 3a73db11..0d54ba97 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java @@ -46,8 +46,9 @@ public void findProfilesByNames(String[] usernames, Agent agent, ProfileLookupCa try { sliceProfiles = new BatchProfileByUsernameRequest(sliceUsernames).request().playerProfiles; } catch (Exception e) { + boolean debug = LogHelper.isDebugEnabled(); for (String username : sliceUsernames) { - if (LogHelper.isDebugEnabled()) { + if (debug) { LogHelper.debug("Couldn't find profile '%s': %s", username, e); } callback.onProfileLookupFailed(new GameProfile((UUID) null, username), e); @@ -59,11 +60,13 @@ public void findProfilesByNames(String[] usernames, Agent agent, ProfileLookupCa } // Request succeeded! - for (int i = 0; i < sliceProfiles.length; i++) { + int len = sliceProfiles.length; + boolean debug = len > 0 && LogHelper.isDebugEnabled(); + for (int i = 0; i < len; i++) { PlayerProfile pp = sliceProfiles[i]; if (pp == null) { String username = sliceUsernames[i]; - if (LogHelper.isDebugEnabled()) { + if (debug) { LogHelper.debug("Couldn't find profile '%s'", username); } callback.onProfileLookupFailed(new GameProfile((UUID) null, username), new ProfileNotFoundException("Server did not find the requested profile")); @@ -71,7 +74,7 @@ public void findProfilesByNames(String[] usernames, Agent agent, ProfileLookupCa } // Report as looked up - if (LogHelper.isDebugEnabled()) { + if (debug) { LogHelper.debug("Successfully looked up profile '%s'", pp.username); } callback.onProfileLookupSucceeded(YggdrasilMinecraftSessionService.toGameProfile(pp)); diff --git a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java index 783ac600..d7afaede 100644 --- a/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java +++ b/LauncherAuthlib/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java @@ -33,7 +33,8 @@ public final class YggdrasilMinecraftSessionService extends BaseMinecraftSession public static final boolean NO_TEXTURES = Boolean.parseBoolean("launcher.com.mojang.authlib.noTextures"); public static void fillTextureProperties(GameProfile profile, PlayerProfile pp) { - if (LogHelper.isDebugEnabled()) { + boolean debug = LogHelper.isDebugEnabled(); + if (debug) { LogHelper.debug("fillTextureProperties, Username: '%s'", profile.getName()); } if (NO_TEXTURES) @@ -44,14 +45,14 @@ public static void fillTextureProperties(GameProfile profile, PlayerProfile pp) if (pp.skin != null) { properties.put(Launcher.SKIN_URL_PROPERTY, new Property(Launcher.SKIN_URL_PROPERTY, pp.skin.url, "")); properties.put(Launcher.SKIN_DIGEST_PROPERTY, new Property(Launcher.SKIN_DIGEST_PROPERTY, SecurityHelper.toHex(pp.skin.digest), "")); - if (LogHelper.isDebugEnabled()) { + if (debug) { LogHelper.debug("fillTextureProperties, Has skin texture for username '%s'", profile.getName()); } } if (pp.cloak != null) { properties.put(Launcher.CLOAK_URL_PROPERTY, new Property(Launcher.CLOAK_URL_PROPERTY, pp.cloak.url, "")); properties.put(Launcher.CLOAK_DIGEST_PROPERTY, new Property(Launcher.CLOAK_DIGEST_PROPERTY, SecurityHelper.toHex(pp.cloak.digest), "")); - if (LogHelper.isDebugEnabled()) { + if (debug) { LogHelper.debug("fillTextureProperties, Has cloak texture for username '%s'", profile.getName()); } } @@ -98,7 +99,8 @@ public YggdrasilMinecraftSessionService(AuthenticationService service) { public GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) { // Verify has UUID UUID uuid = profile.getUUID(); - if (LogHelper.isDebugEnabled()) { + boolean debug = LogHelper.isDebugEnabled(); + if (debug) { LogHelper.debug("fillProfileProperties, UUID: %s", uuid); } if (uuid == null) @@ -109,7 +111,7 @@ public GameProfile fillProfileProperties(GameProfile profile, boolean requireSec try { pp = new ProfileByUUIDRequest(uuid).request().playerProfile; } catch (Exception e) { - if (LogHelper.isDebugEnabled()) { + if (debug) { LogHelper.debug("Couldn't fetch profile properties for '%s': %s", profile, e); } return profile; @@ -117,12 +119,14 @@ public GameProfile fillProfileProperties(GameProfile profile, boolean requireSec // Verify is found if (pp == null) { - LogHelper.debug("Couldn't fetch profile properties for '%s' as the profile does not exist", profile); + if (debug) { + LogHelper.debug("Couldn't fetch profile properties for '%s' as the profile does not exist", profile); + } return profile; } // Create new game profile from player profile - if (LogHelper.isDebugEnabled()) { + if (debug) { LogHelper.debug("Successfully fetched profile properties for '%s'", profile); } fillTextureProperties(profile, pp); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java index 77b34f1b..1d602582 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java @@ -624,7 +624,11 @@ public static void setSocketFlags(Socket socket) throws SocketException { // Set socket options socket.setSoTimeout(SOCKET_TIMEOUT); - socket.setTrafficClass(0b11100); + try { + socket.setTrafficClass(0b11100); + } catch (SocketException ignored) { + // Windows XP has no support for that + } socket.setPerformancePreferences(1, 0, 2); } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java index 59ed544e..694c56db 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java @@ -345,14 +345,9 @@ public static void subWarning(String format, Object... args) { @LauncherAPI public static String toString(Throwable exc) { - try (StringWriter sw = new StringWriter()) { - try (PrintWriter pw = new PrintWriter(sw)) { - exc.printStackTrace(pw); - } - return sw.toString(); - } catch (IOException e) { - throw new InternalError(e); - } + StringWriter sw = new StringWriter(); + exc.printStackTrace(new PrintWriter(sw)); + return sw.toString(); } @LauncherAPI diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index 8c7bba1c..a0fd85ea 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -105,7 +105,7 @@ public void run(String... args) throws Throwable { loadConfig(); ServerWrapperSetup setup = new ServerWrapperSetup(); setup.run(); - System.exit(0); + System.exit(1); } modulesManager = new ModulesManager(wrapper); modulesManager.autoload(modulesDir);