diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AddAccountPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/AddAccountPane.java index 18dee5651..cb6c19f33 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AddAccountPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/AddAccountPane.java @@ -36,14 +36,13 @@ import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorAccount; import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorServer; import org.jackhuang.hmcl.auth.offline.OfflineAccount; import org.jackhuang.hmcl.auth.yggdrasil.GameProfile; +import org.jackhuang.hmcl.auth.yggdrasil.RemoteAuthenticationException; import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount; import org.jackhuang.hmcl.game.AccountHelper; import org.jackhuang.hmcl.setting.Accounts; import org.jackhuang.hmcl.setting.Settings; import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Task; -import org.jackhuang.hmcl.ui.animation.ContainerAnimations; -import org.jackhuang.hmcl.ui.animation.TransitionHandler; import org.jackhuang.hmcl.ui.construct.AdvancedListBox; import org.jackhuang.hmcl.ui.construct.IconedItem; import org.jackhuang.hmcl.ui.construct.SpinnerPane; @@ -253,16 +252,22 @@ public class AddAccountPane extends StackPane { } public static String accountException(Exception exception) { - if (exception instanceof InvalidCredentialsException) { - return Launcher.i18n("account.failed.invalid_credentials"); - } else if (exception instanceof NoCharacterException) { - return Launcher.i18n("account.failed.no_charactor"); + if (exception instanceof NoCharacterException) { + return Launcher.i18n("account.failed.no_character"); } else if (exception instanceof ServerDisconnectException) { return Launcher.i18n("account.failed.connect_authentication_server"); - } else if (exception instanceof InvalidTokenException) { - return Launcher.i18n("account.failed.invalid_token"); - } else if (exception instanceof InvalidPasswordException) { - return Launcher.i18n("account.failed.invalid_password"); + } else if (exception instanceof RemoteAuthenticationException) { + RemoteAuthenticationException remoteException = (RemoteAuthenticationException) exception; + String remoteMessage = remoteException.getRemoteMessage(); + if ("ForbiddenOperationException".equals(remoteException.getRemoteName()) && remoteMessage != null) { + if (remoteMessage.contains("Invalid credentials")) + return Launcher.i18n("account.failed.invalid_credentials"); + else if (remoteMessage.contains("Invalid token")) + return Launcher.i18n("account.failed.invalid_token"); + else if (remoteMessage.contains("Invalid username or password")) + return Launcher.i18n("account.failed.invalid_password"); + } + return exception.getMessage(); } else { return exception.getClass() + ": " + exception.getLocalizedMessage(); } diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index ae9d4098d..6ac579604 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -38,7 +38,7 @@ account.failed.connect_authentication_server=Cannot connect to the authenticatio account.failed.invalid_credentials=Incorrect password, or you are forbidden to login temporarily. account.failed.invalid_password=Invalid password account.failed.invalid_token=Please log out and re-input your password to login. -account.failed.no_charactor=No character in this account. +account.failed.no_character=No character in this account. account.failed.no_selected_server=No authentication server is selected. account.failed.connect_injector_server=Cannot connect to the authentication server. Check your network and ensure the URL is correct. account.injector.add=Add authentication server 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 bb41a354e..fbd0332fb 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -38,7 +38,7 @@ account.failed.connect_authentication_server=无法连接认证服务器,可能 account.failed.invalid_credentials=您的用户名或密码错误,或者登录次数过多被暂时禁止登录,请稍后再试 account.failed.invalid_password=无效的密码 account.failed.invalid_token=请尝试登出并重新输入密码登录 -account.failed.no_charactor=该帐号没有角色 +account.failed.no_character=该帐号没有角色 account.failed.no_selected_server=未选择认证服务器 account.failed.connect_injector_server=无法连接认证服务器,可能是网络故障或 URL 输入错误 account.injector.add=添加认证服务器 diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/InvalidCredentialsException.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/InvalidCredentialsException.java deleted file mode 100644 index f443e287f..000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/InvalidCredentialsException.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Hello Minecraft! Launcher. - * Copyright (C) 2018 huangyuhui - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see {http://www.gnu.org/licenses/}. - */ -package org.jackhuang.hmcl.auth; - -/** - * throws if wrong password or logging fails for too many times. - * @author huangyuhui - */ -public final class InvalidCredentialsException extends AuthenticationException { -} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/InvalidPasswordException.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/InvalidPasswordException.java deleted file mode 100644 index ffc0d6356..000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/InvalidPasswordException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Hello Minecraft! Launcher. - * Copyright (C) 2018 huangyuhui - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see {http://www.gnu.org/licenses/}. - */ -package org.jackhuang.hmcl.auth; - -/** - * throws if wrong password. - */ -public class InvalidPasswordException extends AuthenticationException { -} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/InvalidTokenException.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/InvalidTokenException.java deleted file mode 100644 index 8e95724ee..000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/InvalidTokenException.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Hello Minecraft! Launcher. - * Copyright (C) 2018 huangyuhui - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see {http://www.gnu.org/licenses/}. - */ -package org.jackhuang.hmcl.auth; - -/** - * - * @author huangyuhui - */ -public class InvalidTokenException extends AuthenticationException { -} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilService.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilService.java index aa9fefbc1..8c2c68612 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilService.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilService.java @@ -83,7 +83,7 @@ public class YggdrasilService { try { requireEmpty(request(provider.getValidationURL(), createRequestWithCredentials(accessToken, clientToken))); return true; - } catch (InvalidCredentialsException | InvalidTokenException e) { + } catch (RemoteAuthenticationException e) { return false; } } @@ -145,17 +145,6 @@ public class YggdrasilService { private static void handleErrorMessage(ErrorResponse response) throws AuthenticationException { if (!StringUtils.isBlank(response.error)) { - if (response.errorMessage != null && "ForbiddenOperationException".equals(response.error)) { - if (response.errorMessage.contains("Invalid credentials")) - throw new InvalidCredentialsException(); - - else if (response.errorMessage.contains("Invalid token")) - throw new InvalidTokenException(); - - else if (response.errorMessage.contains("Invalid username or password")) - throw new InvalidPasswordException(); - } - throw new RemoteAuthenticationException(response.error, response.errorMessage, response.cause); } }