Can join server without command packet from server
This commit is contained in:
parent
51c887bc3f
commit
7613b68fc8
|
|
@ -21,18 +21,22 @@ public class AmbassadorConfig {
|
|||
@Expose
|
||||
private int serverSwitchCancellationTime = 120;
|
||||
|
||||
@Expose
|
||||
private boolean silenceWarnings = false;
|
||||
|
||||
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.disconnectResetMessage = kickResetMessage;
|
||||
this.serverSwitchCancellationTime = serverSwitchCancellationTime;
|
||||
this.silenceWarnings = silenceWarnings;
|
||||
};
|
||||
|
||||
public void validate() {
|
||||
final int connectionTimeout = Ambassador.getInstance().server.getConfiguration().getConnectTimeout();
|
||||
if (resetTimeout >= connectionTimeout) {
|
||||
throw new InvalidValueException("'reset-timeout' can't be more than nor equal to 'connection-timeout': reset-timeout=" + resetTimeout + " connection-timeout=" + connectionTimeout);
|
||||
if (resetTimeout > connectionTimeout) {
|
||||
throw new InvalidValueException("'reset-timeout' can't be more than to 'connection-timeout': reset-timeout=" + resetTimeout + " connection-timeout=" + connectionTimeout);
|
||||
}
|
||||
if (resetTimeout <= 0) {
|
||||
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();
|
||||
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);
|
||||
String kickResetMessage = config.getOrElse("disconnect-reset-message", "Please reconnect");
|
||||
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() {
|
||||
|
|
@ -82,4 +100,8 @@ public class AmbassadorConfig {
|
|||
public int getServerSwitchCancellationTime() {
|
||||
return serverSwitchCancellationTime;
|
||||
}
|
||||
|
||||
public boolean isSilenceWarnings() {
|
||||
return silenceWarnings;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,14 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
|||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
|
||||
import com.velocitypowered.proxy.protocol.packet.AvailableCommands;
|
||||
import com.velocitypowered.proxy.protocol.packet.Disconnect;
|
||||
import com.velocitypowered.proxy.util.except.QuietRuntimeException;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.handler.codec.CorruptedFrameException;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.adde0109.ambassador.Ambassador;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CommandDecoderErrorCatcher extends ChannelInboundHandlerAdapter {
|
||||
|
|
@ -23,6 +24,7 @@ public class CommandDecoderErrorCatcher extends ChannelInboundHandlerAdapter {
|
|||
private final StateRegistry.PacketRegistry.ProtocolRegistry registry;
|
||||
|
||||
private final ConnectedPlayer player;
|
||||
private boolean sentWarning = false;
|
||||
|
||||
public CommandDecoderErrorCatcher(ProtocolVersion protocolVersion, ConnectedPlayer player) {
|
||||
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);
|
||||
} catch (QuietRuntimeException | CorruptedFrameException e) {
|
||||
RegisteredServer server = player.getConnectedServer().getServer();
|
||||
player.handleConnectionException(server,
|
||||
Disconnect.create(Component.text("Ambassador: Unsupported command argument type detected! " +
|
||||
"Please install Proxy-Compatible-Forge mod on this backend server."),
|
||||
player.getProtocolVersion()),true);
|
||||
if (!Ambassador.getInstance().config.isSilenceWarnings() && !sentWarning) {
|
||||
player.sendMessage(Component.text("[Ambassador Warning]: Unsupported command argument type detected! " +
|
||||
"Please install Proxy-Compatible-Forge mod on this backend server to have access to commands. " +
|
||||
"This message can be silenced in the ambassador.toml config file.", NamedTextColor.YELLOW));
|
||||
sentWarning = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# 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)
|
||||
reset-timeout = 1000
|
||||
|
|
@ -8,3 +8,4 @@ reset-timeout = 1000
|
|||
disconnect-reset-message = "&6Please reconnect"
|
||||
# How much time the player has to reconnect before canceling the server switch. (In seconds)
|
||||
server-switch-cancellation-time = 120
|
||||
silence-warnings = false
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user