fix(auth): legacy user type for OfflineAccount.

This commit is contained in:
huanghongxun 2022-10-25 21:48:50 +08:00
parent ff78297ee5
commit 0f39aad429
6 changed files with 17 additions and 7 deletions

View File

@ -30,16 +30,21 @@ import java.util.UUID;
*/ */
@Immutable @Immutable
public class AuthInfo implements AutoCloseable { 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 String username;
private final UUID uuid; private final UUID uuid;
private final String accessToken; private final String accessToken;
private final String userType;
private final String userProperties; 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.username = username;
this.uuid = uuid; this.uuid = uuid;
this.accessToken = accessToken; this.accessToken = accessToken;
this.userType = userType;
this.userProperties = userProperties; this.userProperties = userProperties;
} }
@ -55,6 +60,10 @@ public class AuthInfo implements AutoCloseable {
return accessToken; return accessToken;
} }
public String getUserType() {
return userType;
}
/** /**
* Properties of this user. * Properties of this user.
* Don't know the difference between user properties and user property map. * Don't know the difference between user properties and user property map.

View File

@ -120,7 +120,7 @@ public class AuthlibInjectorAccount extends YggdrasilAccount {
private final String prefetchedMeta; private final String prefetchedMeta;
public AuthlibInjectorAuthInfo(AuthInfo authInfo, AuthlibInjectorArtifactInfo artifact, AuthlibInjectorServer server, 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.artifact = artifact;
this.server = server; this.server = server;

View File

@ -110,7 +110,7 @@ public class MicrosoftSession {
public AuthInfo toAuthInfo() { public AuthInfo toAuthInfo() {
requireNonNull(profile); 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 { public static class User {

View File

@ -104,7 +104,8 @@ public class OfflineAccount extends Account {
@Override @Override
public AuthInfo logIn() throws AuthenticationException { 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)) { if (loadAuthlibInjector(skin)) {
CompletableFuture<AuthlibInjectorArtifactInfo> artifactTask = CompletableFuture.supplyAsync(() -> { CompletableFuture<AuthlibInjectorArtifactInfo> artifactTask = CompletableFuture.supplyAsync(() -> {
@ -144,7 +145,7 @@ public class OfflineAccount extends Account {
private YggdrasilServer server; private YggdrasilServer server;
public OfflineAuthInfo(AuthInfo authInfo, AuthlibInjectorArtifactInfo artifact) { 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; this.artifact = artifact;
} }

View File

@ -104,7 +104,7 @@ public class YggdrasilSession {
if (selectedProfile == null) if (selectedProfile == null)
throw new IllegalStateException("No character is selected"); 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) Optional.ofNullable(userProperties)
.map(properties -> properties.entrySet().stream() .map(properties -> properties.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, .collect(Collectors.toMap(Map.Entry::getKey,

View File

@ -401,7 +401,7 @@ public class DefaultLauncher extends Launcher {
pair("${profile_name}", Optional.ofNullable(options.getProfileName()).orElse("Minecraft")), pair("${profile_name}", Optional.ofNullable(options.getProfileName()).orElse("Minecraft")),
pair("${version_type}", Optional.ofNullable(options.getVersionType()).orElse(version.getType().getId())), pair("${version_type}", Optional.ofNullable(options.getVersionType()).orElse(version.getType().getId())),
pair("${game_directory}", repository.getRunDirectory(version.getId()).getAbsolutePath()), 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("${assets_index_name}", version.getAssetIndex().getId()),
pair("${user_properties}", authInfo.getUserProperties()), pair("${user_properties}", authInfo.getUserProperties()),
pair("${resolution_width}", options.getWidth().toString()), pair("${resolution_width}", options.getWidth().toString()),