Skip to content

Commit

Permalink
Add an option that allows non ascii username to login (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Dec 2, 2023
1 parent e480819 commit c4591f4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.izzel.arclight.common.bridge.core.network.NetworkManagerBridge;
import io.izzel.arclight.common.bridge.core.server.MinecraftServerBridge;
import io.izzel.arclight.common.bridge.core.server.management.PlayerListBridge;
import io.izzel.arclight.i18n.ArclightConfig;
import net.minecraft.DefaultUncaughtExceptionHandler;
import net.minecraft.core.UUIDUtil;
import net.minecraft.network.Connection;
Expand Down Expand Up @@ -132,6 +133,11 @@ public void handleAcceptedLogin() {
}
}

private static boolean arclight$validUsernameCheck(String name) {
var regex = ArclightConfig.spec().getCompat().getValidUsernameRegex();
return !regex.isBlank() && name.matches(regex);
}

/**
* @author IzzelAliz
* @reason
Expand All @@ -140,7 +146,7 @@ public void handleAcceptedLogin() {
public void handleHello(ServerboundHelloPacket packetIn) {
Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet");
Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet");
Validate.validState(isValidUsername(packetIn.name()), "Invalid characters in username");
Validate.validState(arclight$validUsernameCheck(packetIn.name()) || isValidUsername(packetIn.name()), "Invalid characters in username");
this.profilePublicKeyData = packetIn.publicKey().orElse(null);
GameProfile gameprofile = this.server.getSingleplayerProfile();
if (gameprofile != null && packetIn.name().equalsIgnoreCase(gameprofile.getName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class CompatSpec {
@Setting("forward-permission")
private String forwardPermission;

@Setting("valid-username-regex")
private String validUsernameRegex;

public Map<String, MaterialPropertySpec> getMaterials() {
return materials;
}
Expand Down Expand Up @@ -57,4 +60,8 @@ public boolean isForwardPermission() {
public boolean isForwardPermissionReverse() {
return Objects.equals(forwardPermission, "reverse");
}

public String getValidUsernameRegex() {
return validUsernameRegex;
}
}
1 change: 1 addition & 0 deletions i18n-config/src/main/resources/META-INF/arclight.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ compatibility {
"com.example.mod.ExtraLogicWorld"
]
forward-permission = true
valid-username-regex = ""
}
async-catcher {
dump = true
Expand Down
7 changes: 7 additions & 0 deletions i18n-config/src/main/resources/META-INF/i18n/en_us.conf
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,12 @@ comments {
"false - Disable permission forward"
"reverse - Forward Bukkit player perimission query to Forge"
]
valid-username-regex.comment = [
"Regex for valid username check. Leave it blank will fallback to vanilla check"
"Following allows Chinese characters:"
"valid-username-regex = \"^[ -~\\\\p{sc=Han}]{1,16}$\""
"Following allows any username to login:"
"valid-username-regex = \".+\""
]
}
}
7 changes: 7 additions & 0 deletions i18n-config/src/main/resources/META-INF/i18n/zh_cn.conf
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,12 @@ comments {
"false - 不启用权限转发"
"reverse - 将 Bukkit 玩家权限查询请求转发至 Forge"
]
valid-username-regex.comment = [
"用户名合法检查正则表达式,留空为使用原版检查"
"如果需要允许中文字符可以使用"
"valid-username-regex = \"^[ -~\\p{sc=Han}]{1,16}$\""
"如果允许任何用户名可以使用"
"valid-username-regex = \".+\""
]
}
}

0 comments on commit c4591f4

Please sign in to comment.