Warn if username is invalid when creating a offline account. 在离线账户创建时对不合法的账户名做出警告 (#2309)
* Fix #2258 * Fix checkstyle * Merge official branch into current branch and fix checkstyle
This commit is contained in:
@@ -56,7 +56,6 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -69,6 +69,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
@@ -80,6 +81,7 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||
import static org.jackhuang.hmcl.util.javafx.ExtendedProperties.classPropertyFor;
|
||||
|
||||
public class CreateAccountPane extends JFXDialogLayout implements DialogAware {
|
||||
private static final Pattern USERNAME_CHECKER_PATTERN = Pattern.compile("^[A-Za-z0-9_]+$");
|
||||
|
||||
private boolean showMethodSwitcher;
|
||||
private AccountFactory<?> factory;
|
||||
@@ -222,35 +224,50 @@ public class CreateAccountPane extends JFXDialogLayout implements DialogAware {
|
||||
additionalData = null;
|
||||
}
|
||||
|
||||
logging.set(true);
|
||||
deviceCode.set(null);
|
||||
if (factory instanceof OfflineAccountFactory && username != null) {
|
||||
if (!USERNAME_CHECKER_PATTERN.matcher(username).matches()) {
|
||||
Controllers.confirm(
|
||||
i18n("account.methods.offline.name.invalid"), i18n("message.warning"),
|
||||
MessageDialogPane.MessageType.WARNING,
|
||||
() -> {
|
||||
logging.set(true);
|
||||
deviceCode.set(null);
|
||||
|
||||
loginTask = Task.supplyAsync(() -> factory.create(new DialogCharacterSelector(), username, password, null, additionalData))
|
||||
.whenComplete(Schedulers.javafx(), account -> {
|
||||
int oldIndex = Accounts.getAccounts().indexOf(account);
|
||||
if (oldIndex == -1) {
|
||||
Accounts.getAccounts().add(account);
|
||||
} else {
|
||||
// adding an already-added account
|
||||
// instead of discarding the new account, we first remove the existing one then add the new one
|
||||
Accounts.getAccounts().remove(oldIndex);
|
||||
Accounts.getAccounts().add(oldIndex, account);
|
||||
}
|
||||
loginTask = Task.supplyAsync(() -> factory.create(new DialogCharacterSelector(), username, password, null, additionalData))
|
||||
.whenComplete(Schedulers.javafx(), account -> {
|
||||
int oldIndex = Accounts.getAccounts().indexOf(account);
|
||||
if (oldIndex == -1) {
|
||||
Accounts.getAccounts().add(account);
|
||||
} else {
|
||||
// adding an already-added account
|
||||
// instead of discarding the new account, we first remove the existing one then add the new one
|
||||
Accounts.getAccounts().remove(oldIndex);
|
||||
Accounts.getAccounts().add(oldIndex, account);
|
||||
}
|
||||
|
||||
// select the new account
|
||||
Accounts.setSelectedAccount(account);
|
||||
// select the new account
|
||||
Accounts.setSelectedAccount(account);
|
||||
|
||||
spinner.hideSpinner();
|
||||
fireEvent(new DialogCloseEvent());
|
||||
}, exception -> {
|
||||
if (exception instanceof NoSelectedCharacterException) {
|
||||
fireEvent(new DialogCloseEvent());
|
||||
} else {
|
||||
lblErrorMessage.setText(Accounts.localizeErrorMessage(exception));
|
||||
}
|
||||
body.setDisable(false);
|
||||
spinner.hideSpinner();
|
||||
}).executor(true);
|
||||
spinner.hideSpinner();
|
||||
fireEvent(new DialogCloseEvent());
|
||||
}, exception -> {
|
||||
if (exception instanceof NoSelectedCharacterException) {
|
||||
fireEvent(new DialogCloseEvent());
|
||||
} else {
|
||||
lblErrorMessage.setText(Accounts.localizeErrorMessage(exception));
|
||||
}
|
||||
body.setDisable(false);
|
||||
spinner.hideSpinner();
|
||||
}).executor(true);
|
||||
},
|
||||
() -> {
|
||||
lblErrorMessage.setText(i18n("account.methods.offline.name.invalid"));
|
||||
body.setDisable(false);
|
||||
spinner.hideSpinner();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onCancel() {
|
||||
|
||||
@@ -116,6 +116,10 @@ account.methods.microsoft.snapshot=You are using an unofficial build of HMCL. Pl
|
||||
account.methods.microsoft.snapshot.website=Official Website
|
||||
account.methods.offline=Offline
|
||||
account.methods.offline.name.special_characters=Recommended to use letters, numbers and underscores for naming
|
||||
account.methods.offline.name.invalid=Under normal circumstances, the game username can only contain English characters, numbers and underscores, and the length cannot exceed 16 characters. \n\
|
||||
Some legitimate usernames: HuangYu, huang_Yu, Huang_Yu_123;\n\
|
||||
Some illegal usernames: Huang Yu, Huang-Yu_%%%, Huang_Yu_hello_world_hello_world. \n\
|
||||
If you believe that there is a corresponding mod or plugin on the server side to remove this restriction, you can ignore this warning.
|
||||
account.methods.offline.uuid=UUID
|
||||
account.methods.offline.uuid.hint=UUID is the unique identifier for the game character in Minecraft. The way that it is generated might vary between different game launchers. Changing it to the one generated by other launchers allows you to keep your items in your offline account inventory.\n\
|
||||
\n\
|
||||
|
||||
@@ -131,6 +131,10 @@ account.methods.microsoft.snapshot=你正在使用非官方構建的 HMCL,請
|
||||
account.methods.microsoft.snapshot.website=官方網站
|
||||
account.methods.offline=離線模式
|
||||
account.methods.offline.name.special_characters=建議使用英文字符、數字以及下劃線命名
|
||||
account.methods.offline.name.invalid=正常情況下,遊戲用戶名只能包括英文字符、數字以及下劃線,且長度不能超過 16 個字符。 \n\
|
||||
一些合法的用戶名:HuangYu,huang_Yu,Huang_Yu_123;\n\
|
||||
一些不合法的用戶名:黃魚,Huang Yu,Huang-Yu_%%%,Huang_Yu_hello_world_hello_world。 \n\
|
||||
如果你相信服務器端有相應的 Mod 或插件來解除此限制,你可以忽略本警告。
|
||||
account.methods.offline.uuid=UUID
|
||||
account.methods.offline.uuid.hint=UUID 是 Minecraft 對玩家角色的唯一標識符,每個啟動器生成 UUID 的方式可能不同。通過修改 UUID 選項至原啟動器所生成的 UUID,你可以保證在切換啟動器後,遊戲還能將你的遊戲角色識別為給定 UUID 所對應的角色,從而保留原來角色的背包物品。UUID 選項為高級選項,除非你知道你在做什麼,否則你不需要調整該選項。
|
||||
account.methods.offline.uuid.malformed=格式錯誤
|
||||
|
||||
@@ -130,6 +130,10 @@ account.methods.microsoft.snapshot=你正在使用非官方构建的 HMCL,请
|
||||
account.methods.microsoft.snapshot.website=官方网站
|
||||
account.methods.offline=离线模式
|
||||
account.methods.offline.name.special_characters=建议使用英文字符、数字以及下划线命名
|
||||
account.methods.offline.name.invalid=正常情况下,游戏用户名只能包括英文字符、数字以及下划线,且长度不能超过 16 个字符。\n\
|
||||
一些合法的用户名:HuangYu,huang_Yu,Huang_Yu_123;\n\
|
||||
一些不合法的用户名:黄鱼,Huang Yu,Huang-Yu_%%%,Huang_Yu_hello_world_hello_world。\n\
|
||||
如果你相信服务器端有相应的 Mod 或插件来解除此限制,你可以忽略本警告。
|
||||
account.methods.offline.uuid=UUID
|
||||
account.methods.offline.uuid.hint=UUID 是 Minecraft 对玩家角色的唯一标识符,每个启动器生成 UUID 的方式可能不同。通过修改 UUID 选项至原启动器所生成的 UUID,你可以保证在切换启动器后,游戏还能将你的游戏角色识别为给定 UUID 所对应的角色,从而保留原来角色的背包物品。UUID 选项为高级选项,除非你知道你在做什么,否则你不需要调整该选项。
|
||||
account.methods.offline.uuid.malformed=格式错误
|
||||
|
||||
Reference in New Issue
Block a user