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

Fix Disconnects

Dieser Commit ist enthalten in:
pkt77 2023-12-06 14:19:08 -05:00 committet von Shane Freeder
Ursprung eb03feebd9
Commit eaa83378d7
10 geänderte Dateien mit 37 neuen und 37 gelöschten Zeilen

Datei anzeigen

@ -651,7 +651,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
return; return;
} }
Component disconnectReason = GsonComponentSerializer.gson().deserialize(disconnect.getReason()); Component disconnectReason = disconnect.getReason().getComponent();
String plainTextReason = PASS_THRU_TRANSLATE.serialize(disconnectReason); String plainTextReason = PASS_THRU_TRANSLATE.serialize(disconnectReason);
if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) { if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) {
logger.info("{}: kicked from server {}: {}", this, server.getServerInfo().getName(), logger.info("{}: kicked from server {}: {}", this, server.getServerInfo().getName(),

Datei anzeigen

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

Datei anzeigen

@ -24,7 +24,6 @@ import com.velocitypowered.proxy.protocol.packet.Disconnect;
import java.util.Optional; import java.util.Optional;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
/** /**
* Common connection request results. * Common connection request results.
@ -64,13 +63,12 @@ public class ConnectionRequestResults {
} }
public static Impl forDisconnect(Disconnect disconnect, RegisteredServer server) { public static Impl forDisconnect(Disconnect disconnect, RegisteredServer server) {
Component deserialized = GsonComponentSerializer.gson().deserialize(disconnect.getReason()); return forDisconnect(disconnect.getReason().getComponent(), server);
return forDisconnect(deserialized, server);
} }
public static Impl forUnsafeDisconnect(Disconnect disconnect, RegisteredServer server) { public static Impl forUnsafeDisconnect(Disconnect disconnect, RegisteredServer server) {
Component deserialized = GsonComponentSerializer.gson().deserialize(disconnect.getReason()); return new Impl(Status.SERVER_DISCONNECTED, disconnect.getReason().getComponent(), server,
return new Impl(Status.SERVER_DISCONNECTED, deserialized, server, false); false);
} }
/** /**

Datei anzeigen

@ -158,7 +158,7 @@ public class BossBar implements MinecraftPacket {
if (name == null) { if (name == null) {
throw new IllegalStateException("No name specified!"); throw new IllegalStateException("No name specified!");
} }
name.write(buf, version); name.write(buf);
buf.writeFloat(percent); buf.writeFloat(percent);
ProtocolUtils.writeVarInt(buf, color); ProtocolUtils.writeVarInt(buf, color);
ProtocolUtils.writeVarInt(buf, overlay); ProtocolUtils.writeVarInt(buf, overlay);
@ -173,7 +173,7 @@ public class BossBar implements MinecraftPacket {
if (name == null) { if (name == null) {
throw new IllegalStateException("No name specified!"); throw new IllegalStateException("No name specified!");
} }
name.write(buf, version); name.write(buf);
break; break;
case UPDATE_STYLE: case UPDATE_STYLE:
ProtocolUtils.writeVarInt(buf, color); ProtocolUtils.writeVarInt(buf, color);

Datei anzeigen

@ -22,28 +22,30 @@ import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class Disconnect implements MinecraftPacket { public class Disconnect implements MinecraftPacket {
private @Nullable String reason; private @Nullable ComponentHolder reason;
public Disconnect() { public Disconnect() {
} }
public Disconnect(String reason) { public Disconnect(ComponentHolder reason) {
this.reason = Preconditions.checkNotNull(reason, "reason"); this.reason = Preconditions.checkNotNull(reason, "reason");
} }
public String getReason() { public ComponentHolder getReason() {
if (reason == null) { if (reason == null) {
throw new IllegalStateException("No reason specified"); throw new IllegalStateException("No reason specified");
} }
return reason; return reason;
} }
public void setReason(@Nullable String reason) { public void setReason(@Nullable ComponentHolder reason) {
this.reason = reason; this.reason = reason;
} }
@ -56,15 +58,12 @@ public class Disconnect implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
reason = ProtocolUtils.readString(buf); reason = ComponentHolder.read(buf, version);
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (reason == null) { getReason().write(buf);
throw new IllegalStateException("No reason specified.");
}
ProtocolUtils.writeString(buf, reason);
} }
@Override @Override
@ -72,9 +71,8 @@ public class Disconnect implements MinecraftPacket {
return handler.handle(this); return handler.handle(this);
} }
public static Disconnect create(net.kyori.adventure.text.Component component, public static Disconnect create(Component component, ProtocolVersion version) {
ProtocolVersion version) {
Preconditions.checkNotNull(component, "component"); Preconditions.checkNotNull(component, "component");
return new Disconnect(ProtocolUtils.getJsonChatSerializer(version).serialize(component)); return new Disconnect(new ComponentHolder(version, component));
} }
} }

Datei anzeigen

@ -57,8 +57,8 @@ public class HeaderAndFooter implements MinecraftPacket {
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
header.write(buf, version); header.write(buf);
footer.write(buf, version); footer.write(buf);
} }
@Override @Override

Datei anzeigen

@ -118,7 +118,7 @@ public class ResourcePackRequest implements MinecraftPacket {
buf.writeBoolean(isRequired); buf.writeBoolean(isRequired);
if (prompt != null) { if (prompt != null) {
buf.writeBoolean(true); buf.writeBoolean(true);
prompt.write(buf, protocolVersion); prompt.write(buf);
} else { } else {
buf.writeBoolean(false); buf.writeBoolean(false);
} }

Datei anzeigen

@ -76,7 +76,7 @@ public class ServerData implements MinecraftPacket {
buf.writeBoolean(hasDescription); buf.writeBoolean(hasDescription);
} }
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_4) >= 0 || hasDescription) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_4) >= 0 || hasDescription) {
this.description.write(buf, protocolVersion); this.description.write(buf);
} }
boolean hasFavicon = this.favicon != null; boolean hasFavicon = this.favicon != null;

Datei anzeigen

@ -186,7 +186,7 @@ public class UpsertPlayerInfo implements MinecraftPacket {
}, (version, buf, info) -> { // write }, (version, buf, info) -> { // write
buf.writeBoolean(info.displayName != null); buf.writeBoolean(info.displayName != null);
if (info.displayName != null) { if (info.displayName != null) {
info.displayName.write(buf, version); info.displayName.write(buf);
} }
}); });

Datei anzeigen

@ -268,7 +268,7 @@ public class ComponentHolder {
} }
} }
public void write(ByteBuf buf, ProtocolVersion version) { public void write(ByteBuf buf) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) {
ProtocolUtils.writeBinaryTag(buf, version, getBinaryTag()); ProtocolUtils.writeBinaryTag(buf, version, getBinaryTag());
} else { } else {