From fe374c1f9ec47319101a7e9c174e99a2c921b098 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Tue, 21 Nov 2023 13:17:48 +0700 Subject: [PATCH 01/16] [ANY] Update modules --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index a70de386..8b3543b3 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit a70de3865daff53f44fb93cb6c80df99e3cdc0a1 +Subproject commit 8b3543b37a749843c333b70aadc1c1d493e4e606 From 54bfc6de9cd08b0580523747836283123410b327 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Tue, 21 Nov 2023 13:40:21 +0700 Subject: [PATCH 02/16] [FIX] No refresh in client --- .../launcher/debug/ClientRuntimeProvider.java | 2 +- .../pro/gravit/launcher/request/Request.java | 20 ++++++++++++------- .../client/ClientLauncherEntryPoint.java | 2 +- .../main/java/pro/gravit/utils/Version.java | 4 ++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/debug/ClientRuntimeProvider.java b/Launcher/src/main/java/pro/gravit/launcher/debug/ClientRuntimeProvider.java index 82bd51e2..f9a1a682 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/debug/ClientRuntimeProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/debug/ClientRuntimeProvider.java @@ -57,7 +57,7 @@ public void run(String[] args) { if(uuid == null) { if(accessToken != null) { Request.setOAuth(authId, new AuthRequestEvent.OAuthRequestEvent(accessToken, refreshToken, expire)); - Request.RequestRestoreReport report = Request.restore(true, false); + Request.RequestRestoreReport report = Request.restore(true, false, true); permissions = report.userInfo.permissions; username = report.userInfo.playerProfile.username; uuid = report.userInfo.playerProfile.uuid.toString(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java index 9500de2f..f2b8a418 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java @@ -159,7 +159,7 @@ public static void reconnect() throws Exception { } public static RequestRestoreReport restore() throws Exception { - return restore(false, false); + return restore(false, false, false); } private synchronized static Map getExpiredExtendedTokens() { @@ -178,16 +178,22 @@ private synchronized static Map getExpiredExtendedTokens() { return makeNewTokens(set); } - public static synchronized RequestRestoreReport restore(boolean needUserInfo, boolean refreshOnly) throws Exception { + public static synchronized RequestRestoreReport restore(boolean needUserInfo, boolean refreshOnly, boolean noRefresh) throws Exception { boolean refreshed = false; RestoreRequest request; if (oauth != null) { - if (isTokenExpired() || oauth.accessToken == null) { - RefreshTokenRequest refreshRequest = new RefreshTokenRequest(authId, oauth.refreshToken); - RefreshTokenRequestEvent event = refreshRequest.request(); - setOAuth(authId, event.oauth); - refreshed = true; + if(isTokenExpired() || oauth.accessToken == null) { + if(noRefresh) { + oauth = null; + } else { + RefreshTokenRequest refreshRequest = new RefreshTokenRequest(authId, oauth.refreshToken); + RefreshTokenRequestEvent event = refreshRequest.request(); + setOAuth(authId, event.oauth); + refreshed = true; + } } + } + if (oauth != null) { request = new RestoreRequest(authId, oauth.accessToken, refreshOnly ? getExpiredExtendedTokens() : getStringExtendedTokens(), needUserInfo); } else { request = new RestoreRequest(authId, null, refreshOnly ? getExpiredExtendedTokens() : getStringExtendedTokens(), false); diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java index 70c7c739..64f292fe 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -124,7 +124,7 @@ private static void realMain(String[] args) throws Throwable { service = StdWebSocketService.initWebSockets(Launcher.getConfig().address).get(); Request.setRequestService(service); LogHelper.debug("Restore sessions"); - Request.restore(); + Request.restore(false, false, true); service.registerEventHandler(new BasicLauncherEventHandler()); ((StdWebSocketService) service).reconnectCallback = () -> { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index 69a95013..272fc6be 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -6,9 +6,9 @@ public final class Version implements Comparable { public static final int MAJOR = 5; public static final int MINOR = 5; - public static final int PATCH = 2; + public static final int PATCH = 3; public static final int BUILD = 1; - public static final Version.Type RELEASE = Type.STABLE; + public static final Version.Type RELEASE = Type.DEV; public final int major; public final int minor; public final int patch; From 1bc9351b0c82569d999f56b2db6a5f41ac89c2ff Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Tue, 21 Nov 2023 13:58:10 +0700 Subject: [PATCH 03/16] [FIX] Compile fix --- .../src/main/java/pro/gravit/launcher/request/Request.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java index f2b8a418..47de5f3a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java @@ -46,7 +46,7 @@ public static synchronized void startAutoRefresh() { } executorService.scheduleAtFixedRate(() -> { try { - restore(false, true); + restore(false, true, false); } catch (Exception e) { LogHelper.error(e); } From d678daac7b77c7aa808f6f7e0aca691178e3788c Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sat, 25 Nov 2023 00:28:00 +0700 Subject: [PATCH 04/16] [FIX] Systemd notify logger --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 8b3543b3..dfb51367 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 8b3543b37a749843c333b70aadc1c1d493e4e606 +Subproject commit dfb513672dedc40b01d37c8065efc9d06cf73656 From 2e60d45c63433f7e55d3180d8f5ae403ca7a389a Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sun, 26 Nov 2023 15:07:50 +0700 Subject: [PATCH 05/16] [FEATURE][EXPERIMENTAL] Support add javafx in LauncherEngineWrapper --- .../pro/gravit/launcher/LauncherEngine.java | 5 ++- .../launcher/LauncherEngineWrapper.java | 36 ++++++++++++++++++- .../gravit/utils/launch/LaunchOptions.java | 1 + .../pro/gravit/utils/launch/ModuleLaunch.java | 30 +++++++++++++--- .../launcher/ClientLauncherWrapper.java | 25 ------------- 5 files changed, 65 insertions(+), 32 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index 04c94de4..6acaa780 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -105,7 +105,10 @@ public static boolean contains(String[] array, String value) { public static void main(String... args) throws Throwable { JVMHelper.checkStackTrace(LauncherEngineWrapper.class); - JVMHelper.verifySystemProperties(Launcher.class, true); + JVMHelper.verifySystemProperties(Launcher.class, false); + { + LauncherEngine.checkClass(LauncherEngine.class.getClassLoader().getClass()); + } EnvHelper.checkDangerousParams(); //if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set"); verifyNoAgent(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngineWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngineWrapper.java index 25906d97..a637a571 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngineWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngineWrapper.java @@ -1,8 +1,42 @@ package pro.gravit.launcher; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.launch.LaunchOptions; +import pro.gravit.utils.launch.ModuleLaunch; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + @LauncherNetworkAPI public class LauncherEngineWrapper { + private static final List modules = new ArrayList<>(); + + static { + modules.add("javafx.base"); + modules.add("javafx.graphics"); + modules.add("javafx.fxml"); + modules.add("javafx.controls"); + modules.add("javafx.media"); + modules.add("javafx.web"); + } public static void main(String[] args) throws Throwable { - LauncherEngine.main(args); + ModuleLaunch launch = new ModuleLaunch(); + LaunchOptions options = new LaunchOptions(); + options.disablePackageDelegateSupport = true; + options.moduleConf = new LaunchOptions.ModuleConf(); + List classpath = new ArrayList<>(); + classpath.add(IOHelper.getCodeSource(LauncherEngine.class)); + var libDirectory = Path.of(System.getProperty("java.home")).resolve("lib"); + for(var moduleName : modules) { + var path = libDirectory.resolve(moduleName.concat(".jar")); + if(Files.exists(path)) { + options.moduleConf.modules.add(moduleName); + options.moduleConf.modulePath.add(path.toAbsolutePath().toString()); + } + } + var control = launch.init(classpath, null, options); + launch.launch(LauncherEngine.class.getName(), null, List.of(args)); } } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/launch/LaunchOptions.java b/LauncherCore/src/main/java/pro/gravit/utils/launch/LaunchOptions.java index f5232739..fa95d0d8 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/launch/LaunchOptions.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/launch/LaunchOptions.java @@ -7,6 +7,7 @@ public class LaunchOptions { public boolean enableHacks; + public boolean disablePackageDelegateSupport; public ModuleConf moduleConf; diff --git a/LauncherCore/src/main/java11/pro/gravit/utils/launch/ModuleLaunch.java b/LauncherCore/src/main/java11/pro/gravit/utils/launch/ModuleLaunch.java index dea2b3f4..58c69a5c 100644 --- a/LauncherCore/src/main/java11/pro/gravit/utils/launch/ModuleLaunch.java +++ b/LauncherCore/src/main/java11/pro/gravit/utils/launch/ModuleLaunch.java @@ -18,10 +18,7 @@ import java.net.URLClassLoader; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; public class ModuleLaunch implements Launch { @@ -31,8 +28,10 @@ public class ModuleLaunch implements Launch { private ModuleFinder moduleFinder; private ModuleLayer layer; private MethodHandles.Lookup hackLookup; + private boolean disablePackageDelegateSupport; @Override public ClassLoaderControl init(List files, String nativePath, LaunchOptions options) { + this.disablePackageDelegateSupport = options.disablePackageDelegateSupport; moduleClassLoader = new ModuleClassLoader(files.stream().map((e) -> { try { return e.toUri().toURL(); @@ -122,6 +121,7 @@ public ClassLoaderControl init(List files, String nativePath, LaunchOption } } } + moduleClassLoader.initializeWithLayer(layer); } return moduleClassLoader.makeControl(); } @@ -160,6 +160,7 @@ private class ModuleClassLoader extends URLClassLoader { private final ClassLoader SYSTEM_CLASS_LOADER = ClassLoader.getSystemClassLoader(); private final List transformers = new ArrayList<>(); private final Map> classMap = new ConcurrentHashMap<>(); + private final Map packageToModule = new HashMap<>(); private String nativePath; private final List packages = new ArrayList<>(); @@ -169,9 +170,17 @@ public ModuleClassLoader(URL[] urls, ClassLoader parent) { packages.add("pro.gravit.utils."); } + private void initializeWithLayer(ModuleLayer layer) { + for(var m : layer.modules()) { + for(var p : m.getPackages()) { + packageToModule.put(p, m); + } + } + } + @Override protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - if(name != null) { + if(name != null && !disablePackageDelegateSupport) { for(String pkg : packages) { if(name.startsWith(pkg)) { return SYSTEM_CLASS_LOADER.loadClass(name); @@ -220,6 +229,17 @@ protected Class findClass(String moduleName, String name) { } } } + if(clazz == null && layer != null && name != null) { + var pkg = getPackageFromClass(name); + var module = packageToModule.get(pkg); + if(module != null) { + try { + clazz = module.getClassLoader().loadClass(name); + } catch (ClassNotFoundException e) { + return null; + } + } + } if(clazz == null) { try { clazz = super.findClass(name); diff --git a/LauncherStart/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/LauncherStart/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index 185bbb5f..30e4301b 100644 --- a/LauncherStart/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/LauncherStart/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -129,31 +129,6 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep args.add(context.executePath.toAbsolutePath().toString()); args.addAll(context.args); context.jvmProperties.forEach((key, value) -> args.add(String.format("-D%s=%s", key, value))); - if (context.javaVersion.version >= 9) { - context.javaFXPaths.add(context.javaVersion.jvmDir); - context.javaFXPaths.add(context.javaVersion.jvmDir.resolve("jre")); - Path openjfxPath = JavaHelper.tryGetOpenJFXPath(context.javaVersion.jvmDir); - if (openjfxPath != null) { - context.javaFXPaths.add(openjfxPath); - } - StringBuilder modulesPath = new StringBuilder(); - StringBuilder modulesAdd = new StringBuilder(); - for (String moduleName : context.jvmModules) { - boolean success = JavaHelper.tryAddModule(context.javaFXPaths, moduleName, modulesPath); - if (success) { - if (modulesAdd.length() > 0) modulesAdd.append(","); - modulesAdd.append(moduleName); - } - } - if (modulesAdd.length() > 0) { - args.add("--add-modules"); - args.add(modulesAdd.toString()); - } - if (modulesPath.length() > 0) { - args.add("--module-path"); - args.add(modulesPath.toString()); - } - } if (context.memoryLimit != 0) { args.add(String.format("-Xmx%dM", context.memoryLimit)); } From 380179faa33d756da6a1eb0fe7c043d131fe7076 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sun, 26 Nov 2023 15:08:05 +0700 Subject: [PATCH 06/16] [FIX] SystemdNotifyModule --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index dfb51367..54f04dd7 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit dfb513672dedc40b01d37c8065efc9d06cf73656 +Subproject commit 54f04dd7794ebb7c8397b21397c30cec62a0815e From 43626bf1f4d9b8ebfd378d0f46e48057bb77abc7 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sun, 26 Nov 2023 20:51:58 +0700 Subject: [PATCH 07/16] [FEATURE] Support createHackLookupNative --- .../src/main/java/pro/gravit/utils/helper/HackHelper.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/HackHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/HackHelper.java index 87d95ddc..8be8d890 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/HackHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/HackHelper.java @@ -7,8 +7,13 @@ import java.util.function.Consumer; public class HackHelper { - + private static native MethodHandles.Lookup createHackLookupNative(Class lookupClass); private static MethodHandles.Lookup createHackLookupImpl(Class lookupClass) { + try { + return createHackLookupNative(lookupClass); + } catch (Throwable ignored) { + + } try { Field trusted = MethodHandles.Lookup.class.getDeclaredField("TRUSTED"); trusted.setAccessible(true); From d2f34ced287b825bbaef03bc0d0baaf175476b58 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Mon, 27 Nov 2023 22:41:49 +0700 Subject: [PATCH 08/16] [FEATURE][EXPERIMENTAL] Add ClientServer and AuthService to ServerWrapper, extended check server, remove deprecated interfaces --- .../auth/core/AbstractSQLCoreProvider.java | 22 ++++++---- .../auth/core/AuthCoreProvider.java | 23 ----------- .../auth/core/MySQLCoreProvider.java | 41 ++++++++++++++----- .../provider/AuthSupportAssetUpload.java | 2 +- .../AuthSupportExtendedCheckServer.java | 11 +++++ .../provider/AuthSupportHardware.java | 5 --- .../AuthSupportRemoteClientAccess.java | 9 ---- .../session/UserSessionSupportHardware.java | 8 ++++ .../session/UserSessionSupportProperties.java | 7 ++++ .../interfaces/user/UserSupportHardware.java | 7 ---- .../launchserver/manangers/AuthManager.java | 27 +++++++++--- .../response/auth/CheckServerResponse.java | 15 ++++++- .../auth/GetAvailabilityAuthResponse.java | 1 - .../pro/gravit/launcher/api/AuthService.java | 9 ++++ .../gravit/launcher/api/ClientService.java | 1 - .../pro/gravit/launcher/api/KeyService.java | 2 + .../request/CheckServerRequestEvent.java | 7 ++++ .../request/auth/CheckServerRequest.java | 14 +++++++ .../client/ClientLauncherEntryPoint.java | 1 + .../gravit/launcher/server/ServerWrapper.java | 17 +++++--- build.gradle | 2 +- 21 files changed, 151 insertions(+), 80 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportRemoteClientAccess.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportHardware.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportProperties.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportHardware.java rename {LauncherClient => LauncherAPI}/src/main/java/pro/gravit/launcher/api/AuthService.java (69%) rename {LauncherClient => LauncherAPI}/src/main/java/pro/gravit/launcher/api/ClientService.java (92%) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java index 4028feeb..7306b88b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java @@ -108,7 +108,7 @@ public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws O if (user == null) { return null; } - return new SQLUserSession(user); + return createSession(user); } catch (ExpiredJwtException e) { throw new OAuthAccessTokenExpired(); } catch (JwtException e) { @@ -133,13 +133,13 @@ public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthRespon return null; } var accessToken = LegacySessionHelper.makeAccessJwtTokenFromString(user, LocalDateTime.now(Clock.systemUTC()).plusSeconds(expireSeconds), server.keyAgreementManager.ecdsaPrivateKey); - return new AuthManager.AuthReport(null, accessToken, refreshToken, SECONDS.toMillis(expireSeconds), new SQLUserSession(user)); + return new AuthManager.AuthReport(null, accessToken, refreshToken, SECONDS.toMillis(expireSeconds), createSession(user)); } @Override public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext context, AuthRequest.AuthPasswordInterface password, boolean minecraftAccess) throws IOException { - SQLUser SQLUser = (SQLUser) getUserByLogin(login); - if (SQLUser == null) { + SQLUser user = (SQLUser) getUserByLogin(login); + if (user == null) { throw AuthException.userNotFound(); } if (context != null) { @@ -147,16 +147,16 @@ public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext c if (plainPassword == null) { throw AuthException.wrongPassword(); } - if (!passwordVerifier.check(SQLUser.password, plainPassword.password)) { + if (!passwordVerifier.check(user.password, plainPassword.password)) { throw AuthException.wrongPassword(); } } - SQLUserSession session = new SQLUserSession(SQLUser); - var accessToken = LegacySessionHelper.makeAccessJwtTokenFromString(SQLUser, LocalDateTime.now(Clock.systemUTC()).plusSeconds(expireSeconds), server.keyAgreementManager.ecdsaPrivateKey); - var refreshToken = SQLUser.username.concat(".").concat(LegacySessionHelper.makeRefreshTokenFromPassword(SQLUser.username, SQLUser.password, server.keyAgreementManager.legacySalt)); + SQLUserSession session = createSession(user); + var accessToken = LegacySessionHelper.makeAccessJwtTokenFromString(user, LocalDateTime.now(Clock.systemUTC()).plusSeconds(expireSeconds), server.keyAgreementManager.ecdsaPrivateKey); + var refreshToken = user.username.concat(".").concat(LegacySessionHelper.makeRefreshTokenFromPassword(user.username, user.password, server.keyAgreementManager.legacySalt)); if (minecraftAccess) { String minecraftAccessToken = SecurityHelper.randomStringToken(); - updateAuth(SQLUser, minecraftAccessToken); + updateAuth(user, minecraftAccessToken); return AuthManager.AuthReport.ofOAuthWithMinecraft(minecraftAccessToken, accessToken, refreshToken, SECONDS.toMillis(expireSeconds), session); } else { return AuthManager.AuthReport.ofOAuth(accessToken, refreshToken, SECONDS.toMillis(expireSeconds), session); @@ -299,6 +299,10 @@ private List queryPermissions(String sql, String value) throws SQLExcept } } + protected SQLUserSession createSession(SQLUser user) { + return new SQLUserSession(user); + } + public boolean isEnabledPermissions() { return permissionsPermissionColumn != null; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java index 99805cc2..f1d8cf7d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java @@ -16,7 +16,6 @@ import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportGetAllUsers; import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportHardware; import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportRegistration; -import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportHardware; import pro.gravit.launchserver.manangers.AuthManager; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.auth.AuthResponse; @@ -176,28 +175,6 @@ public void invoke(String... args) throws Exception { } } }); - map.put("getuserhardware", new SubCommand("[username]", "get hardware by username") { - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 1); - User user = getUserByUUID(UUID.fromString(args[0])); - if (user == null) { - logger.info("User {} not found", args[0]); - } - UserSupportHardware hardware = instance.fetchUserHardware(user); - if (hardware == null) { - logger.error("Method fetchUserHardware return null"); - return; - } - UserHardware userHardware = hardware.getHardware(); - if (userHardware == null) { - logger.info("User {} not contains hardware info", args[0]); - } else { - logger.info("UserHardware: {}", userHardware); - logger.info("HardwareInfo(JSON): {}", Launcher.gsonManager.gson.toJson(userHardware.getHardwareInfo())); - } - } - }); map.put("findmulti", new SubCommand("[hardware id]", "get all users in one hardware id") { @Override public void invoke(String... args) throws Exception { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java index 28a95a42..ce093a2e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java @@ -7,7 +7,7 @@ import pro.gravit.launchserver.auth.SQLSourceConfig; import pro.gravit.launchserver.auth.core.interfaces.UserHardware; import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportHardware; -import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportHardware; +import pro.gravit.launchserver.auth.core.interfaces.session.UserSessionSupportHardware; import pro.gravit.utils.helper.IOHelper; import java.io.ByteArrayInputStream; @@ -260,6 +260,34 @@ public void unbanHardware(UserHardware hardware) { } } + @Override + protected SQLUserSession createSession(SQLUser user) { + return new MySQLUserSession(user); + } + + public class MySQLUserSession extends SQLUserSession implements UserSessionSupportHardware { + private transient MySQLUser mySQLUser; + protected transient MySQLUserHardware hardware; + + public MySQLUserSession(SQLUser user) { + super(user); + mySQLUser = (MySQLUser) user; + } + + @Override + public String getHardwareId() { + return mySQLUser.hwidId == 0 ? null : String.valueOf(mySQLUser.hwidId); + } + + @Override + public UserHardware getHardware() { + if(hardware == null) { + hardware = (MySQLUserHardware) getHardwareInfoById(String.valueOf(mySQLUser.hwidId)); + } + return hardware; + } + } + public static class MySQLUserHardware implements UserHardware { private final HardwareReportRequest.HardwareInfo hardwareInfo; private final long id; @@ -304,23 +332,14 @@ public String toString() { } } - public class MySQLUser extends SQLUser implements UserSupportHardware { + public class MySQLUser extends SQLUser { protected long hwidId; - protected transient MySQLUserHardware hardware; public MySQLUser(UUID uuid, String username, String accessToken, String serverId, String password, ClientPermissions permissions, long hwidId) { super(uuid, username, accessToken, serverId, password, permissions); this.hwidId = hwidId; } - @Override - public UserHardware getHardware() { - if (hardware != null) return hardware; - MySQLUserHardware result = (MySQLUserHardware) getHardwareInfoById(String.valueOf(hwidId)); - hardware = result; - return result; - } - @Override public String toString() { return "MySQLUser{" + diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java index f738804f..f1978698 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java @@ -9,7 +9,7 @@ import java.util.Set; @Feature(GetAssetUploadUrlRequestEvent.FEATURE_NAME) -public interface AuthSupportAssetUpload { +public interface AuthSupportAssetUpload extends AuthSupport { String getAssetUploadUrl(String name, User user); default AuthRequestEvent.OAuthRequestEvent getAssetUploadToken(String name, User user) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java new file mode 100644 index 00000000..fb188782 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java @@ -0,0 +1,11 @@ +package pro.gravit.launchserver.auth.core.interfaces.provider; + +import pro.gravit.launchserver.auth.core.User; +import pro.gravit.launchserver.auth.core.UserSession; +import pro.gravit.launchserver.socket.Client; + +import java.io.IOException; + +public interface AuthSupportExtendedCheckServer { + UserSession extendedCheckServer(Client client, String username, String serverID) throws IOException; +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportHardware.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportHardware.java index b3f1f761..943e4993 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportHardware.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportHardware.java @@ -4,7 +4,6 @@ import pro.gravit.launchserver.auth.core.User; import pro.gravit.launchserver.auth.core.UserSession; import pro.gravit.launchserver.auth.core.interfaces.UserHardware; -import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportHardware; import pro.gravit.launchserver.helper.DamerauHelper; import java.util.Arrays; @@ -28,10 +27,6 @@ public interface AuthSupportHardware extends AuthSupport { void unbanHardware(UserHardware hardware); - default UserSupportHardware fetchUserHardware(User user) { - return (UserSupportHardware) user; - } - default void normalizeHardwareInfo(HardwareReportRequest.HardwareInfo hardwareInfo) { if (hardwareInfo.baseboardSerialNumber != null) hardwareInfo.baseboardSerialNumber = hardwareInfo.baseboardSerialNumber.trim(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportRemoteClientAccess.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportRemoteClientAccess.java deleted file mode 100644 index 6fa5d411..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportRemoteClientAccess.java +++ /dev/null @@ -1,9 +0,0 @@ -package pro.gravit.launchserver.auth.core.interfaces.provider; - -import java.util.List; - -public interface AuthSupportRemoteClientAccess { - String getClientApiUrl(); - - List getClientApiFeatures(); -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportHardware.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportHardware.java new file mode 100644 index 00000000..8c8b06cf --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportHardware.java @@ -0,0 +1,8 @@ +package pro.gravit.launchserver.auth.core.interfaces.session; + +import pro.gravit.launchserver.auth.core.interfaces.UserHardware; + +public interface UserSessionSupportHardware { + String getHardwareId(); + UserHardware getHardware(); +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportProperties.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportProperties.java new file mode 100644 index 00000000..3bbda98c --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportProperties.java @@ -0,0 +1,7 @@ +package pro.gravit.launchserver.auth.core.interfaces.session; + +import java.util.Map; + +public interface UserSessionSupportProperties { + Map getProperties(); +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportHardware.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportHardware.java deleted file mode 100644 index a52da511..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportHardware.java +++ /dev/null @@ -1,7 +0,0 @@ -package pro.gravit.launchserver.auth.core.interfaces.user; - -import pro.gravit.launchserver.auth.core.interfaces.UserHardware; - -public interface UserSupportHardware { - UserHardware getHardware(); -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java index 8c24e6d6..5b7c3c21 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java @@ -16,6 +16,7 @@ import pro.gravit.launchserver.auth.core.AuthCoreProvider; import pro.gravit.launchserver.auth.core.User; import pro.gravit.launchserver.auth.core.UserSession; +import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportExtendedCheckServer; import pro.gravit.launchserver.auth.core.interfaces.session.UserSessionSupportKeys; import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportProperties; import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportTextures; @@ -161,9 +162,16 @@ public UserSessionSupportKeys.ClientProfileKeys createClientProfileKeys(UUID pla public CheckServerReport checkServer(Client client, String username, String serverID) throws IOException { if (client.auth == null) return null; - User user = client.auth.core.checkServer(client, username, serverID); - if (user == null) return null; - else return CheckServerReport.ofUser(user, getPlayerProfile(client.auth, user)); + var supportExtended = client.auth.core.isSupport(AuthSupportExtendedCheckServer.class); + if(supportExtended != null) { + var session = supportExtended.extendedCheckServer(client, username, serverID); + if(session == null) return null; + return CheckServerReport.ofUserSession(session, getPlayerProfile(client.auth, session.getUser())); + } else { + var user = client.auth.core.checkServer(client, username, serverID); + if (user == null) return null; + return CheckServerReport.ofUser(user, getPlayerProfile(client.auth, user)); + } } public boolean joinServer(Client client, String username, UUID uuid, String accessToken, String serverID) throws IOException { @@ -322,20 +330,27 @@ public boolean accept(Client client, AuthProviderPair pair, String extendedToken public static class CheckServerReport { public UUID uuid; public User user; + public UserSession session; public PlayerProfile playerProfile; - public CheckServerReport(UUID uuid, User user, PlayerProfile playerProfile) { + public CheckServerReport(UUID uuid, User user, UserSession session, PlayerProfile playerProfile) { this.uuid = uuid; this.user = user; + this.session = session; this.playerProfile = playerProfile; } public static CheckServerReport ofUser(User user, PlayerProfile playerProfile) { - return new CheckServerReport(user.getUUID(), user, playerProfile); + return new CheckServerReport(user.getUUID(), user, null, playerProfile); + } + + public static CheckServerReport ofUserSession(UserSession session, PlayerProfile playerProfile) { + var user = session.getUser(); + return new CheckServerReport(user.getUUID(), user, session, playerProfile); } public static CheckServerReport ofUUID(UUID uuid, PlayerProfile playerProfile) { - return new CheckServerReport(uuid, null, playerProfile); + return new CheckServerReport(uuid, null, null, playerProfile); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java index 71f5a255..7795a9bb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java @@ -5,6 +5,8 @@ import org.apache.logging.log4j.Logger; import pro.gravit.launcher.events.request.CheckServerRequestEvent; import pro.gravit.launchserver.auth.AuthException; +import pro.gravit.launchserver.auth.core.interfaces.session.UserSessionSupportHardware; +import pro.gravit.launchserver.auth.core.interfaces.session.UserSessionSupportProperties; import pro.gravit.launchserver.manangers.AuthManager; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; @@ -14,7 +16,9 @@ public class CheckServerResponse extends SimpleResponse { private transient final Logger logger = LogManager.getLogger(); public String serverID; public String username; - public String client; + public String serverName; + public boolean needHardware; + public boolean needProperties; @Override public String getType() { @@ -37,6 +41,15 @@ public void execute(ChannelHandlerContext ctx, Client pClient) { } result.playerProfile = report.playerProfile; result.uuid = report.uuid; + if(report.session != null) { + result.sessionId = report.session.getID(); + if(needProperties && report.session instanceof UserSessionSupportProperties supportProperties) { + result.sessionProperties = supportProperties.getProperties(); + } + if(needHardware && report.session instanceof UserSessionSupportHardware supportHardware) { + result.hardwareId = supportHardware.getHardwareId(); + } + } server.authHookManager.postCheckServerHook.hook(report, pClient); logger.debug("checkServer: {} uuid: {} serverID: {}", result.playerProfile == null ? null : result.playerProfile.username, result.uuid, serverID); } catch (AuthException | HookException e) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java index fcc16ae8..913218c1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java @@ -3,7 +3,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; import pro.gravit.launchserver.auth.AuthProviderPair; -import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportRemoteClientAccess; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/api/AuthService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/api/AuthService.java similarity index 69% rename from LauncherClient/src/main/java/pro/gravit/launcher/api/AuthService.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/api/AuthService.java index 93b90de9..0020d954 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/api/AuthService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/api/AuthService.java @@ -3,6 +3,7 @@ import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.profiles.ClientProfile; +import java.util.List; import java.util.UUID; public class AuthService { @@ -14,4 +15,12 @@ public class AuthService { public static boolean hasPermission(String permission) { return permissions.hasPerm(permission); } + + public static boolean hasRole(String role) { + return permissions.hasRole(role); + } + + public static List getRoles() { + return permissions.getRoles(); + } } diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/api/ClientService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/api/ClientService.java similarity index 92% rename from LauncherClient/src/main/java/pro/gravit/launcher/api/ClientService.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/api/ClientService.java index a065319d..50c3a8da 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/api/ClientService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/api/ClientService.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.api; -import pro.gravit.launcher.utils.ApiBridgeService; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.launch.ClassLoaderControl; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/api/KeyService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/api/KeyService.java index aea481d8..5976d4f8 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/api/KeyService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/api/KeyService.java @@ -1,7 +1,9 @@ package pro.gravit.launcher.api; +import java.security.interfaces.ECPublicKey; import java.security.interfaces.RSAPublicKey; public class KeyService { public static RSAPublicKey serverRsaPublicKey; + public static ECPublicKey serverEcPublicKey; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java index d4fc571a..47a78f93 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java @@ -4,6 +4,7 @@ import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; +import java.util.Map; import java.util.UUID; @@ -14,6 +15,12 @@ public class CheckServerRequestEvent extends RequestEvent { public UUID uuid; @LauncherNetworkAPI public PlayerProfile playerProfile; + @LauncherNetworkAPI + public String sessionId; + @LauncherNetworkAPI + public String hardwareId; + @LauncherNetworkAPI + public Map sessionProperties; public CheckServerRequestEvent(PlayerProfile playerProfile) { this.playerProfile = playerProfile; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java index ac647341..d59fc144 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java @@ -11,6 +11,12 @@ public final class CheckServerRequest extends Request i public final String username; @LauncherNetworkAPI public final String serverID; + @LauncherNetworkAPI + public String serverName; + @LauncherNetworkAPI + public boolean needHardware; + @LauncherNetworkAPI + public boolean needProperties; public CheckServerRequest(String username, String serverID) { @@ -18,6 +24,14 @@ public CheckServerRequest(String username, String serverID) { this.serverID = VerifyHelper.verifyServerID(serverID); } + public CheckServerRequest(String username, String serverID, String serverName, boolean needHardware, boolean needProperties) { + this.username = username; + this.serverID = serverID; + this.serverName = serverName; + this.needHardware = needHardware; + this.needProperties = needProperties; + } + @Override public String getType() { return "checkServer"; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java index 64f292fe..368d2967 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -176,6 +176,7 @@ private static void realMain(String[] args) throws Throwable { AuthService.username = params.playerProfile.username; AuthService.uuid = params.playerProfile.uuid; KeyService.serverRsaPublicKey = Launcher.getConfig().rsaPublicKey; + KeyService.serverEcPublicKey = Launcher.getConfig().ecdsaPublicKey; modulesManager.invokeEvent(new ClientProcessReadyEvent(params)); LogHelper.debug("Starting JVM and client WatchService"); FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher(); diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index 6884ef9b..c92f4caa 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -3,6 +3,8 @@ import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; +import pro.gravit.launcher.api.AuthService; +import pro.gravit.launcher.api.ClientService; import pro.gravit.launcher.api.KeyService; import pro.gravit.launcher.config.JsonConfigurable; import pro.gravit.launcher.events.request.AuthRequestEvent; @@ -39,11 +41,7 @@ public class ServerWrapper extends JsonConfigurable { public static ServerWrapper wrapper; public static ClassLoaderControl classLoaderControl; public Config config; - public PublicURLClassLoader ucp; - public ClassLoader loader; - public ClientPermissions permissions; public ClientProfile profile; - public PlayerProfile playerProfile; public ClientProfile.ServerProfile serverProfile; public ServerWrapper(Type type, Path configPath) { @@ -69,7 +67,7 @@ public void restore() throws Exception { if(config.extendedTokens != null) { Request.addAllExtendedToken(config.extendedTokens); } - Request.restore(); + Request.RequestRestoreReport report = Request.restore(config.oauth != null, false, false); } public void getProfiles() throws Exception { @@ -144,6 +142,9 @@ public void run(String... args) throws Throwable { if(config.encodedServerRsaPublicKey != null) { KeyService.serverRsaPublicKey = SecurityHelper.toPublicRSAKey(config.encodedServerRsaPublicKey); } + if(config.encodedServerEcPublicKey != null) { + KeyService.serverEcPublicKey = SecurityHelper.toPublicECDSAKey(config.encodedServerEcPublicKey); + } String classname = (config.mainclass == null || config.mainclass.isEmpty()) ? args[0] : config.mainclass; if (classname.length() == 0) { LogHelper.error("MainClass not found. Please set MainClass for ServerWrapper.json or first commandline argument"); @@ -192,6 +193,12 @@ public void run(String... args) throws Throwable { options.enableHacks = config.enableHacks; options.moduleConf = config.moduleConf; classLoaderControl = launch.init(config.classpath.stream().map(Paths::get).collect(Collectors.toCollection(ArrayList::new)), config.nativesDir, options); + if(ServerAgent.isAgentStarted()) { + ClientService.instrumentation = ServerAgent.inst; + } + ClientService.classLoaderControl = classLoaderControl; + ClientService.baseURLs = classLoaderControl.getURLs(); + ClientService.nativePath = config.nativesDir; LogHelper.info("Start Minecraft Server"); LogHelper.debug("Invoke main method %s with %s", classname, launch.getClass().getName()); try { diff --git a/build.gradle b/build.gradle index 7c41c2e6..aff07ff7 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ id 'org.openjfx.javafxplugin' version '0.0.10' apply false } group = 'pro.gravit.launcher' -version = '5.5.2' +version = '5.5.3-SNAPSHOT' apply from: 'props.gradle' From 3754a327b054145892881971944c5a81c2ace378 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Tue, 28 Nov 2023 18:21:32 +0700 Subject: [PATCH 09/16] [FEATURE] ConfigService --- .../response/auth/CheckServerResponse.java | 1 - .../gravit/launcher/api/ConfigService.java | 11 ++++++++ .../request/auth/CheckServerRequest.java | 7 ++---- .../gravit/launcher/server/ServerWrapper.java | 25 +++++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/api/ConfigService.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java index 7795a9bb..947e5dcb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java @@ -16,7 +16,6 @@ public class CheckServerResponse extends SimpleResponse { private transient final Logger logger = LogManager.getLogger(); public String serverID; public String username; - public String serverName; public boolean needHardware; public boolean needProperties; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/api/ConfigService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/api/ConfigService.java new file mode 100644 index 00000000..01bafb3d --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/api/ConfigService.java @@ -0,0 +1,11 @@ +package pro.gravit.launcher.api; + +public class ConfigService { + public static boolean disableLogging; + public static String serverName; + public static CheckServerConfig checkServerConfig = new CheckServerConfig(); + public static class CheckServerConfig { + public boolean needProperties; + public boolean needHardware; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java index d59fc144..9e3ff5f6 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java @@ -12,8 +12,6 @@ public final class CheckServerRequest extends Request i @LauncherNetworkAPI public final String serverID; @LauncherNetworkAPI - public String serverName; - @LauncherNetworkAPI public boolean needHardware; @LauncherNetworkAPI public boolean needProperties; @@ -24,10 +22,9 @@ public CheckServerRequest(String username, String serverID) { this.serverID = VerifyHelper.verifyServerID(serverID); } - public CheckServerRequest(String username, String serverID, String serverName, boolean needHardware, boolean needProperties) { + public CheckServerRequest(String username, String serverID, boolean needHardware, boolean needProperties) { this.username = username; - this.serverID = serverID; - this.serverName = serverName; + this.serverID = VerifyHelper.verifyServerID(serverID); this.needHardware = needHardware; this.needProperties = needProperties; } diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index c92f4caa..4b82b2a3 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -5,6 +5,7 @@ import pro.gravit.launcher.LauncherConfig; import pro.gravit.launcher.api.AuthService; import pro.gravit.launcher.api.ClientService; +import pro.gravit.launcher.api.ConfigService; import pro.gravit.launcher.api.KeyService; import pro.gravit.launcher.config.JsonConfigurable; import pro.gravit.launcher.events.request.AuthRequestEvent; @@ -68,6 +69,13 @@ public void restore() throws Exception { Request.addAllExtendedToken(config.extendedTokens); } Request.RequestRestoreReport report = Request.restore(config.oauth != null, false, false); + if(report.userInfo != null) { + if(report.userInfo.playerProfile != null) { + AuthService.username = report.userInfo.playerProfile.username; + AuthService.uuid = report.userInfo.playerProfile.uuid; + } + AuthService.permissions = report.userInfo.permissions; + } } public void getProfiles() throws Exception { @@ -80,6 +88,7 @@ public void getProfiles() throws Exception { this.serverProfile = srv; this.profile = p; Launcher.profile = p; + AuthService.profile = p; LogHelper.debug("Found profile: %s", Launcher.profile.getTitle()); isFound = true; break; @@ -199,6 +208,10 @@ public void run(String... args) throws Throwable { ClientService.classLoaderControl = classLoaderControl; ClientService.baseURLs = classLoaderControl.getURLs(); ClientService.nativePath = config.nativesDir; + ConfigService.serverName = config.serverName; + if(config.configServiceSettings != null) { + config.configServiceSettings.apply(); + } LogHelper.info("Start Minecraft Server"); LogHelper.debug("Invoke main method %s with %s", classname, launch.getClass().getName()); try { @@ -274,5 +287,17 @@ public static final class Config { public boolean enableHacks; public Map properties; + public ConfigServiceSettings configServiceSettings = new ConfigServiceSettings(); + + public static class ConfigServiceSettings { + public boolean disableLogging = false; + public boolean checkServerNeedProperties = false; + public boolean checkServerNeedHardware = false; + public void apply() { + ConfigService.disableLogging = disableLogging; + ConfigService.checkServerConfig.needHardware = checkServerNeedHardware; + ConfigService.checkServerConfig.needProperties = checkServerNeedProperties; + } + } } } From ebbd1c87e8ffa2a8e696a71a71b32abf4a0d0238 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Thu, 30 Nov 2023 00:05:59 +0700 Subject: [PATCH 10/16] [FIX] ModuleLaunch NPE --- .../src/main/java11/pro/gravit/utils/launch/ModuleLaunch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LauncherCore/src/main/java11/pro/gravit/utils/launch/ModuleLaunch.java b/LauncherCore/src/main/java11/pro/gravit/utils/launch/ModuleLaunch.java index 58c69a5c..ab4d829d 100644 --- a/LauncherCore/src/main/java11/pro/gravit/utils/launch/ModuleLaunch.java +++ b/LauncherCore/src/main/java11/pro/gravit/utils/launch/ModuleLaunch.java @@ -120,8 +120,8 @@ public ClassLoaderControl init(List files, String nativePath, LaunchOption controller.addReads(source, target); } } + moduleClassLoader.initializeWithLayer(layer); } - moduleClassLoader.initializeWithLayer(layer); } return moduleClassLoader.makeControl(); } From ee0a7bc25a605271b392fba887cf95312153f798 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 1 Dec 2023 17:59:05 +0700 Subject: [PATCH 11/16] [FIX] Support mysql/postgresql 1.20.2 --- .../gravit/launchserver/auth/core/AbstractSQLCoreProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java index 7306b88b..274c6b85 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java @@ -179,7 +179,7 @@ public User checkServer(Client client, String username, String serverID) throws public boolean joinServer(Client client, String username, UUID uuid, String accessToken, String serverID) throws IOException { SQLUser user = (SQLUser) client.getUser(); if (user == null) return false; - return user.getUsername().equals(username) && user.getAccessToken().equals(accessToken) && updateServerID(user, serverID); + return (uuid == null ? user.getUsername().equals(username) : user.getUUID().equals(uuid)) && user.getAccessToken().equals(accessToken) && updateServerID(user, serverID); } @Override From 2ff1d8107625770905c2d17429d35972d3d67e5e Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 1 Dec 2023 20:26:06 +0700 Subject: [PATCH 12/16] [FEATURE] Support run Minecraft with Wayland --- .../pro/gravit/launcher/client/ClientLauncherEntryPoint.java | 4 ++++ .../main/java/pro/gravit/launcher/client/ClientParams.java | 1 + modules | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java index 368d2967..15436bd5 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -173,6 +173,10 @@ private static void realMain(String[] args) throws Throwable { if(profile.hasFlag(ClientProfile.CompatibilityFlags.CLASS_CONTROL_API)) { ClientService.classLoaderControl = classLoaderControl; } + if(params.lwjglGlfwWayland) { + String glfwPath = ClientService.findLibrary("glfw_wayland"); + System.setProperty("org.lwjgl.glfw.libname", glfwPath); + } AuthService.username = params.playerProfile.username; AuthService.uuid = params.playerProfile.uuid; KeyService.serverRsaPublicKey = Launcher.getConfig().rsaPublicKey; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientParams.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientParams.java index d464dfba..da72aba6 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientParams.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientParams.java @@ -35,6 +35,7 @@ public class ClientParams { public boolean autoEnter; public boolean fullScreen; + public boolean lwjglGlfwWayland; public int ram; diff --git a/modules b/modules index 54f04dd7..4d376aa6 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 54f04dd7794ebb7c8397b21397c30cec62a0815e +Subproject commit 4d376aa6fcb2167cef2fc5ed373d560ebea6e483 From ae24fd6ccb46676c15a648eeade09431fdaeaa5b Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 8 Dec 2023 16:51:10 +0700 Subject: [PATCH 13/16] [ANY] 5.5.3-stable --- LauncherCore/src/main/java/pro/gravit/utils/Version.java | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index 272fc6be..d42ebb45 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -8,7 +8,7 @@ public final class Version implements Comparable { public static final int MINOR = 5; public static final int PATCH = 3; public static final int BUILD = 1; - public static final Version.Type RELEASE = Type.DEV; + public static final Version.Type RELEASE = Type.STABLE; public final int major; public final int minor; public final int patch; diff --git a/build.gradle b/build.gradle index aff07ff7..30340061 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ id 'org.openjfx.javafxplugin' version '0.0.10' apply false } group = 'pro.gravit.launcher' -version = '5.5.3-SNAPSHOT' +version = '5.5.3' apply from: 'props.gradle' From 7b1f449667cbccd6a602ccbb13478e18d89e283e Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 8 Dec 2023 16:51:26 +0700 Subject: [PATCH 14/16] [ANY] Update modules --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 4d376aa6..4bba9cca 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 4d376aa6fcb2167cef2fc5ed373d560ebea6e483 +Subproject commit 4bba9ccad7593577167f06124df5a9a957a81c84 From 1c90681b3b90a68344283a8c725570999b8dba5d Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:53:38 +0700 Subject: [PATCH 15/16] [FEATURE] Support Minecraft 1.20.3/1.20.4 --- .../pro/gravit/launchserver/helper/MakeProfileHelper.java | 4 ++++ .../pro/gravit/launcher/profiles/ClientProfileVersions.java | 1 + 2 files changed, 5 insertions(+) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java index 6f2354ad..8bcac9bb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java @@ -124,6 +124,10 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti builder.setMinJavaVersion(17); builder.setRecommendJavaVersion(17); } + if(version.compareTo(ClientProfileVersions.MINECRAFT_1_20_3) >= 0) { + builder.setMinJavaVersion(21); + builder.setRecommendJavaVersion(21); + } jvmArgs.add("-Dfml.ignorePatchDiscrepancies=true"); jvmArgs.add("-Dfml.ignoreInvalidMinecraftCertificates=true"); builder.setJvmArgs(jvmArgs); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileVersions.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileVersions.java index 7d44b68d..e1c70b82 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileVersions.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileVersions.java @@ -17,4 +17,5 @@ private ClientProfileVersions() { public static final ClientProfile.Version MINECRAFT_1_19 = ClientProfile.Version.of("1.19"); public static final ClientProfile.Version MINECRAFT_1_20 = ClientProfile.Version.of("1.20"); public static final ClientProfile.Version MINECRAFT_1_20_2 = ClientProfile.Version.of("1.20.2"); + public static final ClientProfile.Version MINECRAFT_1_20_3 = ClientProfile.Version.of("1.20.3"); } From a601a4ceefe86863574916510a34f96d3a352ac3 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:53:51 +0700 Subject: [PATCH 16/16] [ANY] Update modules --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 4bba9cca..7581b6c0 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 4bba9ccad7593577167f06124df5a9a957a81c84 +Subproject commit 7581b6c01470a5ec32ac67170635d10f6f589b0a