diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/AuthInfo.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/AuthInfo.java index aabbe7ebd..3d9e51f61 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/AuthInfo.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/AuthInfo.java @@ -30,16 +30,21 @@ import java.util.UUID; */ @Immutable public class AuthInfo implements AutoCloseable { + public static final String USER_TYPE_MOJANG = "mojang"; + public static final String USER_TYPE_LEGACY = "legacy"; + private final String username; private final UUID uuid; private final String accessToken; + private final String userType; private final String userProperties; - public AuthInfo(String username, UUID uuid, String accessToken, String userProperties) { + public AuthInfo(String username, UUID uuid, String accessToken, String userType, String userProperties) { this.username = username; this.uuid = uuid; this.accessToken = accessToken; + this.userType = userType; this.userProperties = userProperties; } @@ -55,6 +60,10 @@ public class AuthInfo implements AutoCloseable { return accessToken; } + public String getUserType() { + return userType; + } + /** * Properties of this user. * Don't know the difference between user properties and user property map. diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorAccount.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorAccount.java index b7d25d37f..fe8583555 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorAccount.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorAccount.java @@ -120,7 +120,7 @@ public class AuthlibInjectorAccount extends YggdrasilAccount { private final String prefetchedMeta; public AuthlibInjectorAuthInfo(AuthInfo authInfo, AuthlibInjectorArtifactInfo artifact, AuthlibInjectorServer server, String prefetchedMeta) { - super(authInfo.getUsername(), authInfo.getUUID(), authInfo.getAccessToken(), authInfo.getUserProperties()); + super(authInfo.getUsername(), authInfo.getUUID(), authInfo.getAccessToken(), authInfo.getUserType(), authInfo.getUserProperties()); this.artifact = artifact; this.server = server; diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftSession.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftSession.java index d664807ab..f8ec9046c 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftSession.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftSession.java @@ -110,7 +110,7 @@ public class MicrosoftSession { public AuthInfo toAuthInfo() { requireNonNull(profile); - return new AuthInfo(profile.getName(), profile.getId(), accessToken, "{}"); + return new AuthInfo(profile.getName(), profile.getId(), accessToken, AuthInfo.USER_TYPE_MOJANG, "{}"); } public static class User { diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/offline/OfflineAccount.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/offline/OfflineAccount.java index 8cd8b22ff..2e7214186 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/offline/OfflineAccount.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/offline/OfflineAccount.java @@ -104,7 +104,8 @@ public class OfflineAccount extends Account { @Override public AuthInfo logIn() throws AuthenticationException { - AuthInfo authInfo = new AuthInfo(username, uuid, UUIDTypeAdapter.fromUUID(UUID.randomUUID()), "{}"); + // Using "legacy" user type here because "mojang" user type may cause "invalid session token" or "disconnected" when connecting to a game server. + AuthInfo authInfo = new AuthInfo(username, uuid, UUIDTypeAdapter.fromUUID(UUID.randomUUID()), AuthInfo.USER_TYPE_LEGACY, "{}"); if (loadAuthlibInjector(skin)) { CompletableFuture artifactTask = CompletableFuture.supplyAsync(() -> { @@ -144,7 +145,7 @@ public class OfflineAccount extends Account { private YggdrasilServer server; public OfflineAuthInfo(AuthInfo authInfo, AuthlibInjectorArtifactInfo artifact) { - super(authInfo.getUsername(), authInfo.getUUID(), authInfo.getAccessToken(), authInfo.getUserProperties()); + super(authInfo.getUsername(), authInfo.getUUID(), authInfo.getAccessToken(), USER_TYPE_LEGACY, authInfo.getUserProperties()); this.artifact = artifact; } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilSession.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilSession.java index 6f9854760..f0bf4f8d7 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilSession.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilSession.java @@ -104,7 +104,7 @@ public class YggdrasilSession { if (selectedProfile == null) throw new IllegalStateException("No character is selected"); - return new AuthInfo(selectedProfile.getName(), selectedProfile.getId(), accessToken, + return new AuthInfo(selectedProfile.getName(), selectedProfile.getId(), accessToken, AuthInfo.USER_TYPE_MOJANG, Optional.ofNullable(userProperties) .map(properties -> properties.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java index 62da0d165..ce679dbb6 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java @@ -401,7 +401,7 @@ public class DefaultLauncher extends Launcher { pair("${profile_name}", Optional.ofNullable(options.getProfileName()).orElse("Minecraft")), pair("${version_type}", Optional.ofNullable(options.getVersionType()).orElse(version.getType().getId())), pair("${game_directory}", repository.getRunDirectory(version.getId()).getAbsolutePath()), - pair("${user_type}", "mojang"), + pair("${user_type}", authInfo.getUserType()), pair("${assets_index_name}", version.getAssetIndex().getId()), pair("${user_properties}", authInfo.getUserProperties()), pair("${resolution_width}", options.getWidth().toString()),