Change config and fixed some bugs

This commit is contained in:
Adrian Bergqvist 2023-06-03 00:35:31 +02:00
parent cd8df2c5a0
commit 9c5f49f6e9
No known key found for this signature in database
GPG Key ID: FAE7D8EDE225E686
7 changed files with 11 additions and 25 deletions

View File

@ -5,7 +5,7 @@ plugins {
}
group = "org.adde0109"
version = "1.4.0-beta-rc4"
version = "1.4.0-beta-rc7"
repositories {
mavenCentral()

View File

@ -40,7 +40,7 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_19;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_19_3;
import static com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentIdentifier.mapSet;
@Plugin(id = "ambassador", name = "Ambassador", version = "1.4.0-beta-rc4", authors = {"adde0109"})
@Plugin(id = "ambassador", name = "Ambassador", version = "1.4.0-beta-rc7", authors = {"adde0109"})
public class Ambassador {
public ProxyServer server;

View File

@ -12,8 +12,6 @@ import java.nio.file.Path;
public class AmbassadorConfig {
@Expose
private int resetTimeout = 1000;
@Expose
private String disconnectResetMessage = "Please reconnect";
@ -26,21 +24,13 @@ public class AmbassadorConfig {
private net.kyori.adventure.text.@MonotonicNonNull Component messageAsAsComponent;
private AmbassadorConfig(int resetTimeout, String kickResetMessage, int serverSwitchCancellationTime, boolean silenceWarnings) {
this.resetTimeout = resetTimeout;
private AmbassadorConfig(String kickResetMessage, int serverSwitchCancellationTime, boolean silenceWarnings) {
this.disconnectResetMessage = kickResetMessage;
this.serverSwitchCancellationTime = serverSwitchCancellationTime;
this.silenceWarnings = silenceWarnings;
};
public void validate() {
final int connectionTimeout = Ambassador.getInstance().server.getConfiguration().getReadTimeout();
if (resetTimeout >= connectionTimeout) {
throw new InvalidValueException("'reset-timeout' can't be more than nor equal to 'read-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);
}
if (serverSwitchCancellationTime <= 0) {
throw new InvalidValueException("'server-switch-cancellation-time' can't be less than nor equal to zero: server-switch-cancellation-time=" + serverSwitchCancellationTime);
}
@ -70,20 +60,15 @@ public class AmbassadorConfig {
if (configVersion < 1.1) {
config.set("silence-warnings", false);
config.set("config-version", "1.1");
config.set("config-version", "1.2");
}
int resetTimeout = config.getIntOrElse("reset-timeout", 3000);
String kickResetMessage = config.getOrElse("disconnect-reset-message", "Please reconnect");
int serverSwitchCancellationTime = config.getIntOrElse("server-switch-cancellation-time", 120);
boolean silenceWarnings = config.getOrElse("silence-warnings", false);
return new AmbassadorConfig(resetTimeout, kickResetMessage, serverSwitchCancellationTime, silenceWarnings);
}
public int getResetTimeout() {
return resetTimeout;
return new AmbassadorConfig(kickResetMessage, serverSwitchCancellationTime, silenceWarnings);
}
public net.kyori.adventure.text.Component getDisconnectResetMessage() {

View File

@ -66,7 +66,9 @@ public enum VelocityForgeBackendConnectionPhase implements BackendConnectionPhas
//Reset client if not ready to receive new handshake
VelocityForgeClientConnectionPhase clientPhase = (VelocityForgeClientConnectionPhase) player.getPhase();
clientPhase.resetConnectionPhase(player);
if (clientPhase != VelocityForgeClientConnectionPhase.NOT_STARTED) {
clientPhase.resetConnectionPhase(player);
}
message.retain();
player.getConnection().write(message);
//Forge server

View File

@ -63,6 +63,7 @@ public enum VelocityForgeClientConnectionPhase implements ClientConnectionPhase
if (connection.getState() == StateRegistry.PLAY) {
connection.write(new PluginMessage("fml:handshake", Unpooled.wrappedBuffer(ForgeHandshakeUtils.generatePluginResetPacket())));
connection.setState(StateRegistry.LOGIN);
} else {
connection.write(new LoginPluginMessage(98,"fml:loginwrapper", Unpooled.wrappedBuffer(ForgeHandshakeUtils.generateResetPacket())));
}
@ -98,7 +99,6 @@ public enum VelocityForgeClientConnectionPhase implements ClientConnectionPhase
if (msg.getId() == 98) {
player.getConnection().getChannel().pipeline().remove(ForgeConstants.RESET_LISTENER);
player.setPhase(NOT_STARTED);
player.getConnection().setState(StateRegistry.LOGIN);
player.getConnection().getChannel().pipeline().remove(ForgeConstants.LOGIN_PACKET_QUEUE);
@ -133,7 +133,6 @@ public enum VelocityForgeClientConnectionPhase implements ClientConnectionPhase
buf.writeBytes((player.getVirtualHost().get().getHostName() + ":"
+ player.getVirtualHost().get().getPort()).getBytes(StandardCharsets.UTF_8));
player.getConnection().write(new PluginMessage("srvredirect:red", buf));
player.getConnection().close();
} else {
player.disconnect(Ambassador.getInstance().config.getDisconnectResetMessage());
}

View File

@ -49,10 +49,12 @@ public class ForgeLoginSessionHandler implements MinecraftSessionHandler {
}
ConnectedPlayer player = serverConnection.getPlayer();
if (!(serverConnection.getConnection().getType() instanceof ForgeFMLConnectionType)) {
if (player.getConnection() == null || player.getConnection().getType() instanceof ForgeFMLConnectionType) {
//Initial Vanilla
//Forge -> vanilla
player.getPhase().resetConnectionPhase(player);
player.getConnectionInFlight().getConnection().getChannel().config().setAutoRead(false);
}
} else {
((VelocityForgeClientConnectionPhase) player.getPhase()).complete(player);
}

View File

@ -1,8 +1,6 @@
# Do not change this
config-version = "1.1"
# How long to wait for the client to reset before disconnecting (In milliseconds)
reset-timeout = 3000
# Message displayed to the player when disconnected from proxy during server switch.
# Legacy color codes and JSON are accepted.
disconnect-reset-message = "&6Please reconnect"