Merge branch 'release/5.1.1'

This commit is contained in:
Gravit 2020-03-15 23:14:27 +07:00
commit 79f12edee6
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
36 changed files with 463 additions and 83 deletions

View file

@ -8,7 +8,7 @@
url "https://oss.sonatype.org/content/repositories/snapshots" url "https://oss.sonatype.org/content/repositories/snapshots"
} }
maven { maven {
url "http://maven.geomajas.org/" url "https://maven.geomajas.org/"
} }
} }
@ -24,7 +24,7 @@
launch4j launch4j
launch4jCJ launch4jCJ
bundleOnly.extendsFrom bundle bundleOnly.extendsFrom bundle
compile.extendsFrom bundle, hikari, pack, launch4jCJ, launch4j api.extendsFrom bundle, hikari, pack, launch4jCJ, launch4j
} }
jar { jar {
@ -114,15 +114,17 @@ pack project(':LauncherAPI')
compileOnlyA 'com.google.guava:guava:26.0-jre' compileOnlyA 'com.google.guava:guava:26.0-jre'
compileOnlyA 'log4j:log4j:1.2.17' // Do not update (laggy dep). compileOnlyA 'log4j:log4j:1.2.17' // Do not update (laggy dep).
compileOnlyA 'org.apache.logging.log4j:log4j-core:2.11.2' 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) { task hikari(type: Copy) {
duplicatesStrategy = 'EXCLUDE'
into "$buildDir/libs/libraries/hikaricp" into "$buildDir/libs/libraries/hikaricp"
from configurations.hikari from configurations.hikari
} }
task launch4jM(type: Copy) { task launch4jM(type: Copy) {
duplicatesStrategy = 'EXCLUDE'
into "$buildDir/libs/libraries/launch4j" into "$buildDir/libs/libraries/launch4j"
from(configurations.launch4jCJ.collect { it.isDirectory() ? it : zipTree(it) }) from(configurations.launch4jCJ.collect { it.isDirectory() ? it : zipTree(it) })
includeEmptyDirs false includeEmptyDirs false
@ -139,6 +141,7 @@ task launch4jM(type: Copy) {
} }
task launch4jA(type: Copy) { task launch4jA(type: Copy) {
duplicatesStrategy = 'EXCLUDE'
into "$buildDir/libs/libraries/launch4j" into "$buildDir/libs/libraries/launch4j"
from(configurations.launch4j) from(configurations.launch4j)
includeEmptyDirs false includeEmptyDirs false
@ -151,20 +154,23 @@ task launch4jA(type: Copy) {
} }
task dumpLibs(type: Copy) { task dumpLibs(type: Copy) {
duplicatesStrategy = 'EXCLUDE'
dependsOn tasks.hikari, tasks.launch4jM, tasks.launch4jA dependsOn tasks.hikari, tasks.launch4jM, tasks.launch4jA
into "$buildDir/libs/libraries" into "$buildDir/libs/libraries"
from configurations.bundleOnly from configurations.bundleOnly
} }
task dumpCompileOnlyLibs(type: Copy) { task dumpCompileOnlyLibs(type: Copy) {
duplicatesStrategy = 'EXCLUDE'
into "$buildDir/libs/launcher-libraries-compile" into "$buildDir/libs/launcher-libraries-compile"
from configurations.compileOnlyA from configurations.compileOnlyA
} }
task bundle(type: Zip) { task bundle(type: Zip) {
duplicatesStrategy = 'EXCLUDE'
dependsOn parent.childProjects.Launcher.tasks.build, tasks.dumpLibs, tasks.dumpCompileOnlyLibs, tasks.jar dependsOn parent.childProjects.Launcher.tasks.build, tasks.dumpLibs, tasks.dumpCompileOnlyLibs, tasks.jar
archiveName 'LaunchServer.zip' archiveFileName = 'LaunchServer.zip'
destinationDir file("$buildDir") destinationDirectory = file("$buildDir")
from(tasks.dumpLibs.destinationDir) { into 'libraries' } from(tasks.dumpLibs.destinationDir) { into 'libraries' }
from(tasks.dumpCompileOnlyLibs.destinationDir) { into 'launcher-libraries-compile' } from(tasks.dumpCompileOnlyLibs.destinationDir) { into 'launcher-libraries-compile' }
from tasks.jar.archivePath from tasks.jar.archivePath

View file

@ -18,7 +18,6 @@
import pro.gravit.launchserver.manangers.LaunchServerGsonManager; import pro.gravit.launchserver.manangers.LaunchServerGsonManager;
import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager; import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager;
import pro.gravit.launchserver.socket.WebSocketService; import pro.gravit.launchserver.socket.WebSocketService;
import pro.gravit.utils.Version;
import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.CommandHandler;
import pro.gravit.utils.command.JLineCommandHandler; import pro.gravit.utils.command.JLineCommandHandler;
import pro.gravit.utils.command.StdCommandHandler; import pro.gravit.utils.command.StdCommandHandler;

View file

@ -5,7 +5,6 @@
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
import org.objectweb.asm.tree.*; import org.objectweb.asm.tree.*;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.JVMHelper;
import pro.gravit.utils.helper.JarHelper; import pro.gravit.utils.helper.JarHelper;
import java.io.IOException; import java.io.IOException;

View file

@ -63,7 +63,7 @@ public void invoke(String... args) throws Exception {
public abstract void ban(List<HWID> hwid) throws HWIDException; public abstract void ban(List<HWID> hwid) throws HWIDException;
public void check(HWID hwid, String username) throws HWIDException { public void check(HWID hwid, String username) throws HWIDException {
if (hwid.isNull()) return; if (hwid == null || hwid.isNull()) return;
check0(hwid, username); check0(hwid, username);
} }

View file

@ -1,7 +1,6 @@
package pro.gravit.launchserver.binary; package pro.gravit.launchserver.binary;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.asm.NodeUtils;
import pro.gravit.utils.helper.*; import pro.gravit.utils.helper.*;
import java.io.IOException; import java.io.IOException;

View file

@ -2,7 +2,6 @@
import pro.gravit.launcher.NeedGarbageCollection; import pro.gravit.launcher.NeedGarbageCollection;
import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.Client;
import pro.gravit.launchserver.socket.response.auth.AuthResponse;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -41,6 +40,11 @@ public Client getOrNewClient(long session) {
return clientSet.computeIfAbsent(session, Client::new); return clientSet.computeIfAbsent(session, Client::new);
} }
public Client removeClient(long session)
{
return clientSet.remove(session);
}
public void updateClient(long session) { public void updateClient(long session) {
Client c = clientSet.get(session); Client c = clientSet.get(session);

View file

@ -66,6 +66,11 @@ public WebSocketService(ChannelGroup channels, LaunchServer server) {
public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) { public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) {
String request = frame.text(); String request = frame.text();
WebSocketServerResponse response = gson.fromJson(request, WebSocketServerResponse.class); 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); process(ctx, response, client, ip);
} }
@ -123,6 +128,7 @@ public static void registerResponses() {
providers.register("getAvailabilityAuth", GetAvailabilityAuthResponse.class); providers.register("getAvailabilityAuth", GetAvailabilityAuthResponse.class);
providers.register("register", RegisterResponse.class); providers.register("register", RegisterResponse.class);
providers.register("setPassword", SetPasswordResponse.class); providers.register("setPassword", SetPasswordResponse.class);
providers.register("exit", ExitResponse.class);
} }
public void sendObject(ChannelHandlerContext ctx, Object obj) { public void sendObject(ChannelHandlerContext ctx, Object obj) {

View file

@ -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));
}
}
}

View file

@ -1,6 +1,4 @@
plugins { apply plugin: 'org.openjfx.javafxplugin'
id 'org.openjfx.javafxplugin' version '0.0.5'
}
apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'com.github.johnrengelman.shadow'
String mainClassName = "pro.gravit.launcher.ClientLauncherWrapper" String mainClassName = "pro.gravit.launcher.ClientLauncherWrapper"
@ -8,7 +6,7 @@
repositories { repositories {
maven { maven {
url "http://repo.spring.io/plugins-release/" url "https://repo.spring.io/plugins-release/"
} }
} }
javafx { javafx {
@ -21,7 +19,7 @@
configurations { configurations {
bundle bundle
pack pack
compile.extendsFrom bundle, pack api.extendsFrom bundle, pack
} }
jar { jar {
@ -45,6 +43,7 @@ task javadocJar(type: Jar) {
} }
shadowJar { shadowJar {
duplicatesStrategy = 'EXCLUDE'
classifier = null classifier = null
relocate 'org.objectweb.asm', 'pro.gravit.repackage.org.objectweb.asm' relocate 'org.objectweb.asm', 'pro.gravit.repackage.org.objectweb.asm'
relocate 'io.netty', 'pro.gravit.repackage.io.netty' relocate 'io.netty', 'pro.gravit.repackage.io.netty'
@ -60,12 +59,14 @@ pack project(':LauncherAPI')
} }
task genRuntimeJS(type: Zip) { task genRuntimeJS(type: Zip) {
archiveName = "runtime.zip" duplicatesStrategy = 'EXCLUDE'
destinationDir = file("${buildDir}/tmp") archiveFileName = "runtime.zip"
destinationDirectory = file("${buildDir}/tmp")
from "runtime/" from "runtime/"
} }
task dumpLibs(type: Copy) { task dumpLibs(type: Copy) {
duplicatesStrategy = 'EXCLUDE'
into "$buildDir/libs/libraries" into "$buildDir/libs/libraries"
from configurations.bundle from configurations.bundle
} }

View file

@ -1,6 +1,5 @@
package pro.gravit.launcher; package pro.gravit.launcher;
import pro.gravit.launcher.api.SystemService;
import pro.gravit.launcher.client.*; import pro.gravit.launcher.client.*;
import pro.gravit.launcher.client.events.ClientEngineInitPhase; import pro.gravit.launcher.client.events.ClientEngineInitPhase;
import pro.gravit.launcher.client.events.ClientExitPhase; import pro.gravit.launcher.client.events.ClientExitPhase;
@ -61,11 +60,10 @@ public static void exitLauncher(int code)
modulesManager.invokeEvent(new ClientExitPhase(code)); modulesManager.invokeEvent(new ClientExitPhase(code));
try { try {
System.exit(code); System.exit(code);
} catch (Exception e) //Forge Security Manager? } catch (Throwable e) //Forge Security Manager?
{ {
NativeJVMHalt.haltA(code); NativeJVMHalt.haltA(code);
} }
} }
public static void main(String... args) throws Throwable { 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); LogHelper.debug("Launcher started in %dms", endTime - startTime);
//Request.service.close(); //Request.service.close();
//FunctionalBridge.close(); //FunctionalBridge.close();
SystemService.exit(0); LauncherEngine.exitLauncher(0);
} }
public static void initGson(ClientModuleManager modulesManager) { public static void initGson(ClientModuleManager modulesManager) {

View file

@ -3,6 +3,7 @@
import pro.gravit.launcher.*; import pro.gravit.launcher.*;
import pro.gravit.launcher.api.AuthService; import pro.gravit.launcher.api.AuthService;
import pro.gravit.launcher.api.ClientService; 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.ClientLaunchPhase;
import pro.gravit.launcher.client.events.ClientLauncherInitPhase; import pro.gravit.launcher.client.events.ClientLauncherInitPhase;
import pro.gravit.launcher.client.events.ClientLauncherPostInitPhase; import pro.gravit.launcher.client.events.ClientLauncherPostInitPhase;
@ -13,6 +14,7 @@
import pro.gravit.launcher.managers.ClientGsonManager; import pro.gravit.launcher.managers.ClientGsonManager;
import pro.gravit.launcher.managers.ClientHookManager; import pro.gravit.launcher.managers.ClientHookManager;
import pro.gravit.launcher.modules.events.PreConfigPhase; import pro.gravit.launcher.modules.events.PreConfigPhase;
import pro.gravit.launcher.patches.FMLPatcher;
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.PlayerProfile; import pro.gravit.launcher.profiles.PlayerProfile;
import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.Request;
@ -32,10 +34,7 @@
import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType; import java.lang.invoke.MethodType;
import java.net.InetSocketAddress; import java.net.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URL;
import java.nio.file.FileVisitResult; import java.nio.file.FileVisitResult;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor; 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()); LogHelper.info("ClassLoader URL: %s", u.toString());
} }
FMLPatcher.apply();
MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)).asFixedArity(); MethodHandle mainMethod = MethodHandles.publicLookup().findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)).asFixedArity();
Launcher.LAUNCHED.set(true); Launcher.LAUNCHED.set(true);
JVMHelper.fullGC(); JVMHelper.fullGC();
// Invoke main method // Invoke main method
try { try {
mainMethod.invokeWithArguments((Object) args.toArray(new String[0])); mainMethod.invokeWithArguments((Object) args.toArray(new String[0]));
LogHelper.debug("Main exit successful");
} catch (Throwable e) {
LogHelper.error(e);
throw e;
} finally { } finally {
Request.service.close(); LauncherEngine.exitLauncher(0);
} }
} }

