Can join server without command packet from server

This commit is contained in:
Adrian Bergqvist 2023-03-30 22:39:47 +02:00
parent 51c887bc3f
commit 7613b68fc8
No known key found for this signature in database
GPG Key ID: FAE7D8EDE225E686
3 changed files with 38 additions and 10 deletions

View File

@ -21,18 +21,22 @@ public class AmbassadorConfig {
@Expose @Expose
private int serverSwitchCancellationTime = 120; private int serverSwitchCancellationTime = 120;
@Expose
private boolean silenceWarnings = false;
private net.kyori.adventure.text.@MonotonicNonNull Component messageAsAsComponent; private net.kyori.adventure.text.@MonotonicNonNull Component messageAsAsComponent;
private AmbassadorConfig(int resetTimeout, String kickResetMessage, int serverSwitchCancellationTime) { private AmbassadorConfig(int resetTimeout, String kickResetMessage, int serverSwitchCancellationTime, boolean silenceWarnings) {
this.resetTimeout = resetTimeout; this.resetTimeout = resetTimeout;
this.disconnectResetMessage = kickResetMessage; this.disconnectResetMessage = kickResetMessage;
this.serverSwitchCancellationTime = serverSwitchCancellationTime; this.serverSwitchCancellationTime = serverSwitchCancellationTime;
this.silenceWarnings = silenceWarnings;
}; };
public void validate() { public void validate() {
final int connectionTimeout = Ambassador.getInstance().server.getConfiguration().getConnectTimeout(); final int connectionTimeout = Ambassador.getInstance().server.getConfiguration().getConnectTimeout();
if (resetTimeout >= connectionTimeout) { if (resetTimeout > connectionTimeout) {
throw new InvalidValueException("'reset-timeout' can't be more than nor equal to 'connection-timeout': reset-timeout=" + resetTimeout + " connection-timeout=" + connectionTimeout); throw new InvalidValueException("'reset-timeout' can't be more than to 'connection-timeout': reset-timeout=" + resetTimeout + " connection-timeout=" + connectionTimeout);
} }
if (resetTimeout <= 0) { if (resetTimeout <= 0) {
throw new InvalidValueException("'reset-timeout' can't be less than nor equal to zero: reset-timeout=" + resetTimeout); throw new InvalidValueException("'reset-timeout' can't be less than nor equal to zero: reset-timeout=" + resetTimeout);
@ -57,11 +61,25 @@ public class AmbassadorConfig {
.build(); .build();
config.load(); config.load();
double configVersion;
try {
configVersion = Double.parseDouble(config.getOrElse("config-version", "1.0"));
} catch (NumberFormatException e) {
configVersion = 1.0;
}
if (configVersion < 1.1) {
config.set("silence-warnings", false);
config.set("config-version", "1.1");
}
int resetTimeout = config.getIntOrElse("reset-timeout", 3000); int resetTimeout = config.getIntOrElse("reset-timeout", 3000);
String kickResetMessage = config.getOrElse("disconnect-reset-message", "Please reconnect"); String kickResetMessage = config.getOrElse("disconnect-reset-message", "Please reconnect");
int serverSwitchCancellationTime = config.getIntOrElse("server-switch-cancellation-time", 120000); int serverSwitchCancellationTime = config.getIntOrElse("server-switch-cancellation-time", 120000);
return new AmbassadorConfig(resetTimeout, kickResetMessage, serverSwitchCancellationTime); boolean silenceWarnings = config.getOrElse("silence-warnings", false);
return new AmbassadorConfig(resetTimeout, kickResetMessage, serverSwitchCancellationTime, silenceWarnings);
} }
public int getResetTimeout() { public int getResetTimeout() {
@ -82,4 +100,8 @@ public class AmbassadorConfig {
public int getServerSwitchCancellationTime() { public int getServerSwitchCancellationTime() {
return serverSwitchCancellationTime; return serverSwitchCancellationTime;
} }
public boolean isSilenceWarnings() {
return silenceWarnings;
}
} }

View File

@ -9,13 +9,14 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
import com.velocitypowered.proxy.protocol.packet.AvailableCommands; import com.velocitypowered.proxy.protocol.packet.AvailableCommands;
import com.velocitypowered.proxy.protocol.packet.Disconnect;
import com.velocitypowered.proxy.util.except.QuietRuntimeException; import com.velocitypowered.proxy.util.except.QuietRuntimeException;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.CorruptedFrameException; import io.netty.handler.codec.CorruptedFrameException;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.adde0109.ambassador.Ambassador;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class CommandDecoderErrorCatcher extends ChannelInboundHandlerAdapter { public class CommandDecoderErrorCatcher extends ChannelInboundHandlerAdapter {
@ -23,6 +24,7 @@ public class CommandDecoderErrorCatcher extends ChannelInboundHandlerAdapter {
private final StateRegistry.PacketRegistry.ProtocolRegistry registry; private final StateRegistry.PacketRegistry.ProtocolRegistry registry;
private final ConnectedPlayer player; private final ConnectedPlayer player;
private boolean sentWarning = false;
public CommandDecoderErrorCatcher(ProtocolVersion protocolVersion, ConnectedPlayer player) { public CommandDecoderErrorCatcher(ProtocolVersion protocolVersion, ConnectedPlayer player) {
this.registry = StateRegistry.PLAY.getProtocolRegistry(ProtocolUtils.Direction.CLIENTBOUND, protocolVersion); this.registry = StateRegistry.PLAY.getProtocolRegistry(ProtocolUtils.Direction.CLIENTBOUND, protocolVersion);
@ -46,10 +48,13 @@ public class CommandDecoderErrorCatcher extends ChannelInboundHandlerAdapter {
((MinecraftDecoder) ctx.pipeline().get(Connections.MINECRAFT_DECODER)).channelRead(ctx, msg); ((MinecraftDecoder) ctx.pipeline().get(Connections.MINECRAFT_DECODER)).channelRead(ctx, msg);
} catch (QuietRuntimeException | CorruptedFrameException e) { } catch (QuietRuntimeException | CorruptedFrameException e) {
RegisteredServer server = player.getConnectedServer().getServer(); RegisteredServer server = player.getConnectedServer().getServer();
player.handleConnectionException(server, if (!Ambassador.getInstance().config.isSilenceWarnings() && !sentWarning) {
Disconnect.create(Component.text("Ambassador: Unsupported command argument type detected! " + player.sendMessage(Component.text("[Ambassador Warning]: Unsupported command argument type detected! " +
"Please install Proxy-Compatible-Forge mod on this backend server."), "Please install Proxy-Compatible-Forge mod on this backend server to have access to commands. " +
player.getProtocolVersion()),true); "This message can be silenced in the ambassador.toml config file.", NamedTextColor.YELLOW));
sentWarning = true;
}
} }
} else { } else {

View File

@ -1,5 +1,5 @@
# Do not change this # Do not change this
config-version = "1.0" config-version = "1.1"
# How long to wait for the client to reset before disconnecting (In milliseconds) # How long to wait for the client to reset before disconnecting (In milliseconds)
reset-timeout = 1000 reset-timeout = 1000
@ -8,3 +8,4 @@ reset-timeout = 1000
disconnect-reset-message = "&6Please reconnect" disconnect-reset-message = "&6Please reconnect"
# How much time the player has to reconnect before canceling the server switch. (In seconds) # How much time the player has to reconnect before canceling the server switch. (In seconds)
server-switch-cancellation-time = 120 server-switch-cancellation-time = 120
silence-warnings = false