Skip to content

Commit

Permalink
Don't remove configuration packet storage on login
Browse files Browse the repository at this point in the history
Needed with proxies if a server is doing nonstandard optimizations
Fixes #881
  • Loading branch information
kennytv committed Sep 8, 2024
1 parent ffb9852 commit 0bac920
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected void register() {
@Override
public void register() {
handler(wrapper -> {
final ConfigurationPacketStorage configurationPacketStorage = wrapper.user().remove(ConfigurationPacketStorage.class);
final ConfigurationPacketStorage configurationPacketStorage = wrapper.user().get(ConfigurationPacketStorage.class);
wrapper.passthrough(Types.INT); // Entity id
wrapper.passthrough(Types.BOOLEAN); // Hardcore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
package com.viaversion.viabackwards.protocol.v1_20_2to1_20.storage;

import com.google.common.base.Preconditions;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viabackwards.protocol.v1_20_2to1_20.Protocol1_20_2To1_20;
import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ClientboundPackets1_19_4;
import com.viaversion.nbt.tag.CompoundTag;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
Expand Down Expand Up @@ -77,17 +77,21 @@ private QueuedPacket toQueuedPacket(final PacketWrapper wrapper, final PacketTyp

public void sendQueuedPackets(final UserConnection connection) {
// Send resource pack at the end
List<QueuedPacket> packets = rawPackets;
if (resourcePack != null) {
rawPackets.add(resourcePack);
packets = new ArrayList<>(rawPackets);
packets.add(resourcePack);
resourcePack = null;
}

for (final QueuedPacket queuedPacket : rawPackets) {
for (final QueuedPacket queuedPacket : packets) {
// Don't clear the list or use the original buffer, we might need them later if a server skips subsequent config phases
final ByteBuf buf = queuedPacket.buf().copy();
try {
final PacketWrapper packet = PacketWrapper.create(queuedPacket.packetType(), queuedPacket.buf(), connection);
final PacketWrapper packet = PacketWrapper.create(queuedPacket.packetType(), buf, connection);
packet.send(Protocol1_20_2To1_20.class);
} finally {
queuedPacket.buf().release();
buf.release();
}
}
}
Expand Down

0 comments on commit 0bac920

Please sign in to comment.