View file

@ -10,6 +10,7 @@
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType; import java.lang.invoke.MethodType;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Locale;
import java.util.Random; import java.util.Random;
import java.util.Vector; 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) { 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 StringBuilder sb = new StringBuilder(lenght);
final Random random = SecurityHelper.newRandom(); final Random random = SecurityHelper.newRandom();
for (int i = 0; i < lenght; i++) for (int i = 0; i < lenght; i++)

View file

@ -2,6 +2,7 @@
import pro.gravit.launcher.patches.FMLPatcher; import pro.gravit.launcher.patches.FMLPatcher;
import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.JVMHelper;
import pro.gravit.utils.helper.LogHelper;
import javax.swing.*; import javax.swing.*;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
@ -22,23 +23,30 @@ private boolean aaabBooleanC_D() {
} }
public static void haltA(int code) { public static void haltA(int code) {
Throwable[] th = new Throwable[3];
NativeJVMHalt halt = new NativeJVMHalt(code); NativeJVMHalt halt = new NativeJVMHalt(code);
try { try {
JVMHelper.RUNTIME.exit(code); JVMHelper.RUNTIME.exit(code);
} catch (Throwable ignored) { } catch (Throwable exitExc) {
th[0] = exitExc;
try { try {
new WindowShutdown(); new WindowShutdown();
} catch (Throwable ignored1) { } catch (Throwable windowExc) {
th[1] = windowExc;
} }
} }
try { try {
FMLPatcher.exit(code); 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(); boolean a = halt.aaabBooleanC_D();
System.out.println(a); System.out.println(a);
halt.aaabbb38C_D();
} }

View file

@ -2,9 +2,9 @@
targetCompatibility = '1.8' targetCompatibility = '1.8'
dependencies { dependencies {
compile project(':LauncherCore') api project(':LauncherCore')
compileOnly 'io.netty:netty-codec-http:4.1.43.Final' 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 { test {

View file

@ -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";
}
}

View file

@ -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<ExitRequestEvent> {
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";
}
}

View file

@ -107,6 +107,7 @@ public void registerResults() {
results.register("setpassword", SetPasswordRequestEvent.class); results.register("setpassword", SetPasswordRequestEvent.class);
results.register("notification", NotificationEvent.class); results.register("notification", NotificationEvent.class);
results.register("signal", SignalEvent.class); results.register("signal", SignalEvent.class);
results.register("exit", ExitRequestEvent.class);
} }
public void waitIfNotConnected() { public void waitIfNotConnected() {

View file

@ -2,7 +2,7 @@
targetCompatibility = '1.8' targetCompatibility = '1.8'
dependencies { dependencies {
compile project(':LauncherAPI') api project(':LauncherAPI')
compileOnly 'com.google.guava:guava:26.0-jre' compileOnly 'com.google.guava:guava:26.0-jre'
compile files('../compat/authlib/authlib-clean.jar') api files('../compat/authlib/authlib-clean.jar')
} }

View file

@ -1,4 +1,3 @@
apply plugin: 'java-library'
sourceCompatibility = '1.8' sourceCompatibility = '1.8'
targetCompatibility = '1.8' targetCompatibility = '1.8'
@ -8,8 +7,8 @@
compileOnly 'org.jline:jline-reader:3.11.0' compileOnly 'org.jline:jline-reader:3.11.0'
compileOnly 'org.jline:jline-terminal:3.11.0' compileOnly 'org.jline:jline-terminal:3.11.0'
compileOnly 'org.bouncycastle:bcprov-jdk15:1.46' compileOnly 'org.bouncycastle:bcprov-jdk15:1.46'
compile 'com.google.code.gson:gson:2.8.5' api 'com.google.code.gson:gson:2.8.5'
testCompile 'org.junit.jupiter:junit-jupiter:5.4.1' testImplementation 'org.junit.jupiter:junit-jupiter:5.4.1'
} }
test { test {

View file

@ -15,24 +15,41 @@ public class UniversalJsonAdapter<R> implements JsonSerializer<R>, JsonDeseriali
public final ProviderMap<R> providerMap; public final ProviderMap<R> providerMap;
public final String name; public final String name;
public final String PROP_NAME; public final String PROP_NAME;
public final boolean printErrorIfUnknownType;
public UniversalJsonAdapter(ProviderMap<R> providerMap) { public UniversalJsonAdapter(ProviderMap<R> providerMap) {
this.providerMap = providerMap; this.providerMap = providerMap;
this.name = providerMap.getName(); this.name = providerMap.getName();
this.PROP_NAME = "type"; this.PROP_NAME = "type";
printErrorIfUnknownType = true;
} }
public UniversalJsonAdapter(ProviderMap<R> providerMap, String PROP_NAME) { public UniversalJsonAdapter(ProviderMap<R> providerMap, String PROP_NAME) {
this.providerMap = providerMap; this.providerMap = providerMap;
this.name = providerMap.getName(); this.name = providerMap.getName();
this.PROP_NAME = PROP_NAME; this.PROP_NAME = PROP_NAME;
printErrorIfUnknownType = true;
}
public UniversalJsonAdapter(ProviderMap<R> 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<R> 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 { public R deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
Class<? extends R> cls = providerMap.getClass(typename); Class<? extends R> cls = providerMap.getClass(typename);
if (cls == null) { if (cls == null) {
LogHelper.error("%s %s not found", name, typename); if(printErrorIfUnknownType) LogHelper.error("%s %s not found", name, typename);
return null; return null;
} }
return context.deserialize(json, cls); return context.deserialize(json, cls);
@ -48,9 +65,9 @@ public JsonElement serialize(R src, Type typeOfSrc, JsonSerializationContext con
} }
if(classPath == null) 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; return jo;
} }

View file

@ -15,8 +15,8 @@ public final class Version {
public final Type release; public final Type release;
public static final int MAJOR = 5; public static final int MAJOR = 5;
public static final int MINOR = 1; public static final int MINOR = 1;
public static final int PATCH = 0; public static final int PATCH = 1;
public static final int BUILD = 1; public static final int BUILD = 2;
public static final Version.Type RELEASE = Type.BETA; public static final Version.Type RELEASE = Type.BETA;

View file

@ -1,5 +1,6 @@
package pro.gravit.utils.helper; package pro.gravit.utils.helper;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Path; import java.nio.file.Path;
@ -100,6 +101,21 @@ public static InputStream getClassBytesStream(Class<?> clazz, ClassLoader classL
{ {
return classLoader.getResourceAsStream(getClassFile(clazz)); 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);
}
} }

View file

@ -5,12 +5,12 @@
configurations { configurations {
pack pack
compile.extendsFrom pack api.extendsFrom pack
} }
repositories { repositories {
maven { maven {
url "http://repo.spring.io/plugins-release/" url "https://repo.spring.io/plugins-release/"
} }
} }
@ -42,6 +42,7 @@ pack project(':LauncherAuthlib')
} }
shadowJar { shadowJar {
duplicatesStrategy = 'EXCLUDE'
classifier = null classifier = null
relocate 'io.netty', 'pro.gravit.repackage.io.netty' relocate 'io.netty', 'pro.gravit.repackage.io.netty'
configurations = [project.configurations.pack] configurations = [project.configurations.pack]

View file

@ -1,39 +1,43 @@
plugins { 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 'maven-publish'
id 'signing' id 'signing'
id 'org.openjfx.javafxplugin' version '0.0.7' apply false
} }
group = 'pro.gravit.launcher' group = 'pro.gravit.launcher'
version = '5.1.0' version = '5.1.1'
configure(subprojects.findAll { it.name != 'modules' }) { configure(subprojects.findAll { it.name != 'modules' }) {
apply plugin: 'idea' apply plugin: 'idea'
apply plugin: 'eclipse' apply plugin: 'eclipse'
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'java-library'
group = 'pro.gravit' group = 'pro.gravit'
repositories { repositories {
mavenCentral() mavenCentral()
maven { url 'http://oss.sonatype.org/content/groups/public' } maven { url 'https://oss.sonatype.org/content/groups/public' }
maven { maven {
url "http://clojars.org/repo/" url "https://clojars.org/repo/"
} }
} }
configurations { jar {
apt duplicatesStrategy = 'EXCLUDE'
aptCompileOnly }
aptOnly
aptOnly.extendsFrom apt, aptCompileOnly eclipse {
compile.extendsFrom apt classpath {
compileOnly.extendsFrom aptCompileOnly downloadSources = true
downloadJavadoc = true
}
} }
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
options.encoding = "UTF-8" options.encoding = "UTF-8"
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
options.annotationProcessorPath = configurations.aptOnly
options.incremental = true // one flag, and things will get MUCH faster options.incremental = true // one flag, and things will get MUCH faster
} }
} }

View file

@ -0,0 +1,36 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
class LauncherAuthController extends Controller
{
public function json(Request $request) {
$data = json_decode($request->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' => 'Неверный логин или пароль',
]);
}
}
}

