diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java index 7b78cb8f9a..2aee028f1f 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java @@ -468,7 +468,9 @@ public static String localizeErrorMessage(Exception exception) { } } else if (exception instanceof MicrosoftService.XBox400Exception) { return i18n("account.methods.microsoft.error.wrong_verify_method"); - } else if (exception instanceof MicrosoftService.NoMinecraftJavaEditionProfileException) { + } else if (exception instanceof MicrosoftService.MinecraftJavaEditionLicenseNotFoundException) { + return i18n("account.methods.microsoft.error.no_license"); + } else if (exception instanceof MicrosoftService.MinecraftJavaEditionProfileNotFoundException) { return i18n("account.methods.microsoft.error.no_character"); } else if (exception instanceof MicrosoftService.NoXuiException) { return i18n("account.methods.microsoft.error.add_family"); diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index cc67b62d3a..ab1bd7e040 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -108,9 +108,9 @@ account.methods.microsoft.close_page=Microsoft account authorization is now comp account.methods.microsoft.deauthorize=Deauthorize account.methods.microsoft.error.add_family=Please click here to change your account birth date to be over 18 years old, or add your account to a family. account.methods.microsoft.error.country_unavailable=Xbox Live is not available in your current country/region. -account.methods.microsoft.error.missing_xbox_account=Your Microsoft account does not have a linked Xbox account yet. Please click here to link one. -account.methods.microsoft.error.no_character=Please confirm that you have purchased Minecraft: Java Edition.\n\ - If you have already purchased it, a game profile may not have been created. Please click here to create a game profile. +account.methods.microsoft.error.missing_xbox_account=Please confirm that you have purchased Minecraft: Java Edition. If you have, please click here to create your game profile. +account.methods.microsoft.error.no_license=No Minecraft purchase record found. Please click here to get the game.\nIf you are using Game Pass, please create your game profile here. If you have already purchased the game, please check if you are logged into the correct account. +account.methods.microsoft.error.no_character=You have not created a game profile yet. Please click here to create one. account.methods.microsoft.error.banned=Your account may have been banned by Xbox Live.\n\ You can click here to check the ban status of your account. account.methods.microsoft.error.unknown=Failed to log in, error code: %d. diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index da02e13533..91828e4c6f 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -109,8 +109,9 @@ account.methods.microsoft.close_page=已完成 Microsoft 帳戶授權。啟動 account.methods.microsoft.deauthorize=移除應用存取權 account.methods.microsoft.error.add_family=請點擊 此處 更改你的帳戶出生日期,使年齡滿 18 歲以上,或將帳戶加入到家庭中。 account.methods.microsoft.error.country_unavailable=你所在的國家或地區不受 Xbox Live 的支援。 -account.methods.microsoft.error.missing_xbox_account=請點擊下方 此處 關聯 Xbox 帳戶。 -account.methods.microsoft.error.no_character=請確認你已經購買了 Minecraft: Java 版。\n若已購買,則可能未建立遊戲檔案。請點擊 此處 建立遊戲檔案。 +account.methods.microsoft.error.missing_xbox_account=請確認你已經購買了 Minecraft: Java 版。若已購買,請點擊 此處 建立遊戲檔案。 +account.methods.microsoft.error.no_license=未找到 Minecraft 購買記錄。請點擊 此處 購買遊戲。\n若你使用 Game Pass,請在 此處 建立遊戲檔案。若已購買,請檢查登入的帳戶是否正確。 +account.methods.microsoft.error.no_character=你可能未建立遊戲檔案。請點擊 此處 建立遊戲檔案。 account.methods.microsoft.error.banned=你的帳戶可能被 Xbox Live 封禁。\n你可以點擊 此處 按鈕查詢帳戶封禁狀態。 account.methods.microsoft.error.unknown=登入失敗。錯誤碼:%d。 account.methods.microsoft.error.wrong_verify_method=登入失敗。請在 Microsoft 帳戶登入頁面嘗試使用密碼登入,不要使用其他登入方式。 diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index c53c6f3aa2..79d2634057 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -110,8 +110,9 @@ account.methods.microsoft.close_page=已完成微软账户授权。其余登录 account.methods.microsoft.deauthorize=解除账户授权 account.methods.microsoft.error.add_family=请点击 此处 更改你的账户出生日期,使年龄满 18 岁以上,或将账户加入到家庭中。\n你可以点击右上角帮助按钮进行求助。 account.methods.microsoft.error.country_unavailable=你所在的国家或地区不受 Xbox Live 的支持。 -account.methods.microsoft.error.missing_xbox_account=请点击 此处 关联 Xbox 账户。\n你可以点击右上角帮助按钮进行求助。 -account.methods.microsoft.error.no_character=请确认你已经购买了 Minecraft: Java 版。\n若已购买,则可能未创建游戏档案。请点击 此处 创建游戏档案。\n你可以点击右上角帮助按钮进行求助。 +account.methods.microsoft.error.missing_xbox_account=请确认你已经购买了 Minecraft: Java 版。若已购买,请点击 此处 创建游戏档案。\n你可以点击右上角帮助按钮进行求助。 +account.methods.microsoft.error.no_license=未找到 Minecraft 购买记录。请点击 此处 购买游戏。\n若你使用 Game Pass,请在 此处 创建游戏档案。若已购买,请检查登录的账户是否正确。\n你可以点击右上角帮助按钮进行求助。 +account.methods.microsoft.error.no_character=你尚未创建游戏档案。请点击 此处 创建游戏档案。\n你可以点击右上角帮助按钮进行求助。 account.methods.microsoft.error.banned=你的账户可能被 Xbox Live 封禁。\n你可以点击 此处 按钮查询账户封禁状态。 account.methods.microsoft.error.unknown=未知问题。错误码:%d。\n你可以点击右上角帮助按钮进行求助。 account.methods.microsoft.error.wrong_verify_method=登录失败。请在微软账户登录页面使用密码登录,不要使用其他登录方式。\n你可以点击右上角帮助按钮进行求助。 diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftService.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftService.java index 2174d10877..883d2d0b74 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftService.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftService.java @@ -25,7 +25,10 @@ import org.jackhuang.hmcl.auth.OAuth; import org.jackhuang.hmcl.auth.ServerDisconnectException; import org.jackhuang.hmcl.auth.ServerResponseMalformedException; -import org.jackhuang.hmcl.auth.yggdrasil.*; +import org.jackhuang.hmcl.auth.yggdrasil.CompleteGameProfile; +import org.jackhuang.hmcl.auth.yggdrasil.RemoteAuthenticationException; +import org.jackhuang.hmcl.auth.yggdrasil.Texture; +import org.jackhuang.hmcl.auth.yggdrasil.TextureType; import org.jackhuang.hmcl.util.StringUtils; import org.jackhuang.hmcl.util.gson.*; import org.jackhuang.hmcl.util.io.*; @@ -245,7 +248,16 @@ private static MinecraftProfileResponse getMinecraftProfile(String tokenType, St .createConnection(); int responseCode = conn.getResponseCode(); if (responseCode == HTTP_NOT_FOUND) { - throw new NoMinecraftJavaEditionProfileException(); + MinecraftLicense license = HttpRequest.GET("https://api.minecraftservices.com/entitlements/license") + .authorization(tokenType, accessToken) + .getJson(MinecraftLicense.class); + boolean hasMinecraftLicense = license != null && license.items() != null && license.items().stream() + .anyMatch(item -> "game_minecraft".equals(item.name())); + if (!hasMinecraftLicense) { + throw new MinecraftJavaEditionLicenseNotFoundException(); + } else { + throw new MinecraftJavaEditionProfileNotFoundException(); + } } else if (responseCode != 200) { throw new ResponseCodeException("https://api.minecraftservices.com/minecraft/profile", responseCode); } @@ -324,7 +336,10 @@ public String getRedirect() { public final static class XBox400Exception extends AuthenticationException { } - public final static class NoMinecraftJavaEditionProfileException extends AuthenticationException { + public final static class MinecraftJavaEditionProfileNotFoundException extends AuthenticationException { + } + + public final static class MinecraftJavaEditionLicenseNotFoundException extends AuthenticationException { } public final static class NoXuiException extends AuthenticationException { @@ -425,6 +440,21 @@ public static class MinecraftProfileResponseCape { } + @JsonSerializable + public record MinecraftLicense( + @SerializedName("items") List items, + @SerializedName("signature") String signature, + @SerializedName("keyId") String keyId + ) { + } + + @JsonSerializable + public record MinecraftLicenseItem( + @SerializedName("name") String name, + @SerializedName("signature") String signature + ) { + } + public static class MinecraftProfileResponse extends MinecraftErrorResponse implements Validation { @SerializedName("id") UUID id;