mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2024-11-14 19:15:08 -05:00
parent
3b9885a055
commit
f5c330168f
4 changed files with 31 additions and 0 deletions
|
@ -64,6 +64,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion.
|
|||
private final OptionSpec<Boolean> optionAllowBetaPinging;
|
||||
private final OptionSpec<Boolean> optionIgnoreProtocolTranslationErrors;
|
||||
private final OptionSpec<Boolean> optionAllowLegacyClientPassthrough;
|
||||
private final OptionSpec<String> optionCustomMotd;
|
||||
private final OptionSpec<String> optionResourcePackUrl;
|
||||
private final OptionSpec<WildcardDomainHandling> optionWildcardDomainHandling;
|
||||
|
||||
|
@ -82,6 +83,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion.
|
|||
private boolean allowBetaPinging = false;
|
||||
private boolean ignoreProtocolTranslationErrors = false;
|
||||
private boolean allowLegacyClientPassthrough = false;
|
||||
private String customMotd = "";
|
||||
private String resourcePackUrl = "";
|
||||
private WildcardDomainHandling wildcardDomainHandling = WildcardDomainHandling.NONE;
|
||||
|
||||
|
@ -105,6 +107,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion.
|
|||
this.optionAllowBetaPinging = this.optionParser.accepts("allow-beta-pinging").withRequiredArg().ofType(Boolean.class).defaultsTo(this.allowBetaPinging);
|
||||
this.optionIgnoreProtocolTranslationErrors = this.optionParser.accepts("ignore-protocol-translation-errors").withRequiredArg().ofType(Boolean.class).defaultsTo(this.ignoreProtocolTranslationErrors);
|
||||
this.optionAllowLegacyClientPassthrough = this.optionParser.accepts("allow-legacy-client-passthrough").withRequiredArg().ofType(Boolean.class).defaultsTo(this.allowLegacyClientPassthrough);
|
||||
this.optionCustomMotd = this.optionParser.accepts("custom-motd").withRequiredArg().ofType(String.class).defaultsTo(this.customMotd);
|
||||
this.optionResourcePackUrl = this.optionParser.accepts("resource-pack-url").withRequiredArg().ofType(String.class).defaultsTo(this.resourcePackUrl);
|
||||
this.optionWildcardDomainHandling = this.optionParser.accepts("wildcard-domain-handling").withRequiredArg().ofType(WildcardDomainHandling.class).defaultsTo(this.wildcardDomainHandling);
|
||||
}
|
||||
|
@ -135,6 +138,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion.
|
|||
this.allowBetaPinging = this.getBoolean("allow-beta-pinging", this.allowBetaPinging);
|
||||
this.ignoreProtocolTranslationErrors = this.getBoolean("ignore-protocol-translation-errors", this.ignoreProtocolTranslationErrors);
|
||||
this.allowLegacyClientPassthrough = this.getBoolean("allow-legacy-client-passthrough", this.allowLegacyClientPassthrough);
|
||||
this.customMotd = this.getString("custom-motd", this.customMotd);
|
||||
this.resourcePackUrl = this.getString("resource-pack-url", this.resourcePackUrl);
|
||||
this.wildcardDomainHandling = WildcardDomainHandling.byName(this.getString("wildcard-domain-handling", this.wildcardDomainHandling.name()));
|
||||
}
|
||||
|
@ -169,6 +173,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion.
|
|||
this.allowBetaPinging = options.valueOf(this.optionAllowBetaPinging);
|
||||
this.ignoreProtocolTranslationErrors = options.valueOf(this.optionIgnoreProtocolTranslationErrors);
|
||||
this.allowLegacyClientPassthrough = options.valueOf(this.optionAllowLegacyClientPassthrough);
|
||||
this.customMotd = options.valueOf(this.optionCustomMotd);
|
||||
this.resourcePackUrl = options.valueOf(this.optionResourcePackUrl);
|
||||
this.wildcardDomainHandling = options.valueOf(this.optionWildcardDomainHandling);
|
||||
ViaProxy.EVENT_MANAGER.call(new PostOptionsParseEvent(options));
|
||||
|
@ -342,6 +347,15 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion.
|
|||
this.set("allow-legacy-client-passthrough", allowLegacyClientPassthrough);
|
||||
}
|
||||
|
||||
public String getCustomMotd() {
|
||||
return this.customMotd;
|
||||
}
|
||||
|
||||
public void setCustomMotd(final String customMotd) {
|
||||
this.customMotd = customMotd;
|
||||
this.set("custom-motd", customMotd);
|
||||
}
|
||||
|
||||
public String getResourcePackUrl() {
|
||||
return this.resourcePackUrl;
|
||||
}
|
||||
|
|
|
@ -163,6 +163,9 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
|
|||
}
|
||||
|
||||
if (packet.intendedState.getConnectionState() == ConnectionState.STATUS && !ViaProxy.getConfig().shouldAllowBetaPinging() && serverVersion.olderThanOrEqualTo(LegacyProtocolVersion.b1_7tob1_7_3)) {
|
||||
if (!ViaProxy.getConfig().getCustomMotd().isBlank()) {
|
||||
this.proxyConnection.kickClient(ViaProxy.getConfig().getCustomMotd());
|
||||
}
|
||||
this.proxyConnection.kickClient("§7ViaProxy is working!\n§7Connect to join the configured server");
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,13 @@
|
|||
*/
|
||||
package net.raphimc.viaproxy.proxy.packethandler;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import net.raphimc.netminecraft.packet.IPacket;
|
||||
import net.raphimc.netminecraft.packet.impl.status.S2CStatusPongPacket;
|
||||
import net.raphimc.netminecraft.packet.impl.status.S2CStatusResponsePacket;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -34,6 +38,13 @@ public class StatusPacketHandler extends PacketHandler {
|
|||
public boolean handleP2S(IPacket packet, List<ChannelFutureListener> listeners) {
|
||||
if (packet instanceof S2CStatusPongPacket) {
|
||||
listeners.add(ChannelFutureListener.CLOSE);
|
||||
} else if (packet instanceof S2CStatusResponsePacket statusResponsePacket && !ViaProxy.getConfig().getCustomMotd().isBlank()) {
|
||||
try {
|
||||
final JsonObject obj = JsonParser.parseString(statusResponsePacket.statusJson).getAsJsonObject();
|
||||
obj.addProperty("description", ViaProxy.getConfig().getCustomMotd());
|
||||
statusResponsePacket.statusJson = obj.toString();
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -55,6 +55,9 @@ ignore-protocol-translation-errors: false
|
|||
# Allow <= 1.6.4 clients to connect through ViaProxy to the target server. (No protocol translation or packet handling)
|
||||
allow-legacy-client-passthrough: false
|
||||
#
|
||||
# Custom MOTD to send when clients ping the proxy. Leave empty to use the target server's MOTD.
|
||||
custom-motd: ""
|
||||
#
|
||||
# URL of a resource pack which clients can optionally download when connecting to the server. Leave empty to disable.
|
||||
# Example: http://example.com/resourcepack.zip
|
||||
resource-pack-url: ""
|
||||
|
|
Loading…
Reference in a new issue