View file

@ -0,0 +1,9 @@
#Контроллер авторизации методом json
Route:
```php
Route::put('launcher/auth', 'LauncherAuthController@json');
```
Добавить в **.env** строку `LAUNCHER_APIKEY=none`
Где `none` ваш apiKey

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddPermissionCollum extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->integer('launcher_permission')->default('0');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('launcher_permission');
});
}
}

View file

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateHwidTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users_hwids', function (Blueprint $table) {
$table->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');
}
}

View file

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddAuthHandlerCollums extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->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');
});
}
}

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddHwidHandlerCollums extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->bigInteger('hwid')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('hwid');
});
}
}

View file

@ -0,0 +1 @@
# Миграции для Laravel

Binary file not shown.

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

35
gradlew vendored
View file

@ -7,7 +7,7 @@
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # 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 # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # 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\"" GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi fi
# For Cygwin, switch paths to Windows format before running java # For Cygwin or MSYS, switch paths to Windows format before running java
if $cygwin ; then if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"` APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"` JAVACMD=`cygpath --unix "$JAVACMD"`
@ -154,19 +154,19 @@ if $cygwin ; then
else else
eval `echo args$i`="\"$arg\"" eval `echo args$i`="\"$arg\""
fi fi
i=$((i+1)) i=`expr $i + 1`
done done
case $i in case $i in
(0) set -- ;; 0) set -- ;;
(1) set -- "$args0" ;; 1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;; 2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;; 3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;; 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac esac
fi fi
@ -175,14 +175,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " " echo " "
} }
APP_ARGS=$(save "$@") APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules # 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" 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" "$@" exec "$JAVACMD" "$@"

2
gradlew.bat vendored
View file

@ -5,7 +5,7 @@
@rem you may not use this file except in compliance with the License. @rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at @rem You may obtain a copy of the License at
@rem @rem
@rem http://www.apache.org/licenses/LICENSE-2.0 @rem https://www.apache.org/licenses/LICENSE-2.0
@rem @rem
@rem Unless required by applicable law or agreed to in writing, software @rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS, @rem distributed under the License is distributed on an "AS IS" BASIS,

@ -1 +1 @@
Subproject commit 0fbc3fb26c505800a61976cdf1310cad6ab7808d Subproject commit 2edb2c7259d5a7dba3fa82c503f88a8a0e171840