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 0e274f59a..13f49eb80 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AddAccountPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/AddAccountPane.java @@ -125,34 +125,51 @@ public class AddAccountPane extends StackPane { @FXML private void onCreationAccept() { - int type = cboType.getSelectionModel().getSelectedIndex(); String username = txtUsername.getText(); String password = txtPassword.getText(); - String apiRoot = Optional.ofNullable(cboServers.getSelectionModel().getSelectedItem()).map(AuthlibInjectorServer::getUrl).orElse(null); + Object addtionalData; + + int type = cboType.getSelectionModel().getSelectedIndex(); + AccountFactory factory; + switch (type) { + case 0: + factory = Accounts.ACCOUNT_FACTORY.get(Accounts.OFFLINE_ACCOUNT_KEY); + addtionalData = null; + break; + case 1: + factory = Accounts.ACCOUNT_FACTORY.get(Accounts.YGGDRASIL_ACCOUNT_KEY); + addtionalData = null; + break; + case 2: + factory = Accounts.ACCOUNT_FACTORY.get(Accounts.AUTHLIB_INJECTOR_ACCOUNT_KEY); + Optional server = Optional.ofNullable(cboServers.getSelectionModel().getSelectedItem()); + if (server.isPresent()) { + addtionalData = server.get().getUrl(); + } else { + lblCreationWarning.setText(Launcher.i18n("account.failed.no_selected_server")); + return; + } + break; + default: + throw new Error(); + } + showSpinner(); lblCreationWarning.setText(""); - Task.ofResult("create_account", () -> { - AccountFactory factory; - switch (type) { - case 0: factory = Accounts.ACCOUNT_FACTORY.get(Accounts.OFFLINE_ACCOUNT_KEY); break; - case 1: factory = Accounts.ACCOUNT_FACTORY.get(Accounts.YGGDRASIL_ACCOUNT_KEY); break; - case 2: factory = Accounts.ACCOUNT_FACTORY.get(Accounts.AUTHLIB_INJECTOR_ACCOUNT_KEY); break; - default: throw new Error(); - } - return factory.create(new Selector(), username, password, apiRoot, Settings.INSTANCE.getProxy()); - }).finalized(Schedulers.javafx(), variables -> { - Settings.INSTANCE.addAccount(variables.get("create_account")); - hideSpinner(); - finalization.accept(this); - }, exception -> { - if (exception instanceof NoSelectedCharacterException) { - finalization.accept(this); - } else { - lblCreationWarning.setText(accountException(exception)); - } - hideSpinner(); - }).start(); + Task.ofResult("create_account", () -> factory.create(new Selector(), username, password, addtionalData, Settings.INSTANCE.getProxy())) + .finalized(Schedulers.javafx(), variables -> { + Settings.INSTANCE.addAccount(variables.get("create_account")); + hideSpinner(); + finalization.accept(this); + }, exception -> { + if (exception instanceof NoSelectedCharacterException) { + finalization.accept(this); + } else { + lblCreationWarning.setText(accountException(exception)); + } + hideSpinner(); + }).start(); } @FXML diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index ad46e0e54..ce380d777 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -39,6 +39,7 @@ account.failed.invalid_credentials=Incorrect password. Or forbidden to log in te account.failed.invalid_password=Invalid password account.failed.invalid_token=Please log out and re-input your password to log in. account.failed.no_charactor=No character in this account. +account.failed.no_selected_server=No authentication server is selected. account.injector.add=Add authentication server account.injector.manage=Manage authentication servers account.injector.http=Warning: This server is using HTTP, which will cause your password be transmitted in clear text. 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 cadd3af9d..2473ea9ac 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -39,6 +39,7 @@ account.failed.invalid_credentials=您的用户名或密码错误,或者登录 account.failed.invalid_password=无效的密码 account.failed.invalid_token=请尝试登出并重新输入密码登录 account.failed.no_charactor=该帐号没有角色 +account.failed.no_selected_server=未选择认证服务器 account.injector.add=添加认证服务器 account.injector.manage=管理认证服务器 account.injector.http=警告:此服务器使用不安全的http协议,您的密码在登录时会被明文传输。