Changed to Auto Detect if version is not specified in wildcard-domain

This commit is contained in:
Kamesuta 2025-01-12 19:13:00 +09:00
parent 625cbf147e
commit 118af38576
No known key found for this signature in database
GPG key ID: 62D73B99C24685B6
2 changed files with 10 additions and 5 deletions
src/main/java/net/raphimc/viaproxy
protocoltranslator/viaproxy
proxy/client2proxy

View file

@ -168,7 +168,7 @@ public class ViaProxyConfig {
@Description({
"Allows clients to specify a target server and version using wildcard domains.",
"none: No wildcard domain handling.",
"public: Public wildcard domain handling. Intended for usage by external clients. (Example: address.<address>.port.<port>.version.<version>.viaproxy.127.0.0.1.nip.io)",
"public: Public wildcard domain handling. Intended for usage by external clients. (Example: address.<address>.port.<port>.version.<version>.viaproxy.127.0.0.1.nip.io (version is optional))",
"internal: Internal wildcard domain handling. Intended for local usage by custom clients. (Example: original-handshake-address\\7address:port\\7version\\7classic-mppass)"
})
private WildcardDomainHandling wildcardDomainHandling = WildcardDomainHandling.NONE;

View file

@ -67,7 +67,7 @@ import java.util.regex.Pattern;
public class Client2ProxyHandler extends SimpleChannelInboundHandler<Packet> {
private static final Pattern ADDRESS_SYNTAX_PATTERN = Pattern.compile(
"^address\\.(.+?)\\.port\\.(\\d+?)\\.version\\.(.+?)$"
"^address\\.(.+?)\\.port\\.(\\d+?)(?:\\.version\\.(.+?))?$"
);
private ProxyConnection proxyConnection;
@ -161,9 +161,14 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<Packet> {
final int connectPort = Integer.parseInt(matcher.group(2));
final String versionString = matcher.group(3);
serverVersion = ProtocolVersionUtil.fromNameLenient(versionString);
if (serverVersion == null) {
this.proxyConnection.kickClient("§cWrong domain syntax!\n§cUnknown server version.");
if (versionString != null) {
serverVersion = ProtocolVersionUtil.fromNameLenient(versionString);
if (serverVersion == null) {
this.proxyConnection.kickClient("§cWrong domain syntax!\n§cUnknown server version.");
}
} else {
// When no version is specified, use the auto-detect protocol
serverVersion = ProtocolTranslator.AUTO_DETECT_PROTOCOL;
}
serverAddress = AddressUtil.parse(connectAddress + ":" + connectPort, serverVersion);