Skip to content

Commit d6648a8

Browse files
authored
优化微软登录未购买提示 (#5611)
1 parent f8c2af7 commit d6648a8

5 files changed

Lines changed: 45 additions & 11 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/setting/Accounts.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,9 @@ public static String localizeErrorMessage(Exception exception) {
468468
}
469469
} else if (exception instanceof MicrosoftService.XBox400Exception) {
470470
return i18n("account.methods.microsoft.error.wrong_verify_method");
471-
} else if (exception instanceof MicrosoftService.NoMinecraftJavaEditionProfileException) {
471+
} else if (exception instanceof MicrosoftService.MinecraftJavaEditionLicenseNotFoundException) {
472+
return i18n("account.methods.microsoft.error.no_license");
473+
} else if (exception instanceof MicrosoftService.MinecraftJavaEditionProfileNotFoundException) {
472474
return i18n("account.methods.microsoft.error.no_character");
473475
} else if (exception instanceof MicrosoftService.NoXuiException) {
474476
return i18n("account.methods.microsoft.error.add_family");

HMCL/src/main/resources/assets/lang/I18N.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ account.methods.microsoft.close_page=Microsoft account authorization is now comp
108108
account.methods.microsoft.deauthorize=Deauthorize
109109
account.methods.microsoft.error.add_family=Please click <a href="https://support.microsoft.com/account-billing/837badbc-999e-54d2-2617-d19206b9540a">here</a> to change your account birth date to be over 18 years old, or add your account to a family.
110110
account.methods.microsoft.error.country_unavailable=Xbox Live is not available in your current country/region.
111-
account.methods.microsoft.error.missing_xbox_account=Your Microsoft account does not have a linked Xbox account yet. Please click <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">here</a> to link one.
112-
account.methods.microsoft.error.no_character=Please confirm that you have purchased Minecraft: Java Edition.\n\
113-
If you have already purchased it, a game profile may not have been created. Please click <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">here</a> to create a game profile.
111+
account.methods.microsoft.error.missing_xbox_account=Please confirm that you have purchased Minecraft: Java Edition. If you have, please click <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">here</a> to create your game profile.
112+
account.methods.microsoft.error.no_license=No Minecraft purchase record found. Please click <a href="https://www.xbox.com/games/store/minecraft-java-bedrock-edition-for-pc/9nxp44l49shj">here</a> to get the game.\nIf you are using Game Pass, please create your game profile <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">here</a>. If you have already purchased the game, please check if you are logged into the correct account.
113+
account.methods.microsoft.error.no_character=You have not created a game profile yet. Please click <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">here</a> to create one.
114114
account.methods.microsoft.error.banned=Your account may have been banned by Xbox Live.\n\
115115
You can click <a href="https://enforcement.xbox.com/enforcement/showenforcementhistory">here</a> to check the ban status of your account.
116116
account.methods.microsoft.error.unknown=Failed to log in, error code: %d.

HMCL/src/main/resources/assets/lang/I18N_zh.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ account.methods.microsoft.close_page=已完成 Microsoft 帳戶授權。啟動
109109
account.methods.microsoft.deauthorize=移除應用存取權
110110
account.methods.microsoft.error.add_family=請點擊 <a href="https://support.microsoft.com/account-billing/837badbc-999e-54d2-2617-d19206b9540a">此處</a> 更改你的帳戶出生日期,使年齡滿 18 歲以上,或將帳戶加入到家庭中。
111111
account.methods.microsoft.error.country_unavailable=你所在的國家或地區不受 Xbox Live 的支援。
112-
account.methods.microsoft.error.missing_xbox_account=請點擊下方 <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">此處</a> 關聯 Xbox 帳戶。
113-
account.methods.microsoft.error.no_character=請確認你已經購買了 Minecraft: Java 版。\n若已購買,則可能未建立遊戲檔案。請點擊 <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">此處</a> 建立遊戲檔案。
112+
account.methods.microsoft.error.missing_xbox_account=請確認你已經購買了 Minecraft: Java 版。若已購買,請點擊 <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">此處</a> 建立遊戲檔案。
113+
account.methods.microsoft.error.no_license=未找到 Minecraft 購買記錄。請點擊 <a href="https://www.xbox.com/games/store/minecraft-java-bedrock-edition-for-pc/9nxp44l49shj">此處</a> 購買遊戲。\n若你使用 Game Pass,請在 <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">此處</a> 建立遊戲檔案。若已購買,請檢查登入的帳戶是否正確。
114+
account.methods.microsoft.error.no_character=你可能未建立遊戲檔案。請點擊 <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">此處</a> 建立遊戲檔案。
114115
account.methods.microsoft.error.banned=你的帳戶可能被 Xbox Live 封禁。\n你可以點擊 <a href="https://enforcement.xbox.com/enforcement/showenforcementhistory">此處</a> 按鈕查詢帳戶封禁狀態。
115116
account.methods.microsoft.error.unknown=登入失敗。錯誤碼:%d。
116117
account.methods.microsoft.error.wrong_verify_method=登入失敗。請在 Microsoft 帳戶登入頁面嘗試使用密碼登入,不要使用其他登入方式。

HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ account.methods.microsoft.close_page=已完成微软账户授权。其余登录
110110
account.methods.microsoft.deauthorize=解除账户授权
111111
account.methods.microsoft.error.add_family=请点击 <a href="https://support.microsoft.com/account-billing/837badbc-999e-54d2-2617-d19206b9540a">此处</a> 更改你的账户出生日期,使年龄满 18 岁以上,或将账户加入到家庭中。\n你可以点击右上角帮助按钮进行求助。
112112
account.methods.microsoft.error.country_unavailable=你所在的国家或地区不受 Xbox Live 的支持。
113-
account.methods.microsoft.error.missing_xbox_account=请点击 <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">此处</a> 关联 Xbox 账户。\n你可以点击右上角帮助按钮进行求助。
114-
account.methods.microsoft.error.no_character=请确认你已经购买了 Minecraft: Java 版。\n若已购买,则可能未创建游戏档案。请点击 <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">此处</a> 创建游戏档案。\n你可以点击右上角帮助按钮进行求助。
113+
account.methods.microsoft.error.missing_xbox_account=请确认你已经购买了 Minecraft: Java 版。若已购买,请点击 <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">此处</a> 创建游戏档案。\n你可以点击右上角帮助按钮进行求助。
114+
account.methods.microsoft.error.no_license=未找到 Minecraft 购买记录。请点击 <a href="https://www.xbox.com/games/store/minecraft-java-bedrock-edition-for-pc/9nxp44l49shj">此处</a> 购买游戏。\n若你使用 Game Pass,请在 <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">此处</a> 创建游戏档案。若已购买,请检查登录的账户是否正确。\n你可以点击右上角帮助按钮进行求助。
115+
account.methods.microsoft.error.no_character=你尚未创建游戏档案。请点击 <a href="https://www.minecraft.net/msaprofile/mygames/editprofile">此处</a> 创建游戏档案。\n你可以点击右上角帮助按钮进行求助。
115116
account.methods.microsoft.error.banned=你的账户可能被 Xbox Live 封禁。\n你可以点击 <a href="https://enforcement.xbox.com/enforcement/showenforcementhistory">此处</a> 按钮查询账户封禁状态。
116117
account.methods.microsoft.error.unknown=未知问题。错误码:%d。\n你可以点击右上角帮助按钮进行求助。
117118
account.methods.microsoft.error.wrong_verify_method=登录失败。请在微软账户登录页面使用密码登录,不要使用其他登录方式。\n你可以点击右上角帮助按钮进行求助。

HMCLCore/src/main/java/org/jackhuang/hmcl/auth/microsoft/MicrosoftService.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
import org.jackhuang.hmcl.auth.OAuth;
2626
import org.jackhuang.hmcl.auth.ServerDisconnectException;
2727
import org.jackhuang.hmcl.auth.ServerResponseMalformedException;
28-
import org.jackhuang.hmcl.auth.yggdrasil.*;
28+
import org.jackhuang.hmcl.auth.yggdrasil.CompleteGameProfile;
29+
import org.jackhuang.hmcl.auth.yggdrasil.RemoteAuthenticationException;
30+
import org.jackhuang.hmcl.auth.yggdrasil.Texture;
31+
import org.jackhuang.hmcl.auth.yggdrasil.TextureType;
2932
import org.jackhuang.hmcl.util.StringUtils;
3033
import org.jackhuang.hmcl.util.gson.*;
3134
import org.jackhuang.hmcl.util.io.*;
@@ -245,7 +248,16 @@ private static MinecraftProfileResponse getMinecraftProfile(String tokenType, St
245248
.createConnection();
246249
int responseCode = conn.getResponseCode();
247250
if (responseCode == HTTP_NOT_FOUND) {
248-
throw new NoMinecraftJavaEditionProfileException();
251+
MinecraftLicense license = HttpRequest.GET("https://api.minecraftservices.com/entitlements/license")
252+
.authorization(tokenType, accessToken)
253+
.getJson(MinecraftLicense.class);
254+
boolean hasMinecraftLicense = license != null && license.items() != null && license.items().stream()
255+
.anyMatch(item -> "game_minecraft".equals(item.name()));
256+
if (!hasMinecraftLicense) {
257+
throw new MinecraftJavaEditionLicenseNotFoundException();
258+
} else {
259+
throw new MinecraftJavaEditionProfileNotFoundException();
260+
}
249261
} else if (responseCode != 200) {
250262
throw new ResponseCodeException("https://api.minecraftservices.com/minecraft/profile", responseCode);
251263
}
@@ -324,7 +336,10 @@ public String getRedirect() {
324336
public final static class XBox400Exception extends AuthenticationException {
325337
}
326338

327-
public final static class NoMinecraftJavaEditionProfileException extends AuthenticationException {
339+
public final static class MinecraftJavaEditionProfileNotFoundException extends AuthenticationException {
340+
}
341+
342+
public final static class MinecraftJavaEditionLicenseNotFoundException extends AuthenticationException {
328343
}
329344

330345
public final static class NoXuiException extends AuthenticationException {
@@ -425,6 +440,21 @@ public static class MinecraftProfileResponseCape {
425440

426441
}
427442

443+
@JsonSerializable
444+
public record MinecraftLicense(
445+
@SerializedName("items") List<MinecraftLicenseItem> items,
446+
@SerializedName("signature") String signature,
447+
@SerializedName("keyId") String keyId
448+
) {
449+
}
450+
451+
@JsonSerializable
452+
public record MinecraftLicenseItem(
453+
@SerializedName("name") String name,
454+
@SerializedName("signature") String signature
455+
) {
456+
}
457+
428458
public static class MinecraftProfileResponse extends MinecraftErrorResponse implements Validation {
429459
@SerializedName("id")
430460
UUID id;

0 commit comments

Comments
 (0)