mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2025-01-17 20:41:53 +01:00
Readd internal wildcard domain handling
This commit is contained in:
parent
43732f22e3
commit
0c04ac45d9
@ -44,6 +44,7 @@ public class Options {
|
|||||||
public static SocketAddress BIND_ADDRESS;
|
public static SocketAddress BIND_ADDRESS;
|
||||||
public static SocketAddress CONNECT_ADDRESS;
|
public static SocketAddress CONNECT_ADDRESS;
|
||||||
public static ProtocolVersion PROTOCOL_VERSION;
|
public static ProtocolVersion PROTOCOL_VERSION;
|
||||||
|
public static boolean OPENAUTHMOD_AUTH;
|
||||||
public static boolean ONLINE_MODE;
|
public static boolean ONLINE_MODE;
|
||||||
public static boolean BETACRAFT_AUTH;
|
public static boolean BETACRAFT_AUTH;
|
||||||
public static Account MC_ACCOUNT;
|
public static Account MC_ACCOUNT;
|
||||||
@ -55,6 +56,7 @@ public class Options {
|
|||||||
|
|
||||||
public static int COMPRESSION_THRESHOLD = 256;
|
public static int COMPRESSION_THRESHOLD = 256;
|
||||||
public static boolean SRV_MODE;
|
public static boolean SRV_MODE;
|
||||||
|
public static boolean INTERNAL_SRV_MODE;
|
||||||
public static String RESOURCE_PACK_URL;
|
public static String RESOURCE_PACK_URL;
|
||||||
public static boolean SERVER_HAPROXY_PROTOCOL;
|
public static boolean SERVER_HAPROXY_PROTOCOL;
|
||||||
public static boolean LEGACY_CLIENT_PASSTHROUGH;
|
public static boolean LEGACY_CLIENT_PASSTHROUGH;
|
||||||
@ -76,6 +78,7 @@ public class Options {
|
|||||||
final OptionSpec<String> connectAddress = parser.acceptsAll(asList("connect_address", "target_ip", "ca", "a"), "The address of the target server").withRequiredArg().ofType(String.class).required();
|
final OptionSpec<String> connectAddress = parser.acceptsAll(asList("connect_address", "target_ip", "ca", "a"), "The address of the target server").withRequiredArg().ofType(String.class).required();
|
||||||
final OptionSpec<ProtocolVersion> version = parser.acceptsAll(asList("version", "v"), "The version of the target server").withRequiredArg().withValuesConvertedBy(new ProtocolVersionConverter()).required();
|
final OptionSpec<ProtocolVersion> version = parser.acceptsAll(asList("version", "v"), "The version of the target server").withRequiredArg().withValuesConvertedBy(new ProtocolVersionConverter()).required();
|
||||||
final OptionSpec<Void> srvMode = parser.acceptsAll(asList("srv_mode", "srv", "s"), "Enable srv mode");
|
final OptionSpec<Void> srvMode = parser.acceptsAll(asList("srv_mode", "srv", "s"), "Enable srv mode");
|
||||||
|
final OptionSpec<Void> iSrvMode = parser.acceptsAll(asList("internal_srv_mode", "isrv"), "Enable internal srv mode").availableUnless(srvMode);
|
||||||
final OptionSpec<Void> proxyOnlineMode = parser.acceptsAll(asList("online_mode", "om", "o"), "Enable proxy online mode");
|
final OptionSpec<Void> proxyOnlineMode = parser.acceptsAll(asList("online_mode", "om", "o"), "Enable proxy online mode");
|
||||||
final OptionSpec<Integer> compressionThreshold = parser.acceptsAll(asList("compression_threshold", "ct", "c"), "The threshold for packet compression").withRequiredArg().ofType(Integer.class).defaultsTo(COMPRESSION_THRESHOLD);
|
final OptionSpec<Integer> compressionThreshold = parser.acceptsAll(asList("compression_threshold", "ct", "c"), "The threshold for packet compression").withRequiredArg().ofType(Integer.class).defaultsTo(COMPRESSION_THRESHOLD);
|
||||||
final OptionSpec<Void> openAuthModAuth = parser.acceptsAll(asList("openauthmod_auth", "oam_auth"), "Use OpenAuthMod for joining online mode servers");
|
final OptionSpec<Void> openAuthModAuth = parser.acceptsAll(asList("openauthmod_auth", "oam_auth"), "Use OpenAuthMod for joining online mode servers");
|
||||||
@ -103,6 +106,8 @@ public class Options {
|
|||||||
BIND_ADDRESS = AddressUtil.parse(options.valueOf(bindAddress), null);
|
BIND_ADDRESS = AddressUtil.parse(options.valueOf(bindAddress), null);
|
||||||
CONNECT_ADDRESS = AddressUtil.parse(options.valueOf(connectAddress), PROTOCOL_VERSION);
|
CONNECT_ADDRESS = AddressUtil.parse(options.valueOf(connectAddress), PROTOCOL_VERSION);
|
||||||
SRV_MODE = options.has(srvMode);
|
SRV_MODE = options.has(srvMode);
|
||||||
|
INTERNAL_SRV_MODE = options.has(iSrvMode);
|
||||||
|
OPENAUTHMOD_AUTH = options.has(openAuthModAuth);
|
||||||
ONLINE_MODE = options.has(proxyOnlineMode);
|
ONLINE_MODE = options.has(proxyOnlineMode);
|
||||||
COMPRESSION_THRESHOLD = options.valueOf(compressionThreshold);
|
COMPRESSION_THRESHOLD = options.valueOf(compressionThreshold);
|
||||||
if (options.has(guiAccountIndex)) {
|
if (options.has(guiAccountIndex)) {
|
||||||
@ -164,10 +169,11 @@ public class Options {
|
|||||||
config.setChatSigning(CHAT_SIGNING);
|
config.setChatSigning(CHAT_SIGNING);
|
||||||
config.setCompressionThreshold(COMPRESSION_THRESHOLD);
|
config.setCompressionThreshold(COMPRESSION_THRESHOLD);
|
||||||
config.setResourcePackUrl(RESOURCE_PACK_URL);
|
config.setResourcePackUrl(RESOURCE_PACK_URL);
|
||||||
config.setSrvMode(SRV_MODE);
|
config.setWildcardDomainHandling(SRV_MODE ? ViaProxyConfig.WildcardDomainHandling.PUBLIC : INTERNAL_SRV_MODE ? ViaProxyConfig.WildcardDomainHandling.INTERNAL : ViaProxyConfig.WildcardDomainHandling.NONE);
|
||||||
config.setAllowBetaPinging(ALLOW_BETA_PINGING);
|
config.setAllowBetaPinging(ALLOW_BETA_PINGING);
|
||||||
config.setIgnoreProtocolTranslationErrors(IGNORE_PACKET_TRANSLATION_ERRORS);
|
config.setIgnoreProtocolTranslationErrors(IGNORE_PACKET_TRANSLATION_ERRORS);
|
||||||
config.setAllowLegacyClientPassthrough(LEGACY_CLIENT_PASSTHROUGH);
|
config.setAllowLegacyClientPassthrough(LEGACY_CLIENT_PASSTHROUGH);
|
||||||
|
config.setAuthMethod(OPENAUTHMOD_AUTH ? ViaProxyConfig.AuthMethod.OPENAUTHMOD : ViaProxyConfig.AuthMethod.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadFromConfig(final ViaProxyConfig config) {
|
public static void loadFromConfig(final ViaProxyConfig config) {
|
||||||
@ -185,7 +191,8 @@ public class Options {
|
|||||||
IGNORE_PACKET_TRANSLATION_ERRORS = config.shouldIgnoreProtocolTranslationErrors();
|
IGNORE_PACKET_TRANSLATION_ERRORS = config.shouldIgnoreProtocolTranslationErrors();
|
||||||
LEGACY_CLIENT_PASSTHROUGH = config.shouldAllowLegacyClientPassthrough();
|
LEGACY_CLIENT_PASSTHROUGH = config.shouldAllowLegacyClientPassthrough();
|
||||||
RESOURCE_PACK_URL = config.getResourcePackUrl();
|
RESOURCE_PACK_URL = config.getResourcePackUrl();
|
||||||
SRV_MODE = config.isSrvMode();
|
SRV_MODE = config.getWildcardDomainHandling() == ViaProxyConfig.WildcardDomainHandling.PUBLIC;
|
||||||
|
INTERNAL_SRV_MODE = config.getWildcardDomainHandling() == ViaProxyConfig.WildcardDomainHandling.INTERNAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion.
|
|||||||
private boolean ignoreProtocolTranslationErrors;
|
private boolean ignoreProtocolTranslationErrors;
|
||||||
private boolean allowLegacyClientPassthrough;
|
private boolean allowLegacyClientPassthrough;
|
||||||
private String resourcePackUrl;
|
private String resourcePackUrl;
|
||||||
private boolean srvMode;
|
private WildcardDomainHandling wildcardDomainHandling;
|
||||||
|
|
||||||
public ViaProxyConfig(final File configFile) {
|
public ViaProxyConfig(final File configFile) {
|
||||||
super(configFile);
|
super(configFile);
|
||||||
@ -103,7 +103,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion.
|
|||||||
this.ignoreProtocolTranslationErrors = this.getBoolean("ignore-protocol-translation-errors", false);
|
this.ignoreProtocolTranslationErrors = this.getBoolean("ignore-protocol-translation-errors", false);
|
||||||
this.allowLegacyClientPassthrough = this.getBoolean("allow-legacy-client-passthrough", false);
|
this.allowLegacyClientPassthrough = this.getBoolean("allow-legacy-client-passthrough", false);
|
||||||
this.resourcePackUrl = this.getString("resource-pack-url", "");
|
this.resourcePackUrl = this.getString("resource-pack-url", "");
|
||||||
this.srvMode = this.getBoolean("srv-mode", false);
|
this.wildcardDomainHandling = WildcardDomainHandling.byName(this.getString("wildcard-domain-handling", "none"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -265,13 +265,13 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion.
|
|||||||
this.set("resource-pack-url", resourcePackUrl);
|
this.set("resource-pack-url", resourcePackUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSrvMode() {
|
public WildcardDomainHandling getWildcardDomainHandling() {
|
||||||
return this.srvMode;
|
return this.wildcardDomainHandling;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSrvMode(final boolean srvMode) {
|
public void setWildcardDomainHandling(final WildcardDomainHandling wildcardDomainHandling) {
|
||||||
this.srvMode = srvMode;
|
this.wildcardDomainHandling = wildcardDomainHandling;
|
||||||
this.set("srv-mode", srvMode);
|
this.set("wildcard-domain-handling", wildcardDomainHandling.name().toLowerCase(Locale.ROOT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum AuthMethod {
|
public enum AuthMethod {
|
||||||
@ -311,4 +311,31 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion.
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum WildcardDomainHandling {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* No wildcard domain handling
|
||||||
|
*/
|
||||||
|
NONE,
|
||||||
|
/**
|
||||||
|
* Public wildcard domain handling
|
||||||
|
*/
|
||||||
|
PUBLIC,
|
||||||
|
/**
|
||||||
|
* Iternal wildcard domain handling
|
||||||
|
*/
|
||||||
|
INTERNAL;
|
||||||
|
|
||||||
|
public static WildcardDomainHandling byName(String name) {
|
||||||
|
for (WildcardDomainHandling mode : values()) {
|
||||||
|
if (mode.name().equalsIgnoreCase(name)) {
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ import net.raphimc.viaproxy.plugins.events.PreConnectEvent;
|
|||||||
import net.raphimc.viaproxy.plugins.events.Proxy2ServerHandlerCreationEvent;
|
import net.raphimc.viaproxy.plugins.events.Proxy2ServerHandlerCreationEvent;
|
||||||
import net.raphimc.viaproxy.plugins.events.ProxySessionCreationEvent;
|
import net.raphimc.viaproxy.plugins.events.ProxySessionCreationEvent;
|
||||||
import net.raphimc.viaproxy.protocoltranslator.ProtocolTranslator;
|
import net.raphimc.viaproxy.protocoltranslator.ProtocolTranslator;
|
||||||
|
import net.raphimc.viaproxy.protocoltranslator.viaproxy.ViaProxyConfig;
|
||||||
import net.raphimc.viaproxy.proxy.packethandler.*;
|
import net.raphimc.viaproxy.proxy.packethandler.*;
|
||||||
import net.raphimc.viaproxy.proxy.proxy2server.Proxy2ServerChannelInitializer;
|
import net.raphimc.viaproxy.proxy.proxy2server.Proxy2ServerChannelInitializer;
|
||||||
import net.raphimc.viaproxy.proxy.proxy2server.Proxy2ServerHandler;
|
import net.raphimc.viaproxy.proxy.proxy2server.Proxy2ServerHandler;
|
||||||
@ -125,7 +126,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
|
|||||||
ProtocolVersion serverVersion = ViaProxy.getConfig().getTargetVersion();
|
ProtocolVersion serverVersion = ViaProxy.getConfig().getTargetVersion();
|
||||||
String classicMpPass = ViaProxy.getConfig().getAccount() instanceof ClassicAccount classicAccount ? classicAccount.getMppass() : null;
|
String classicMpPass = ViaProxy.getConfig().getAccount() instanceof ClassicAccount classicAccount ? classicAccount.getMppass() : null;
|
||||||
|
|
||||||
if (ViaProxy.getConfig().isSrvMode()) {
|
if (ViaProxy.getConfig().getWildcardDomainHandling() == ViaProxyConfig.WildcardDomainHandling.PUBLIC) {
|
||||||
try {
|
try {
|
||||||
if (handshakeParts[0].toLowerCase().contains(".viaproxy.")) {
|
if (handshakeParts[0].toLowerCase().contains(".viaproxy.")) {
|
||||||
handshakeParts[0] = handshakeParts[0].substring(0, handshakeParts[0].toLowerCase().lastIndexOf(".viaproxy."));
|
handshakeParts[0] = handshakeParts[0].substring(0, handshakeParts[0].toLowerCase().lastIndexOf(".viaproxy."));
|
||||||
@ -146,7 +147,19 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
|
|||||||
final int connectPort = arrayHelper.getInteger(arrayHelper.getLength() - 2);
|
final int connectPort = arrayHelper.getInteger(arrayHelper.getLength() - 2);
|
||||||
serverAddress = AddressUtil.parse(connectIP + ":" + connectPort, serverVersion);
|
serverAddress = AddressUtil.parse(connectIP + ":" + connectPort, serverVersion);
|
||||||
} catch (CloseAndReturn e) {
|
} catch (CloseAndReturn e) {
|
||||||
this.proxyConnection.kickClient("§cWrong SRV syntax! §6Please use:\n§7ip_port_version.viaproxy.hostname");
|
this.proxyConnection.kickClient("§cWrong wildcard syntax! §6Please use:\n§7address_port_version.viaproxy.hostname");
|
||||||
|
}
|
||||||
|
} else if (ViaProxy.getConfig().getWildcardDomainHandling() == ViaProxyConfig.WildcardDomainHandling.INTERNAL) {
|
||||||
|
final ArrayHelper arrayHelper = ArrayHelper.instanceOf(handshakeParts[0].split("\7"));
|
||||||
|
final String versionString = arrayHelper.get(1);
|
||||||
|
serverVersion = ProtocolVersion.getClosest(versionString);
|
||||||
|
if (serverVersion == null) {
|
||||||
|
serverVersion = ProtocolVersion.getClosest(versionString.replace("-", " "));
|
||||||
|
}
|
||||||
|
if (serverVersion == null) throw CloseAndReturn.INSTANCE;
|
||||||
|
serverAddress = AddressUtil.parse(arrayHelper.get(0), serverVersion);
|
||||||
|
if (arrayHelper.isIndexValid(2)) {
|
||||||
|
classicMpPass = arrayHelper.getString(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,9 +56,11 @@ allow-legacy-client-passthrough: false
|
|||||||
# Example: http://example.com/resourcepack.zip
|
# Example: http://example.com/resourcepack.zip
|
||||||
resource-pack-url: ""
|
resource-pack-url: ""
|
||||||
#
|
#
|
||||||
# Allows players to specify the target server address and protocol in their client.
|
# Allows clients to specify a target server and version using wildcard domains.
|
||||||
# Example: viaversion.com_25565_1.8.x.viaproxy.127.0.0.1.nip.io
|
# none: No wildcard domain handling.
|
||||||
srv-mode: false
|
# public: Public wildcard domain handling. Intended for usage by external clients. (Example: address_port_version.viaproxy.127.0.0.1.nip.io)
|
||||||
|
# internal: Internal wildcard domain handling. Intended for local usage by custom clients. (Example: address:port\7version\7classic-mppass)
|
||||||
|
wildcard-domain-handling: "none"
|
||||||
#
|
#
|
||||||
# Configuration version. Do not change this.
|
# Configuration version. Do not change this.
|
||||||
config-version: 1
|
config-version: 1
|
||||||
|
Loading…
Reference in New Issue
Block a user