diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index 5cadc5a7..84875664 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -8,7 +8,7 @@ url "https://oss.sonatype.org/content/repositories/snapshots" } maven { - url "http://maven.geomajas.org/" + url "https://maven.geomajas.org/" } } @@ -24,7 +24,7 @@ launch4j launch4jCJ bundleOnly.extendsFrom bundle - compile.extendsFrom bundle, hikari, pack, launch4jCJ, launch4j + api.extendsFrom bundle, hikari, pack, launch4jCJ, launch4j } jar { @@ -114,15 +114,17 @@ pack project(':LauncherAPI') compileOnlyA 'com.google.guava:guava:26.0-jre' compileOnlyA 'log4j:log4j:1.2.17' // Do not update (laggy dep). compileOnlyA 'org.apache.logging.log4j:log4j-core:2.11.2' - testCompile 'org.junit.jupiter:junit-jupiter:5.4.1' + testImplementation 'org.junit.jupiter:junit-jupiter:5.4.1' } task hikari(type: Copy) { + duplicatesStrategy = 'EXCLUDE' into "$buildDir/libs/libraries/hikaricp" from configurations.hikari } task launch4jM(type: Copy) { + duplicatesStrategy = 'EXCLUDE' into "$buildDir/libs/libraries/launch4j" from(configurations.launch4jCJ.collect { it.isDirectory() ? it : zipTree(it) }) includeEmptyDirs false @@ -139,6 +141,7 @@ task launch4jM(type: Copy) { } task launch4jA(type: Copy) { + duplicatesStrategy = 'EXCLUDE' into "$buildDir/libs/libraries/launch4j" from(configurations.launch4j) includeEmptyDirs false @@ -151,20 +154,23 @@ task launch4jA(type: Copy) { } task dumpLibs(type: Copy) { + duplicatesStrategy = 'EXCLUDE' dependsOn tasks.hikari, tasks.launch4jM, tasks.launch4jA into "$buildDir/libs/libraries" from configurations.bundleOnly } task dumpCompileOnlyLibs(type: Copy) { + duplicatesStrategy = 'EXCLUDE' into "$buildDir/libs/launcher-libraries-compile" from configurations.compileOnlyA } task bundle(type: Zip) { + duplicatesStrategy = 'EXCLUDE' dependsOn parent.childProjects.Launcher.tasks.build, tasks.dumpLibs, tasks.dumpCompileOnlyLibs, tasks.jar - archiveName 'LaunchServer.zip' - destinationDir file("$buildDir") + archiveFileName = 'LaunchServer.zip' + destinationDirectory = file("$buildDir") from(tasks.dumpLibs.destinationDir) { into 'libraries' } from(tasks.dumpCompileOnlyLibs.destinationDir) { into 'launcher-libraries-compile' } from tasks.jar.archivePath diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 3e31b828..16d2fc44 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -18,7 +18,6 @@ import pro.gravit.launchserver.manangers.LaunchServerGsonManager; import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager; import pro.gravit.launchserver.socket.WebSocketService; -import pro.gravit.utils.Version; import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.JLineCommandHandler; import pro.gravit.utils.command.StdCommandHandler; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java index ea8f00f1..9a0ea2b1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/NodeUtils.java @@ -5,7 +5,6 @@ import org.objectweb.asm.Type; import org.objectweb.asm.tree.*; import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.JarHelper; import java.io.IOException; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java index 77ba174b..9fc786cf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java @@ -63,7 +63,7 @@ public void invoke(String... args) throws Exception { public abstract void ban(List hwid) throws HWIDException; public void check(HWID hwid, String username) throws HWIDException { - if (hwid.isNull()) return; + if (hwid == null || hwid.isNull()) return; check0(hwid, username); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java index 7b3bf8fc..6dfcd9e0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/ProguardConf.java @@ -1,7 +1,6 @@ package pro.gravit.launchserver.binary; import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.asm.NodeUtils; import pro.gravit.utils.helper.*; import java.io.IOException; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java index 2601c110..db19f4f5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/SessionManager.java @@ -2,7 +2,6 @@ import pro.gravit.launcher.NeedGarbageCollection; import pro.gravit.launchserver.socket.Client; -import pro.gravit.launchserver.socket.response.auth.AuthResponse; import java.util.HashMap; import java.util.HashSet; @@ -41,6 +40,11 @@ public Client getOrNewClient(long session) { return clientSet.computeIfAbsent(session, Client::new); } + public Client removeClient(long session) + { + return clientSet.remove(session); + } + public void updateClient(long session) { Client c = clientSet.get(session); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java index e717dcb0..3c060a60 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -66,6 +66,11 @@ public WebSocketService(ChannelGroup channels, LaunchServer server) { public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) { String request = frame.text(); WebSocketServerResponse response = gson.fromJson(request, WebSocketServerResponse.class); + if(response == null) + { + RequestEvent event= new ErrorRequestEvent("This type of request is not supported"); + sendObject(ctx, event); + } process(ctx, response, client, ip); } @@ -123,6 +128,7 @@ public static void registerResponses() { providers.register("getAvailabilityAuth", GetAvailabilityAuthResponse.class); providers.register("register", RegisterResponse.class); providers.register("setPassword", SetPasswordResponse.class); + providers.register("exit", ExitResponse.class); } public void sendObject(ChannelHandlerContext ctx, Object obj) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java new file mode 100644 index 00000000..07af9fff --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java @@ -0,0 +1,90 @@ +package pro.gravit.launchserver.socket.response.auth; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.events.request.ExitRequestEvent; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler; +import pro.gravit.launchserver.socket.response.SimpleResponse; + +public class ExitResponse extends SimpleResponse { + public boolean exitAll; + public String username; + @Override + public String getType() { + return "exit"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + if(username != null && ( !client.isAuth || client.permissions == null || !client.permissions.canAdmin )) + { + sendError("Permissions denied"); + return; + } + if(username == null) + { + if(client.session == 0 && exitAll) + { + sendError("Session invalid"); + return; + } + WebSocketFrameHandler handler = ctx.pipeline().get(WebSocketFrameHandler.class); + if(handler == null) + { + sendError("Exit internal error"); + return; + } + Client newClient = new Client(0); + newClient.isSecure = client.isSecure; + newClient.checkSign = client.checkSign; + handler.setClient(newClient); + if(client.session != 0) server.sessionManager.removeClient(client.session); + if(exitAll) + { + service.channels.forEach((channel) -> { + if(channel == null || channel.pipeline() == null) return; + WebSocketFrameHandler wsHandler = channel.pipeline().get(WebSocketFrameHandler.class); + if(wsHandler == null || wsHandler == handler) return; + Client chClient = wsHandler.getClient(); + if(client.isAuth && client.username != null) + { + if(!chClient.isAuth || !client.username.equals(chClient.username)) return; + } + else + { + if(chClient.session != client.session) return; + } + Client newCusClient = new Client(0); + newCusClient.isSecure = chClient.isSecure; + newCusClient.checkSign = chClient.checkSign; + wsHandler.setClient(newCusClient); + if(chClient.session != 0) server.sessionManager.removeClient(chClient.session); + ExitRequestEvent event = new ExitRequestEvent(ExitRequestEvent.ExitReason.SERVER); + event.requestUUID = RequestEvent.eventUUID; + wsHandler.service.sendObject(channel, event); + }); + } + sendResult(new ExitRequestEvent(ExitRequestEvent.ExitReason.CLIENT)); + } + else + { + service.channels.forEach((channel -> { + if(channel == null || channel.pipeline() == null) return; + WebSocketFrameHandler wsHandler = channel.pipeline().get(WebSocketFrameHandler.class); + if(wsHandler == null) return; + Client chClient = wsHandler.getClient(); + if(!chClient.isAuth || !username.equals(chClient.username)) return; + Client newCusClient = new Client(0); + newCusClient.isSecure = chClient.isSecure; + newCusClient.checkSign = chClient.checkSign; + wsHandler.setClient(newCusClient); + if(chClient.session != 0) server.sessionManager.removeClient(chClient.session); + ExitRequestEvent event = new ExitRequestEvent(ExitRequestEvent.ExitReason.SERVER); + event.requestUUID = RequestEvent.eventUUID; + wsHandler.service.sendObject(channel, event); + })); + sendResult(new ExitRequestEvent(ExitRequestEvent.ExitReason.NO_EXIT)); + } + } +} diff --git a/Launcher/build.gradle b/Launcher/build.gradle index b99e62a8..918ace4a 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -1,6 +1,4 @@ -plugins { - id 'org.openjfx.javafxplugin' version '0.0.5' -} +apply plugin: 'org.openjfx.javafxplugin' apply plugin: 'com.github.johnrengelman.shadow' String mainClassName = "pro.gravit.launcher.ClientLauncherWrapper" @@ -8,7 +6,7 @@ repositories { maven { - url "http://repo.spring.io/plugins-release/" + url "https://repo.spring.io/plugins-release/" } } javafx { @@ -21,7 +19,7 @@ configurations { bundle pack - compile.extendsFrom bundle, pack + api.extendsFrom bundle, pack } jar { @@ -45,6 +43,7 @@ task javadocJar(type: Jar) { } shadowJar { + duplicatesStrategy = 'EXCLUDE' classifier = null relocate 'org.objectweb.asm', 'pro.gravit.repackage.org.objectweb.asm' relocate 'io.netty', 'pro.gravit.repackage.io.netty' @@ -60,12 +59,14 @@ pack project(':LauncherAPI') } task genRuntimeJS(type: Zip) { - archiveName = "runtime.zip" - destinationDir = file("${buildDir}/tmp") + duplicatesStrategy = 'EXCLUDE' + archiveFileName = "runtime.zip" + destinationDirectory = file("${buildDir}/tmp") from "runtime/" } task dumpLibs(type: Copy) { + duplicatesStrategy = 'EXCLUDE' into "$buildDir/libs/libraries" from configurations.bundle } diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 301cd7b1..1b68a380 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -1,6 +1,5 @@ package pro.gravit.launcher; -import pro.gravit.launcher.api.SystemService; import pro.gravit.launcher.client.*; import pro.gravit.launcher.client.events.ClientEngineInitPhase; import pro.gravit.launcher.client.events.ClientExitPhase; @@ -61,11 +60,10 @@ public static void exitLauncher(int code) modulesManager.invokeEvent(new ClientExitPhase(code)); try { System.exit(code); - } catch (Exception e) //Forge Security Manager? + } catch (Throwable e) //Forge Security Manager? { NativeJVMHalt.haltA(code); } - } public static void main(String... args) throws Throwable { @@ -99,7 +97,7 @@ public static void main(String... args) throws Throwable { LogHelper.debug("Launcher started in %dms", endTime - startTime); //Request.service.close(); //FunctionalBridge.close(); - SystemService.exit(0); + LauncherEngine.exitLauncher(0); } public static void initGson(ClientModuleManager modulesManager) { diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index db685b77..d91eb126 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -3,6 +3,7 @@ import pro.gravit.launcher.*; import pro.gravit.launcher.api.AuthService; import pro.gravit.launcher.api.ClientService; +import pro.gravit.launcher.api.SystemService; import pro.gravit.launcher.client.events.ClientLaunchPhase; import pro.gravit.launcher.client.events.ClientLauncherInitPhase; import pro.gravit.launcher.client.events.ClientLauncherPostInitPhase; @@ -13,6 +14,7 @@ import pro.gravit.launcher.managers.ClientGsonManager; import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.modules.events.PreConfigPhase; +import pro.gravit.launcher.patches.FMLPatcher; import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.PlayerProfile; import pro.gravit.launcher.request.Request; @@ -32,10 +34,7 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; -import java.net.InetSocketAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.URL; +import java.net.*; import java.nio.file.FileVisitResult; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; @@ -293,14 +292,19 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl { LogHelper.info("ClassLoader URL: %s", u.toString()); } + FMLPatcher.apply(); MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)).asFixedArity(); Launcher.LAUNCHED.set(true); JVMHelper.fullGC(); // Invoke main method try { mainMethod.invokeWithArguments((Object) args.toArray(new String[0])); + LogHelper.debug("Main exit successful"); + } catch (Throwable e) { + LogHelper.error(e); + throw e; } finally { - Request.service.close(); + LauncherEngine.exitLauncher(0); } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java b/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java index 79b7a085..fb325aab 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/patches/FMLPatcher.java @@ -10,6 +10,7 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.nio.ByteBuffer; +import java.util.Locale; import java.util.Random; import java.util.Vector; @@ -87,7 +88,8 @@ private static byte[] gen(final String name, final String exName) { // "cpw/mods } public static String randomStr(final int lenght) { - final String alphabet = "abcdefghijklmnopqrstuvwxyz"; + String alphabet = "abcdefghijklmnopqrstuvwxyz"; + alphabet += alphabet.toUpperCase(Locale.US); final StringBuilder sb = new StringBuilder(lenght); final Random random = SecurityHelper.newRandom(); for (int i = 0; i < lenght; i++) diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java b/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java index 257808d0..7b9293ec 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java @@ -2,6 +2,7 @@ import pro.gravit.launcher.patches.FMLPatcher; import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.helper.LogHelper; import javax.swing.*; import java.awt.event.WindowEvent; @@ -22,23 +23,30 @@ private boolean aaabBooleanC_D() { } public static void haltA(int code) { + Throwable[] th = new Throwable[3]; NativeJVMHalt halt = new NativeJVMHalt(code); try { JVMHelper.RUNTIME.exit(code); - } catch (Throwable ignored) { + } catch (Throwable exitExc) { + th[0] = exitExc; try { new WindowShutdown(); - } catch (Throwable ignored1) { + } catch (Throwable windowExc) { + th[1] = windowExc; } } try { FMLPatcher.exit(code); - } catch (Throwable ignored) { + } catch (Throwable fmlExc) { + th[2] = fmlExc; + } + for(Throwable t : th) + { + if(t != null) LogHelper.error(t); } - - halt.aaabbb38C_D(); boolean a = halt.aaabBooleanC_D(); System.out.println(a); + halt.aaabbb38C_D(); } diff --git a/LauncherAPI/build.gradle b/LauncherAPI/build.gradle index c6382a08..3cb0f2c7 100644 --- a/LauncherAPI/build.gradle +++ b/LauncherAPI/build.gradle @@ -2,9 +2,9 @@ targetCompatibility = '1.8' dependencies { - compile project(':LauncherCore') + api project(':LauncherCore') compileOnly 'io.netty:netty-codec-http:4.1.43.Final' - testCompile 'org.junit.jupiter:junit-jupiter:5.4.1' + testImplementation 'org.junit.jupiter:junit-jupiter:5.4.1' } test { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ExitRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ExitRequestEvent.java new file mode 100644 index 00000000..8916cf79 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ExitRequestEvent.java @@ -0,0 +1,20 @@ +package pro.gravit.launcher.events.request; + +import pro.gravit.launcher.events.RequestEvent; + +public class ExitRequestEvent extends RequestEvent { + public enum ExitReason + { + SERVER, CLIENT, TIMEOUT, NO_EXIT + } + public final ExitReason reason; + + public ExitRequestEvent(ExitReason reason) { + this.reason = reason; + } + + @Override + public String getType() { + return "exit"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/ExitRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/ExitRequest.java new file mode 100644 index 00000000..240c27a3 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/ExitRequest.java @@ -0,0 +1,29 @@ +package pro.gravit.launcher.request.auth; + +import pro.gravit.launcher.events.request.ExitRequestEvent; +import pro.gravit.launcher.request.Request; + +public class ExitRequest extends Request { + public final boolean exitAll; + public final String username; + + public ExitRequest() { + this.exitAll = false; + this.username = null; + } + + public ExitRequest(boolean exitAll) { + this.exitAll = exitAll; + this.username = null; + } + + public ExitRequest(boolean exitAll, String username) { + this.exitAll = exitAll; + this.username = username; + } + + @Override + public String getType() { + return "exit"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index 5b896a35..c6604048 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -107,6 +107,7 @@ public void registerResults() { results.register("setpassword", SetPasswordRequestEvent.class); results.register("notification", NotificationEvent.class); results.register("signal", SignalEvent.class); + results.register("exit", ExitRequestEvent.class); } public void waitIfNotConnected() { diff --git a/LauncherAuthlib/build.gradle b/LauncherAuthlib/build.gradle index c80e6841..b0be2cb6 100644 --- a/LauncherAuthlib/build.gradle +++ b/LauncherAuthlib/build.gradle @@ -2,7 +2,7 @@ targetCompatibility = '1.8' dependencies { - compile project(':LauncherAPI') + api project(':LauncherAPI') compileOnly 'com.google.guava:guava:26.0-jre' - compile files('../compat/authlib/authlib-clean.jar') + api files('../compat/authlib/authlib-clean.jar') } diff --git a/LauncherCore/build.gradle b/LauncherCore/build.gradle index c4783f31..40e2fe6e 100644 --- a/LauncherCore/build.gradle +++ b/LauncherCore/build.gradle @@ -1,4 +1,3 @@ -apply plugin: 'java-library' sourceCompatibility = '1.8' targetCompatibility = '1.8' @@ -8,8 +7,8 @@ compileOnly 'org.jline:jline-reader:3.11.0' compileOnly 'org.jline:jline-terminal:3.11.0' compileOnly 'org.bouncycastle:bcprov-jdk15:1.46' - compile 'com.google.code.gson:gson:2.8.5' - testCompile 'org.junit.jupiter:junit-jupiter:5.4.1' + api 'com.google.code.gson:gson:2.8.5' + testImplementation 'org.junit.jupiter:junit-jupiter:5.4.1' } test { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java b/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java index 221df950..209354cb 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java @@ -15,24 +15,41 @@ public class UniversalJsonAdapter implements JsonSerializer, JsonDeseriali public final ProviderMap providerMap; public final String name; public final String PROP_NAME; + public final boolean printErrorIfUnknownType; public UniversalJsonAdapter(ProviderMap providerMap) { this.providerMap = providerMap; this.name = providerMap.getName(); this.PROP_NAME = "type"; + printErrorIfUnknownType = true; } public UniversalJsonAdapter(ProviderMap providerMap, String PROP_NAME) { this.providerMap = providerMap; this.name = providerMap.getName(); this.PROP_NAME = PROP_NAME; + printErrorIfUnknownType = true; + } + + public UniversalJsonAdapter(ProviderMap providerMap, String name, String PROP_NAME, boolean printErrorIfUnknownType) { + this.providerMap = providerMap; + this.name = name; + this.PROP_NAME = PROP_NAME; + this.printErrorIfUnknownType = printErrorIfUnknownType; + } + + public UniversalJsonAdapter(ProviderMap providerMap, String name, boolean printErrorIfUnknownType) { + this.providerMap = providerMap; + this.name = name; + this.PROP_NAME = "type"; + this.printErrorIfUnknownType = printErrorIfUnknownType; } public R deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); Class cls = providerMap.getClass(typename); if (cls == null) { - LogHelper.error("%s %s not found", name, typename); + if(printErrorIfUnknownType) LogHelper.error("%s %s not found", name, typename); return null; } return context.deserialize(json, cls); @@ -48,9 +65,9 @@ public JsonElement serialize(R src, Type typeOfSrc, JsonSerializationContext con } if(classPath == null) { - LogHelper.warning("Class %s type null", src.getClass()); + if(printErrorIfUnknownType) LogHelper.warning("Class %s type null", src.getClass()); } - jo.add(PROP_NAME, new JsonPrimitive(classPath)); + else jo.add(PROP_NAME, new JsonPrimitive(classPath)); return jo; } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index 0f5b3f1e..eeb67e46 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -15,8 +15,8 @@ public final class Version { public final Type release; public static final int MAJOR = 5; public static final int MINOR = 1; - public static final int PATCH = 0; - public static final int BUILD = 1; + public static final int PATCH = 1; + public static final int BUILD = 2; public static final Version.Type RELEASE = Type.BETA; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JarHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JarHelper.java index 62500774..e28bc9a6 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JarHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JarHelper.java @@ -1,5 +1,6 @@ package pro.gravit.utils.helper; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; @@ -100,6 +101,21 @@ public static InputStream getClassBytesStream(Class clazz, ClassLoader classL { return classLoader.getResourceAsStream(getClassFile(clazz)); } - - + public static byte[] getClassFromJar(String name, Path file) throws IOException + { + String filename = getClassFile(name); + try(ZipInputStream inputStream = IOHelper.newZipInput(file)) + { + ZipEntry entry = inputStream.getNextEntry(); + while(entry != null) + { + if(entry.getName().equals(filename)) + { + return IOHelper.read(inputStream); + } + entry = inputStream.getNextEntry(); + } + } + throw new FileNotFoundException(filename); + } } diff --git a/ServerWrapper/build.gradle b/ServerWrapper/build.gradle index 9db86cf6..0c801681 100644 --- a/ServerWrapper/build.gradle +++ b/ServerWrapper/build.gradle @@ -5,12 +5,12 @@ configurations { pack - compile.extendsFrom pack + api.extendsFrom pack } repositories { maven { - url "http://repo.spring.io/plugins-release/" + url "https://repo.spring.io/plugins-release/" } } @@ -42,6 +42,7 @@ pack project(':LauncherAuthlib') } shadowJar { + duplicatesStrategy = 'EXCLUDE' classifier = null relocate 'io.netty', 'pro.gravit.repackage.io.netty' configurations = [project.configurations.pack] diff --git a/build.gradle b/build.gradle index ddaddb54..80e39138 100644 --- a/build.gradle +++ b/build.gradle @@ -1,39 +1,43 @@ plugins { - id 'com.github.johnrengelman.shadow' version '5.0.0' apply false + id 'com.github.johnrengelman.shadow' version '5.2.0' apply false id 'maven-publish' id 'signing' + id 'org.openjfx.javafxplugin' version '0.0.7' apply false } group = 'pro.gravit.launcher' -version = '5.1.0' +version = '5.1.1' configure(subprojects.findAll { it.name != 'modules' }) { apply plugin: 'idea' apply plugin: 'eclipse' apply plugin: 'java' + apply plugin: 'java-library' + group = 'pro.gravit' repositories { mavenCentral() - maven { url 'http://oss.sonatype.org/content/groups/public' } + maven { url 'https://oss.sonatype.org/content/groups/public' } maven { - url "http://clojars.org/repo/" + url "https://clojars.org/repo/" } } - configurations { - apt - aptCompileOnly - aptOnly - aptOnly.extendsFrom apt, aptCompileOnly - compile.extendsFrom apt - compileOnly.extendsFrom aptCompileOnly + jar { + duplicatesStrategy = 'EXCLUDE' + } + + eclipse { + classpath { + downloadSources = true + downloadJavadoc = true + } } tasks.withType(JavaCompile) { options.encoding = "UTF-8" options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" - options.annotationProcessorPath = configurations.aptOnly options.incremental = true // one flag, and things will get MUCH faster } } diff --git a/compat/auth/laravel/authcontroller/LauncherAuthController.php b/compat/auth/laravel/authcontroller/LauncherAuthController.php new file mode 100644 index 00000000..6c41adc4 --- /dev/null +++ b/compat/auth/laravel/authcontroller/LauncherAuthController.php @@ -0,0 +1,36 @@ +getContent()); + + if ($data->apiKey !== env('LAUNCHER_APIKEY')) { + return response()->json([ + 'error' => 'Неверный ключ. Обратитесь к администратору', + ]); + } + + if (Auth::attempt(['name' => $data->username, 'password' => $data->password])) { + $perm = DB::table('users') + ->select('launcher_permission') + ->where('name', '=', $data->username) + ->first(); + + return response()->json([ + 'username' => $data->username, + 'permission' => $perm->launcher_permission, + ]); + } else { + return response()->json([ + 'error' => 'Неверный логин или пароль', + ]); + } + } +} diff --git a/compat/auth/laravel/authcontroller/README.MD b/compat/auth/laravel/authcontroller/README.MD new file mode 100644 index 00000000..d09d30bd --- /dev/null +++ b/compat/auth/laravel/authcontroller/README.MD @@ -0,0 +1,9 @@ +#Контроллер авторизации методом json + +Route: +```php +Route::put('launcher/auth', 'LauncherAuthController@json'); +``` + +Добавить в **.env** строку `LAUNCHER_APIKEY=none` +Где `none` ваш apiKey \ No newline at end of file diff --git a/compat/auth/laravel/authcontroller/migrations/2020_03_05_151322_add_permission_collum.php b/compat/auth/laravel/authcontroller/migrations/2020_03_05_151322_add_permission_collum.php new file mode 100644 index 00000000..d82e5eb2 --- /dev/null +++ b/compat/auth/laravel/authcontroller/migrations/2020_03_05_151322_add_permission_collum.php @@ -0,0 +1,32 @@ +integer('launcher_permission')->default('0'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('launcher_permission'); + }); + } +} diff --git a/compat/auth/laravel/migrations/2020_03_04_172425_create_hwid_table.php b/compat/auth/laravel/migrations/2020_03_04_172425_create_hwid_table.php new file mode 100644 index 00000000..db0c8b9f --- /dev/null +++ b/compat/auth/laravel/migrations/2020_03_04_172425_create_hwid_table.php @@ -0,0 +1,36 @@ +bigIncrements('id'); + $table->tinyInteger('isBanned')->default('0'); + $table->text('totalMemory'); + $table->text('serialNumber'); + $table->text('HWDiskSerial'); + $table->text('processorID'); + $table->text('macAddr'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('users_hwids'); + } +} diff --git a/compat/auth/laravel/migrations/2020_03_05_140131_add_auth_handler_collums.php b/compat/auth/laravel/migrations/2020_03_05_140131_add_auth_handler_collums.php new file mode 100644 index 00000000..8a456f60 --- /dev/null +++ b/compat/auth/laravel/migrations/2020_03_05_140131_add_auth_handler_collums.php @@ -0,0 +1,36 @@ +char('uuid', '36')->unique()->nullable(); + $table->char('accessToken', '32')->nullable(); + $table->string('serverID', '41')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('uuid'); + $table->dropColumn('accessToken'); + $table->dropColumn('serverID'); + }); + } +} diff --git a/compat/auth/laravel/migrations/2020_03_05_142041_add_hwid_handler_collums.php b/compat/auth/laravel/migrations/2020_03_05_142041_add_hwid_handler_collums.php new file mode 100644 index 00000000..5040340b --- /dev/null +++ b/compat/auth/laravel/migrations/2020_03_05_142041_add_hwid_handler_collums.php @@ -0,0 +1,32 @@ +bigInteger('hwid')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('hwid'); + }); + } +} diff --git a/compat/auth/laravel/migrations/README.MD b/compat/auth/laravel/migrations/README.MD new file mode 100644 index 00000000..856151ac --- /dev/null +++ b/compat/auth/laravel/migrations/README.MD @@ -0,0 +1 @@ +# Миграции для Laravel \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 5c2d1cf0..f3d88b1c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ee69dd68..4e1cc9db 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index b0d6d0ab..2fe81a7d 100755 --- a/gradlew +++ b/gradlew @@ -7,7 +7,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -125,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` @@ -154,19 +154,19 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi @@ -175,14 +175,9 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=$(save "$@") +APP_ARGS=`save "$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 9991c503..9618d8d9 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -5,7 +5,7 @@ @rem you may not use this file except in compliance with the License. @rem You may obtain a copy of the License at @rem -@rem http://www.apache.org/licenses/LICENSE-2.0 +@rem https://www.apache.org/licenses/LICENSE-2.0 @rem @rem Unless required by applicable law or agreed to in writing, software @rem distributed under the License is distributed on an "AS IS" BASIS, diff --git a/modules b/modules index 0fbc3fb2..2edb2c72 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 0fbc3fb26c505800a61976cdf1310cad6ab7808d +Subproject commit 2edb2c7259d5a7dba3fa82c503f88a8a0e171840