|
13 | 13 | import net.lenni0451.miniconnect.utils.ChannelUtils; |
14 | 14 | import net.raphimc.netminecraft.constants.ConnectionState; |
15 | 15 | import net.raphimc.netminecraft.packet.Packet; |
| 16 | +import net.raphimc.viaproxy.util.WildcardDomainParser; |
16 | 17 | import net.raphimc.viaproxy.util.logging.Logger; |
17 | 18 |
|
| 19 | +import java.net.InetSocketAddress; |
18 | 20 | import java.nio.channels.ClosedChannelException; |
19 | 21 | import java.util.UUID; |
20 | 22 | import java.util.concurrent.TimeUnit; |
@@ -44,6 +46,7 @@ public void loadPlayerConfig(final Channel channel, final UUID uuid) { |
44 | 46 | this.playerConfig.handshakeAddress = handshakeData.host(); |
45 | 47 | this.playerConfig.handshakePort = handshakeData.port(); |
46 | 48 | this.playerConfig.clientVersion = handshakeData.clientVersion(); |
| 49 | + this.checkHandshakeAddress(); |
47 | 50 | } |
48 | 51 |
|
49 | 52 | public PlayerConfig getPlayerConfig() { |
@@ -89,4 +92,25 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { |
89 | 92 | ctx.close(); |
90 | 93 | } |
91 | 94 |
|
| 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 | + |
92 | 116 | } |
0 commit comments