From 20a326a7072aabb92adebcf611c334d2e4de4a52 Mon Sep 17 00:00:00 2001 From: Gravita Date: Mon, 31 May 2021 08:25:33 +0700 Subject: [PATCH] [FIX] CheckServer fix --- .../auth/core/AuthCoreProvider.java | 4 +-- .../launchserver/manangers/AuthManager.java | 28 +++++++++++++++++-- .../response/auth/CheckServerResponse.java | 8 ++++-- .../launcher/ClientLauncherWrapper.java | 15 +++++++++- 4 files changed, 46 insertions(+), 9 deletions(-) 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 4c5551ac..b247a2b8 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 @@ -121,10 +121,10 @@ public void invoke(String... args) throws Exception { return map; } - public UUID checkServer(Client client, String username, String serverID) throws IOException { + public User checkServer(Client client, String username, String serverID) throws IOException { User user = getUserByUsername(username); if (user.getUsername().equals(username) && user.getServerId().equals(serverID)) { - return user.getUUID(); + return user; } return null; } 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 6fd434e0..83a50d35 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java @@ -210,12 +210,34 @@ public void internalAuth(Client client, AuthResponse.ConnectTypes authType, Auth } } - public UUID checkServer(Client client, String username, String serverID) throws IOException { + public static class CheckServerReport { + public UUID uuid; + public User user; + public PlayerProfile playerProfile; + + public CheckServerReport(UUID uuid, User user, PlayerProfile playerProfile) { + this.uuid = uuid; + this.user = user; + this.playerProfile = playerProfile; + } + + public static CheckServerReport ofUser(User user, PlayerProfile playerProfile) { + return new CheckServerReport(user.getUUID(), user, playerProfile); + } + + public static CheckServerReport ofUUID(UUID uuid, PlayerProfile playerProfile) { + return new CheckServerReport(uuid, null, playerProfile); + } + } + + public CheckServerReport checkServer(Client client, String username, String serverID) throws IOException { if (client.auth == null) return null; if (client.auth.isUseCore()) { - return client.auth.core.checkServer(client, username, serverID); + User user = client.auth.core.checkServer(client, username, serverID); + return user == null ? null : CheckServerReport.ofUser(user, getPlayerProfile(user)); } else { - return client.auth.handler.checkServer(username, serverID); + UUID uuid = client.auth.handler.checkServer(username, serverID); + return uuid == null ? null : CheckServerReport.ofUUID(uuid, getPlayerProfile(client.auth, uuid)); } } 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 5196a99d..ac289125 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,7 @@ import org.apache.logging.log4j.Logger; import pro.gravit.launcher.events.request.CheckServerRequestEvent; import pro.gravit.launchserver.auth.AuthException; +import pro.gravit.launchserver.manangers.AuthManager; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.utils.HookException; @@ -29,9 +30,10 @@ public void execute(ChannelHandlerContext ctx, Client pClient) { CheckServerRequestEvent result = new CheckServerRequestEvent(); try { server.authHookManager.checkServerHook.hook(this, pClient); - result.uuid = server.authManager.checkServer(pClient, username, serverID); - if (result.uuid != null) { - result.playerProfile = server.authManager.getPlayerProfile(pClient); + AuthManager.CheckServerReport report = server.authManager.checkServer(pClient, username, serverID); + if (report != null) { + result.playerProfile = report.playerProfile; + result.uuid = report.uuid; logger.debug("checkServer: {} uuid: {} serverID: {}", result.playerProfile.username, result.uuid, serverID); } } catch (AuthException | HookException e) { diff --git a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java index 2a42accf..26cad7f9 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java @@ -58,6 +58,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep if (!noJavaCheck) { List javaVersions = findJava(); for (JavaVersion version : javaVersions) { + LogHelper.debug("Found Java %d b%d in %s javafx %s", version.version, version.build, version.jvmDir.toString(), version.enabledJavaFX ? "supported" : "not supported"); if (context.javaVersion == null) { context.javaVersion = version; continue; @@ -78,6 +79,9 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep } catch (Throwable e) { LogHelper.error(e); } + if (context.javaVersion == null) { + context.javaVersion = JavaVersion.getCurrentJavaVersion(); + } context.executePath = IOHelper.resolveJavaBin(context.javaVersion.jvmDir); //List args = new LinkedList<>(); @@ -322,7 +326,16 @@ public JavaVersion(Path jvmDir, int version, int build, boolean enabledJavaFX) { } public static JavaVersion getCurrentJavaVersion() { - return new JavaVersion(Paths.get(System.getProperty("java.home")), JVMHelper.getVersion()); + return new JavaVersion(Paths.get(System.getProperty("java.home")), JVMHelper.getVersion(), 0, isCurrentJavaSupportJavaFX()); + } + + private static boolean isCurrentJavaSupportJavaFX() { + try { + Class.forName("javafx.application.Application"); + return true; + } catch (ClassNotFoundException e) { + return false; + } } public static JavaVersion getByPath(Path jvmDir) throws IOException {