[FIX] CheckServer fix

This commit is contained in:
Gravita 2021-05-31 08:25:33 +07:00
parent ffad6c0b74
commit 20a326a707
4 changed files with 46 additions and 9 deletions

View file

@ -121,10 +121,10 @@ public void invoke(String... args) throws Exception {
return map; 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); User user = getUserByUsername(username);
if (user.getUsername().equals(username) && user.getServerId().equals(serverID)) { if (user.getUsername().equals(username) && user.getServerId().equals(serverID)) {
return user.getUUID(); return user;
} }
return null; return null;
} }

View file

@ -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 == null) return null;
if (client.auth.isUseCore()) { 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 { } 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));
} }
} }

View file

@ -5,6 +5,7 @@
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import pro.gravit.launcher.events.request.CheckServerRequestEvent; import pro.gravit.launcher.events.request.CheckServerRequestEvent;
import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.auth.AuthException;
import pro.gravit.launchserver.manangers.AuthManager;
import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.Client;
import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.launchserver.socket.response.SimpleResponse;
import pro.gravit.utils.HookException; import pro.gravit.utils.HookException;
@ -29,9 +30,10 @@ public void execute(ChannelHandlerContext ctx, Client pClient) {
CheckServerRequestEvent result = new CheckServerRequestEvent(); CheckServerRequestEvent result = new CheckServerRequestEvent();
try { try {
server.authHookManager.checkServerHook.hook(this, pClient); server.authHookManager.checkServerHook.hook(this, pClient);
result.uuid = server.authManager.checkServer(pClient, username, serverID); AuthManager.CheckServerReport report = server.authManager.checkServer(pClient, username, serverID);
if (result.uuid != null) { if (report != null) {
result.playerProfile = server.authManager.getPlayerProfile(pClient); result.playerProfile = report.playerProfile;
result.uuid = report.uuid;
logger.debug("checkServer: {} uuid: {} serverID: {}", result.playerProfile.username, result.uuid, serverID); logger.debug("checkServer: {} uuid: {} serverID: {}", result.playerProfile.username, result.uuid, serverID);
} }
} catch (AuthException | HookException e) { } catch (AuthException | HookException e) {

View file

@ -58,6 +58,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep
if (!noJavaCheck) { if (!noJavaCheck) {
List<JavaVersion> javaVersions = findJava(); List<JavaVersion> javaVersions = findJava();
for (JavaVersion version : javaVersions) { 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) { if (context.javaVersion == null) {
context.javaVersion = version; context.javaVersion = version;
continue; continue;
@ -78,6 +79,9 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep
} catch (Throwable e) { } catch (Throwable e) {
LogHelper.error(e); LogHelper.error(e);
} }
if (context.javaVersion == null) {
context.javaVersion = JavaVersion.getCurrentJavaVersion();
}
context.executePath = IOHelper.resolveJavaBin(context.javaVersion.jvmDir); context.executePath = IOHelper.resolveJavaBin(context.javaVersion.jvmDir);
//List<String> args = new LinkedList<>(); //List<String> args = new LinkedList<>();
@ -322,7 +326,16 @@ public JavaVersion(Path jvmDir, int version, int build, boolean enabledJavaFX) {
} }
public static JavaVersion getCurrentJavaVersion() { 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 { public static JavaVersion getByPath(Path jvmDir) throws IOException {