From 87669d1d46757693fc4736e60158e4e2f7d8948d Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 20 Dec 2018 22:45:01 +0700 Subject: [PATCH] IDEA Code Reformat --- .../ru/gravit/launchserver/LaunchServer.java | 78 ++- .../ru/gravit/launchserver/ProguardConf.java | 16 +- .../ru/gravit/launchserver/StarterAgent.java | 12 +- .../launchserver/asm/ClassMetadataReader.java | 132 ++--- .../launchserver/asm/SafeClassWriter.java | 50 +- .../gravit/launchserver/auth/AuthLimiter.java | 15 +- .../launchserver/auth/MySQLSourceConfig.java | 10 +- .../auth/handler/AuthHandler.java | 12 +- .../auth/handler/BinaryFileAuthHandler.java | 10 +- .../auth/handler/CachedAuthHandler.java | 12 +- .../auth/handler/FileAuthHandler.java | 22 +- .../auth/handler/MemoryAuthHandler.java | 8 +- .../auth/handler/MySQLAuthHandler.java | 10 +- .../auth/handler/NullAuthHandler.java | 8 +- .../auth/handler/TextFileAuthHandler.java | 16 +- .../auth/hwid/AcceptHWIDHandler.java | 6 +- .../launchserver/auth/hwid/HWIDHandler.java | 10 +- .../auth/hwid/JsonHWIDHandler.java | 58 +-- .../auth/hwid/MysqlHWIDHandler.java | 16 +- .../auth/provider/AuthProvider.java | 10 +- .../auth/provider/FileAuthProvider.java | 22 +- .../auth/provider/JsonAuthProvider.java | 17 +- .../auth/provider/MojangAuthProvider.java | 24 +- .../auth/provider/MySQLAuthProvider.java | 10 +- .../auth/provider/NullAuthProvider.java | 6 +- .../auth/provider/RequestAuthProvider.java | 10 +- .../launchserver/binary/BuildContext.java | 4 +- .../binary/EXEL4JLauncherBinary.java | 12 +- .../binary/EXELauncherBinary.java | 6 +- .../launchserver/binary/JAConfigurator.java | 26 +- .../binary/JARLauncherBinary.java | 492 +++++++++--------- .../launchserver/binary/LauncherBinary.java | 6 +- .../gravit/launchserver/command/Command.java | 4 +- .../command/auth/AuthCommand.java | 4 +- .../launchserver/command/auth/BanCommand.java | 4 +- .../command/auth/UUIDToUsernameCommand.java | 6 +- .../command/auth/UnbanCommand.java | 4 +- .../command/auth/UsernameToUUIDCommand.java | 6 +- .../command/basic/HelpCommand.java | 4 +- .../basic/RegenProguardDictCommand.java | 4 +- .../basic/RemoveMappingsProguardCommand.java | 6 +- .../command/handler/CommandHandler.java | 45 +- .../command/handler/JLineCommandHandler.java | 4 +- .../command/handler/StdCommandHandler.java | 6 +- .../command/hash/DownloadAssetCommand.java | 8 +- .../command/hash/DownloadClientCommand.java | 14 +- .../command/hash/IndexAssetCommand.java | 28 +- .../command/hash/SyncBinariesCommand.java | 4 +- .../command/hash/SyncProfilesCommand.java | 4 +- .../command/hash/SyncUpdatesCommand.java | 8 +- .../command/hash/UnindexAssetCommand.java | 20 +- .../command/modules/LoadModuleCommand.java | 6 +- .../ClosingChannelFutureListener.java | 4 +- .../fileserver/FileServerHandler.java | 52 +- .../manangers/BuildHookManager.java | 56 +- .../launchserver/manangers/MirrorManager.java | 4 +- .../manangers/ModulesManager.java | 6 +- .../manangers/NodeTransformer.java | 57 +- .../manangers/SessionManager.java | 6 +- .../launchserver/response/PingResponse.java | 4 +- .../launchserver/response/Response.java | 21 +- .../response/auth/AuthResponse.java | 15 +- .../response/auth/AuthServerResponse.java | 11 +- .../response/auth/CheckServerResponse.java | 6 +- .../response/auth/JoinServerResponse.java | 4 +- .../response/auth/SetProfileResponse.java | 4 +- .../BatchProfileByUsernameResponse.java | 6 +- .../profile/ProfileByUUIDResponse.java | 6 +- .../profile/ProfileByUsernameResponse.java | 6 +- .../response/update/LauncherResponse.java | 6 +- .../update/LegacyLauncherResponse.java | 4 +- .../response/update/ProfilesResponse.java | 6 +- .../response/update/UpdateListResponse.java | 6 +- .../response/update/UpdateResponse.java | 16 +- .../socket/NettyServerSocketHandler.java | 56 +- .../launchserver/socket/ResponseThread.java | 10 +- .../socket/ServerSocketHandler.java | 22 +- .../websocket/WebSocketFrameHandler.java | 1 - .../websocket/WebSocketIndexPageHandler.java | 25 +- .../socket/websocket/WebSocketService.java | 5 +- .../websocket/json/JsonResponseAdapter.java | 14 +- .../websocket/json/auth/AuthResponse.java | 4 +- .../json/update/LauncherResponse.java | 6 +- .../texture/NullTextureProvider.java | 8 +- .../texture/RequestTextureProvider.java | 8 +- .../launchserver/texture/TextureProvider.java | 10 +- .../texture/VoidTextureProvider.java | 4 +- .../launcher/ClientLauncherWrapper.java | 14 +- .../ru/gravit/launcher/JSApplication.java | 4 +- .../ru/gravit/launcher/LauncherEngine.java | 53 +- .../ru/gravit/launcher/RequestWorker.java | 12 +- .../launcher/client/ClientLauncher.java | 73 ++- .../launcher/client/ClientModuleManager.java | 6 +- .../ru/gravit/launcher/client/DirBridge.java | 58 +-- .../launcher/client/FunctionalBridge.java | 31 +- .../launcher/client/LauncherSettings.java | 29 +- .../gravit/launcher/client/ServerPinger.java | 22 +- .../gui/choosebox/CheckBitSetModelBase.java | 9 +- .../launcher/gui/choosebox/CheckComboBox.java | 14 +- .../gui/choosebox/CheckComboBoxSkin.java | 7 +- .../indicator/ProgressCircleIndicator.java | 14 +- .../gui/indicator/RingProgressIndicator.java | 9 +- .../indicator/RingProgressIndicatorSkin.java | 3 + .../launcher/hwid/OshiHWIDProvider.java | 54 +- .../gravit/launcher/managers/HasherStore.java | 41 +- .../authlib/yggdrasil/CompatBridge.java | 4 +- .../authlib/yggdrasil/CompatProfile.java | 4 +- .../YggdrasilAuthenticationService.java | 5 +- .../YggdrasilGameProfileRepository.java | 7 +- .../YggdrasilMinecraftSessionService.java | 13 +- .../gravit/launcher/request/PingRequest.java | 4 +- .../ru/gravit/launcher/request/Request.java | 8 +- .../launcher/request/auth/AuthRequest.java | 8 +- .../request/auth/AuthServerRequest.java | 4 +- .../request/auth/ChangeServerRequest.java | 4 +- .../request/auth/CheckServerRequest.java | 4 +- .../request/auth/JoinServerRequest.java | 4 +- .../request/update/LauncherRequest.java | 12 +- .../request/update/LegacyLauncherRequest.java | 16 +- .../request/update/ProfilesRequest.java | 8 +- .../request/update/UpdateListRequest.java | 10 +- .../request/update/UpdateRequest.java | 34 +- .../uuid/BatchProfileByUsernameRequest.java | 4 +- .../request/uuid/ProfileByUUIDRequest.java | 8 +- .../uuid/ProfileByUsernameRequest.java | 4 +- .../request/websockets/ClientJSONPoint.java | 7 +- .../websockets/ClientWebSocketService.java | 11 +- .../websockets/JsonRequestAdapter.java | 11 +- .../launcher/server/ModulesManager.java | 6 +- .../gravit/launcher/server/ServerAgent.java | 20 +- .../launcher/server/ServerModuleContext.java | 2 +- .../gravit/launcher/server/ServerWrapper.java | 73 ++- .../main/java/ru/gravit/launcher/HWID.java | 2 + .../java/ru/gravit/launcher/Launcher.java | 16 +- .../ru/gravit/launcher/LauncherAgent.java | 4 +- .../ru/gravit/launcher/LauncherConfig.java | 34 +- .../java/ru/gravit/launcher/OshiHWID.java | 10 +- .../gravit/launcher/events/ControlEvent.java | 4 +- .../ru/gravit/launcher/events/PingEvent.java | 4 +- .../gravit/launcher/events/SignalEvent.java | 4 +- .../ru/gravit/launcher/hasher/DirWatcher.java | 23 +- .../launcher/hasher/FileNameMatcher.java | 4 +- .../ru/gravit/launcher/hasher/HashedDir.java | 22 +- .../gravit/launcher/hasher/HashedEntry.java | 4 +- .../launcher/hasher/HashedEntryAdapter.java | 11 +- .../ru/gravit/launcher/hasher/HashedFile.java | 8 +- .../launcher/managers/GarbageManager.java | 4 +- .../launcher/modules/SimpleModuleManager.java | 24 +- .../launcher/profiles/ClientProfile.java | 20 +- .../launcher/profiles/PlayerProfile.java | 8 +- .../ru/gravit/launcher/profiles/Texture.java | 12 +- .../launcher/request/RequestException.java | 4 +- .../gravit/launcher/request/RequestType.java | 4 +- .../gravit/launcher/request/UpdateAction.java | 4 +- .../ru/gravit/launcher/serialize/HInput.java | 6 +- .../ru/gravit/launcher/serialize/HOutput.java | 6 +- .../serialize/config/ConfigObject.java | 6 +- .../serialize/config/TextConfigReader.java | 13 +- .../serialize/config/TextConfigWriter.java | 11 +- .../config/entry/BlockConfigEntry.java | 12 +- .../config/entry/BooleanConfigEntry.java | 4 +- .../serialize/config/entry/ConfigEntry.java | 6 +- .../config/entry/IntegerConfigEntry.java | 4 +- .../config/entry/ListConfigEntry.java | 8 +- .../config/entry/StringConfigEntry.java | 4 +- .../serialize/signed/DigestBytesHolder.java | 8 +- .../serialize/signed/SignedBytesHolder.java | 10 +- .../serialize/signed/SignedObjectHolder.java | 8 +- .../serialize/stream/EnumSerializer.java | 8 +- .../serialize/stream/StreamObject.java | 6 +- .../launcher/ssl/LauncherSSLContext.java | 16 +- .../java/ru/gravit/utils/HTTPRequest.java | 9 +- .../java/ru/gravit/utils/HttpDownloader.java | 6 +- .../ru/gravit/utils/PublicURLClassLoader.java | 4 +- .../main/java/ru/gravit/utils/Version.java | 4 +- .../gravit/utils/downloader/Downloader.java | 9 +- .../ru/gravit/utils/event/EventManager.java | 6 +- .../ru/gravit/utils/helper/CommonHelper.java | 9 +- .../java/ru/gravit/utils/helper/IOHelper.java | 54 +- .../ru/gravit/utils/helper/JVMHelper.java | 8 +- .../ru/gravit/utils/helper/LogHelper.java | 23 +- .../gravit/utils/helper/SecurityHelper.java | 26 +- .../ru/gravit/utils/helper/UnpackHelper.java | 32 +- .../ru/gravit/utils/helper/VerifyHelper.java | 4 +- 184 files changed, 1389 insertions(+), 1733 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 42a0dcb0..4627a2ca 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -1,36 +1,5 @@ package ru.gravit.launchserver; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.MalformedURLException; -import java.net.SocketAddress; -import java.nio.file.DirectoryStream; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.security.KeyPair; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; -import java.security.spec.InvalidKeySpecException; -import java.time.Duration; -import java.time.Instant; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.zip.CRC32; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.hasher.HashedDir; @@ -39,17 +8,16 @@ import ru.gravit.launcher.serialize.config.ConfigObject; import ru.gravit.launcher.serialize.config.TextConfigReader; import ru.gravit.launcher.serialize.config.TextConfigWriter; -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; -import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry; -import ru.gravit.launcher.serialize.config.entry.IntegerConfigEntry; -import ru.gravit.launcher.serialize.config.entry.ListConfigEntry; -import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; +import ru.gravit.launcher.serialize.config.entry.*; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launchserver.auth.AuthLimiter; import ru.gravit.launchserver.auth.handler.AuthHandler; import ru.gravit.launchserver.auth.hwid.HWIDHandler; import ru.gravit.launchserver.auth.provider.AuthProvider; -import ru.gravit.launchserver.binary.*; +import ru.gravit.launchserver.binary.EXEL4JLauncherBinary; +import ru.gravit.launchserver.binary.EXELauncherBinary; +import ru.gravit.launchserver.binary.JARLauncherBinary; +import ru.gravit.launchserver.binary.LauncherBinary; import ru.gravit.launchserver.command.handler.CommandHandler; import ru.gravit.launchserver.command.handler.JLineCommandHandler; import ru.gravit.launchserver.command.handler.StdCommandHandler; @@ -60,12 +28,26 @@ import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.socket.ServerSocketHandler; import ru.gravit.launchserver.texture.TextureProvider; -import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.JVMHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.SecurityHelper; -import ru.gravit.utils.helper.VerifyHelper; +import ru.gravit.utils.helper.*; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.MalformedURLException; +import java.net.SocketAddress; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.security.KeyPair; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.InvalidKeySpecException; +import java.time.Duration; +import java.time.Instant; +import java.util.*; +import java.util.Map.Entry; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.zip.CRC32; public final class LaunchServer implements Runnable, AutoCloseable { public static final class Config extends ConfigObject { @@ -82,10 +64,10 @@ public static final class Config extends ConfigObject { public final HWIDHandler hwidHandler; // Misc options - public final int threadCount; - - public final int threadCoreCount; - + public final int threadCount; + + public final int threadCoreCount; + public final ExeConf launch4j; public final PostBuildTransformConf buildPostTransform; @@ -259,7 +241,7 @@ private PostBuildTransformConf(BlockConfigEntry block, Path coredir) { enabled = block.getEntryValue("enabled", BooleanConfigEntry.class); script = new ArrayList<>(1); if (block.hasEntry("script")) - block.getEntry("script", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(script::add); + block.getEntry("script", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(script::add); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java b/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java index 29e38b60..817acd01 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java @@ -1,19 +1,15 @@ package ru.gravit.launchserver; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.nio.file.Files; -import java.nio.file.Path; -import java.security.SecureRandom; -import java.util.ArrayList; - import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.SecureRandom; +import java.util.ArrayList; + public class ProguardConf { private static final String charsFirst = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"; private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ"; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java b/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java index 84893450..f0c1c091 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java @@ -2,12 +2,7 @@ import java.io.IOException; import java.lang.instrument.Instrumentation; -import java.nio.file.FileVisitOption; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; +import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.Collections; import java.util.jar.JarFile; @@ -28,10 +23,11 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO return super.visitFile(file, attrs); } } + public static Instrumentation inst; private static boolean isStarted = false; - public static boolean isAgentStarted() - { + + public static boolean isAgentStarted() { return isStarted; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java b/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java index e26c05a2..ca10e53b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java @@ -1,5 +1,10 @@ package ru.gravit.launchserver.asm; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.Opcodes; +import ru.gravit.utils.helper.IOHelper; + import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -7,87 +12,84 @@ import java.util.List; import java.util.jar.JarFile; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.Opcodes; - -import ru.gravit.utils.helper.IOHelper; - /** * Позволяет искать методы внутри незагруженных классов и общие суперклассы для * чего угодно. Работает через поиск class-файлов в classpath. */ public class ClassMetadataReader { - private class CheckSuperClassVisitor extends ClassVisitor { + private class CheckSuperClassVisitor extends ClassVisitor { - String superClassName; + String superClassName; - public CheckSuperClassVisitor() { - super(Opcodes.ASM5); - } + public CheckSuperClassVisitor() { + super(Opcodes.ASM5); + } - @Override - public void visit(int version, int access, String name, String signature, String superName, - String[] interfaces) { - superClassName = superName; - } - } + @Override + public void visit(int version, int access, String name, String signature, String superName, + String[] interfaces) { + superClassName = superName; + } + } - private final List cp; + private final List cp; - public ClassMetadataReader(List cp) { - this.cp = cp; - } - - public List getCp() { - return cp; - } + public ClassMetadataReader(List cp) { + this.cp = cp; + } - public ClassMetadataReader() { - this.cp = new ArrayList<>(); - } + public List getCp() { + return cp; + } - public void acceptVisitor(byte[] classData, ClassVisitor visitor) { - new ClassReader(classData).accept(visitor, 0); - } + public ClassMetadataReader() { + this.cp = new ArrayList<>(); + } - public void acceptVisitor(String className, ClassVisitor visitor) throws IOException { - acceptVisitor(getClassData(className), visitor); - } + public void acceptVisitor(byte[] classData, ClassVisitor visitor) { + new ClassReader(classData).accept(visitor, 0); + } - public byte[] getClassData(String className) throws IOException { - for (JarFile f : cp) { - if (f.getEntry(className + ".class") != null) try (InputStream in = f.getInputStream(f.getEntry(className + ".class"))) { return IOHelper.read(in); } - } - return IOHelper.read(IOHelper.getResourceURL(className + ".class")); - } + public void acceptVisitor(String className, ClassVisitor visitor) throws IOException { + acceptVisitor(getClassData(className), visitor); + } - public String getSuperClass(String type) { - if (type.equals("java/lang/Object")) return null; - try { - return getSuperClassASM(type); - } catch (Exception e) { - return "java/lang/Object"; - } - } + public byte[] getClassData(String className) throws IOException { + for (JarFile f : cp) { + if (f.getEntry(className + ".class") != null) + try (InputStream in = f.getInputStream(f.getEntry(className + ".class"))) { + return IOHelper.read(in); + } + } + return IOHelper.read(IOHelper.getResourceURL(className + ".class")); + } - protected String getSuperClassASM(String type) throws IOException { - CheckSuperClassVisitor cv = new CheckSuperClassVisitor(); - acceptVisitor(type, cv); - return cv.superClassName; - } + public String getSuperClass(String type) { + if (type.equals("java/lang/Object")) return null; + try { + return getSuperClassASM(type); + } catch (Exception e) { + return "java/lang/Object"; + } + } - /** - * Возвращает суперклассы в порядке возрастающей конкретности (начиная с - * java/lang/Object и заканчивая данным типом) - */ - public ArrayList getSuperClasses(String type) { - ArrayList superclasses = new ArrayList<>(1); - superclasses.add(type); - while ((type = getSuperClass(type)) != null) - superclasses.add(type); - Collections.reverse(superclasses); - return superclasses; - } + protected String getSuperClassASM(String type) throws IOException { + CheckSuperClassVisitor cv = new CheckSuperClassVisitor(); + acceptVisitor(type, cv); + return cv.superClassName; + } + + /** + * Возвращает суперклассы в порядке возрастающей конкретности (начиная с + * java/lang/Object и заканчивая данным типом) + */ + public ArrayList getSuperClasses(String type) { + ArrayList superclasses = new ArrayList<>(1); + superclasses.add(type); + while ((type = getSuperClass(type)) != null) + superclasses.add(type); + Collections.reverse(superclasses); + return superclasses; + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/asm/SafeClassWriter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/asm/SafeClassWriter.java index 5aa2a11c..34ef1b44 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/asm/SafeClassWriter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/asm/SafeClassWriter.java @@ -1,40 +1,40 @@ package ru.gravit.launchserver.asm; -import java.util.ArrayList; - import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; +import java.util.ArrayList; + /** * ClassWriter с другой реализацией метода getCommonSuperClass: при его * использовании не происходит загрузки классов. */ public class SafeClassWriter extends ClassWriter { - private final ClassMetadataReader classMetadataReader; + private final ClassMetadataReader classMetadataReader; - public SafeClassWriter(ClassMetadataReader classMetadataReader, int flags) { - super(flags); - this.classMetadataReader = classMetadataReader; - } + public SafeClassWriter(ClassMetadataReader classMetadataReader, int flags) { + super(flags); + this.classMetadataReader = classMetadataReader; + } - public SafeClassWriter(ClassReader classReader, ClassMetadataReader classMetadataReader, int flags) { - super(classReader, flags); - this.classMetadataReader = classMetadataReader; - } - - @Override - protected String getCommonSuperClass(String type1, String type2) { - ArrayList superClasses1 = classMetadataReader.getSuperClasses(type1); - ArrayList superClasses2 = classMetadataReader.getSuperClasses(type2); - int size = Math.min(superClasses1.size(), superClasses2.size()); - int i; - for (i = 0; i < size && superClasses1.get(i).equals(superClasses2.get(i)); i++) - ; - if (i == 0) - return "java/lang/Object"; - else - return superClasses1.get(i - 1); - } + public SafeClassWriter(ClassReader classReader, ClassMetadataReader classMetadataReader, int flags) { + super(classReader, flags); + this.classMetadataReader = classMetadataReader; + } + + @Override + protected String getCommonSuperClass(String type1, String type2) { + ArrayList superClasses1 = classMetadataReader.getSuperClasses(type1); + ArrayList superClasses2 = classMetadataReader.getSuperClasses(type2); + int size = Math.min(superClasses1.size(), superClasses2.size()); + int i; + for (i = 0; i < size && superClasses1.get(i).equals(superClasses2.get(i)); i++) + ; + if (i == 0) + return "java/lang/Object"; + else + return superClasses1.get(i - 1); + } } \ No newline at end of file diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthLimiter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthLimiter.java index faef83be..6e141fb0 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthLimiter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthLimiter.java @@ -1,13 +1,13 @@ package ru.gravit.launchserver.auth; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - import ru.gravit.launcher.NeedGarbageCollection; import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; import ru.gravit.launchserver.LaunchServer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + public class AuthLimiter implements NeedGarbageCollection { static class AuthEntry { public int value; @@ -54,12 +54,13 @@ public String toString() { public final int rateLimitMilis; private final HashMap map; - private final List excludeIps; + private final List excludeIps; public AuthLimiter(LaunchServer srv) { map = new HashMap<>(); excludeIps = new ArrayList<>(); - if (srv.config.authLimitExclusions != null) srv.config.authLimitExclusions.stream(StringConfigEntry.class).forEach(excludeIps::add); + if (srv.config.authLimitExclusions != null) + srv.config.authLimitExclusions.stream(StringConfigEntry.class).forEach(excludeIps::add); rateLimit = srv.config.authRateLimit; rateLimitMilis = srv.config.authRateLimitMilis; } @@ -72,7 +73,7 @@ public void garbageCollection() { } public boolean isLimit(String ip) { - if (excludeIps.contains(ip)) return false; + if (excludeIps.contains(ip)) return false; if (map.containsKey(ip)) { AuthEntry rate = map.get(ip); long currenttime = System.currentTimeMillis(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java index 11837fbd..03fc48fe 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java @@ -1,14 +1,8 @@ package ru.gravit.launchserver.auth; -import java.sql.Connection; -import java.sql.SQLException; - -import javax.sql.DataSource; - import com.mysql.cj.jdbc.MysqlDataSource; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; - import ru.gravit.launcher.serialize.config.ConfigObject; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry; @@ -17,6 +11,10 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; + public final class MySQLSourceConfig extends ConfigObject implements AutoCloseable { public static final int TIMEOUT = VerifyHelper.verifyInt( diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java index 823b777a..26b2aaff 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java @@ -1,17 +1,17 @@ package ru.gravit.launchserver.auth.handler; -import java.io.IOException; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - import ru.gravit.launcher.serialize.config.ConfigObject; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.provider.AuthProviderResult; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + public abstract class AuthHandler extends ConfigObject implements AutoCloseable { private static final Map> AUTH_HANDLERS = new ConcurrentHashMap<>(4); private static boolean registredHandl = false; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java index 869a37b0..ebe2947c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java @@ -1,15 +1,15 @@ package ru.gravit.launchserver.auth.handler; -import java.io.IOException; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.utils.helper.IOHelper; +import java.io.IOException; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + public final class BinaryFileAuthHandler extends FileAuthHandler { public BinaryFileAuthHandler(BlockConfigEntry block) { super(block); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java index 03bbb464..2306702c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java @@ -1,11 +1,5 @@ package ru.gravit.launchserver.auth.handler; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; - import ru.gravit.launcher.NeedGarbageCollection; import ru.gravit.launcher.managers.GarbageManager; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; @@ -15,6 +9,12 @@ import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; + public abstract class CachedAuthHandler extends AuthHandler implements NeedGarbageCollection { public static final class Entry { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java index 881b5471..f5d6d13e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java @@ -1,15 +1,5 @@ package ru.gravit.launchserver.auth.handler; -import java.io.IOException; -import java.nio.file.Path; -import java.security.SecureRandom; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.locks.ReentrantReadWriteLock; - import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -18,11 +8,13 @@ import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; import ru.gravit.launcher.serialize.stream.StreamObject; import ru.gravit.launchserver.auth.provider.AuthProviderResult; -import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.SecurityHelper; -import ru.gravit.utils.helper.VerifyHelper; +import ru.gravit.utils.helper.*; + +import java.io.IOException; +import java.nio.file.Path; +import java.security.SecureRandom; +import java.util.*; +import java.util.concurrent.locks.ReentrantReadWriteLock; public abstract class FileAuthHandler extends AuthHandler { public static final class Entry extends StreamObject { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MemoryAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MemoryAuthHandler.java index 8afe2704..ada8bff4 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MemoryAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MemoryAuthHandler.java @@ -1,14 +1,14 @@ package ru.gravit.launchserver.auth.handler; -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.UUID; - import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.UUID; + public final class MemoryAuthHandler extends CachedAuthHandler { private static String toUsername(UUID uuid) { byte[] bytes = ByteBuffer.allocate(16). diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java index 234c71d2..dba83b2e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java @@ -1,5 +1,10 @@ package ru.gravit.launchserver.auth.handler; +import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; +import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; +import ru.gravit.launchserver.auth.MySQLSourceConfig; +import ru.gravit.utils.helper.VerifyHelper; + import java.io.IOException; import java.sql.Connection; import java.sql.PreparedStatement; @@ -7,11 +12,6 @@ import java.sql.SQLException; import java.util.UUID; -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; -import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; -import ru.gravit.launchserver.auth.MySQLSourceConfig; -import ru.gravit.utils.helper.VerifyHelper; - public final class MySQLAuthHandler extends CachedAuthHandler { private final MySQLSourceConfig mySQLHolder; private final String uuidColumn; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/NullAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/NullAuthHandler.java index 0c5ab784..6fac6757 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/NullAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/NullAuthHandler.java @@ -1,13 +1,13 @@ package ru.gravit.launchserver.auth.handler; -import java.io.IOException; -import java.util.Objects; -import java.util.UUID; - import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.launchserver.auth.provider.AuthProviderResult; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.Objects; +import java.util.UUID; + public final class NullAuthHandler extends AuthHandler { private volatile AuthHandler handler; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/TextFileAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/TextFileAuthHandler.java index cbbbec84..1ef885f1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/TextFileAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/TextFileAuthHandler.java @@ -1,13 +1,5 @@ package ru.gravit.launchserver.auth.handler; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - import ru.gravit.launcher.serialize.config.TextConfigReader; import ru.gravit.launcher.serialize.config.TextConfigWriter; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; @@ -17,6 +9,14 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + public final class TextFileAuthHandler extends FileAuthHandler { private static StringConfigEntry cc(String value) { StringConfigEntry entry = new StringConfigEntry(value, true, 4); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java index 5a9802ab..9387822c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.auth.hwid; -import java.util.ArrayList; -import java.util.List; - import ru.gravit.launcher.HWID; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; +import java.util.ArrayList; +import java.util.List; + public class AcceptHWIDHandler extends HWIDHandler { public AcceptHWIDHandler(BlockConfigEntry block) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java index 197c5501..a60e3194 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java @@ -1,15 +1,15 @@ package ru.gravit.launchserver.auth.hwid; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; - import ru.gravit.launcher.HWID; import ru.gravit.launcher.serialize.config.ConfigObject; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.utils.helper.VerifyHelper; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; + public abstract class HWIDHandler extends ConfigObject implements AutoCloseable { private static final Map> HW_HANDLERS = new ConcurrentHashMap<>(4); private static boolean registredHandl = false; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java index ca72ea45..6c0b1f1c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java @@ -1,13 +1,7 @@ package ru.gravit.launchserver.auth.hwid; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - import com.google.gson.Gson; import com.google.gson.JsonElement; - import ru.gravit.launcher.HWID; import ru.gravit.launcher.OshiHWID; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; @@ -16,25 +10,30 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + public final class JsonHWIDHandler extends HWIDHandler { private static final Gson gson = new Gson(); @SuppressWarnings("unused") - private final URL url; + private final URL url; private final URL urlBan; private final URL urlUnBan; @SuppressWarnings("unused") private final URL urlGet; - public class banRequest - { + public class banRequest { public banRequest(String hwid) { this.hwid = hwid; } + String hwid; } - public class checkRequest - { + + public class checkRequest { public checkRequest(String username, String hwid) { this.username = username; this.hwid = hwid; @@ -44,21 +43,21 @@ public checkRequest(String username, String hwid) { String hwid; } - public class Result - { + + public class Result { String error; } - public class BannedResult - { + + public class BannedResult { boolean isBanned; String error; } - public class HWIDResult - { + + public class HWIDResult { String string; } - public class HWIDRequest - { + + public class HWIDRequest { public HWIDRequest(String username) { this.username = username; } @@ -84,8 +83,8 @@ public void ban(List l_hwid) throws HWIDException { banRequest request = new banRequest(hwid.getSerializeString()); try { JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan); - Result r = gson.fromJson(result,Result.class); - if(r.error != null) throw new HWIDException(r.error); + Result r = gson.fromJson(result, Result.class); + if (r.error != null) throw new HWIDException(r.error); } catch (IOException e) { LogHelper.error(e); throw new HWIDException("HWID service error"); @@ -95,11 +94,11 @@ public void ban(List l_hwid) throws HWIDException { @Override public void check0(HWID hwid, String username) throws HWIDException { - checkRequest request = new checkRequest(username,hwid.getSerializeString()); + checkRequest request = new checkRequest(username, hwid.getSerializeString()); try { JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan); - BannedResult r = gson.fromJson(result,BannedResult.class); - if(r.error != null) throw new HWIDException(r.error); + BannedResult r = gson.fromJson(result, BannedResult.class); + if (r.error != null) throw new HWIDException(r.error); boolean isBanned = r.isBanned; if (isBanned) throw new HWIDException("You will BANNED!"); } catch (IOException e) { @@ -119,10 +118,9 @@ public List getHwid(String username) throws HWIDException { HWIDRequest request = new HWIDRequest(username); try { JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan); - HWIDResult[] r = gson.fromJson(result,HWIDResult[].class); - for( HWIDResult hw : r) - { - hwids.add(OshiHWID.gson.fromJson(hw.string,OshiHWID.class)); + HWIDResult[] r = gson.fromJson(result, HWIDResult[].class); + for (HWIDResult hw : r) { + hwids.add(OshiHWID.gson.fromJson(hw.string, OshiHWID.class)); } } catch (IOException e) { LogHelper.error(e); @@ -137,8 +135,8 @@ public void unban(List l_hwid) throws HWIDException { banRequest request = new banRequest(hwid.getSerializeString()); try { JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlUnBan); - Result r = gson.fromJson(result,Result.class); - if(r.error != null) throw new HWIDException(r.error); + Result r = gson.fromJson(result, Result.class); + if (r.error != null) throw new HWIDException(r.error); } catch (IOException e) { LogHelper.error(e); throw new HWIDException("HWID service error"); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java index de335272..4d629443 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java @@ -1,12 +1,5 @@ package ru.gravit.launchserver.auth.hwid; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - import ru.gravit.launcher.HWID; import ru.gravit.launcher.OshiHWID; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; @@ -17,6 +10,13 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + public class MysqlHWIDHandler extends HWIDHandler { private final MySQLSourceConfig mySQLHolder; private final String query; @@ -172,7 +172,7 @@ public List getHwid(String username) { hwid_str = set.getString(hwidName); } ArrayList list = new ArrayList<>(); - HWID hwid = OshiHWID.gson.fromJson(hwid_str,OshiHWID.class); + HWID hwid = OshiHWID.gson.fromJson(hwid_str, OshiHWID.class); if (hwid.isNull()) { LogHelper.warning("Null HWID"); } else { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java index 3e7199c9..03340ff0 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java @@ -1,10 +1,5 @@ package ru.gravit.launchserver.auth.provider; -import java.io.IOException; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; - import ru.gravit.launcher.serialize.config.ConfigObject; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.launchserver.LaunchServer; @@ -12,6 +7,11 @@ import ru.gravit.launchserver.auth.handler.AuthHandler; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; + public abstract class AuthProvider extends ConfigObject implements AutoCloseable { private static final Map> AUTH_PROVIDERS = new ConcurrentHashMap<>(8); private static boolean registredProv = false; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/FileAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/FileAuthProvider.java index b2ddf936..d9c98106 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/FileAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/FileAuthProvider.java @@ -1,13 +1,5 @@ package ru.gravit.launchserver.auth.provider; -import java.io.BufferedReader; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.attribute.FileTime; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - import ru.gravit.launcher.serialize.config.ConfigObject; import ru.gravit.launcher.serialize.config.TextConfigReader; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; @@ -15,11 +7,15 @@ import ru.gravit.launcher.serialize.config.entry.ConfigEntry.Type; import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; import ru.gravit.launchserver.LaunchServer; -import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.SecurityHelper; -import ru.gravit.utils.helper.VerifyHelper; +import ru.gravit.utils.helper.*; + +import java.io.BufferedReader; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.attribute.FileTime; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; public final class FileAuthProvider extends DigestAuthProvider { private static final class Entry extends ConfigObject { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java index adcebad6..21b641c4 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/JsonAuthProvider.java @@ -1,11 +1,7 @@ package ru.gravit.launchserver.auth.provider; -import java.io.IOException; -import java.net.URL; - import com.google.gson.Gson; import com.google.gson.JsonElement; - import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; import ru.gravit.launchserver.LaunchServer; @@ -14,17 +10,20 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.net.URL; + public final class JsonAuthProvider extends AuthProvider { private final Gson gson = new Gson(); private final URL url; - public class authResult - { + + public class authResult { String username; String error; long permissions; } - public class authRequest - { + + public class authRequest { public authRequest(String username, String password, String ip) { this.username = username; this.password = password; @@ -44,7 +43,7 @@ public authRequest(String username, String password, String ip) { @Override public AuthProviderResult auth(String login, String password, String ip) throws IOException { - authRequest authRequest = new authRequest(login,password,ip); + authRequest authRequest = new authRequest(login, password, ip); JsonElement request = gson.toJsonTree(authRequest); JsonElement content = HTTPRequest.jsonRequest(request, url); if (!content.isJsonObject()) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MojangAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MojangAuthProvider.java index c7a56de9..3feaba8c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MojangAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MojangAuthProvider.java @@ -1,18 +1,17 @@ package ru.gravit.launchserver.auth.provider; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.utils.HTTPRequest; + import java.net.MalformedURLException; import java.net.URL; import java.util.UUID; import java.util.regex.Pattern; -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.utils.HTTPRequest; - public final class MojangAuthProvider extends AuthProvider { private static final Pattern UUID_REGEX = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})"); private static final URL URL; @@ -29,8 +28,8 @@ public final class MojangAuthProvider extends AuthProvider { public MojangAuthProvider(BlockConfigEntry block, LaunchServer server) { super(block, server); } - public class mojangAuth - { + + public class mojangAuth { public mojangAuth(String username, String password) { this.username = username; this.password = password; @@ -44,13 +43,14 @@ public mojangAuth(String username, String password) { String password; } + @Override public AuthProviderResult auth(String login, String password, String ip) throws Exception { - mojangAuth mojangAuth = new mojangAuth(login,password); + mojangAuth mojangAuth = new mojangAuth(login, password); JsonElement request = gson.toJsonTree(mojangAuth); // Verify there's no error - JsonObject response = HTTPRequest.jsonRequest(request,URL).getAsJsonObject(); + JsonObject response = HTTPRequest.jsonRequest(request, URL).getAsJsonObject(); if (response == null) authError("Empty com.mojang response"); JsonElement errorMessage = response.get("errorMessage"); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java index 6a4dd9f7..524ea713 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java @@ -1,10 +1,5 @@ package ru.gravit.launchserver.auth.provider; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry; import ru.gravit.launcher.serialize.config.entry.ListConfigEntry; @@ -17,6 +12,11 @@ import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + public final class MySQLAuthProvider extends AuthProvider { private final MySQLSourceConfig mySQLHolder; private final String query; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/NullAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/NullAuthProvider.java index b523fdea..c3590692 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/NullAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/NullAuthProvider.java @@ -1,12 +1,12 @@ package ru.gravit.launchserver.auth.provider; -import java.io.IOException; -import java.util.Objects; - import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.Objects; + public final class NullAuthProvider extends AuthProvider { private volatile AuthProvider provider; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RequestAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RequestAuthProvider.java index 2ca028ba..125c0c49 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RequestAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RequestAuthProvider.java @@ -1,10 +1,5 @@ package ru.gravit.launchserver.auth.provider; -import java.io.IOException; -import java.net.URL; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry; import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; @@ -14,6 +9,11 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.net.URL; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + public final class RequestAuthProvider extends AuthProvider { private final String url; private final Pattern response; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java index 49a9e669..c8905f15 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/BuildContext.java @@ -1,5 +1,7 @@ package ru.gravit.launchserver.binary; +import ru.gravit.utils.helper.IOHelper; + import java.io.IOException; import java.io.InputStream; import java.util.Set; @@ -7,8 +9,6 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; -import ru.gravit.utils.helper.IOHelper; - public class BuildContext { public final ZipOutputStream output; public final JAConfigurator config; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java index 5d6c5c06..1169083b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java @@ -1,20 +1,16 @@ package ru.gravit.launchserver.binary; -import java.io.IOException; -import java.nio.file.Path; - import net.sf.launch4j.Builder; import net.sf.launch4j.Log; -import net.sf.launch4j.config.Config; -import net.sf.launch4j.config.ConfigPersister; -import net.sf.launch4j.config.Jre; -import net.sf.launch4j.config.LanguageID; -import net.sf.launch4j.config.VersionInfo; +import net.sf.launch4j.config.*; import ru.gravit.launcher.Launcher; import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.Path; + public final class EXEL4JLauncherBinary extends LauncherBinary { private final static class Launch4JLog extends Log { private static final Launch4JLog INSTANCE = new Launch4JLog(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXELauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXELauncherBinary.java index 8b5b0520..50b13d4b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXELauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXELauncherBinary.java @@ -1,12 +1,12 @@ package ru.gravit.launchserver.binary; -import java.io.IOException; -import java.nio.file.Files; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.Files; + public class EXELauncherBinary extends LauncherBinary { public EXELauncherBinary(LaunchServer server) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java index 07a107c8..3803b744 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java @@ -1,16 +1,11 @@ - package ru.gravit.launchserver.binary; +package ru.gravit.launchserver.binary; + +import javassist.*; +import ru.gravit.launcher.LauncherConfig; import java.io.IOException; -import javassist.CannotCompileException; -import javassist.ClassPool; -import javassist.CtClass; -import javassist.CtConstructor; -import javassist.CtMethod; -import javassist.NotFoundException; -import ru.gravit.launcher.LauncherConfig; - - public class JAConfigurator implements AutoCloseable { +public class JAConfigurator implements AutoCloseable { public ClassPool pool; public CtClass ctClass; public CtConstructor ctConstructor; @@ -21,9 +16,9 @@ public class JAConfigurator implements AutoCloseable { int autoincrement; public JAConfigurator(String configclass, JARLauncherBinary jarLauncherBinary) throws NotFoundException { - pool = new ClassPool(false); - pool.insertClassPath(jarLauncherBinary.cleanJar.toFile().getAbsolutePath()); - pool.appendSystemPath(); + pool = new ClassPool(false); + pool.insertClassPath(jarLauncherBinary.cleanJar.toFile().getAbsolutePath()); + pool.appendSystemPath(); classname = configclass; ctClass = pool.get(classname); ctConstructor = ctClass.getDeclaredConstructor(null); @@ -93,10 +88,10 @@ public void setPort(int port) { body.append(port); body.append(";"); } + public void setEnv(LauncherConfig.LauncherEnvironment env) { int i = 2; - switch(env) - { + switch (env) { case DEV: i = 0; @@ -133,6 +128,7 @@ public void setDownloadJava(boolean b) { body.append(b ? "true" : "false"); body.append(";"); } + public void setWarningMissArchJava(boolean b) { body.append("this.isWarningMissArchJava = "); body.append(b ? "true" : "false"); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java index 68ffa9e2..7cfe660b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java @@ -1,6 +1,20 @@ package ru.gravit.launchserver.binary; -import static ru.gravit.utils.helper.IOHelper.newZipEntry; +import javassist.CannotCompileException; +import javassist.NotFoundException; +import proguard.Configuration; +import proguard.ConfigurationParser; +import proguard.ParseException; +import proguard.ProGuard; +import ru.gravit.launcher.AutogenConfig; +import ru.gravit.launcher.Launcher; +import ru.gravit.launcher.LauncherConfig; +import ru.gravit.launcher.serialize.HOutput; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.asm.ClassMetadataReader; +import ru.gravit.launchserver.manangers.BuildHookManager.ZipBuildHook; +import ru.gravit.utils.helper.*; +import ru.gravit.utils.helper.SecurityHelper.DigestAlgorithm; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -20,276 +34,258 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; -import javassist.CannotCompileException; -import javassist.NotFoundException; -import proguard.Configuration; -import proguard.ConfigurationParser; -import proguard.ParseException; -import proguard.ProGuard; -import ru.gravit.launcher.AutogenConfig; -import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.LauncherConfig; -import ru.gravit.launcher.serialize.HOutput; -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.asm.ClassMetadataReader; -import ru.gravit.launchserver.manangers.BuildHookManager.ZipBuildHook; -import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.SecurityHelper; -import ru.gravit.utils.helper.SecurityHelper.DigestAlgorithm; -import ru.gravit.utils.helper.UnpackHelper; +import static ru.gravit.utils.helper.IOHelper.newZipEntry; public final class JARLauncherBinary extends LauncherBinary { - private final class RuntimeDirVisitor extends SimpleFileVisitor { - private final ZipOutputStream output; - private final Map runtime; + private final class RuntimeDirVisitor extends SimpleFileVisitor { + private final ZipOutputStream output; + private final Map runtime; - private RuntimeDirVisitor(ZipOutputStream output, Map runtime) { - this.output = output; - this.runtime = runtime; - } + private RuntimeDirVisitor(ZipOutputStream output, Map runtime) { + this.output = output; + this.runtime = runtime; + } - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { - String dirName = IOHelper.toString(runtimeDir.relativize(dir)); - output.putNextEntry(newEntry(dirName + '/')); - return super.preVisitDirectory(dir, attrs); - } + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + String dirName = IOHelper.toString(runtimeDir.relativize(dir)); + output.putNextEntry(newEntry(dirName + '/')); + return super.preVisitDirectory(dir, attrs); + } - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - String fileName = IOHelper.toString(runtimeDir.relativize(file)); - runtime.put(fileName, SecurityHelper.digest(DigestAlgorithm.MD5, file)); + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + String fileName = IOHelper.toString(runtimeDir.relativize(file)); + runtime.put(fileName, SecurityHelper.digest(DigestAlgorithm.MD5, file)); - // Create zip entry and transfer contents - output.putNextEntry(newEntry(fileName)); - IOHelper.transfer(file, output); + // Create zip entry and transfer contents + output.putNextEntry(newEntry(fileName)); + IOHelper.transfer(file, output); - // Return result - return super.visitFile(file, attrs); - } - } + // Return result + return super.visitFile(file, attrs); + } + } - // TODO: new native security wrapper and library... - @SuppressWarnings("unused") - private final class GuardDirVisitor extends SimpleFileVisitor { - private final ZipOutputStream output; - private final Map guard; + // TODO: new native security wrapper and library... + @SuppressWarnings("unused") + private final class GuardDirVisitor extends SimpleFileVisitor { + private final ZipOutputStream output; + private final Map guard; - private GuardDirVisitor(ZipOutputStream output, Map guard) { - this.output = output; - this.guard = guard; - } + private GuardDirVisitor(ZipOutputStream output, Map guard) { + this.output = output; + this.guard = guard; + } - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { - String dirName = IOHelper.toString(guardDir.relativize(dir)); - output.putNextEntry(newGuardEntry(dirName + '/')); - return super.preVisitDirectory(dir, attrs); - } + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + String dirName = IOHelper.toString(guardDir.relativize(dir)); + output.putNextEntry(newGuardEntry(dirName + '/')); + return super.preVisitDirectory(dir, attrs); + } - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - String fileName = IOHelper.toString(guardDir.relativize(file)); - guard.put(fileName, SecurityHelper.digest(DigestAlgorithm.MD5, file)); + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + String fileName = IOHelper.toString(guardDir.relativize(file)); + guard.put(fileName, SecurityHelper.digest(DigestAlgorithm.MD5, file)); - // Create zip entry and transfer contents - output.putNextEntry(newGuardEntry(fileName)); - IOHelper.transfer(file, output); + // Create zip entry and transfer contents + output.putNextEntry(newGuardEntry(fileName)); + IOHelper.transfer(file, output); - // Return result - return super.visitFile(file, attrs); - } - } + // Return result + return super.visitFile(file, attrs); + } + } - private static ZipEntry newEntry(String fileName) { - return newZipEntry(Launcher.RUNTIME_DIR + IOHelper.CROSS_SEPARATOR + fileName); - } + private static ZipEntry newEntry(String fileName) { + return newZipEntry(Launcher.RUNTIME_DIR + IOHelper.CROSS_SEPARATOR + fileName); + } - private static ZipEntry newGuardEntry(String fileName) { - return newZipEntry(Launcher.GUARD_DIR + IOHelper.CROSS_SEPARATOR + fileName); - } + private static ZipEntry newGuardEntry(String fileName) { + return newZipEntry(Launcher.GUARD_DIR + IOHelper.CROSS_SEPARATOR + fileName); + } - public final Path cleanJar; - public final Path runtimeDir; - public final Path guardDir; - public final Path initScriptFile; - public final Path obfJar; - public final Path obfOutJar; - public ClassMetadataReader reader; + public final Path cleanJar; + public final Path runtimeDir; + public final Path guardDir; + public final Path initScriptFile; + public final Path obfJar; + public final Path obfOutJar; + public ClassMetadataReader reader; - public JARLauncherBinary(LaunchServer server) throws IOException { - super(server, server.dir.resolve(server.config.binaryName + "-nonObf.jar"), - server.dir.resolve(server.config.binaryName + ".jar")); - runtimeDir = server.dir.resolve(Launcher.RUNTIME_DIR); - guardDir = server.dir.resolve(Launcher.GUARD_DIR); - initScriptFile = runtimeDir.resolve(Launcher.INIT_SCRIPT_FILE); - obfJar = server.dir.resolve(server.config.binaryName + "-obfed.jar"); - obfOutJar = server.config.buildPostTransform.enabled ? server.dir.resolve(server.config.binaryName + "-obf.jar") - : syncBinaryFile; - cleanJar = server.dir.resolve(server.config.binaryName + "-clean.jar"); - reader = new ClassMetadataReader(); - UnpackHelper.unpack(IOHelper.getResourceURL("Launcher.jar"), cleanJar); - reader.getCp().add(new JarFile(cleanJar.toFile())); - tryUnpack(); - } + public JARLauncherBinary(LaunchServer server) throws IOException { + super(server, server.dir.resolve(server.config.binaryName + "-nonObf.jar"), + server.dir.resolve(server.config.binaryName + ".jar")); + runtimeDir = server.dir.resolve(Launcher.RUNTIME_DIR); + guardDir = server.dir.resolve(Launcher.GUARD_DIR); + initScriptFile = runtimeDir.resolve(Launcher.INIT_SCRIPT_FILE); + obfJar = server.dir.resolve(server.config.binaryName + "-obfed.jar"); + obfOutJar = server.config.buildPostTransform.enabled ? server.dir.resolve(server.config.binaryName + "-obf.jar") + : syncBinaryFile; + cleanJar = server.dir.resolve(server.config.binaryName + "-clean.jar"); + reader = new ClassMetadataReader(); + UnpackHelper.unpack(IOHelper.getResourceURL("Launcher.jar"), cleanJar); + reader.getCp().add(new JarFile(cleanJar.toFile())); + tryUnpack(); + } - @Override - public void build() throws IOException { - tryUnpack(); + @Override + public void build() throws IOException { + tryUnpack(); - // Build launcher binary - LogHelper.info("Building launcher binary file"); - stdBuild(); + // Build launcher binary + LogHelper.info("Building launcher binary file"); + stdBuild(); - // ProGuard - Configuration proguard_cfg = new Configuration(); - ConfigurationParser parser = new ConfigurationParser(server.proguardConf.confStrs.toArray(new String[0]), - server.proguardConf.proguard.toFile(), System.getProperties()); - try { - parser.parse(proguard_cfg); - ProGuard proGuard = new ProGuard(proguard_cfg); - proGuard.execute(); - } catch (ParseException e1) { - e1.printStackTrace(); - } - for (Runnable r : server.buildHookManager.getPostProguardRunHooks()) - r.run(); - try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(obfJar)); - ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(obfOutJar))) { - ZipEntry e = input.getNextEntry(); - while (e != null) { - String filename = e.getName(); - output.putNextEntry(IOHelper.newZipEntry(e.getName())); - if (filename.endsWith(".class")) { - String classname = filename.replace('/', '.').substring(0, filename.length() - ".class".length()); - byte[] bytes; - try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) { - IOHelper.transfer(input, outputStream); - bytes = outputStream.toByteArray(); - } - bytes = server.buildHookManager.proGuardClassTransform(bytes, classname, this); - try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) { - IOHelper.transfer(inputStream, output); - } - } else - IOHelper.transfer(input, output); - e = input.getNextEntry(); - } - for (ZipBuildHook h : server.buildHookManager.getProguardBuildHooks()) - h.build(output); - } - if (server.config.buildPostTransform.enabled) - transformedBuild(); - } + // ProGuard + Configuration proguard_cfg = new Configuration(); + ConfigurationParser parser = new ConfigurationParser(server.proguardConf.confStrs.toArray(new String[0]), + server.proguardConf.proguard.toFile(), System.getProperties()); + try { + parser.parse(proguard_cfg); + ProGuard proGuard = new ProGuard(proguard_cfg); + proGuard.execute(); + } catch (ParseException e1) { + e1.printStackTrace(); + } + for (Runnable r : server.buildHookManager.getPostProguardRunHooks()) + r.run(); + try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(obfJar)); + ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(obfOutJar))) { + ZipEntry e = input.getNextEntry(); + while (e != null) { + String filename = e.getName(); + output.putNextEntry(IOHelper.newZipEntry(e.getName())); + if (filename.endsWith(".class")) { + String classname = filename.replace('/', '.').substring(0, filename.length() - ".class".length()); + byte[] bytes; + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) { + IOHelper.transfer(input, outputStream); + bytes = outputStream.toByteArray(); + } + bytes = server.buildHookManager.proGuardClassTransform(bytes, classname, this); + try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) { + IOHelper.transfer(inputStream, output); + } + } else + IOHelper.transfer(input, output); + e = input.getNextEntry(); + } + for (ZipBuildHook h : server.buildHookManager.getProguardBuildHooks()) + h.build(output); + } + if (server.config.buildPostTransform.enabled) + transformedBuild(); + } - private void transformedBuild() throws IOException { - List cmd = new ArrayList<>(1); - for (String v : server.config.buildPostTransform.script) - cmd.add(CommonHelper.replace(v, "launcher-output", IOHelper.toAbsPathString(syncBinaryFile), "launcher-obf", - IOHelper.toAbsPathString(obfJar), "launcher-nonObf", IOHelper.toAbsPathString(binaryFile))); - ProcessBuilder builder = new ProcessBuilder(); - builder.directory(IOHelper.toAbsPath(server.dir).toFile()); - builder.inheritIO(); - builder.command(cmd); - Process proc = builder.start(); - try { - LogHelper.debug("Transformer process return code: " + proc.waitFor()); - } catch (InterruptedException e) { - LogHelper.error(e); - } - } + private void transformedBuild() throws IOException { + List cmd = new ArrayList<>(1); + for (String v : server.config.buildPostTransform.script) + cmd.add(CommonHelper.replace(v, "launcher-output", IOHelper.toAbsPathString(syncBinaryFile), "launcher-obf", + IOHelper.toAbsPathString(obfJar), "launcher-nonObf", IOHelper.toAbsPathString(binaryFile))); + ProcessBuilder builder = new ProcessBuilder(); + builder.directory(IOHelper.toAbsPath(server.dir).toFile()); + builder.inheritIO(); + builder.command(cmd); + Process proc = builder.start(); + try { + LogHelper.debug("Transformer process return code: " + proc.waitFor()); + } catch (InterruptedException e) { + LogHelper.error(e); + } + } - private void stdBuild() throws IOException { - try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(binaryFile)); - JAConfigurator jaConfigurator = new JAConfigurator(AutogenConfig.class.getName(), this)) { - jaConfigurator.pool.insertClassPath(cleanJar.toFile().getAbsolutePath()); - BuildContext context = new BuildContext(output, jaConfigurator, this); - server.buildHookManager.preHook(context); - jaConfigurator.setAddress(server.config.getAddress()); - jaConfigurator.setPort(server.config.port); - jaConfigurator.setProjectName(server.config.projectName); - jaConfigurator.setSecretKey(SecurityHelper.randomStringAESKey()); - jaConfigurator.setClientPort(32148 + SecurityHelper.newRandom().nextInt(512)); - jaConfigurator.setUsingWrapper(server.config.isUsingWrapper); - jaConfigurator.setDownloadJava(server.config.isDownloadJava); - jaConfigurator.setEnv(server.config.env); - server.buildHookManager.registerAllClientModuleClass(jaConfigurator); - try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(cleanJar))) { - ZipEntry e = input.getNextEntry(); - while (e != null) { - String filename = e.getName(); - if (server.buildHookManager.isContainsBlacklist(filename)) { - e = input.getNextEntry(); - continue; - } - try { - output.putNextEntry(IOHelper.newZipEntry(e.getName())); - } catch (ZipException ex) { - LogHelper.error(ex); - e = input.getNextEntry(); - continue; - } - if (filename.endsWith(".class")) { - String classname = filename.replace('/', '.').substring(0, - filename.length() - ".class".length()); - byte[] bytes; - try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) { - IOHelper.transfer(input, outputStream); - bytes = outputStream.toByteArray(); - } - bytes = server.buildHookManager.classTransform(bytes, classname, this); - try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) { - IOHelper.transfer(inputStream, output); - } - } else - IOHelper.transfer(input, output); - e = input.getNextEntry(); - } - } - // write additional classes - for (Entry ent : server.buildHookManager.getIncludeClass().entrySet()) { - output.putNextEntry(newZipEntry(ent.getKey().replace('.', '/').concat(".class"))); - output.write(server.buildHookManager.classTransform(ent.getValue(), ent.getKey(), this)); - } - // map for guard - Map runtime = new HashMap<>(256); - if (server.buildHookManager.buildRuntime()) { - // Verify has init script file - if (!IOHelper.isFile(initScriptFile)) - throw new IOException(String.format("Missing init script file ('%s')", Launcher.INIT_SCRIPT_FILE)); - // Write launcher guard dir - IOHelper.walk(runtimeDir, new RuntimeDirVisitor(output, runtime), false); - // IOHelper.walk(guardDir, new GuardDirVisitor(output, runtime), false); - } - // Create launcher config file - byte[] launcherConfigBytes; - try (ByteArrayOutputStream configArray = IOHelper.newByteArrayOutput()) { - try (HOutput configOutput = new HOutput(configArray)) { - new LauncherConfig(server.config.getAddress(), server.config.port, server.publicKey, runtime) - .write(configOutput); - } - launcherConfigBytes = configArray.toByteArray(); - } + private void stdBuild() throws IOException { + try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(binaryFile)); + JAConfigurator jaConfigurator = new JAConfigurator(AutogenConfig.class.getName(), this)) { + jaConfigurator.pool.insertClassPath(cleanJar.toFile().getAbsolutePath()); + BuildContext context = new BuildContext(output, jaConfigurator, this); + server.buildHookManager.preHook(context); + jaConfigurator.setAddress(server.config.getAddress()); + jaConfigurator.setPort(server.config.port); + jaConfigurator.setProjectName(server.config.projectName); + jaConfigurator.setSecretKey(SecurityHelper.randomStringAESKey()); + jaConfigurator.setClientPort(32148 + SecurityHelper.newRandom().nextInt(512)); + jaConfigurator.setUsingWrapper(server.config.isUsingWrapper); + jaConfigurator.setDownloadJava(server.config.isDownloadJava); + jaConfigurator.setEnv(server.config.env); + server.buildHookManager.registerAllClientModuleClass(jaConfigurator); + try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(cleanJar))) { + ZipEntry e = input.getNextEntry(); + while (e != null) { + String filename = e.getName(); + if (server.buildHookManager.isContainsBlacklist(filename)) { + e = input.getNextEntry(); + continue; + } + try { + output.putNextEntry(IOHelper.newZipEntry(e.getName())); + } catch (ZipException ex) { + LogHelper.error(ex); + e = input.getNextEntry(); + continue; + } + if (filename.endsWith(".class")) { + String classname = filename.replace('/', '.').substring(0, + filename.length() - ".class".length()); + byte[] bytes; + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) { + IOHelper.transfer(input, outputStream); + bytes = outputStream.toByteArray(); + } + bytes = server.buildHookManager.classTransform(bytes, classname, this); + try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) { + IOHelper.transfer(inputStream, output); + } + } else + IOHelper.transfer(input, output); + e = input.getNextEntry(); + } + } + // write additional classes + for (Entry ent : server.buildHookManager.getIncludeClass().entrySet()) { + output.putNextEntry(newZipEntry(ent.getKey().replace('.', '/').concat(".class"))); + output.write(server.buildHookManager.classTransform(ent.getValue(), ent.getKey(), this)); + } + // map for guard + Map runtime = new HashMap<>(256); + if (server.buildHookManager.buildRuntime()) { + // Verify has init script file + if (!IOHelper.isFile(initScriptFile)) + throw new IOException(String.format("Missing init script file ('%s')", Launcher.INIT_SCRIPT_FILE)); + // Write launcher guard dir + IOHelper.walk(runtimeDir, new RuntimeDirVisitor(output, runtime), false); + // IOHelper.walk(guardDir, new GuardDirVisitor(output, runtime), false); + } + // Create launcher config file + byte[] launcherConfigBytes; + try (ByteArrayOutputStream configArray = IOHelper.newByteArrayOutput()) { + try (HOutput configOutput = new HOutput(configArray)) { + new LauncherConfig(server.config.getAddress(), server.config.port, server.publicKey, runtime) + .write(configOutput); + } + launcherConfigBytes = configArray.toByteArray(); + } - // Write launcher config file - output.putNextEntry(newZipEntry(Launcher.CONFIG_FILE)); - output.write(launcherConfigBytes); - ZipEntry e = newZipEntry(jaConfigurator.getZipEntryPath()); - output.putNextEntry(e); - jaConfigurator.compile(); - output.write(jaConfigurator.getBytecode()); - server.buildHookManager.postHook(context); - } catch (CannotCompileException | NotFoundException e) { - LogHelper.error(e); - } - } + // Write launcher config file + output.putNextEntry(newZipEntry(Launcher.CONFIG_FILE)); + output.write(launcherConfigBytes); + ZipEntry e = newZipEntry(jaConfigurator.getZipEntryPath()); + output.putNextEntry(e); + jaConfigurator.compile(); + output.write(jaConfigurator.getBytecode()); + server.buildHookManager.postHook(context); + } catch (CannotCompileException | NotFoundException e) { + LogHelper.error(e); + } + } - public void tryUnpack() throws IOException { - LogHelper.info("Unpacking launcher native guard files and runtime"); - UnpackHelper.unpackZipNoCheck("guard.zip", guardDir); - UnpackHelper.unpackZipNoCheck("runtime.zip", runtimeDir); - } + public void tryUnpack() throws IOException { + LogHelper.info("Unpacking launcher native guard files and runtime"); + UnpackHelper.unpackZipNoCheck("guard.zip", guardDir); + UnpackHelper.unpackZipNoCheck("runtime.zip", runtimeDir); + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/LauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/LauncherBinary.java index 75429ba0..2dc99d26 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/LauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/LauncherBinary.java @@ -1,13 +1,13 @@ package ru.gravit.launchserver.binary; -import java.io.IOException; -import java.nio.file.Path; - import ru.gravit.launcher.serialize.signed.DigestBytesHolder; import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.nio.file.Path; + public abstract class LauncherBinary { public final LaunchServer server; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/Command.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/Command.java index 402444e5..a69b023a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/Command.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/Command.java @@ -1,10 +1,10 @@ package ru.gravit.launchserver.command; -import java.util.UUID; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.VerifyHelper; +import java.util.UUID; + public abstract class Command { protected static String parseUsername(String username) throws CommandException { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/AuthCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/AuthCommand.java index c5048a5b..5a34131e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/AuthCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/AuthCommand.java @@ -1,13 +1,13 @@ package ru.gravit.launchserver.command.auth; -import java.util.UUID; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.AuthProviderResult; import ru.gravit.launchserver.command.Command; import ru.gravit.utils.helper.LogHelper; +import java.util.UUID; + public final class AuthCommand extends Command { public AuthCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/BanCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/BanCommand.java index 3511028c..3cfad3be 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/BanCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/BanCommand.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.auth; -import java.util.List; - import ru.gravit.launcher.HWID; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; +import java.util.List; + public class BanCommand extends Command { public BanCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java index 4fb600d8..49dc4d47 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java @@ -1,13 +1,13 @@ package ru.gravit.launchserver.command.auth; -import java.io.IOException; -import java.util.UUID; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.CommandException; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.util.UUID; + public final class UUIDToUsernameCommand extends Command { public UUIDToUsernameCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UnbanCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UnbanCommand.java index edfb3602..a0c801a3 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UnbanCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UnbanCommand.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.auth; -import java.util.List; - import ru.gravit.launcher.HWID; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; +import java.util.List; + public class UnbanCommand extends Command { public UnbanCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java index bac45f34..eca96027 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java @@ -1,13 +1,13 @@ package ru.gravit.launchserver.command.auth; -import java.io.IOException; -import java.util.UUID; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.CommandException; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.util.UUID; + public final class UsernameToUUIDCommand extends Command { public UsernameToUUIDCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/HelpCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/HelpCommand.java index 364de723..34dd6282 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/HelpCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/HelpCommand.java @@ -1,12 +1,12 @@ package ru.gravit.launchserver.command.basic; -import java.util.Map.Entry; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.CommandException; import ru.gravit.utils.helper.LogHelper; +import java.util.Map.Entry; + public final class HelpCommand extends Command { private static void printCommand(String name, Command command) { String args = command.getArgsDescription(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RegenProguardDictCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RegenProguardDictCommand.java index 047aadb7..c1cdb794 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RegenProguardDictCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RegenProguardDictCommand.java @@ -1,10 +1,10 @@ package ru.gravit.launchserver.command.basic; -import java.io.IOException; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; +import java.io.IOException; + public class RegenProguardDictCommand extends Command { public RegenProguardDictCommand(LaunchServer server) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RemoveMappingsProguardCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RemoveMappingsProguardCommand.java index a08a47f0..ba069f28 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RemoveMappingsProguardCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RemoveMappingsProguardCommand.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.basic; -import java.io.IOException; -import java.nio.file.Files; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; +import java.io.IOException; +import java.nio.file.Files; + public class RemoveMappingsProguardCommand extends Command { public RemoveMappingsProguardCommand(LaunchServer server) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java index 232e532f..75c767a8 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java @@ -1,49 +1,22 @@ package ru.gravit.launchserver.command.handler; -import java.io.IOException; -import java.time.Duration; -import java.time.Instant; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedList; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.CommandException; -import ru.gravit.launchserver.command.auth.AuthCommand; -import ru.gravit.launchserver.command.auth.BanCommand; -import ru.gravit.launchserver.command.auth.UUIDToUsernameCommand; -import ru.gravit.launchserver.command.auth.UnbanCommand; -import ru.gravit.launchserver.command.auth.UsernameToUUIDCommand; -import ru.gravit.launchserver.command.basic.BuildCommand; -import ru.gravit.launchserver.command.basic.ClearCommand; -import ru.gravit.launchserver.command.basic.DebugCommand; -import ru.gravit.launchserver.command.basic.GCCommand; -import ru.gravit.launchserver.command.basic.HelpCommand; -import ru.gravit.launchserver.command.basic.LogConnectionsCommand; -import ru.gravit.launchserver.command.basic.ProguardCleanCommand; -import ru.gravit.launchserver.command.basic.RebindCommand; -import ru.gravit.launchserver.command.basic.RegenProguardDictCommand; -import ru.gravit.launchserver.command.basic.RemoveMappingsProguardCommand; -import ru.gravit.launchserver.command.basic.StopCommand; -import ru.gravit.launchserver.command.basic.TestCommand; -import ru.gravit.launchserver.command.basic.VersionCommand; -import ru.gravit.launchserver.command.hash.DownloadAssetCommand; -import ru.gravit.launchserver.command.hash.DownloadClientCommand; -import ru.gravit.launchserver.command.hash.IndexAssetCommand; -import ru.gravit.launchserver.command.hash.SyncBinariesCommand; -import ru.gravit.launchserver.command.hash.SyncProfilesCommand; -import ru.gravit.launchserver.command.hash.SyncUpdatesCommand; -import ru.gravit.launchserver.command.hash.UnindexAssetCommand; +import ru.gravit.launchserver.command.auth.*; +import ru.gravit.launchserver.command.basic.*; +import ru.gravit.launchserver.command.hash.*; import ru.gravit.launchserver.command.modules.LoadModuleCommand; import ru.gravit.launchserver.command.modules.ModulesCommand; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.time.Duration; +import java.time.Instant; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + public abstract class CommandHandler implements Runnable { private static String[] parse(CharSequence line) throws CommandException { boolean quoted = false; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/JLineCommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/JLineCommandHandler.java index 8fdfef7e..7455b026 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/JLineCommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/JLineCommandHandler.java @@ -1,12 +1,12 @@ package ru.gravit.launchserver.command.handler; -import java.io.IOException; - import jline.console.ConsoleReader; import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper.Output; +import java.io.IOException; + public final class JLineCommandHandler extends CommandHandler { private final class JLineOutput implements Output { @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java index 9e7c6c15..8593cccb 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.handler; -import java.io.BufferedReader; -import java.io.IOException; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.IOHelper; +import java.io.BufferedReader; +import java.io.IOException; + public final class StdCommandHandler extends CommandHandler { private final BufferedReader reader; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadAssetCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadAssetCommand.java index 49a3770a..91c0aac7 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadAssetCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadAssetCommand.java @@ -1,9 +1,5 @@ package ru.gravit.launchserver.command.hash; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; - import ru.gravit.launcher.profiles.ClientProfile.Version; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; @@ -11,6 +7,10 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; + public final class DownloadAssetCommand extends Command { public DownloadAssetCommand(LaunchServer server) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadClientCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadClientCommand.java index 2ddd708e..c0ff1538 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadClientCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadClientCommand.java @@ -1,12 +1,5 @@ package ru.gravit.launchserver.command.hash; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; - import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile.Version; import ru.gravit.launcher.serialize.config.TextConfigReader; @@ -19,6 +12,13 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; + public final class DownloadClientCommand extends Command { public DownloadClientCommand(LaunchServer server) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/IndexAssetCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/IndexAssetCommand.java index 9a3a1e50..16c06595 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/IndexAssetCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/IndexAssetCommand.java @@ -1,5 +1,15 @@ package ru.gravit.launchserver.command.hash; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; +import ru.gravit.launchserver.command.CommandException; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; +import ru.gravit.utils.helper.SecurityHelper; +import ru.gravit.utils.helper.SecurityHelper.DigestAlgorithm; + import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.FileVisitResult; @@ -9,21 +19,10 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.Collections; -import com.google.gson.Gson; -import com.google.gson.JsonArray; - -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.command.Command; -import ru.gravit.launchserver.command.CommandException; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.SecurityHelper; -import ru.gravit.utils.helper.SecurityHelper.DigestAlgorithm; - public final class IndexAssetCommand extends Command { private static Gson gson = new Gson(); - public static class IndexObject - { + + public static class IndexObject { long size; public IndexObject(long size, String hash) { @@ -33,6 +32,7 @@ public IndexObject(long size, String hash) { String hash; } + private static final class IndexAssetVisitor extends SimpleFileVisitor { private final JsonArray objects; private final Path inputAssetDir; @@ -51,7 +51,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO // Add to index and copy file String digest = SecurityHelper.toHex(SecurityHelper.digest(DigestAlgorithm.SHA1, file)); - IndexObject obj = new IndexObject(attrs.size(),digest); + IndexObject obj = new IndexObject(attrs.size(), digest); objects.add(gson.toJsonTree(obj)); IOHelper.copy(file, resolveObjectFile(outputAssetDir, digest)); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncBinariesCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncBinariesCommand.java index 082c37ec..44326cd1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncBinariesCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncBinariesCommand.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.hash; -import java.io.IOException; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; + public final class SyncBinariesCommand extends Command { public SyncBinariesCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncProfilesCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncProfilesCommand.java index 423b3152..e31269ad 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncProfilesCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncProfilesCommand.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.hash; -import java.io.IOException; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; + public final class SyncProfilesCommand extends Command { public SyncProfilesCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncUpdatesCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncUpdatesCommand.java index e4dc8996..6b741c12 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncUpdatesCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/SyncUpdatesCommand.java @@ -1,14 +1,14 @@ package ru.gravit.launchserver.command.hash; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; +import ru.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.util.Collections; import java.util.HashSet; import java.util.Set; -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.command.Command; -import ru.gravit.utils.helper.LogHelper; - public final class SyncUpdatesCommand extends Command { public SyncUpdatesCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/UnindexAssetCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/UnindexAssetCommand.java index 25fc3079..9bb0c797 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/UnindexAssetCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/UnindexAssetCommand.java @@ -1,23 +1,23 @@ package ru.gravit.launchserver.command.hash; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; +import ru.gravit.launchserver.command.CommandException; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; + import java.io.BufferedReader; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; import java.util.Map; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.command.Command; -import ru.gravit.launchserver.command.CommandException; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; - public final class UnindexAssetCommand extends Command { private static JsonParser parser = new JsonParser(); + public UnindexAssetCommand(LaunchServer server) { super(server); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/modules/LoadModuleCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/modules/LoadModuleCommand.java index 1ab8a23a..af69674b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/modules/LoadModuleCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/modules/LoadModuleCommand.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.command.modules; -import java.net.URI; -import java.nio.file.Paths; - import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; +import java.net.URI; +import java.nio.file.Paths; + public class LoadModuleCommand extends Command { public LoadModuleCommand(LaunchServer server) { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/ClosingChannelFutureListener.java b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/ClosingChannelFutureListener.java index 9cd22a0c..6b29eed0 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/ClosingChannelFutureListener.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/ClosingChannelFutureListener.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.fileserver; -import java.io.Closeable; - import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import ru.gravit.utils.helper.IOHelper; +import java.io.Closeable; + public class ClosingChannelFutureListener implements ChannelFutureListener { public final Closeable[] close; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java index c626b7fc..3b78e8ad 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/fileserver/FileServerHandler.java @@ -1,16 +1,14 @@ package ru.gravit.launchserver.fileserver; -import static io.netty.handler.codec.http.HttpMethod.GET; -import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; -import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN; -import static io.netty.handler.codec.http.HttpResponseStatus.FOUND; -import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR; -import static io.netty.handler.codec.http.HttpResponseStatus.METHOD_NOT_ALLOWED; -import static io.netty.handler.codec.http.HttpResponseStatus.NOT_FOUND; -import static io.netty.handler.codec.http.HttpResponseStatus.NOT_MODIFIED; -import static io.netty.handler.codec.http.HttpResponseStatus.OK; -import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.*; +import io.netty.handler.codec.http.*; +import io.netty.handler.ssl.SslHandler; +import io.netty.handler.stream.ChunkedFile; +import io.netty.util.CharsetUtil; +import javax.activation.MimetypesFileTypeMap; import java.io.File; import java.io.FileNotFoundException; import java.io.RandomAccessFile; @@ -18,38 +16,12 @@ import java.net.URLDecoder; import java.nio.file.Path; import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Locale; -import java.util.TimeZone; +import java.util.*; import java.util.regex.Pattern; -import javax.activation.MimetypesFileTypeMap; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelProgressiveFuture; -import io.netty.channel.ChannelProgressiveFutureListener; -import io.netty.channel.DefaultFileRegion; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.http.DefaultFullHttpResponse; -import io.netty.handler.codec.http.DefaultHttpResponse; -import io.netty.handler.codec.http.FullHttpRequest; -import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.HttpChunkedInput; -import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpHeaderValues; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.HttpUtil; -import io.netty.handler.codec.http.LastHttpContent; -import io.netty.handler.ssl.SslHandler; -import io.netty.handler.stream.ChunkedFile; -import io.netty.util.CharsetUtil; +import static io.netty.handler.codec.http.HttpMethod.GET; +import static io.netty.handler.codec.http.HttpResponseStatus.*; +import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; public class FileServerHandler extends SimpleChannelInboundHandler { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/BuildHookManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/BuildHookManager.java index 0a449d24..c4e8509b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/BuildHookManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/BuildHookManager.java @@ -1,17 +1,17 @@ package ru.gravit.launchserver.manangers; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.zip.ZipOutputStream; - import ru.gravit.launcher.AutogenConfig; import ru.gravit.launcher.modules.TestClientModule; import ru.gravit.launchserver.binary.BuildContext; import ru.gravit.launchserver.binary.JAConfigurator; import ru.gravit.launchserver.binary.JARLauncherBinary; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.zip.ZipOutputStream; + public class BuildHookManager { @FunctionalInterface public static interface ZipBuildHook { @@ -64,30 +64,30 @@ public BuildHookManager() { } public NodeTransformer getProguardNoder() { - return proguardNoder; - } + return proguardNoder; + } - public NodeTransformer getNoder() { - return noder; - } + public NodeTransformer getNoder() { + return noder; + } - public Set getProguardBuildHooks() { - return POST_PROGUARD_BUILDHOOKS; - } + public Set getProguardBuildHooks() { + return POST_PROGUARD_BUILDHOOKS; + } + + public Set getPostProguardRunHooks() { + return POST_PROGUARDRUN_HOOKS; + } - public Set getPostProguardRunHooks() { - return POST_PROGUARDRUN_HOOKS; - } - public void addPostProguardRunHook(Runnable hook) { - POST_PROGUARDRUN_HOOKS.add(hook); - } - - public void addPostProguardRunHook(ZipBuildHook hook) { - POST_PROGUARD_BUILDHOOKS.add(hook); + POST_PROGUARDRUN_HOOKS.add(hook); } - public void autoRegisterIgnoredClass(String clazz) { + public void addPostProguardRunHook(ZipBuildHook hook) { + POST_PROGUARD_BUILDHOOKS.add(hook); + } + + public void autoRegisterIgnoredClass(String clazz) { CLASS_BLACKLIST.add(clazz.replace('.', '/').concat(".class")); } @@ -116,10 +116,10 @@ public Map getIncludeClass() { } public boolean isContainsBlacklist(String clazz) { - for (String classB : CLASS_BLACKLIST) { - if (clazz.startsWith(classB)) return true; - } - return false; + for (String classB : CLASS_BLACKLIST) { + if (clazz.startsWith(classB)) return true; + } + return false; } public void postHook(BuildContext context) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/MirrorManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/MirrorManager.java index 89633b36..d9485f64 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/MirrorManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/MirrorManager.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.manangers; +import ru.gravit.utils.helper.IOHelper; + import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; -import ru.gravit.utils.helper.IOHelper; - public class MirrorManager { public class Mirror { URL url; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java index 3364a488..fe6e0e8e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java @@ -1,14 +1,14 @@ package ru.gravit.launchserver.manangers; -import java.net.URL; -import java.util.ArrayList; - import ru.gravit.launcher.modules.SimpleModuleManager; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.modules.CoreModule; import ru.gravit.launchserver.modules.LaunchServerModuleContext; import ru.gravit.utils.PublicURLClassLoader; +import java.net.URL; +import java.util.ArrayList; + public class ModulesManager extends SimpleModuleManager { public ModulesManager(LaunchServer lsrv) { modules = new ArrayList<>(1); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/NodeTransformer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/NodeTransformer.java index 3f713df9..741eecd4 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/NodeTransformer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/NodeTransformer.java @@ -1,40 +1,39 @@ package ru.gravit.launchserver.manangers; -import java.util.ArrayList; -import java.util.List; - import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.ClassNode; - import ru.gravit.launchserver.asm.SafeClassWriter; import ru.gravit.launchserver.binary.JARLauncherBinary; import ru.gravit.launchserver.manangers.BuildHookManager.Transformer; -public class NodeTransformer implements Transformer { - @FunctionalInterface - public static interface ClassNodeTransformer { - void transform(ClassNode node, String classname, JARLauncherBinary data); - } - - private final List transLst; - - public List getTransLst() { - return transLst; - } +import java.util.ArrayList; +import java.util.List; - public NodeTransformer() { - transLst = new ArrayList<>(); - } - - @Override - public byte[] transform(byte[] input, String classname, JARLauncherBinary data) { - ClassReader cr = new ClassReader(input); - ClassNode cn = new ClassNode(); - cr.accept(cn, ClassReader.SKIP_DEBUG); - for (ClassNodeTransformer tr : transLst) tr.transform(cn, classname, data); - ClassWriter cw = new SafeClassWriter(data.reader, ClassWriter.COMPUTE_MAXS); - cn.accept(cw); - return cw.toByteArray(); - } +public class NodeTransformer implements Transformer { + @FunctionalInterface + public static interface ClassNodeTransformer { + void transform(ClassNode node, String classname, JARLauncherBinary data); + } + + private final List transLst; + + public List getTransLst() { + return transLst; + } + + public NodeTransformer() { + transLst = new ArrayList<>(); + } + + @Override + public byte[] transform(byte[] input, String classname, JARLauncherBinary data) { + ClassReader cr = new ClassReader(input); + ClassNode cn = new ClassNode(); + cr.accept(cn, ClassReader.SKIP_DEBUG); + for (ClassNodeTransformer tr : transLst) tr.transform(cn, classname, data); + ClassWriter cw = new SafeClassWriter(data.reader, ClassWriter.COMPUTE_MAXS); + cn.accept(cw); + return cw.toByteArray(); + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/SessionManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/SessionManager.java index 0a395cd4..c2c0a455 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/SessionManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/SessionManager.java @@ -1,11 +1,11 @@ package ru.gravit.launchserver.manangers; -import java.util.HashSet; -import java.util.Set; - import ru.gravit.launcher.NeedGarbageCollection; import ru.gravit.launchserver.socket.Client; +import java.util.HashSet; +import java.util.Set; + public class SessionManager implements NeedGarbageCollection { public static final long SESSION_TIMEOUT = 10 * 60 * 1000; // 10 минут diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/PingResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/PingResponse.java index 0982768f..74b78222 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/PingResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/PingResponse.java @@ -1,12 +1,12 @@ package ru.gravit.launchserver.response; -import java.io.IOException; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; import ru.gravit.launchserver.LaunchServer; +import java.io.IOException; + public final class PingResponse extends Response { public PingResponse(LaunchServer server, long id, HInput input, HOutput output, String ip) { super(server, id, input, output, ip); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/Response.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/Response.java index 4abd5a2a..b09a79e5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/Response.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/Response.java @@ -1,30 +1,21 @@ package ru.gravit.launchserver.response; -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - import ru.gravit.launcher.request.RequestException; import ru.gravit.launcher.request.RequestType; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.response.auth.AuthResponse; -import ru.gravit.launchserver.response.auth.AuthServerResponse; -import ru.gravit.launchserver.response.auth.ChangeServerResponse; -import ru.gravit.launchserver.response.auth.CheckServerResponse; -import ru.gravit.launchserver.response.auth.JoinServerResponse; -import ru.gravit.launchserver.response.auth.SetProfileResponse; +import ru.gravit.launchserver.response.auth.*; import ru.gravit.launchserver.response.profile.BatchProfileByUsernameResponse; import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse; import ru.gravit.launchserver.response.profile.ProfileByUsernameResponse; -import ru.gravit.launchserver.response.update.LauncherResponse; -import ru.gravit.launchserver.response.update.LegacyLauncherResponse; -import ru.gravit.launchserver.response.update.ProfilesResponse; -import ru.gravit.launchserver.response.update.UpdateListResponse; -import ru.gravit.launchserver.response.update.UpdateResponse; +import ru.gravit.launchserver.response.update.*; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + public abstract class Response { @FunctionalInterface public interface Factory { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java index b2d5ca21..61ea5a5a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java @@ -1,12 +1,5 @@ package ru.gravit.launchserver.response.auth; -import java.util.Arrays; -import java.util.Collection; -import java.util.UUID; - -import javax.crypto.BadPaddingException; -import javax.crypto.IllegalBlockSizeException; - import ru.gravit.launcher.OshiHWID; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.HInput; @@ -26,6 +19,12 @@ import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import java.util.Arrays; +import java.util.Collection; +import java.util.UUID; + public final class AuthResponse extends Response { private static String echo(int length) { char[] chars = new char[length]; @@ -91,7 +90,7 @@ public void reply() throws Exception { throw new AuthException("You profile not found"); } } - server.config.hwidHandler.check(OshiHWID.gson.fromJson(hwid_str,OshiHWID.class), result.username); + server.config.hwidHandler.check(OshiHWID.gson.fromJson(hwid_str, OshiHWID.class), result.username); } catch (AuthException | HWIDException e) { requestError(e.getMessage()); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java index f32b914e..87b19a89 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java @@ -1,11 +1,5 @@ package ru.gravit.launchserver.response.auth; -import java.util.Arrays; -import java.util.Collection; - -import javax.crypto.BadPaddingException; -import javax.crypto.IllegalBlockSizeException; - import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -23,6 +17,11 @@ import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import java.util.Arrays; +import java.util.Collection; + public final class AuthServerResponse extends Response { private static String echo(int length) { char[] chars = new char[length]; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java index 81b8f6d8..c2ceec31 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.response.auth; -import java.io.IOException; -import java.util.UUID; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; @@ -13,6 +10,9 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.UUID; + public final class CheckServerResponse extends Response { public CheckServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java index ced86c20..a6f0b426 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java @@ -1,7 +1,5 @@ package ru.gravit.launchserver.response.auth; -import java.io.IOException; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; @@ -12,6 +10,8 @@ import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; + public final class JoinServerResponse extends Response { public JoinServerResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java index 25fcac10..313eac85 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/SetProfileResponse.java @@ -1,7 +1,5 @@ package ru.gravit.launchserver.response.auth; -import java.util.Collection; - import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -11,6 +9,8 @@ import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.socket.Client; +import java.util.Collection; + public class SetProfileResponse extends Response { public SetProfileResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { super(server, session, input, output, ip); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java index 00966979..8d9f5181 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.response.profile; -import java.io.IOException; -import java.util.Arrays; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; @@ -10,6 +7,9 @@ import ru.gravit.launchserver.response.Response; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.Arrays; + public final class BatchProfileByUsernameResponse extends Response { public BatchProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java index f5ab6add..9147c4c0 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.response.profile; -import java.io.IOException; -import java.util.UUID; - import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.profiles.Texture; import ru.gravit.launcher.serialize.HInput; @@ -12,6 +9,9 @@ import ru.gravit.launchserver.response.Response; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.util.UUID; + public final class ProfileByUUIDResponse extends Response { public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String username, String client) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java index 213c8db4..eae95e7c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.response.profile; -import java.io.IOException; -import java.util.UUID; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; @@ -10,6 +7,9 @@ import ru.gravit.launchserver.response.Response; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.UUID; + public final class ProfileByUsernameResponse extends Response { public static void writeProfile(LaunchServer server, HOutput output, String username, String client) throws IOException { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LauncherResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LauncherResponse.java index 4edaadd5..114a55d5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LauncherResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LauncherResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.response.update; -import java.io.IOException; -import java.util.Arrays; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.signed.DigestBytesHolder; @@ -10,6 +7,9 @@ import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.socket.Client; +import java.io.IOException; +import java.util.Arrays; + public final class LauncherResponse extends Response { public LauncherResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LegacyLauncherResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LegacyLauncherResponse.java index 6af47d77..92aba4d6 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LegacyLauncherResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/LegacyLauncherResponse.java @@ -1,7 +1,5 @@ package ru.gravit.launchserver.response.update; -import java.io.IOException; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launchserver.LaunchServer; @@ -9,6 +7,8 @@ import ru.gravit.launchserver.response.Response; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; + public final class LegacyLauncherResponse extends Response { public LegacyLauncherResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/ProfilesResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/ProfilesResponse.java index 45c11676..54a2aceb 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/ProfilesResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/ProfilesResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.response.update; -import java.io.IOException; -import java.util.Collection; - import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -12,6 +9,9 @@ import ru.gravit.launchserver.socket.Client; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.util.Collection; + public final class ProfilesResponse extends Response { public ProfilesResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateListResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateListResponse.java index 75426575..ffb1dddf 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateListResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateListResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.response.update; -import java.util.Map.Entry; -import java.util.Set; - import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -10,6 +7,9 @@ import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.response.Response; +import java.util.Map.Entry; +import java.util.Set; + public final class UpdateListResponse extends Response { public UpdateListResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateResponse.java index 676ea21c..d348c95c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/update/UpdateResponse.java @@ -1,13 +1,5 @@ package ru.gravit.launchserver.response.update; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.Path; -import java.util.Deque; -import java.util.LinkedList; -import java.util.zip.DeflaterOutputStream; - import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedEntry; import ru.gravit.launcher.hasher.HashedEntry.Type; @@ -22,6 +14,14 @@ import ru.gravit.launchserver.socket.Client; import ru.gravit.utils.helper.IOHelper; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Path; +import java.util.Deque; +import java.util.LinkedList; +import java.util.zip.DeflaterOutputStream; + public final class UpdateResponse extends Response { public UpdateResponse(LaunchServer server, long session, HInput input, HOutput output, String ip) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java index 2964aa65..9e4542c8 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/NettyServerSocketHandler.java @@ -1,34 +1,5 @@ package ru.gravit.launchserver.socket; -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.nio.channels.Selector; -import java.nio.channels.ServerSocketChannel; -import java.security.KeyManagementException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; - -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLServerSocketFactory; -import javax.net.ssl.TrustManager; - import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInitializer; @@ -53,10 +24,33 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLServerSocketFactory; +import javax.net.ssl.TrustManager; +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.nio.channels.Selector; +import java.nio.channels.ServerSocketChannel; +import java.security.*; +import java.security.cert.CertificateException; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; + @SuppressWarnings({"unused", "rawtypes"}) public final class NettyServerSocketHandler implements Runnable, AutoCloseable { private static final String WEBSOCKET_PATH = "/api"; - private static SSLServerSocketFactory ssf; + private static SSLServerSocketFactory ssf; private static final ThreadFactory THREAD_FACTORY = r -> CommonHelper.newThread("Network Thread", true, r); public volatile boolean logConnections = Boolean.getBoolean("launcher.logConnections"); @@ -65,7 +59,7 @@ public final class NettyServerSocketHandler implements Runnable, AutoCloseable { private final ExecutorService threadPool = Executors.newCachedThreadPool(THREAD_FACTORY); // API - private final Map customResponses = new ConcurrentHashMap<>(2); + private final Map customResponses = new ConcurrentHashMap<>(2); private final AtomicLong idCounter = new AtomicLong(0L); private Set sockets; private volatile Listener listener; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java index 30691651..bb42f92f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ResponseThread.java @@ -1,10 +1,5 @@ package ru.gravit.launchserver.socket; -import java.io.IOException; -import java.math.BigInteger; -import java.net.Socket; -import java.net.SocketException; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.request.RequestException; import ru.gravit.launcher.serialize.HInput; @@ -16,6 +11,11 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.math.BigInteger; +import java.net.Socket; +import java.net.SocketException; + public final class ResponseThread implements Runnable { class Handshake { int type; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java index c7b50946..e5a01acc 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java @@ -1,23 +1,19 @@ package ru.gravit.launchserver.socket; -import java.io.IOException; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.SynchronousQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; - import ru.gravit.launcher.managers.GarbageManager; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.manangers.SessionManager; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; + public final class ServerSocketHandler implements Runnable, AutoCloseable { public interface Listener { @@ -52,7 +48,7 @@ public ServerSocketHandler(LaunchServer server) { public ServerSocketHandler(LaunchServer server, SessionManager sessionManager) { this.server = server; threadPool = new ThreadPoolExecutor(server.config.threadCoreCount, Integer.MAX_VALUE, - server.config.threadCount, TimeUnit.SECONDS, + server.config.threadCount, TimeUnit.SECONDS, new SynchronousQueue(), THREAD_FACTORY); this.sessionManager = sessionManager; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java index 7f548c8d..dc1bd5ee 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java @@ -1,7 +1,6 @@ package ru.gravit.launchserver.socket.websocket; import com.google.gson.GsonBuilder; - import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.group.DefaultChannelGroup; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketIndexPageHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketIndexPageHandler.java index 6e31a384..b65f25a7 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketIndexPageHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketIndexPageHandler.java @@ -1,28 +1,17 @@ package ru.gravit.launchserver.socket.websocket; -import static io.netty.handler.codec.http.HttpMethod.GET; -import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; -import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN; -import static io.netty.handler.codec.http.HttpResponseStatus.OK; -import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; -import static io.netty.handler.codec.rtsp.RtspResponseStatuses.NOT_FOUND; - import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.http.DefaultFullHttpResponse; -import io.netty.handler.codec.http.FullHttpRequest; -import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpUtil; +import io.netty.channel.*; +import io.netty.handler.codec.http.*; import io.netty.handler.ssl.SslHandler; import io.netty.util.CharsetUtil; +import static io.netty.handler.codec.http.HttpMethod.GET; +import static io.netty.handler.codec.http.HttpResponseStatus.*; +import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; +import static io.netty.handler.codec.rtsp.RtspResponseStatuses.NOT_FOUND; + public class WebSocketIndexPageHandler extends SimpleChannelInboundHandler { private final String websocketPath; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java index a18ff095..31d5a726 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java @@ -1,10 +1,7 @@ package ru.gravit.launchserver.socket.websocket; -import java.util.HashMap; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; - import io.netty.channel.Channel; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; @@ -24,6 +21,8 @@ import ru.gravit.launchserver.socket.websocket.json.update.UpdateListResponse; import ru.gravit.utils.helper.LogHelper; +import java.util.HashMap; + @SuppressWarnings({"unused", "rawtypes"}) public class WebSocketService { public final ChannelGroup channels; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseAdapter.java index 2358ad31..f967c952 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseAdapter.java @@ -1,18 +1,10 @@ package ru.gravit.launchserver.socket.websocket.json; -import java.lang.reflect.Type; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - +import com.google.gson.*; import ru.gravit.launchserver.socket.websocket.WebSocketService; +import java.lang.reflect.Type; + public class JsonResponseAdapter implements JsonSerializer, JsonDeserializer { private final WebSocketService service; private static final String PROP_NAME = "type"; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java index dd4b6200..a9b4eab3 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java @@ -1,7 +1,5 @@ package ru.gravit.launchserver.socket.websocket.json.auth; -import java.util.Collection; - import io.netty.channel.ChannelHandlerContext; import ru.gravit.launcher.HWID; import ru.gravit.launcher.profiles.ClientProfile; @@ -17,6 +15,8 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.util.Collection; + public class AuthResponse implements JsonResponseInterface { public String login; public String client; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java index a3003988..1a63af31 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java @@ -1,8 +1,5 @@ package ru.gravit.launchserver.socket.websocket.json.update; -import java.util.Arrays; -import java.util.Base64; - import io.netty.channel.ChannelHandlerContext; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.socket.Client; @@ -10,6 +7,9 @@ import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; import ru.gravit.utils.Version; +import java.util.Arrays; +import java.util.Base64; + public class LauncherResponse implements JsonResponseInterface { public Version version; public String hash; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/NullTextureProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/NullTextureProvider.java index 2294351c..7e34b258 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/NullTextureProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/NullTextureProvider.java @@ -1,13 +1,13 @@ package ru.gravit.launchserver.texture; -import java.io.IOException; -import java.util.Objects; -import java.util.UUID; - import ru.gravit.launcher.profiles.Texture; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.Objects; +import java.util.UUID; + public final class NullTextureProvider extends TextureProvider { private volatile TextureProvider provider; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/RequestTextureProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/RequestTextureProvider.java index 4bb0b25a..47ccad09 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/RequestTextureProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/RequestTextureProvider.java @@ -1,9 +1,5 @@ package ru.gravit.launchserver.texture; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.UUID; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.profiles.Texture; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; @@ -12,6 +8,10 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.UUID; + public final class RequestTextureProvider extends TextureProvider { private static final UUID ZERO_UUID = new UUID(0, 0); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/TextureProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/TextureProvider.java index c15c2b21..016cfd38 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/TextureProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/TextureProvider.java @@ -1,16 +1,16 @@ package ru.gravit.launchserver.texture; +import ru.gravit.launcher.profiles.Texture; +import ru.gravit.launcher.serialize.config.ConfigObject; +import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; +import ru.gravit.utils.helper.VerifyHelper; + import java.io.IOException; import java.util.Map; import java.util.Objects; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import ru.gravit.launcher.profiles.Texture; -import ru.gravit.launcher.serialize.config.ConfigObject; -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; -import ru.gravit.utils.helper.VerifyHelper; - public abstract class TextureProvider extends ConfigObject implements AutoCloseable { private static final Map> TEXTURE_PROVIDERS = new ConcurrentHashMap<>(2); private static boolean registredProv = false; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/VoidTextureProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/VoidTextureProvider.java index bed81f34..a167da04 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/VoidTextureProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/VoidTextureProvider.java @@ -1,10 +1,10 @@ package ru.gravit.launchserver.texture; -import java.util.UUID; - import ru.gravit.launcher.profiles.Texture; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; +import java.util.UUID; + public final class VoidTextureProvider extends TextureProvider { public VoidTextureProvider(BlockConfigEntry block) { super(block); diff --git a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java index 7252244e..932dc823 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java @@ -1,5 +1,11 @@ package ru.gravit.launcher; +import ru.gravit.launcher.client.ClientLauncher; +import ru.gravit.utils.helper.EnvHelper; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.JVMHelper; +import ru.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; @@ -7,12 +13,6 @@ import java.util.LinkedList; import java.util.List; -import ru.gravit.launcher.client.ClientLauncher; -import ru.gravit.utils.helper.EnvHelper; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.JVMHelper; -import ru.gravit.utils.helper.LogHelper; - public class ClientLauncherWrapper { public static void main(String[] arguments) throws IOException, InterruptedException { LogHelper.printVersion("Launcher"); @@ -42,7 +42,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep Thread.sleep(3000); if (!process.isAlive()) { int errorcode = process.exitValue(); - if(errorcode != 0) + if (errorcode != 0) LogHelper.error("Process exit witch error code: %d", errorcode); else LogHelper.info("Process exit witch code 0"); diff --git a/Launcher/src/main/java/ru/gravit/launcher/JSApplication.java b/Launcher/src/main/java/ru/gravit/launcher/JSApplication.java index 71ae1192..b2c5721d 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/JSApplication.java +++ b/Launcher/src/main/java/ru/gravit/launcher/JSApplication.java @@ -1,9 +1,9 @@ package ru.gravit.launcher; -import java.util.concurrent.atomic.AtomicReference; - import javafx.application.Application; +import java.util.concurrent.atomic.AtomicReference; + @SuppressWarnings("AbstractClassNeverImplemented") public abstract class JSApplication extends Application { private static final AtomicReference INSTANCE = new AtomicReference<>(); diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index e33c5eb9..cdcaf295 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -1,26 +1,6 @@ package ru.gravit.launcher; -import java.io.BufferedReader; -import java.io.IOException; -import java.net.URL; -import java.time.Duration; -import java.time.Instant; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicBoolean; - -import javax.script.Bindings; -import javax.script.Invocable; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptException; - -import ru.gravit.launcher.client.ClientLauncher; -import ru.gravit.launcher.client.ClientModuleManager; -import ru.gravit.launcher.client.DirBridge; -import ru.gravit.launcher.client.FunctionalBridge; -import ru.gravit.launcher.client.LauncherSettings; -import ru.gravit.launcher.client.ServerPinger; +import ru.gravit.launcher.client.*; import ru.gravit.launcher.gui.choosebox.CheckComboBox; import ru.gravit.launcher.gui.choosebox.CheckComboBoxSkin; import ru.gravit.launcher.gui.choosebox.CheckModel; @@ -34,11 +14,7 @@ import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.profiles.Texture; -import ru.gravit.launcher.request.CustomRequest; -import ru.gravit.launcher.request.PingRequest; -import ru.gravit.launcher.request.Request; -import ru.gravit.launcher.request.RequestException; -import ru.gravit.launcher.request.RequestType; +import ru.gravit.launcher.request.*; import ru.gravit.launcher.request.auth.AuthRequest; import ru.gravit.launcher.request.auth.CheckServerRequest; import ru.gravit.launcher.request.auth.JoinServerRequest; @@ -54,24 +30,23 @@ import ru.gravit.launcher.serialize.config.ConfigObject; import ru.gravit.launcher.serialize.config.TextConfigReader; import ru.gravit.launcher.serialize.config.TextConfigWriter; -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; -import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry; -import ru.gravit.launcher.serialize.config.entry.ConfigEntry; -import ru.gravit.launcher.serialize.config.entry.IntegerConfigEntry; -import ru.gravit.launcher.serialize.config.entry.ListConfigEntry; -import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; +import ru.gravit.launcher.serialize.config.entry.*; import ru.gravit.launcher.serialize.signed.SignedBytesHolder; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launcher.serialize.stream.EnumSerializer; import ru.gravit.launcher.serialize.stream.StreamObject; import ru.gravit.utils.HTTPRequest; -import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.EnvHelper; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.JVMHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.SecurityHelper; -import ru.gravit.utils.helper.VerifyHelper; +import ru.gravit.utils.helper.*; + +import javax.script.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.net.URL; +import java.time.Duration; +import java.time.Instant; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; public class LauncherEngine { @LauncherAPI diff --git a/Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java b/Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java index 7ece9196..bbb44ead 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java +++ b/Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java @@ -1,21 +1,21 @@ package ru.gravit.launcher; +import ru.gravit.utils.helper.LogHelper; + import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; -import ru.gravit.utils.helper.LogHelper; - public class RequestWorker implements Runnable { - public RequestWorker() - { + public RequestWorker() { queue = new LinkedBlockingQueue<>(64); } + public BlockingQueue queue; + @Override public void run() { LogHelper.debug("FX Task Thread start"); - while (!Thread.interrupted()) - { + while (!Thread.interrupted()) { try { Runnable task; task = queue.take(); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index cd6b8ce7..e5f7d2c4 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -1,5 +1,23 @@ package ru.gravit.launcher.client; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import ru.gravit.launcher.*; +import ru.gravit.launcher.hasher.DirWatcher; +import ru.gravit.launcher.hasher.FileNameMatcher; +import ru.gravit.launcher.hasher.HashedDir; +import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launcher.request.update.LegacyLauncherRequest; +import ru.gravit.launcher.serialize.HInput; +import ru.gravit.launcher.serialize.HOutput; +import ru.gravit.launcher.serialize.signed.SignedObjectHolder; +import ru.gravit.launcher.serialize.stream.StreamObject; +import ru.gravit.utils.PublicURLClassLoader; +import ru.gravit.utils.helper.*; +import ru.gravit.utils.helper.JVMHelper.OS; + +import javax.swing.*; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.lang.invoke.MethodHandle; @@ -16,45 +34,11 @@ import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.PosixFilePermission; import java.security.interfaces.RSAPublicKey; -import java.util.Collection; -import java.util.Collections; -import java.util.EnumSet; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import javax.swing.JOptionPane; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; - -import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.LauncherAgent; -import ru.gravit.launcher.LauncherConfig; -import ru.gravit.launcher.LauncherEngine; -import ru.gravit.launcher.hasher.DirWatcher; -import ru.gravit.launcher.hasher.FileNameMatcher; -import ru.gravit.launcher.hasher.HashedDir; -import ru.gravit.launcher.profiles.ClientProfile; -import ru.gravit.launcher.profiles.PlayerProfile; -import ru.gravit.launcher.request.update.LegacyLauncherRequest; -import ru.gravit.launcher.serialize.HInput; -import ru.gravit.launcher.serialize.HOutput; -import ru.gravit.launcher.serialize.signed.SignedObjectHolder; -import ru.gravit.launcher.serialize.stream.StreamObject; -import ru.gravit.utils.PublicURLClassLoader; -import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.EnvHelper; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.JVMHelper; -import ru.gravit.utils.helper.JVMHelper.OS; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.SecurityHelper; +import java.util.*; public final class ClientLauncher { private static Gson gson = new Gson(); + private static final class ClassPathFileVisitor extends SimpleFileVisitor { private final Collection result; @@ -183,6 +167,7 @@ public void write(HOutput output) throws IOException { private static final Path NATIVES_DIR = IOHelper.toPath("natives"); private static final Path RESOURCEPACKS_DIR = IOHelper.toPath("resourcepacks"); private static PublicURLClassLoader classLoader; + private static void addClientArgs(Collection args, ClientProfile profile, Params params) { PlayerProfile pp = params.pp; @@ -257,16 +242,16 @@ public static void checkJVMBitsAndVersion() { if (JVMHelper.JVM_BITS != JVMHelper.OS_BITS) { String error = String.format("У Вас установлена Java %d, но Ваша система определена как %d. Установите Java правильной разрядности", JVMHelper.JVM_BITS, JVMHelper.OS_BITS); LogHelper.error(error); - if(Launcher.getConfig().isWarningMissArchJava) - JOptionPane.showMessageDialog(null, error); + if (Launcher.getConfig().isWarningMissArchJava) + JOptionPane.showMessageDialog(null, error); } String jvmVersion = JVMHelper.RUNTIME_MXBEAN.getVmVersion(); LogHelper.info(jvmVersion); if (jvmVersion.startsWith("10.") || jvmVersion.startsWith("9.") || jvmVersion.startsWith("11.")) { String error = String.format("У Вас установлена Java %s. Для правильной работы необходима Java 8", JVMHelper.RUNTIME_MXBEAN.getVmVersion()); LogHelper.error(error); - if(Launcher.getConfig().isWarningMissArchJava) - JOptionPane.showMessageDialog(null, error); + if (Launcher.getConfig().isWarningMissArchJava) + JOptionPane.showMessageDialog(null, error); } } @@ -349,7 +334,8 @@ public static Process launch( boolean wrapper = isUsingWrapper(); Path javaBin; /*if (wrapper) javaBin = AvanguardStarter.wrapper; - else*/ if (isDownloadJava) { + else*/ + if (isDownloadJava) { //Linux и Mac не должны скачивать свою JVM if (JVMHelper.OS_TYPE == OS.MUSTDIE) javaBin = IOHelper.resolveJavaBin(JavaBinPath); @@ -380,10 +366,9 @@ public static Process launch( Collections.addAll(args, profile.object.getJvmArgs()); Collections.addAll(args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path Collections.addAll(args, "-javaagent:".concat(pathLauncher)); - if(wrapper) + if (wrapper) Collections.addAll(args, "-Djava.class.path=".concat(pathLauncher)); // Add Class Path - else - { + else { Collections.addAll(args, "-cp"); Collections.addAll(args, pathLauncher); } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java index 252300f5..80d7450b 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java @@ -1,11 +1,11 @@ package ru.gravit.launcher.client; -import java.net.URL; -import java.util.ArrayList; - import ru.gravit.launcher.LauncherEngine; import ru.gravit.launcher.modules.SimpleModuleManager; +import java.net.URL; +import java.util.ArrayList; + public class ClientModuleManager extends SimpleModuleManager { public ClientModuleManager(LauncherEngine engine) { context = new ClientModuleContext(engine); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java index acf9f8d1..0b3890b1 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java @@ -1,14 +1,14 @@ package ru.gravit.launcher.client; +import ru.gravit.launcher.LauncherAPI; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.JVMHelper; + import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import ru.gravit.launcher.LauncherAPI; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.JVMHelper; - public class DirBridge { @LauncherAPI public static Path dir; @@ -18,63 +18,55 @@ public class DirBridge { public static Path defaultUpdatesDir; @LauncherAPI public static boolean useLegacyDir; + @LauncherAPI - public static void move(Path newDir) throws IOException - { - IOHelper.move(dirUpdates,newDir); + public static void move(Path newDir) throws IOException { + IOHelper.move(dirUpdates, newDir); dirUpdates = newDir; } + @LauncherAPI public static Path getAppDataDir() throws IOException { - Boolean isCustomDir = Boolean.getBoolean(System.getProperty("launcher.usecustomdir","false")); - if(isCustomDir) - { + Boolean isCustomDir = Boolean.getBoolean(System.getProperty("launcher.usecustomdir", "false")); + if (isCustomDir) { return Paths.get(System.getProperty("launcher.customdir")); } - if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) - { - Boolean isOpt = Boolean.getBoolean(System.getProperty("launcher.useoptdir","false")); - if(isOpt) - { + if (JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) { + Boolean isOpt = Boolean.getBoolean(System.getProperty("launcher.useoptdir", "false")); + if (isOpt) { Path opt = Paths.get("/").resolve("opt"); - if(!IOHelper.isDir(opt)) Files.createDirectories(opt); + if (!IOHelper.isDir(opt)) Files.createDirectories(opt); return opt; - } - else - { + } else { Path local = IOHelper.HOME_DIR.resolve(".minecraftlauncher"); - if(!IOHelper.isDir(local)) Files.createDirectories(local); + if (!IOHelper.isDir(local)) Files.createDirectories(local); return local; } - } - else if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) - { + } else if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) { Path appdata = IOHelper.HOME_DIR.resolve("AppData").resolve("Roaming"); - if(!IOHelper.isDir(appdata)) Files.createDirectories(appdata); + if (!IOHelper.isDir(appdata)) Files.createDirectories(appdata); return appdata; - } - else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX) - { + } else if (JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX) { Path minecraft = IOHelper.HOME_DIR.resolve("minecraft"); - if(!IOHelper.isDir(minecraft)) Files.createDirectories(minecraft); + if (!IOHelper.isDir(minecraft)) Files.createDirectories(minecraft); return minecraft; - } - else - { + } else { return IOHelper.HOME_DIR; } } + @LauncherAPI public static Path getLauncherDir(String projectname) throws IOException { return getAppDataDir().resolve(projectname); } + @LauncherAPI public static Path getLegacyLauncherDir(String projectname) throws IOException { return IOHelper.HOME_DIR.resolve(projectname); } + @LauncherAPI - public static void setUseLegacyDir(boolean b) - { + public static void setUseLegacyDir(boolean b) { useLegacyDir = b; } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java index 19590e20..1a2e86a0 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java @@ -1,24 +1,24 @@ package ru.gravit.launcher.client; -import java.io.IOException; -import java.nio.file.Path; -import java.security.SignatureException; - import javafx.concurrent.Task; import ru.gravit.launcher.HWID; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.RequestWorker; -import ru.gravit.launcher.managers.HasherManager; -import ru.gravit.launcher.managers.HasherStore; import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hwid.OshiHWIDProvider; +import ru.gravit.launcher.managers.HasherManager; +import ru.gravit.launcher.managers.HasherStore; import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.update.LegacyLauncherRequest; import ru.gravit.launcher.request.websockets.RequestInterface; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.Path; +import java.security.SignatureException; + public class FunctionalBridge { @LauncherAPI public static LauncherSettings settings; @@ -52,34 +52,33 @@ public static LegacyLauncherRequest.Result offlineLauncherRequest() throws IOExc // Return last sign and profiles return new LegacyLauncherRequest.Result(null, settings.lastDigest, settings.lastProfiles); } + @LauncherAPI - public static void makeJsonRequest(RequestInterface request, Runnable callback) - { + public static void makeJsonRequest(RequestInterface request, Runnable callback) { } @LauncherAPI - public static void startTask(@SuppressWarnings("rawtypes") Task task) - { + public static void startTask(@SuppressWarnings("rawtypes") Task task) { try { worker.queue.put(task); } catch (InterruptedException e) { LogHelper.error(e); } } + @LauncherAPI - public static HWID getHWID() - { + public static HWID getHWID() { return hwidProvider.getHWID(); } + @LauncherAPI - public static long getTotalMemory() - { + public static long getTotalMemory() { return hwidProvider.getTotalMemory() >> 20; } + @LauncherAPI - public static HasherStore getDefaultHasherStore() - { + public static HasherStore getDefaultHasherStore() { return HasherManager.getDefaultStore(); } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java b/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java index 5e53b20a..b63197c6 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/LauncherSettings.java @@ -1,17 +1,5 @@ package ru.gravit.launcher.client; -import java.io.IOException; -import java.nio.file.Path; -import java.security.SignatureException; -import java.security.interfaces.RSAPublicKey; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import javax.crypto.BadPaddingException; -import javax.crypto.IllegalBlockSizeException; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.hasher.HashedDir; @@ -19,11 +7,18 @@ import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.JVMHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.SecurityHelper; -import ru.gravit.utils.helper.VerifyHelper; +import ru.gravit.utils.helper.*; + +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import java.io.IOException; +import java.nio.file.Path; +import java.security.SignatureException; +import java.security.interfaces.RSAPublicKey; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; public class LauncherSettings { public static int settingsMagic = 0xc0de7; diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ServerPinger.java b/Launcher/src/main/java/ru/gravit/launcher/client/ServerPinger.java index 3e9cad54..92f4e82c 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ServerPinger.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ServerPinger.java @@ -1,5 +1,15 @@ package ru.gravit.launcher.client; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import ru.gravit.launcher.LauncherAPI; +import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launcher.serialize.HInput; +import ru.gravit.launcher.serialize.HOutput; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; +import ru.gravit.utils.helper.VerifyHelper; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.InetSocketAddress; @@ -10,19 +20,9 @@ import java.util.Objects; import java.util.regex.Pattern; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.profiles.ClientProfile; -import ru.gravit.launcher.serialize.HInput; -import ru.gravit.launcher.serialize.HOutput; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.VerifyHelper; - public final class ServerPinger { private JsonParser parser = new JsonParser(); + public static final class Result { @LauncherAPI public final int onlinePlayers; diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckBitSetModelBase.java b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckBitSetModelBase.java index 84a5994c..58203cc6 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckBitSetModelBase.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckBitSetModelBase.java @@ -1,17 +1,16 @@ package ru.gravit.launcher.gui.choosebox; -import java.util.BitSet; -import java.util.Map; - import com.sun.javafx.collections.MappingChange; import com.sun.javafx.collections.NonIterableChange; import com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList; - import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; +import java.util.BitSet; +import java.util.Map; + abstract class CheckBitSetModelBase implements IndexedCheckModel { private final Map itemBooleanMap; @@ -163,7 +162,7 @@ public ObservableList getCheckedIndices() { public ObservableList getCheckedItems() { return checkedItemsList; } - + @Override public abstract T getItem(int index); diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBox.java b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBox.java index b68d4f08..262d1fde 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBox.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBox.java @@ -1,13 +1,6 @@ package ru.gravit.launcher.gui.choosebox; -import java.util.HashMap; -import java.util.Map; - -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; +import javafx.beans.property.*; import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; @@ -15,10 +8,13 @@ import javafx.util.StringConverter; import ru.gravit.launcher.LauncherAPI; +import java.util.HashMap; +import java.util.Map; + public class CheckComboBox extends ControlsFXControl { private static class CheckComboBoxBitSetCheckModel extends CheckBitSetModelBase { private final ObservableList items; - + CheckComboBoxBitSetCheckModel(final ObservableList items, final Map itemBooleanMap) { super(itemBooleanMap); diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBoxSkin.java b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBoxSkin.java index d1ebae12..3a826a39 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBoxSkin.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckComboBoxSkin.java @@ -1,12 +1,9 @@ package ru.gravit.launcher.gui.choosebox; -import java.util.Collections; - import com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList; import com.sun.javafx.scene.control.behavior.BehaviorBase; import com.sun.javafx.scene.control.skin.BehaviorSkinBase; import com.sun.javafx.scene.control.skin.ComboBoxListViewSkin; - import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; import javafx.scene.control.ComboBox; @@ -17,6 +14,8 @@ import javafx.scene.input.KeyCode; import ru.gravit.launcher.LauncherAPI; +import java.util.Collections; + public class CheckComboBoxSkin extends BehaviorSkinBase, BehaviorBase>> { private final ComboBox comboBox; @@ -73,7 +72,7 @@ protected void updateItem(T item, boolean empty) { getChildren().add(comboBox); } - + private String buildString() { final StringBuilder sb = new StringBuilder(); for (int i = 0, max = selectedItems.size(); i < max; i++) { diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/ProgressCircleIndicator.java b/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/ProgressCircleIndicator.java index f8ab6548..bf7d4a2e 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/ProgressCircleIndicator.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/ProgressCircleIndicator.java @@ -1,11 +1,6 @@ package ru.gravit.launcher.gui.indicator; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import com.sun.javafx.css.converters.SizeConverter; - import javafx.beans.property.DoubleProperty; import javafx.css.CssMetaData; import javafx.css.Styleable; @@ -14,16 +9,23 @@ import javafx.scene.control.Control; import javafx.scene.control.ProgressIndicator; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + abstract class ProgressCircleIndicator extends ProgressIndicator { public ProgressCircleIndicator() { this.getStylesheets().add(ProgressCircleIndicator.class.getResource("/runtime/launcher/overlay/update/circleprogress.css").toExternalForm()); } + public final void setInnerCircleRadius(int value) { innerCircleRadiusProperty().set(value); } + public final DoubleProperty innerCircleRadiusProperty() { return innerCircleRadius; } + public final double getInnerCircleRadius() { return innerCircleRadiusProperty().get(); } @@ -72,9 +74,11 @@ public StyleableProperty getStyleableProperty(ProgressCircleIndicator n) STYLEABLES = Collections.unmodifiableList(styleables); } } + public static List> getClassCssMetaData() { return StyleableProperties.STYLEABLES; } + @Override public List> getControlCssMetaData() { return StyleableProperties.STYLEABLES; diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicator.java b/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicator.java index c102686b..11c04589 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicator.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicator.java @@ -1,11 +1,6 @@ package ru.gravit.launcher.gui.indicator; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import com.sun.javafx.css.converters.SizeConverter; - import javafx.beans.property.DoubleProperty; import javafx.css.CssMetaData; import javafx.css.Styleable; @@ -16,6 +11,10 @@ import ru.gravit.launcher.LauncherAPI; import ru.gravit.utils.helper.LogHelper; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + public class RingProgressIndicator extends ProgressCircleIndicator { public RingProgressIndicator() { LogHelper.debug("Setting JVM dir name"); diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicatorSkin.java b/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicatorSkin.java index e73f55d2..3367767e 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicatorSkin.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/indicator/RingProgressIndicatorSkin.java @@ -105,14 +105,17 @@ private void initIndeterminate(boolean newVal) { transition.stop(); } } + @Override public RingProgressIndicator getSkinnable() { return indicator; } + @Override public Node getNode() { return container; } + @Override public void dispose() { transition.stop(); diff --git a/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java b/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java index a4efe3f4..0066635b 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java +++ b/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java @@ -1,11 +1,7 @@ package ru.gravit.launcher.hwid; import oshi.SystemInfo; -import oshi.hardware.CentralProcessor; -import oshi.hardware.ComputerSystem; -import oshi.hardware.HWDiskStore; -import oshi.hardware.HardwareAbstractionLayer; -import oshi.hardware.UsbDevice; +import oshi.hardware.*; import ru.gravit.launcher.HWID; import ru.gravit.launcher.LauncherHWIDInterface; import ru.gravit.launcher.OshiHWID; @@ -13,30 +9,28 @@ public class OshiHWIDProvider implements LauncherHWIDInterface { public static SystemInfo systemInfo = new SystemInfo(); - public String getSerial() - { + + public String getSerial() { try { return systemInfo.getHardware().getComputerSystem().getSerialNumber(); - } catch (Exception e) - { + } catch (Exception e) { LogHelper.error(e); return ""; } } - public String getProcessorID() - { + + public String getProcessorID() { try { return systemInfo.getHardware().getProcessor().getProcessorID(); - } catch (Exception e) - { + } catch (Exception e) { LogHelper.error(e); return ""; } } - public String getHWDisk() - { + + public String getHWDisk() { try { HWDiskStore store = null; long size = 0; @@ -47,36 +41,34 @@ public String getHWDisk() } } return store == null ? "" : store.getSerial(); - } catch (Exception e) - { + } catch (Exception e) { LogHelper.error(e); return ""; } } - public long getTotalMemory() - { + + public long getTotalMemory() { return systemInfo.getHardware().getMemory().getTotal(); } - public long getAvailableMemory() - { + + public long getAvailableMemory() { return systemInfo.getHardware().getMemory().getAvailable(); } - public void printHardwareInformation() - { + + public void printHardwareInformation() { HardwareAbstractionLayer hardware = systemInfo.getHardware(); ComputerSystem computerSystem = hardware.getComputerSystem(); - LogHelper.debug("ComputerSystem Model: %s Serial: %s",computerSystem.getModel(),computerSystem.getSerialNumber()); - for (HWDiskStore s : systemInfo.getHardware().getDiskStores()) - { - LogHelper.debug("HWDiskStore Serial: %s Model: %s Size: %d",s.getSerial(),s.getModel(),s.getSize()); + LogHelper.debug("ComputerSystem Model: %s Serial: %s", computerSystem.getModel(), computerSystem.getSerialNumber()); + for (HWDiskStore s : systemInfo.getHardware().getDiskStores()) { + LogHelper.debug("HWDiskStore Serial: %s Model: %s Size: %d", s.getSerial(), s.getModel(), s.getSize()); } - for (UsbDevice s : systemInfo.getHardware().getUsbDevices(true)) - { - LogHelper.debug("USBDevice Serial: %s Name: %s",s.getSerialNumber(),s.getName()); + for (UsbDevice s : systemInfo.getHardware().getUsbDevices(true)) { + LogHelper.debug("USBDevice Serial: %s Name: %s", s.getSerialNumber(), s.getName()); } CentralProcessor processor = hardware.getProcessor(); - LogHelper.debug("Processor Model: %s ID: %s",processor.getModel(),processor.getProcessorID()); + LogHelper.debug("Processor Model: %s ID: %s", processor.getModel(), processor.getProcessorID()); } + @Override public HWID getHWID() { OshiHWID hwid = new OshiHWID(); diff --git a/Launcher/src/main/java/ru/gravit/launcher/managers/HasherStore.java b/Launcher/src/main/java/ru/gravit/launcher/managers/HasherStore.java index 03711df2..2270d2c6 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/managers/HasherStore.java +++ b/Launcher/src/main/java/ru/gravit/launcher/managers/HasherStore.java @@ -17,8 +17,8 @@ public class HasherStore { public Map store; - public class HasherStoreEnity - { + + public class HasherStoreEnity { @LauncherAPI public HashedDir hdir; @LauncherAPI @@ -26,44 +26,41 @@ public class HasherStoreEnity @LauncherAPI public Collection shared; } + @LauncherAPI - public void addProfileUpdateDir(ClientProfile profile, Path dir, HashedDir hdir) - { + public void addProfileUpdateDir(ClientProfile profile, Path dir, HashedDir hdir) { HasherStoreEnity e = new HasherStoreEnity(); e.hdir = hdir; e.dir = dir; e.shared = profile.getShared(); - store.put(profile.getTitle(),e); + store.put(profile.getTitle(), e); } + @LauncherAPI - public void copyCompareFilesTo(String name, Path targetDir, HashedDir targetHDir, String[] shared) - { - store.forEach((key,e) -> { - if(key.equals(name)) return; - FileNameMatcher nm = new FileNameMatcher(shared,null,null); - HashedDir compare = targetHDir.sideCompare(e.hdir,nm, new LinkedList<>(), true); - compare.map().forEach((arg1,arg2) -> recurseCopy(arg1,arg2,name,targetDir,e.dir)); + public void copyCompareFilesTo(String name, Path targetDir, HashedDir targetHDir, String[] shared) { + store.forEach((key, e) -> { + if (key.equals(name)) return; + FileNameMatcher nm = new FileNameMatcher(shared, null, null); + HashedDir compare = targetHDir.sideCompare(e.hdir, nm, new LinkedList<>(), true); + compare.map().forEach((arg1, arg2) -> recurseCopy(arg1, arg2, name, targetDir, e.dir)); }); } + @LauncherAPI - public void recurseCopy(String filename, HashedEntry entry, String name, Path targetDir, Path sourceDir) - { - if(!IOHelper.isDir(targetDir)) { + public void recurseCopy(String filename, HashedEntry entry, String name, Path targetDir, Path sourceDir) { + if (!IOHelper.isDir(targetDir)) { try { Files.createDirectories(targetDir); } catch (IOException e1) { LogHelper.error(e1); } } - if(entry.getType().equals(HashedEntry.Type.DIR)) - { - ((HashedDir)entry).map().forEach((arg1,arg2) -> recurseCopy(arg1,arg2,name,targetDir.resolve(filename),sourceDir.resolve(filename))); - } - else if(entry.getType().equals(HashedEntry.Type.FILE)) - { + if (entry.getType().equals(HashedEntry.Type.DIR)) { + ((HashedDir) entry).map().forEach((arg1, arg2) -> recurseCopy(arg1, arg2, name, targetDir.resolve(filename), sourceDir.resolve(filename))); + } else if (entry.getType().equals(HashedEntry.Type.FILE)) { try { - IOHelper.copy(sourceDir.resolve(filename),targetDir.resolve(filename)); + IOHelper.copy(sourceDir.resolve(filename), targetDir.resolve(filename)); } catch (IOException e) { LogHelper.error(e); } diff --git a/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java b/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java index 7a0e6cb7..69304fa2 100644 --- a/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java +++ b/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/CompatBridge.java @@ -1,7 +1,5 @@ package com.mojang.authlib.yggdrasil; -import java.util.UUID; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.request.auth.CheckServerRequest; @@ -12,6 +10,8 @@ import ru.gravit.launcher.serialize.SerializeLimits; import ru.gravit.utils.helper.LogHelper; +import java.util.UUID; + // Used to bypass Launcher's class name obfuscation and access API @SuppressWarnings("unused") @LauncherAPI diff --git a/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/CompatProfile.java b/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/CompatProfile.java index aee84dcb..14da7047 100644 --- a/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/CompatProfile.java +++ b/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/CompatProfile.java @@ -1,12 +1,12 @@ package com.mojang.authlib.yggdrasil; -import java.util.UUID; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.utils.helper.SecurityHelper; +import java.util.UUID; + @SuppressWarnings("unused") @LauncherAPI public final class CompatProfile { diff --git a/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilAuthenticationService.java b/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilAuthenticationService.java index 08f78482..6cf0b6d6 100644 --- a/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilAuthenticationService.java +++ b/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilAuthenticationService.java @@ -1,15 +1,14 @@ package com.mojang.authlib.yggdrasil; -import java.net.Proxy; - import com.mojang.authlib.Agent; import com.mojang.authlib.AuthenticationService; import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.UserAuthentication; import com.mojang.authlib.minecraft.MinecraftSessionService; - import ru.gravit.utils.helper.LogHelper; +import java.net.Proxy; + public final class YggdrasilAuthenticationService implements AuthenticationService { @SuppressWarnings("UnusedParameters") public YggdrasilAuthenticationService(Proxy proxy, String clientToken) { diff --git a/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java b/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java index 1ec1336c..d869426e 100644 --- a/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java +++ b/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java @@ -1,19 +1,18 @@ package com.mojang.authlib.yggdrasil; -import java.util.Arrays; -import java.util.UUID; - import com.mojang.authlib.Agent; import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.ProfileLookupCallback; - import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.request.uuid.BatchProfileByUsernameRequest; import ru.gravit.launcher.serialize.SerializeLimits; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.util.Arrays; +import java.util.UUID; + public final class YggdrasilGameProfileRepository implements GameProfileRepository { private static final long BUSY_WAIT_MS = VerifyHelper.verifyLong( Long.parseLong(System.getProperty("launcher.com.mojang.authlib.busyWait", Long.toString(100L))), diff --git a/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java b/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java index 98808d4b..3328195f 100644 --- a/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java +++ b/LauncherAPI/src/main/java/com/mojang/authlib/yggdrasil/YggdrasilMinecraftSessionService.java @@ -1,11 +1,5 @@ package com.mojang.authlib.yggdrasil; -import java.net.InetAddress; -import java.util.Base64; -import java.util.EnumMap; -import java.util.Map; -import java.util.UUID; - import com.google.common.collect.Iterables; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -18,7 +12,6 @@ import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.request.auth.CheckServerRequest; @@ -28,6 +21,12 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.net.InetAddress; +import java.util.Base64; +import java.util.EnumMap; +import java.util.Map; +import java.util.UUID; + public final class YggdrasilMinecraftSessionService extends BaseMinecraftSessionService { public static final JsonParser JSON_PARSER = new JsonParser(); public static final boolean NO_TEXTURES = Boolean.parseBoolean("launcher.com.mojang.authlib.noTextures"); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/PingRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/PingRequest.java index c5be8758..36e529a1 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/PingRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/PingRequest.java @@ -1,13 +1,13 @@ package ru.gravit.launcher.request; -import java.io.IOException; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; +import java.io.IOException; + public final class PingRequest extends Request { @LauncherAPI diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java index 93e50fdf..405235d4 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java @@ -1,9 +1,5 @@ package ru.gravit.launcher.request; -import java.io.IOException; -import java.net.Socket; -import java.util.concurrent.atomic.AtomicBoolean; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; @@ -12,6 +8,10 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.net.Socket; +import java.util.concurrent.atomic.AtomicBoolean; + public abstract class Request { private static final long session = SecurityHelper.secureRandom.nextLong(); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java index 47154e75..761ac1c9 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java @@ -1,7 +1,5 @@ package ru.gravit.launcher.request.auth; -import java.io.IOException; - import ru.gravit.launcher.HWID; import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; @@ -16,6 +14,8 @@ import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; + public final class AuthRequest extends Request { public static final class Result { @LauncherAPI @@ -55,7 +55,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword @LauncherAPI public AuthRequest(String login, byte[] encryptedPassword, HWID hwid) { - this(null, login, encryptedPassword,hwid); + this(null, login, encryptedPassword, hwid); } @LauncherAPI @@ -75,7 +75,7 @@ protected Result requestDo(HInput input, HOutput output) throws IOException { if (Launcher.profile != null) output.writeString(Launcher.profile.getTitle(), SerializeLimits.MAX_CLIENT); output.writeInt(auth_id); - output.writeString(hwid.getSerializeString(),0); + output.writeString(hwid.getSerializeString(), 0); //output.writeLong(0); //output.writeLong(0); //output.writeLong(0); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthServerRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthServerRequest.java index 259a8b7e..7a83ab9a 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthServerRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthServerRequest.java @@ -1,7 +1,5 @@ package ru.gravit.launcher.request.auth; -import java.io.IOException; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.profiles.PlayerProfile; @@ -13,6 +11,8 @@ import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; + public final class AuthServerRequest extends Request { public static final class Result { @LauncherAPI diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/ChangeServerRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/ChangeServerRequest.java index ddb4dc60..0ea7877a 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/ChangeServerRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/ChangeServerRequest.java @@ -1,13 +1,13 @@ package ru.gravit.launcher.request.auth; -import java.net.InetSocketAddress; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.RequestType; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; +import java.net.InetSocketAddress; + public class ChangeServerRequest extends Request { @Override public Integer getType() { diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/CheckServerRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/CheckServerRequest.java index 181593d4..fff01495 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/CheckServerRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/CheckServerRequest.java @@ -1,7 +1,5 @@ package ru.gravit.launcher.request.auth; -import java.io.IOException; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; @@ -14,6 +12,8 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; + public final class CheckServerRequest extends Request { private final String username; private final String serverID; diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/JoinServerRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/JoinServerRequest.java index dd7fe6a8..264d9819 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/JoinServerRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/JoinServerRequest.java @@ -1,7 +1,5 @@ package ru.gravit.launcher.request.auth; -import java.io.IOException; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.request.Request; @@ -12,6 +10,8 @@ import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; + public final class JoinServerRequest extends Request { // Instance diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java index b4d428f6..d694773e 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java @@ -1,11 +1,5 @@ package ru.gravit.launcher.request.update; -import java.io.IOException; -import java.nio.file.Path; -import java.security.SignatureException; -import java.util.ArrayList; -import java.util.List; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; @@ -18,6 +12,12 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.nio.file.Path; +import java.security.SignatureException; +import java.util.ArrayList; +import java.util.List; + public final class LauncherRequest extends Request { public static final class Result { private final byte[] binary; diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LegacyLauncherRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LegacyLauncherRequest.java index 3dc59f87..2999b754 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LegacyLauncherRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LegacyLauncherRequest.java @@ -1,13 +1,5 @@ package ru.gravit.launcher.request.update; -import java.io.IOException; -import java.nio.file.Path; -import java.security.SignatureException; -import java.security.interfaces.RSAPublicKey; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; @@ -23,6 +15,14 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.nio.file.Path; +import java.security.SignatureException; +import java.security.interfaces.RSAPublicKey; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + public final class LegacyLauncherRequest extends Request { public static final class Result { @LauncherAPI diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java index 5c13afd0..a009d8b5 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/ProfilesRequest.java @@ -1,9 +1,5 @@ package ru.gravit.launcher.request.update; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.profiles.ClientProfile; @@ -13,6 +9,10 @@ import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + public final class ProfilesRequest extends Request { public static final class Result { diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateListRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateListRequest.java index bff78b4d..fb9c67d2 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateListRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateListRequest.java @@ -1,10 +1,5 @@ package ru.gravit.launcher.request.update; -import java.io.IOException; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.request.Request; @@ -13,6 +8,11 @@ import ru.gravit.launcher.serialize.HOutput; import ru.gravit.utils.helper.IOHelper; +import java.io.IOException; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + public final class UpdateListRequest extends Request> { @LauncherAPI public UpdateListRequest() { diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java index c211c1ca..57d72295 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java @@ -1,21 +1,5 @@ package ru.gravit.launcher.request.update; -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.security.MessageDigest; -import java.security.SignatureException; -import java.time.Duration; -import java.time.Instant; -import java.util.LinkedList; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Queue; -import java.util.zip.InflaterInputStream; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; @@ -35,12 +19,28 @@ import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper.DigestAlgorithm; +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.MessageDigest; +import java.security.SignatureException; +import java.time.Duration; +import java.time.Instant; +import java.util.LinkedList; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Queue; +import java.util.zip.InflaterInputStream; + public final class UpdateRequest extends Request> { public static final class State { @FunctionalInterface public interface Callback { - @LauncherAPI + @LauncherAPI void call(State state); } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java index 66de1570..282489b9 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java @@ -1,7 +1,5 @@ package ru.gravit.launcher.request.uuid; -import java.io.IOException; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.profiles.PlayerProfile; @@ -13,6 +11,8 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; + public final class BatchProfileByUsernameRequest extends Request { private final String[] usernames; diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/uuid/ProfileByUUIDRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/uuid/ProfileByUUIDRequest.java index fde1467a..2199890f 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/uuid/ProfileByUUIDRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/uuid/ProfileByUUIDRequest.java @@ -1,9 +1,5 @@ package ru.gravit.launcher.request.uuid; -import java.io.IOException; -import java.util.Objects; -import java.util.UUID; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; @@ -14,6 +10,10 @@ import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; +import java.io.IOException; +import java.util.Objects; +import java.util.UUID; + public final class ProfileByUUIDRequest extends Request { private final UUID uuid; diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/uuid/ProfileByUsernameRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/uuid/ProfileByUsernameRequest.java index 69aa5f1d..2136ef19 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/uuid/ProfileByUsernameRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/uuid/ProfileByUsernameRequest.java @@ -1,7 +1,5 @@ package ru.gravit.launcher.request.uuid; -import java.io.IOException; - import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; @@ -13,6 +11,8 @@ import ru.gravit.launcher.serialize.SerializeLimits; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; + public final class ProfileByUsernameRequest extends Request { private final String username; diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java index 8fbc2156..070e61d8 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -1,14 +1,9 @@ package ru.gravit.launcher.request.websockets; +import javax.websocket.*; import java.io.IOException; import java.io.Reader; -import javax.websocket.ClientEndpoint; -import javax.websocket.OnError; -import javax.websocket.OnMessage; -import javax.websocket.OnOpen; -import javax.websocket.Session; - /* * public class Client { * diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java index 883be877..5ce34a4e 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -1,15 +1,14 @@ package ru.gravit.launcher.request.websockets; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import ru.gravit.launcher.hasher.HashedEntry; +import ru.gravit.launcher.hasher.HashedEntryAdapter; + import java.io.IOException; import java.io.Reader; import java.util.HashMap; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -import ru.gravit.launcher.hasher.HashedEntry; -import ru.gravit.launcher.hasher.HashedEntryAdapter; - public class ClientWebSocketService { public final GsonBuilder gsonBuilder; public final Gson gson; diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java index 7be04dc5..72411843 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java @@ -1,15 +1,8 @@ package ru.gravit.launcher.request.websockets; -import java.lang.reflect.Type; +import com.google.gson.*; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; public class JsonRequestAdapter implements JsonSerializer, JsonDeserializer { private final ClientWebSocketService service; diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java index b8dd1439..30f90c70 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java @@ -1,11 +1,11 @@ package ru.gravit.launcher.server; +import ru.gravit.launcher.modules.SimpleModuleManager; +import ru.gravit.utils.PublicURLClassLoader; + import java.net.URL; import java.util.ArrayList; -import ru.gravit.utils.PublicURLClassLoader; -import ru.gravit.launcher.modules.SimpleModuleManager; - public class ModulesManager extends SimpleModuleManager { public ModulesManager(ServerWrapper wrapper) { modules = new ArrayList<>(); diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java index 8f3578dc..53374c4f 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java @@ -42,33 +42,33 @@ public static boolean isAgentStarted() { public static long getObjSize(Object obj) { return inst.getObjectSize(obj); } - public static Boolean isAutoloadLibraries = Boolean.getBoolean(System.getProperty("serverwrapper,agentlibrariesload","false")); - public static Boolean isAgentProxy = Boolean.getBoolean(System.getProperty("serverwrapper,agentproxy","false")); + + public static Boolean isAutoloadLibraries = Boolean.getBoolean(System.getProperty("serverwrapper,agentlibrariesload", "false")); + public static Boolean isAgentProxy = Boolean.getBoolean(System.getProperty("serverwrapper,agentproxy", "false")); + public static void premain(String agentArgument, Instrumentation instrumentation) { LogHelper.debug("Server Agent"); inst = instrumentation; isAgentStarted = true; - if(isAutoloadLibraries) - { + if (isAutoloadLibraries) { Path libraries = Paths.get("libraries"); - if(IOHelper.exists(libraries)) loadLibraries(libraries); + if (IOHelper.exists(libraries)) loadLibraries(libraries); } - if(isAgentProxy) - { + if (isAgentProxy) { String proxyClassName = System.getProperty("serverwrapper,agentproxyclass"); Class proxyClass; try { proxyClass = Class.forName(proxyClassName); MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(proxyClass, "premain", MethodType.methodType(void.class, String.class, Instrumentation.class)); - Object[] args = {agentArgument,instrumentation}; + Object[] args = {agentArgument, instrumentation}; mainMethod.invoke(args); } catch (Throwable e) { e.printStackTrace(); } } } - public static void loadLibraries(Path dir) - { + + public static void loadLibraries(Path dir) { try { Files.walkFileTree(dir, Collections.singleton(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new StarterVisitor()); } catch (IOException e) { diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java index 99b23c55..a02d8856 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java @@ -1,9 +1,9 @@ package ru.gravit.launcher.server; import ru.gravit.launcher.Launcher; -import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.launcher.modules.ModuleContext; import ru.gravit.launcher.modules.ModulesManagerInterface; +import ru.gravit.utils.PublicURLClassLoader; public class ServerModuleContext implements ModuleContext { public final PublicURLClassLoader classLoader; diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index 3b8cad0d..f05ab968 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -1,6 +1,25 @@ package ru.gravit.launcher.server; +import ru.gravit.launcher.Launcher; +import ru.gravit.launcher.LauncherConfig; +import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launcher.request.auth.AuthServerRequest; +import ru.gravit.launcher.request.update.ProfilesRequest; +import ru.gravit.launcher.serialize.config.ConfigObject; +import ru.gravit.launcher.serialize.config.TextConfigReader; +import ru.gravit.launcher.serialize.config.TextConfigWriter; +import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; +import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry; +import ru.gravit.launcher.serialize.config.entry.IntegerConfigEntry; +import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; +import ru.gravit.launcher.serialize.signed.SignedObjectHolder; +import ru.gravit.utils.PublicURLClassLoader; +import ru.gravit.utils.helper.CommonHelper; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; +import ru.gravit.utils.helper.SecurityHelper; + import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; @@ -13,34 +32,15 @@ import java.util.Arrays; import java.util.HashMap; -import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.LauncherConfig; -import ru.gravit.launcher.request.auth.AuthServerRequest; -import ru.gravit.launcher.serialize.config.ConfigObject; -import ru.gravit.launcher.serialize.config.TextConfigReader; -import ru.gravit.launcher.serialize.config.TextConfigWriter; -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; -import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry; -import ru.gravit.launcher.serialize.config.entry.IntegerConfigEntry; -import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; -import ru.gravit.utils.PublicURLClassLoader; -import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.launcher.profiles.ClientProfile; -import ru.gravit.launcher.request.update.ProfilesRequest; -import ru.gravit.launcher.serialize.signed.SignedObjectHolder; -import ru.gravit.utils.helper.SecurityHelper; - public class ServerWrapper { public static ModulesManager modulesManager; public static Config config; public static PublicURLClassLoader ucp; public static ClassLoader loader; - public static Path modulesDir = Paths.get(System.getProperty("serverwrapper.modulesDir","modules")); - public static Path configFile = Paths.get(System.getProperty("serverwrapper.configFile","ServerWrapper.cfg")); - public static Path publicKeyFile = Paths.get(System.getProperty("serverwrapper.publicKeyFile","public.key")); + public static Path modulesDir = Paths.get(System.getProperty("serverwrapper.modulesDir", "modules")); + public static Path configFile = Paths.get(System.getProperty("serverwrapper.configFile", "ServerWrapper.cfg")); + public static Path publicKeyFile = Paths.get(System.getProperty("serverwrapper.publicKeyFile", "public.key")); public static boolean auth(ServerWrapper wrapper) { try { @@ -101,47 +101,40 @@ public static void main(String[] args) throws Throwable { CommonHelper.newThread("Server Auth Thread", true, () -> ServerWrapper.loopAuth(wrapper, config.reconnectCount, config.reconnectSleep)); modulesManager.initModules(); String classname = config.mainclass.isEmpty() ? args[0] : config.mainclass; - if(classname.length() == 0) - { + if (classname.length() == 0) { LogHelper.error("MainClass not found. Please set MainClass for ServerWrapper.cfg or first commandline argument"); } Class mainClass; - if(config.customClassPath) - { + if (config.customClassPath) { String[] cp = config.classpath.split(":"); - if(!ServerAgent.isAgentStarted()) - { + if (!ServerAgent.isAgentStarted()) { LogHelper.warning("JavaAgent not found. Using URLClassLoader"); URL[] urls = Arrays.stream(cp).map(Paths::get).map(IOHelper::toURL).toArray(URL[]::new); ucp = new PublicURLClassLoader(urls); Thread.currentThread().setContextClassLoader(ucp); loader = ucp; - } - else - { - LogHelper.info("Found %d custom classpath elements",cp.length); - for(String c : cp) + } else { + LogHelper.info("Found %d custom classpath elements", cp.length); + for (String c : cp) ServerAgent.addJVMClassPath(c); } } - if(config.autoloadLibraries) - { - if(!ServerAgent.isAgentStarted()) - { + if (config.autoloadLibraries) { + if (!ServerAgent.isAgentStarted()) { throw new UnsupportedOperationException("JavaAgent not found, autoloadLibraries not available"); } Path librariesDir = Paths.get(config.librariesDir); LogHelper.info("Load libraries"); ServerAgent.loadLibraries(librariesDir); } - if(loader != null) mainClass = Class.forName(classname,true, loader); + if (loader != null) mainClass = Class.forName(classname, true, loader); else mainClass = Class.forName(classname); MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)); String[] real_args = new String[args.length - 1]; System.arraycopy(args, 1, real_args, 0, args.length - 1); modulesManager.postInitModules(); - LogHelper.info("ServerWrapper: Project %s, LaunchServer address: %s port %d. Title: %s",config.projectname,config.address,config.port,config.title); - LogHelper.info("Minecraft Version (for profile): %s",wrapper.profile.getVersion().name); + LogHelper.info("ServerWrapper: Project %s, LaunchServer address: %s port %d. Title: %s", config.projectname, config.address, config.port, config.title); + LogHelper.info("Minecraft Version (for profile): %s", wrapper.profile.getVersion().name); LogHelper.info("Start Minecraft Server"); LogHelper.debug("Invoke main method %s", mainClass.getName()); mainMethod.invoke(real_args); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/HWID.java b/libLauncher/src/main/java/ru/gravit/launcher/HWID.java index d1cf0f9c..4daa1c31 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/HWID.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/HWID.java @@ -2,6 +2,8 @@ public interface HWID { String getSerializeString(); + int getLevel(); //Уровень доверия, насколько уникальные значения + boolean isNull(); } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index eb0442c6..1dbdcbdb 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -1,5 +1,13 @@ package ru.gravit.launcher; +import ru.gravit.launcher.modules.ModulesManagerInterface; +import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launcher.serialize.HInput; +import ru.gravit.utils.Version; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.JVMHelper; +import ru.gravit.utils.helper.SecurityHelper; + import java.io.IOException; import java.net.URL; import java.nio.file.NoSuchFileException; @@ -10,14 +18,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.regex.Pattern; -import ru.gravit.launcher.modules.ModulesManagerInterface; -import ru.gravit.launcher.profiles.ClientProfile; -import ru.gravit.launcher.serialize.HInput; -import ru.gravit.utils.Version; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.JVMHelper; -import ru.gravit.utils.helper.SecurityHelper; - public final class Launcher { // Authlib constants diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java index 6ee80895..eb3925bd 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java @@ -1,11 +1,11 @@ package ru.gravit.launcher; +import ru.gravit.utils.helper.LogHelper; + import java.io.IOException; import java.lang.instrument.Instrumentation; import java.util.jar.JarFile; -import ru.gravit.utils.helper.LogHelper; - @LauncherAPI public class LauncherAgent { private static boolean isAgentStarted = false; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java index 4a243fce..bff7bfcb 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java @@ -1,15 +1,5 @@ package ru.gravit.launcher; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.security.interfaces.RSAPublicKey; -import java.security.spec.InvalidKeySpecException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Set; - import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.stream.StreamObject; @@ -17,6 +7,12 @@ import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.InvalidKeySpecException; +import java.util.*; + public final class LauncherConfig extends StreamObject { @LauncherAPI public static final String ADDRESS_OVERRIDE_PROPERTY = "launcher.addressOverride"; @@ -59,17 +55,16 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException isUsingWrapper = config.isUsingWrapper; isWarningMissArchJava = config.isWarningMissArchJava; LauncherEnvironment env; - if(config.env == 0) env = LauncherEnvironment.DEV; - else if(config.env == 1) env = LauncherEnvironment.DEBUG; - else if(config.env == 2) env = LauncherEnvironment.STD; - else if(config.env == 3) env = LauncherEnvironment.PROD; + if (config.env == 0) env = LauncherEnvironment.DEV; + else if (config.env == 1) env = LauncherEnvironment.DEBUG; + else if (config.env == 2) env = LauncherEnvironment.STD; + else if (config.env == 3) env = LauncherEnvironment.PROD; else env = LauncherEnvironment.STD; - if(env == LauncherEnvironment.PROD) { + if (env == LauncherEnvironment.PROD) { LogHelper.setStacktraceEnabled(false); LogHelper.setDebugEnabled(false); } - if(env == LauncherEnvironment.DEV || env == LauncherEnvironment.DEBUG) - { + if (env == LauncherEnvironment.DEV || env == LauncherEnvironment.DEBUG) { LogHelper.setDebugEnabled(true); } // Read signed runtime @@ -127,8 +122,7 @@ public void write(HOutput output) throws IOException { } } - public enum LauncherEnvironment - { - DEV,DEBUG,STD,PROD + public enum LauncherEnvironment { + DEV, DEBUG, STD, PROD } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java b/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java index 24be03ea..1d13951d 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java @@ -17,16 +17,18 @@ public class OshiHWID implements HWID { public String getSerializeString() { return gson.toJson(this); } + @Override public int getLevel() //Уровень доверия, насколько уникальные значения { int result = 0; - if(totalMemory != 0) result++; - if(serialNumber != null && !serialNumber.equals("unknown")) result+=4; - if(HWDiskSerial != null && !HWDiskSerial.equals("unknown")) result+=15; - if(processorID != null && !processorID.equals("unknown")) result+=6; + if (totalMemory != 0) result++; + if (serialNumber != null && !serialNumber.equals("unknown")) result += 4; + if (HWDiskSerial != null && !HWDiskSerial.equals("unknown")) result += 15; + if (processorID != null && !processorID.equals("unknown")) result += 6; return result; } + @Override public boolean isNull() { return getLevel() < 2; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/ControlEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/ControlEvent.java index 29834e22..86ba0920 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/ControlEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/ControlEvent.java @@ -1,9 +1,9 @@ package ru.gravit.launcher.events; -import java.util.UUID; - import ru.gravit.utils.event.EventInterface; +import java.util.UUID; + //Набор стандартных событий public class ControlEvent implements EventInterface { private static final UUID uuid = UUID.fromString("f1051a64-0cd0-4ed8-8430-d856a196e91f"); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/PingEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/PingEvent.java index f10806eb..ac4112e4 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/PingEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/PingEvent.java @@ -1,9 +1,9 @@ package ru.gravit.launcher.events; -import java.util.UUID; - import ru.gravit.utils.event.EventInterface; +import java.util.UUID; + //Пустое событие //Все обработчики обязаны его игнорировать public final class PingEvent implements EventInterface { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/SignalEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/SignalEvent.java index afe1c9a5..2e43aca3 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/SignalEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/SignalEvent.java @@ -1,9 +1,9 @@ package ru.gravit.launcher.events; -import java.util.UUID; - import ru.gravit.utils.event.EventInterface; +import java.util.UUID; + //Используется, что бы послать короткое сообщение, которое вмещается в int public class SignalEvent implements EventInterface { private static final UUID uuid = UUID.fromString("edc3afa1-2726-4da3-95c6-7e6994b981e1"); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java b/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java index 05ec1c7f..582e7955 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/hasher/DirWatcher.java @@ -1,20 +1,5 @@ package ru.gravit.launcher.hasher; -import java.io.IOException; -import java.nio.file.ClosedWatchServiceException; -import java.nio.file.FileVisitResult; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.StandardWatchEventKinds; -import java.nio.file.WatchEvent; -import java.nio.file.WatchEvent.Kind; -import java.nio.file.WatchKey; -import java.nio.file.WatchService; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.Deque; -import java.util.LinkedList; -import java.util.Objects; - import cpw.mods.fml.SafeExitJVMLegacy; import net.minecraftforge.fml.SafeExitJVM; import ru.gravit.launcher.LauncherAPI; @@ -25,6 +10,14 @@ import ru.gravit.utils.helper.JVMHelper.OS; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.nio.file.*; +import java.nio.file.WatchEvent.Kind; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Deque; +import java.util.LinkedList; +import java.util.Objects; + public final class DirWatcher implements Runnable, AutoCloseable { private final class RegisterFileVisitor extends SimpleFileVisitor { private final Deque path = new LinkedList<>(); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/hasher/FileNameMatcher.java b/libLauncher/src/main/java/ru/gravit/launcher/hasher/FileNameMatcher.java index a4439ebc..223cc365 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/hasher/FileNameMatcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/hasher/FileNameMatcher.java @@ -1,10 +1,10 @@ package ru.gravit.launcher.hasher; +import ru.gravit.launcher.LauncherAPI; + import java.util.Arrays; import java.util.Collection; -import ru.gravit.launcher.LauncherAPI; - public final class FileNameMatcher { private static final String[] NO_ENTRIES = new String[0]; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedDir.java b/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedDir.java index 71e5f4bc..beec1595 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedDir.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedDir.java @@ -1,19 +1,5 @@ package ru.gravit.launcher.hasher; -import java.io.IOException; -import java.nio.file.FileVisitResult; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.Collections; -import java.util.Deque; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.StringTokenizer; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -22,6 +8,14 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.*; +import java.util.Map.Entry; + public final class HashedDir extends HashedEntry { public static final class Diff { @LauncherAPI diff --git a/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedEntry.java b/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedEntry.java index aa5af9d7..2045dbd5 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedEntry.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedEntry.java @@ -1,13 +1,13 @@ package ru.gravit.launcher.hasher; -import java.io.IOException; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.stream.EnumSerializer; import ru.gravit.launcher.serialize.stream.EnumSerializer.Itf; import ru.gravit.launcher.serialize.stream.StreamObject; +import java.io.IOException; + public abstract class HashedEntry extends StreamObject { @LauncherAPI public enum Type implements Itf { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedEntryAdapter.java b/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedEntryAdapter.java index 6577df95..d31fce3a 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedEntryAdapter.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedEntryAdapter.java @@ -1,15 +1,8 @@ package ru.gravit.launcher.hasher; -import java.lang.reflect.Type; +import com.google.gson.*; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; public class HashedEntryAdapter implements JsonSerializer, JsonDeserializer { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedFile.java b/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedFile.java index b87fd6b7..9179ff9a 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedFile.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/hasher/HashedFile.java @@ -1,9 +1,5 @@ package ru.gravit.launcher.hasher; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Arrays; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -12,6 +8,10 @@ import ru.gravit.utils.helper.SecurityHelper.DigestAlgorithm; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Arrays; + public final class HashedFile extends HashedEntry { public static final DigestAlgorithm DIGEST_ALGO = DigestAlgorithm.MD5; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/managers/GarbageManager.java b/libLauncher/src/main/java/ru/gravit/launcher/managers/GarbageManager.java index 6f7ba8b7..44e21baa 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/managers/GarbageManager.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/managers/GarbageManager.java @@ -1,11 +1,11 @@ package ru.gravit.launcher.managers; +import ru.gravit.launcher.NeedGarbageCollection; + import java.util.ArrayList; import java.util.Timer; import java.util.TimerTask; -import ru.gravit.launcher.NeedGarbageCollection; - public class GarbageManager { static class Entry { NeedGarbageCollection invoke; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java index afbef9c2..91771546 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java @@ -1,22 +1,18 @@ package ru.gravit.launcher.modules; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.jar.JarFile; -import java.util.jar.Manifest; - import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.jar.JarFile; +import java.util.jar.Manifest; + public class SimpleModuleManager implements ModulesManagerInterface, AutoCloseable { protected final class ModulesVisitor extends SimpleFileVisitor { private ModulesVisitor() { @@ -119,7 +115,7 @@ public void loadModuleFull(URL jarpath) throws ClassNotFoundException, IllegalAc LogHelper.info("Module %s version: %s loaded", module.getName(), module.getVersion()); f.close(); } - + @Override public void loadModule(URL jarpath, String classname, boolean preload) throws ClassNotFoundException, IllegalAccessException, InstantiationException { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java index b757d13a..166904e1 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java @@ -1,23 +1,19 @@ package ru.gravit.launcher.profiles; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.*; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.config.ConfigObject; -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; -import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry; -import ru.gravit.launcher.serialize.config.entry.IntegerConfigEntry; -import ru.gravit.launcher.serialize.config.entry.ListConfigEntry; -import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; +import ru.gravit.launcher.serialize.config.entry.*; import ru.gravit.launcher.serialize.stream.StreamObject; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.*; + @SuppressWarnings("ComparableImplementedButEqualsNotOverridden") public final class ClientProfile extends ConfigObject implements Comparable { @LauncherAPI @@ -67,7 +63,7 @@ public String toString() { public static final StreamObject.Adapter RO_ADAPTER = input -> new ClientProfile(input, true); public static final boolean profileCaseSensitive = Boolean.getBoolean("launcher.clientProfile.caseSensitive"); - + private static final FileNameMatcher ASSET_MATCHER = new FileNameMatcher( new String[0], new String[]{"indexes", "objects"}, new String[0]); // Version @@ -228,7 +224,9 @@ public Set getOptional() { } @LauncherAPI - public Collection getShared() { return updateShared; } + public Collection getShared() { + return updateShared; + } @LauncherAPI public void markOptional(String opt) { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/PlayerProfile.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/PlayerProfile.java index 24cae176..c174cc6e 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/profiles/PlayerProfile.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/PlayerProfile.java @@ -1,9 +1,5 @@ package ru.gravit.launcher.profiles; -import java.io.IOException; -import java.util.Objects; -import java.util.UUID; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -11,6 +7,10 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.Objects; +import java.util.UUID; + public final class PlayerProfile extends StreamObject { @LauncherAPI public static PlayerProfile newOfflineProfile(String username) { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/Texture.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/Texture.java index 30763d87..3cf976ac 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/profiles/Texture.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/Texture.java @@ -1,11 +1,5 @@ package ru.gravit.launcher.profiles; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Objects; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -13,6 +7,12 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.SecurityHelper; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Objects; + public final class Texture extends StreamObject { private static final SecurityHelper.DigestAlgorithm DIGEST_ALGO = SecurityHelper.DigestAlgorithm.SHA256; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/request/RequestException.java b/libLauncher/src/main/java/ru/gravit/launcher/request/RequestException.java index 3f0f9ba8..eecb8275 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/request/RequestException.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/request/RequestException.java @@ -1,9 +1,9 @@ package ru.gravit.launcher.request; -import java.io.IOException; - import ru.gravit.launcher.LauncherAPI; +import java.io.IOException; + public final class RequestException extends IOException { private static final long serialVersionUID = 7558237657082664821L; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/request/RequestType.java b/libLauncher/src/main/java/ru/gravit/launcher/request/RequestType.java index 887b1f18..25571eab 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/request/RequestType.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/request/RequestType.java @@ -1,11 +1,11 @@ package ru.gravit.launcher.request; -import java.io.IOException; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.stream.EnumSerializer; +import java.io.IOException; + public enum RequestType implements EnumSerializer.Itf { PING(0), // Ping request LEGACYLAUNCHER(1), UPDATE(2), UPDATE_LIST(3), // Update requests diff --git a/libLauncher/src/main/java/ru/gravit/launcher/request/UpdateAction.java b/libLauncher/src/main/java/ru/gravit/launcher/request/UpdateAction.java index 6b154f71..9f80c671 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/request/UpdateAction.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/request/UpdateAction.java @@ -1,7 +1,5 @@ package ru.gravit.launcher.request; -import java.io.IOException; - import ru.gravit.launcher.hasher.HashedEntry; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -9,6 +7,8 @@ import ru.gravit.launcher.serialize.stream.StreamObject; import ru.gravit.utils.helper.IOHelper; +import java.io.IOException; + public final class UpdateAction extends StreamObject { public enum Type implements EnumSerializer.Itf { CD(1), CD_BACK(2), GET(3), FINISH(255); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/HInput.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/HInput.java index b8ceaa1b..f6811e27 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/HInput.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/HInput.java @@ -1,5 +1,8 @@ package ru.gravit.launcher.serialize; +import ru.gravit.launcher.LauncherAPI; +import ru.gravit.utils.helper.IOHelper; + import java.io.ByteArrayInputStream; import java.io.EOFException; import java.io.IOException; @@ -8,9 +11,6 @@ import java.util.Objects; import java.util.UUID; -import ru.gravit.launcher.LauncherAPI; -import ru.gravit.utils.helper.IOHelper; - public final class HInput implements AutoCloseable { @LauncherAPI public final InputStream stream; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/HOutput.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/HOutput.java index 70af8d0b..3931db32 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/HOutput.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/HOutput.java @@ -1,5 +1,8 @@ package ru.gravit.launcher.serialize; +import ru.gravit.launcher.LauncherAPI; +import ru.gravit.utils.helper.IOHelper; + import java.io.Flushable; import java.io.IOException; import java.io.OutputStream; @@ -7,9 +10,6 @@ import java.util.Objects; import java.util.UUID; -import ru.gravit.launcher.LauncherAPI; -import ru.gravit.utils.helper.IOHelper; - public final class HOutput implements AutoCloseable, Flushable { @LauncherAPI public final OutputStream stream; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/ConfigObject.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/ConfigObject.java index 9b8faaa4..cb13d9a8 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/ConfigObject.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/ConfigObject.java @@ -1,13 +1,13 @@ package ru.gravit.launcher.serialize.config; -import java.io.IOException; -import java.util.Objects; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.launcher.serialize.stream.StreamObject; +import java.io.IOException; +import java.util.Objects; + public abstract class ConfigObject extends StreamObject { @FunctionalInterface public interface Adapter { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/TextConfigReader.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/TextConfigReader.java index a7788095..3c56a7eb 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/TextConfigReader.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/TextConfigReader.java @@ -1,5 +1,9 @@ package ru.gravit.launcher.serialize.config; +import ru.gravit.launcher.LauncherAPI; +import ru.gravit.launcher.serialize.config.entry.*; +import ru.gravit.utils.helper.VerifyHelper; + import java.io.IOException; import java.io.LineNumberReader; import java.io.Reader; @@ -8,15 +12,6 @@ import java.util.List; import java.util.Map; -import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; -import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry; -import ru.gravit.launcher.serialize.config.entry.ConfigEntry; -import ru.gravit.launcher.serialize.config.entry.IntegerConfigEntry; -import ru.gravit.launcher.serialize.config.entry.ListConfigEntry; -import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; -import ru.gravit.utils.helper.VerifyHelper; - public final class TextConfigReader { @LauncherAPI public static BlockConfigEntry read(Reader reader, boolean ro) throws IOException { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/TextConfigWriter.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/TextConfigWriter.java index 07a6ae1d..1337aa79 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/TextConfigWriter.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/TextConfigWriter.java @@ -1,19 +1,14 @@ package ru.gravit.launcher.serialize.config; +import ru.gravit.launcher.LauncherAPI; +import ru.gravit.launcher.serialize.config.entry.*; + import java.io.IOException; import java.io.Writer; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; -import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry; -import ru.gravit.launcher.serialize.config.entry.ConfigEntry; -import ru.gravit.launcher.serialize.config.entry.IntegerConfigEntry; -import ru.gravit.launcher.serialize.config.entry.ListConfigEntry; -import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; - public final class TextConfigWriter { @LauncherAPI public static void write(BlockConfigEntry block, Writer writer, boolean comments) throws IOException { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/BlockConfigEntry.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/BlockConfigEntry.java index f0e11070..9971ee72 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/BlockConfigEntry.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/BlockConfigEntry.java @@ -1,18 +1,14 @@ package ru.gravit.launcher.serialize.config.entry; -import java.io.IOException; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.NoSuchElementException; -import java.util.Set; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.*; +import java.util.Map.Entry; + public final class BlockConfigEntry extends ConfigEntry>> { private static Map> readMap(HInput input, boolean ro) throws IOException { int entriesCount = input.readLength(0); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/BooleanConfigEntry.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/BooleanConfigEntry.java index c1774d67..9b5e35a4 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/BooleanConfigEntry.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/BooleanConfigEntry.java @@ -1,11 +1,11 @@ package ru.gravit.launcher.serialize.config.entry; -import java.io.IOException; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; +import java.io.IOException; + public final class BooleanConfigEntry extends ConfigEntry { @LauncherAPI public BooleanConfigEntry(boolean value, boolean ro, int cc) { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/ConfigEntry.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/ConfigEntry.java index 174945a9..3f250ebf 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/ConfigEntry.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/ConfigEntry.java @@ -1,8 +1,5 @@ package ru.gravit.launcher.serialize.config.entry; -import java.io.IOException; -import java.util.Objects; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; @@ -10,6 +7,9 @@ import ru.gravit.launcher.serialize.stream.EnumSerializer.Itf; import ru.gravit.launcher.serialize.stream.StreamObject; +import java.io.IOException; +import java.util.Objects; + public abstract class ConfigEntry extends StreamObject { @LauncherAPI public enum Type implements Itf { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/IntegerConfigEntry.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/IntegerConfigEntry.java index 1784fd5c..5b37bbae 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/IntegerConfigEntry.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/IntegerConfigEntry.java @@ -1,11 +1,11 @@ package ru.gravit.launcher.serialize.config.entry; -import java.io.IOException; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; +import java.io.IOException; + public final class IntegerConfigEntry extends ConfigEntry { @LauncherAPI public IntegerConfigEntry(HInput input, boolean ro) throws IOException { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/ListConfigEntry.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/ListConfigEntry.java index bbb0c48f..4764cb7a 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/ListConfigEntry.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/ListConfigEntry.java @@ -1,15 +1,15 @@ package ru.gravit.launcher.serialize.config.entry; +import ru.gravit.launcher.LauncherAPI; +import ru.gravit.launcher.serialize.HInput; +import ru.gravit.launcher.serialize.HOutput; + import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Stream; -import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.serialize.HInput; -import ru.gravit.launcher.serialize.HOutput; - public final class ListConfigEntry extends ConfigEntry>> { private static List> readList(HInput input, boolean ro) throws IOException { int elementsCount = input.readLength(0); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/StringConfigEntry.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/StringConfigEntry.java index d3433059..3102fd29 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/StringConfigEntry.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/config/entry/StringConfigEntry.java @@ -1,11 +1,11 @@ package ru.gravit.launcher.serialize.config.entry; -import java.io.IOException; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; +import java.io.IOException; + public final class StringConfigEntry extends ConfigEntry { @LauncherAPI public StringConfigEntry(HInput input, boolean ro) throws IOException { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/signed/DigestBytesHolder.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/signed/DigestBytesHolder.java index 40073ddf..e848db3b 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/signed/DigestBytesHolder.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/signed/DigestBytesHolder.java @@ -1,15 +1,15 @@ package ru.gravit.launcher.serialize.signed; -import java.io.IOException; -import java.security.SignatureException; -import java.util.Arrays; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.stream.StreamObject; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.security.SignatureException; +import java.util.Arrays; + public class DigestBytesHolder extends StreamObject { protected final byte[] bytes; private final byte[] digest; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/signed/SignedBytesHolder.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/signed/SignedBytesHolder.java index 6e9d9fb6..1eb4bd4d 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/signed/SignedBytesHolder.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/signed/SignedBytesHolder.java @@ -1,16 +1,16 @@ package ru.gravit.launcher.serialize.signed; -import java.io.IOException; -import java.security.SignatureException; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.stream.StreamObject; import ru.gravit.utils.helper.SecurityHelper; +import java.io.IOException; +import java.security.SignatureException; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; + public class SignedBytesHolder extends StreamObject { protected final byte[] bytes; private final byte[] sign; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/signed/SignedObjectHolder.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/signed/SignedObjectHolder.java index 7f7860aa..b326634a 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/signed/SignedObjectHolder.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/signed/SignedObjectHolder.java @@ -1,14 +1,14 @@ package ru.gravit.launcher.serialize.signed; +import ru.gravit.launcher.LauncherAPI; +import ru.gravit.launcher.serialize.HInput; +import ru.gravit.launcher.serialize.stream.StreamObject; + import java.io.IOException; import java.security.SignatureException; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; -import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.serialize.HInput; -import ru.gravit.launcher.serialize.stream.StreamObject; - public final class SignedObjectHolder extends SignedBytesHolder { @LauncherAPI public final O object; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/stream/EnumSerializer.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/stream/EnumSerializer.java index 0ee40927..87e91f41 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/stream/EnumSerializer.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/stream/EnumSerializer.java @@ -1,15 +1,15 @@ package ru.gravit.launcher.serialize.stream; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.stream.EnumSerializer.Itf; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + public final class EnumSerializer & Itf> { @FunctionalInterface public interface Itf { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/serialize/stream/StreamObject.java b/libLauncher/src/main/java/ru/gravit/launcher/serialize/stream/StreamObject.java index 30df9e41..ab8f6366 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/serialize/stream/StreamObject.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/serialize/stream/StreamObject.java @@ -1,13 +1,13 @@ package ru.gravit.launcher.serialize.stream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; - import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.utils.helper.IOHelper; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + public abstract class StreamObject { /* public StreamObject(HInput input) */ diff --git a/libLauncher/src/main/java/ru/gravit/launcher/ssl/LauncherSSLContext.java b/libLauncher/src/main/java/ru/gravit/launcher/ssl/LauncherSSLContext.java index 6b935b83..eaa6ba8a 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/ssl/LauncherSSLContext.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/ssl/LauncherSSLContext.java @@ -1,23 +1,13 @@ package ru.gravit.launcher.ssl; -import java.security.KeyManagementException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.security.UnrecoverableKeyException; - -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLServerSocketFactory; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; +import javax.net.ssl.*; +import java.security.*; public class LauncherSSLContext { public SSLServerSocketFactory ssf; public SSLSocketFactory sf; @SuppressWarnings("unused") - private SSLContext sc; + private SSLContext sc; public LauncherSSLContext(KeyStore ks, String keypassword) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException { TrustManager[] trustAllCerts = new TrustManager[]{ diff --git a/libLauncher/src/main/java/ru/gravit/utils/HTTPRequest.java b/libLauncher/src/main/java/ru/gravit/utils/HTTPRequest.java index ec5e75d3..149b2af8 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/HTTPRequest.java +++ b/libLauncher/src/main/java/ru/gravit/utils/HTTPRequest.java @@ -1,5 +1,9 @@ package ru.gravit.utils; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import ru.gravit.utils.helper.IOHelper; + import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; @@ -9,11 +13,6 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; - -import ru.gravit.utils.helper.IOHelper; - public class HTTPRequest { private static final int TIMEOUT = 10; private static final JsonParser parser = new JsonParser(); diff --git a/libLauncher/src/main/java/ru/gravit/utils/HttpDownloader.java b/libLauncher/src/main/java/ru/gravit/utils/HttpDownloader.java index 1f7471a8..a73bca13 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/HttpDownloader.java +++ b/libLauncher/src/main/java/ru/gravit/utils/HttpDownloader.java @@ -1,5 +1,8 @@ package ru.gravit.utils; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; + import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.IOException; @@ -10,9 +13,6 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; - public class HttpDownloader extends Observable { public static final int BUFER_SIZE = 8192; public static final int INTERVAL = 300; diff --git a/libLauncher/src/main/java/ru/gravit/utils/PublicURLClassLoader.java b/libLauncher/src/main/java/ru/gravit/utils/PublicURLClassLoader.java index 05bd40b7..f5866008 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/PublicURLClassLoader.java +++ b/libLauncher/src/main/java/ru/gravit/utils/PublicURLClassLoader.java @@ -1,10 +1,10 @@ package ru.gravit.utils; +import ru.gravit.launcher.LauncherAPI; + import java.net.URL; import java.net.URLClassLoader; -import ru.gravit.launcher.LauncherAPI; - public class PublicURLClassLoader extends URLClassLoader { @LauncherAPI public static ClassLoader systemclassloader = ClassLoader.getSystemClassLoader(); diff --git a/libLauncher/src/main/java/ru/gravit/utils/Version.java b/libLauncher/src/main/java/ru/gravit/utils/Version.java index 553e2384..2d189c7e 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/Version.java +++ b/libLauncher/src/main/java/ru/gravit/utils/Version.java @@ -1,9 +1,9 @@ package ru.gravit.utils; -import java.util.Objects; - import ru.gravit.launcher.LauncherAPI; +import java.util.Objects; + public class Version { @LauncherAPI public final int major; diff --git a/libLauncher/src/main/java/ru/gravit/utils/downloader/Downloader.java b/libLauncher/src/main/java/ru/gravit/utils/downloader/Downloader.java index 4a464042..12dfa4c1 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/downloader/Downloader.java +++ b/libLauncher/src/main/java/ru/gravit/utils/downloader/Downloader.java @@ -1,5 +1,9 @@ package ru.gravit.utils.downloader; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; + +import javax.net.ssl.HttpsURLConnection; import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; @@ -14,11 +18,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import javax.net.ssl.HttpsURLConnection; - -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; - public class Downloader implements Runnable { @FunctionalInterface public interface Handler { diff --git a/libLauncher/src/main/java/ru/gravit/utils/event/EventManager.java b/libLauncher/src/main/java/ru/gravit/utils/event/EventManager.java index 368cacdb..d592fd65 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/event/EventManager.java +++ b/libLauncher/src/main/java/ru/gravit/utils/event/EventManager.java @@ -1,5 +1,8 @@ package ru.gravit.utils.event; +import ru.gravit.utils.helper.CommonHelper; +import ru.gravit.utils.helper.LogHelper; + import java.util.ArrayList; import java.util.Arrays; import java.util.UUID; @@ -7,9 +10,6 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicBoolean; -import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.LogHelper; - public class EventManager { public static final int QUEUE_MAX_SIZE = 2048; public static final int INITIAL_HANDLERS_SIZE = 16; diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/CommonHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/CommonHelper.java index f76fe675..bc7d21f7 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/CommonHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/CommonHelper.java @@ -1,14 +1,13 @@ package ru.gravit.utils.helper; -import java.util.Locale; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import ru.gravit.launcher.LauncherAPI; import javax.script.ScriptEngine; import javax.script.ScriptEngineFactory; import javax.script.ScriptEngineManager; - -import ru.gravit.launcher.LauncherAPI; +import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public final class CommonHelper { @LauncherAPI diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/IOHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/IOHelper.java index 6126ede8..05514c30 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/IOHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/IOHelper.java @@ -1,49 +1,17 @@ package ru.gravit.utils.helper; +import ru.gravit.launcher.Launcher; +import ru.gravit.launcher.LauncherAPI; + +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; import java.awt.image.BufferedImage; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.ByteArrayOutputStream; -import java.io.EOFException; -import java.io.FileDescriptor; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; -import java.net.InetSocketAddress; -import java.net.MalformedURLException; -import java.net.Socket; -import java.net.SocketAddress; -import java.net.SocketException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLDecoder; -import java.net.URLEncoder; +import java.io.*; +import java.net.*; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.nio.file.CopyOption; -import java.nio.file.DirectoryStream; +import java.nio.file.*; import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.FileVisitOption; -import java.nio.file.FileVisitResult; -import java.nio.file.FileVisitor; -import java.nio.file.Files; -import java.nio.file.InvalidPathException; -import java.nio.file.LinkOption; -import java.nio.file.NoSuchFileException; -import java.nio.file.OpenOption; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.StandardCopyOption; -import java.nio.file.StandardOpenOption; import java.nio.file.attribute.BasicFileAttributes; import java.util.Collections; import java.util.Set; @@ -54,12 +22,6 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import javax.imageio.ImageIO; -import javax.imageio.ImageReader; - -import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.LauncherAPI; - public final class IOHelper { private static final class DeleteDirVisitor extends SimpleFileVisitor { private final Path dir; diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java index 1d6c5397..6d608413 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java @@ -1,5 +1,7 @@ package ru.gravit.utils.helper; +import ru.gravit.launcher.LauncherAPI; + import java.io.File; import java.lang.invoke.MethodHandles; import java.lang.management.ManagementFactory; @@ -11,8 +13,6 @@ import java.util.Locale; import java.util.Map; -import ru.gravit.launcher.LauncherAPI; - public final class JVMHelper { @SuppressWarnings("unused") @LauncherAPI @@ -100,8 +100,8 @@ public static String[] getClassPath() { public static URL[] getClassPathURL() { String[] cp = System.getProperty("java.class.path").split(File.pathSeparator); URL[] list = new URL[cp.length]; - - for(int i = 0; i < cp.length; i++) { + + for (int i = 0; i < cp.length; i++) { URL url = null; try { url = new URL(cp[i]); diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java index 23125e63..1dea0de8 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java @@ -1,10 +1,13 @@ package ru.gravit.utils.helper; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.io.Writer; +import org.fusesource.jansi.Ansi; +import org.fusesource.jansi.Ansi.Color; +import org.fusesource.jansi.AnsiConsole; +import org.fusesource.jansi.AnsiOutputStream; +import ru.gravit.launcher.Launcher; +import ru.gravit.launcher.LauncherAPI; + +import java.io.*; import java.nio.file.Path; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -15,14 +18,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; -import org.fusesource.jansi.Ansi; -import org.fusesource.jansi.Ansi.Color; -import org.fusesource.jansi.AnsiConsole; -import org.fusesource.jansi.AnsiOutputStream; - -import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.LauncherAPI; - public final class LogHelper { @LauncherAPI public static final String DEBUG_PROPERTY = "launcher.debug"; @@ -130,6 +125,7 @@ public static void log(Level level, String message, boolean sub) { public static void printVersion(String product) { println(JANSI ? ansiFormatVersion(product) : formatVersion(product)); } + @LauncherAPI public static void printLicense(String product) { println(JANSI ? ansiFormatLicense(product) : formatLicense(product)); @@ -278,6 +274,7 @@ private static String formatLog(Level level, String message, String dateTime, bo private static String formatVersion(String product) { return String.format("GravitLauncher (fork sashok724's Launcher) %s v%s", product, Launcher.getVersion().toString()); } + private static String formatLicense(String product) { return String.format("License for %s GPLv3. SourceCode: https://github.com/GravitLauncher/Launcher", product); } diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/SecurityHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/SecurityHelper.java index c070df67..97da776f 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/SecurityHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/SecurityHelper.java @@ -1,19 +1,17 @@ package ru.gravit.utils.helper; +import ru.gravit.launcher.LauncherAPI; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.nio.file.Path; -import java.security.InvalidKeyException; -import java.security.Key; -import java.security.KeyFactory; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.security.Signature; -import java.security.SignatureException; +import java.security.*; import java.security.interfaces.RSAKey; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; @@ -24,14 +22,6 @@ import java.util.Map; import java.util.Random; -import javax.crypto.Cipher; -import javax.crypto.KeyGenerator; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.SecretKey; -import javax.crypto.spec.SecretKeySpec; - -import ru.gravit.launcher.LauncherAPI; - public final class SecurityHelper { public enum DigestAlgorithm { diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java index ca00a3a7..40dc0212 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java @@ -18,7 +18,7 @@ public static boolean unpack(URL resource, Path target) throws IOException { Files.deleteIfExists(target); Files.createFile(target); try (InputStream in = IOHelper.newInput(resource)) { - IOHelper.transfer(in, target); + IOHelper.transfer(in, target); } return true; } @@ -47,24 +47,24 @@ public static boolean unpackZipNoCheck(URL resource, Path target) throws IOExcep } return true; } - + public static boolean unpackZipNoCheck(String resource, Path target) throws IOException { try { - if (Files.isDirectory(target)) - return false; - Files.deleteIfExists(target); - Files.createDirectory(target); - try (ZipInputStream input = IOHelper.newZipInput(IOHelper.getResourceURL(resource))) { - for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) { - if (entry.isDirectory()) - continue; // Skip dirs - // Unpack file - IOHelper.transfer(input, target.resolve(IOHelper.toPath(entry.getName()))); - } - } - return true; + if (Files.isDirectory(target)) + return false; + Files.deleteIfExists(target); + Files.createDirectory(target); + try (ZipInputStream input = IOHelper.newZipInput(IOHelper.getResourceURL(resource))) { + for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) { + if (entry.isDirectory()) + continue; // Skip dirs + // Unpack file + IOHelper.transfer(input, target.resolve(IOHelper.toPath(entry.getName()))); + } + } + return true; } catch (NoSuchFileException e) { - return true; + return true; } } } diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/VerifyHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/VerifyHelper.java index 7dfa1d77..1d9566ed 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/VerifyHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/VerifyHelper.java @@ -1,5 +1,7 @@ package ru.gravit.utils.helper; +import ru.gravit.launcher.LauncherAPI; + import java.util.Map; import java.util.Objects; import java.util.function.DoublePredicate; @@ -8,8 +10,6 @@ import java.util.function.Predicate; import java.util.regex.Pattern; -import ru.gravit.launcher.LauncherAPI; - public final class VerifyHelper { @LauncherAPI public static final IntPredicate POSITIVE = i -> i > 0;