3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +01:00

fix disconnect decoding

Dieser Commit ist enthalten in:
Gero 2023-12-07 19:07:19 +01:00 committet von Shane Freeder
Ursprung 8a6c20ee32
Commit 32228e85ab
5 geänderte Dateien mit 21 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -28,7 +28,6 @@ import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent;
import com.velocitypowered.api.event.player.ServerResourcePackSendEvent;
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.proxy.player.ResourcePackInfo;
import com.velocitypowered.proxy.VelocityServer;
@ -367,7 +366,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
if (server.getConfiguration().isFailoverOnUnexpectedServerDisconnect()) {
serverConn.getPlayer().handleConnectionException(serverConn.getServer(),
Disconnect.create(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR,
ProtocolVersion.MINECRAFT_1_16), true);
serverConn.getPlayer().getProtocolVersion(), false), true);
} else {
serverConn.getPlayer().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);
}

Datei anzeigen

@ -579,7 +579,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
logger.info("{} has disconnected: {}", this,
LegacyComponentSerializer.legacySection().serialize(translated));
}
connection.closeWith(Disconnect.create(translated, this.getProtocolVersion()));
connection.closeWith(Disconnect.create(translated, this.getProtocolVersion(), duringLogin));
}
public @Nullable VelocityServerConnection getConnectedServer() {
@ -750,7 +750,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
Component reason = status.getReasonComponent()
.orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);
handleConnectionException(res.getServer(),
Disconnect.create(reason, getProtocolVersion()), ((Impl) status).isSafe());
Disconnect.create(reason, getProtocolVersion(), false),
((Impl) status).isSafe());
break;
case SUCCESS:
Component requestedMessage = res.getMessageComponent();
@ -1274,8 +1275,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
case SERVER_DISCONNECTED:
Component reason = status.getReasonComponent()
.orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);
handleConnectionException(toConnect, Disconnect.create(reason, getProtocolVersion()),
status.isSafe());
handleConnectionException(toConnect,
Disconnect.create(reason, getProtocolVersion(), false), status.isSafe());
break;
default:
// The only remaining value is successful (no need to do anything!)

Datei anzeigen

@ -95,9 +95,7 @@ public final class InitialInboundConnection implements VelocityInboundConnection
logger.info("{} has disconnected: {}", this,
LegacyComponentSerializer.legacySection().serialize(translated));
}
connection.closeWith(Disconnect.create(translated,
getProtocolVersion() == ProtocolVersion.MINECRAFT_1_20_3 // Login disconnects are string
? ProtocolVersion.MINECRAFT_1_20_2 : getProtocolVersion()));
connection.closeWith(Disconnect.create(translated, getProtocolVersion(), true));
}
/**
@ -108,8 +106,6 @@ public final class InitialInboundConnection implements VelocityInboundConnection
public void disconnectQuietly(Component reason) {
Component translated = GlobalTranslator.render(reason, ClosestLocaleMatcher.INSTANCE
.lookupClosest(Locale.getDefault()));
connection.closeWith(Disconnect.create(translated,
getProtocolVersion() == ProtocolVersion.MINECRAFT_1_20_3 // Login disconnects are string
? ProtocolVersion.MINECRAFT_1_20_2 : getProtocolVersion()));
connection.closeWith(Disconnect.create(translated, getProtocolVersion(), true));
}
}

Datei anzeigen

@ -149,7 +149,8 @@ public enum StateRegistry {
clientbound.register(
PluginMessage.class, PluginMessage::new, map(0x00, MINECRAFT_1_20_2, false));
clientbound.register(Disconnect.class, Disconnect::new, map(0x01, MINECRAFT_1_20_2, false));
clientbound.register(
Disconnect.class, () -> new Disconnect(false), map(0x01, MINECRAFT_1_20_2, false));
clientbound.register(
FinishedUpdate.class, FinishedUpdate::new, map(0x02, MINECRAFT_1_20_2, false));
clientbound.register(KeepAlive.class, KeepAlive::new, map(0x03, MINECRAFT_1_20_2, false));
@ -335,7 +336,7 @@ public enum StateRegistry {
map(0x18, MINECRAFT_1_20_2, false));
clientbound.register(
Disconnect.class,
Disconnect::new,
() -> new Disconnect(false),
map(0x40, MINECRAFT_1_7_2, false),
map(0x1A, MINECRAFT_1_9, false),
map(0x1B, MINECRAFT_1_13, false),
@ -566,7 +567,8 @@ public enum StateRegistry {
serverbound.register(
LoginAcknowledged.class, LoginAcknowledged::new, map(0x03, MINECRAFT_1_20_2, false));
clientbound.register(Disconnect.class, Disconnect::new, map(0x00, MINECRAFT_1_7_2, false));
clientbound.register(
Disconnect.class, () -> new Disconnect(true), map(0x00, MINECRAFT_1_7_2, false));
clientbound.register(
EncryptionRequest.class, EncryptionRequest::new, map(0x01, MINECRAFT_1_7_2, false));
clientbound.register(

Datei anzeigen

@ -30,11 +30,14 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class Disconnect implements MinecraftPacket {
private @Nullable ComponentHolder reason;
private final boolean login;
public Disconnect() {
public Disconnect(boolean login) {
this.login = login;
}
public Disconnect(ComponentHolder reason) {
private Disconnect(boolean login, ComponentHolder reason) {
this.login = login;
this.reason = Preconditions.checkNotNull(reason, "reason");
}
@ -58,7 +61,7 @@ public class Disconnect implements MinecraftPacket {
@Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
reason = ComponentHolder.read(buf, version);
reason = ComponentHolder.read(buf, login ? ProtocolVersion.MINECRAFT_1_20_2 : version);
}
@Override
@ -71,8 +74,8 @@ public class Disconnect implements MinecraftPacket {
return handler.handle(this);
}
public static Disconnect create(Component component, ProtocolVersion version) {
public static Disconnect create(Component component, ProtocolVersion version, boolean login) {
Preconditions.checkNotNull(component, "component");
return new Disconnect(new ComponentHolder(version, component));
return new Disconnect(login, new ComponentHolder(login ? ProtocolVersion.MINECRAFT_1_20_2 : version, component));
}
}