13
0
geforkt von Mirrors/Velocity

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;
}
Component disconnectReason = GsonComponentSerializer.gson().deserialize(disconnect.getReason());
Component disconnectReason = disconnect.getReason().getComponent();
String plainTextReason = PASS_THRU_TRANSLATE.serialize(disconnectReason);
if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) {
logger.info("{}: kicked from server {}: {}", this, server.getServerInfo().getName(),

Datei anzeigen

@ -47,7 +47,7 @@ public final class InitialInboundConnection implements VelocityInboundConnection
private final Handshake handshake;
InitialInboundConnection(MinecraftConnection connection, String cleanedAddress,
Handshake handshake) {
Handshake handshake) {
this.connection = connection;
this.cleanedAddress = cleanedAddress;
this.handshake = handshake;
@ -95,7 +95,9 @@ public final class InitialInboundConnection implements VelocityInboundConnection
logger.info("{} has disconnected: {}", this,
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) {
Component translated = GlobalTranslator.render(reason, ClosestLocaleMatcher.INSTANCE
.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 javax.annotation.Nullable;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
/**
* Common connection request results.
@ -64,13 +63,12 @@ public class ConnectionRequestResults {
}
public static Impl forDisconnect(Disconnect disconnect, RegisteredServer server) {
Component deserialized = GsonComponentSerializer.gson().deserialize(disconnect.getReason());
return forDisconnect(deserialized, server);
return forDisconnect(disconnect.getReason().getComponent(), server);
}
public static Impl forUnsafeDisconnect(Disconnect disconnect, RegisteredServer server) {
Component deserialized = GsonComponentSerializer.gson().deserialize(disconnect.getReason());
return new Impl(Status.SERVER_DISCONNECTED, deserialized, server, false);
return new Impl(Status.SERVER_DISCONNECTED, disconnect.getReason().getComponent(), server,
false);
}
/**
@ -115,4 +113,4 @@ public class ConnectionRequestResults {
return safe;
}
}
}
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -118,7 +118,7 @@ public class ResourcePackRequest implements MinecraftPacket {
buf.writeBoolean(isRequired);
if (prompt != null) {
buf.writeBoolean(true);
prompt.write(buf, protocolVersion);
prompt.write(buf);
} else {
buf.writeBoolean(false);
}
@ -149,4 +149,4 @@ public class ResourcePackRequest implements MinecraftPacket {
return "ResourcePackRequest{" + "url='" + url + '\'' + ", hash='" + hash + '\'' +
", isRequired=" + isRequired + ", prompt='" + prompt + '\'' + '}';
}
}
}

Datei anzeigen

@ -76,7 +76,7 @@ public class ServerData implements MinecraftPacket {
buf.writeBoolean(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;
@ -115,4 +115,4 @@ public class ServerData implements MinecraftPacket {
public boolean isSecureChatEnforced() {
return secureChatEnforced;
}
}
}

Datei anzeigen

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

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) {
ProtocolUtils.writeBinaryTag(buf, version, getBinaryTag());
} else {