Skip to content

Commit 165ded6

Browse files
committed
Added support for wildcard domains
1 parent 179a7ea commit 165ded6

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/main/java/net/lenni0451/miniconnect/server/LobbyServerHandler.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
import net.lenni0451.miniconnect.utils.ChannelUtils;
1414
import net.raphimc.netminecraft.constants.ConnectionState;
1515
import net.raphimc.netminecraft.packet.Packet;
16+
import net.raphimc.viaproxy.util.WildcardDomainParser;
1617
import net.raphimc.viaproxy.util.logging.Logger;
1718

19+
import java.net.InetSocketAddress;
1820
import java.nio.channels.ClosedChannelException;
1921
import java.util.UUID;
2022
import java.util.concurrent.TimeUnit;
@@ -44,6 +46,7 @@ public void loadPlayerConfig(final Channel channel, final UUID uuid) {
4446
this.playerConfig.handshakeAddress = handshakeData.host();
4547
this.playerConfig.handshakePort = handshakeData.port();
4648
this.playerConfig.clientVersion = handshakeData.clientVersion();
49+
this.checkHandshakeAddress();
4750
}
4851

4952
public PlayerConfig getPlayerConfig() {
@@ -89,4 +92,25 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
8992
ctx.close();
9093
}
9194

95+
private void checkHandshakeAddress() {
96+
String handshakeAddress = this.playerConfig.handshakeAddress;
97+
if (handshakeAddress.toLowerCase().contains("f2.viaproxy.")) { // Format 2: address.<address>.port.<port>.version.<version>.f2.viaproxy.hostname
98+
WildcardDomainParser.ParsedDomain parsedDomain = WildcardDomainParser.parseFormat2(handshakeAddress);
99+
if (parsedDomain != null && parsedDomain.version() != null) {
100+
InetSocketAddress socketAddress = (InetSocketAddress) parsedDomain.address();
101+
this.playerConfig.serverAddress = socketAddress.getHostString();
102+
this.playerConfig.serverPort = socketAddress.getPort();
103+
this.playerConfig.targetVersion = parsedDomain.version();
104+
}
105+
} else if (handshakeAddress.toLowerCase().contains("viaproxy.")) { // Format 1: address_port_version.viaproxy.hostname
106+
WildcardDomainParser.ParsedDomain parsedDomain = WildcardDomainParser.parseFormat1(handshakeAddress);
107+
if (parsedDomain != null && parsedDomain.version() != null) {
108+
InetSocketAddress socketAddress = (InetSocketAddress) parsedDomain.address();
109+
this.playerConfig.serverAddress = socketAddress.getHostString();
110+
this.playerConfig.serverPort = socketAddress.getPort();
111+
this.playerConfig.targetVersion = parsedDomain.version();
112+
}
113+
}
114+
}
115+
92116
}

src/main/java/net/lenni0451/miniconnect/server/states/play/Tutorial.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ After setting all required options (server address, version) you can connect by
5555
When on a server, you can type §2/disconnect§r in the chat to disconnect.
5656
After disconnecting, you will automatically be placed into the lobby again.
5757
All your settings will be retained until you disconnect.
58-
"""
58+
""",
59+
"""
60+
§6§l§oWildcard domains
61+
62+
MiniConnect supports the same wildcard domain format as ViaProxy itself.
63+
Example: §2example.com_25565_1.8.viaproxy.example.com
64+
This autofills the server address and version automatically."""
5965
);
6066

6167
private static FilterableComponent[] buildTutorial(final String... pages) {

0 commit comments

Comments
 (0)