From 865a34690313900691dbcef14f015bcf10ef3622 Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 18 Dec 2018 11:13:10 +1100 Subject: [PATCH] #2546: reducedDebugInfo state not updating when changing servers --- .../protocol/AbstractPacketHandler.java | 5 +++ .../net/md_5/bungee/protocol/Protocol.java | 7 +++ .../bungee/protocol/packet/EntityStatus.java | 43 +++++++++++++++++++ .../java/net/md_5/bungee/ServerConnector.java | 6 ++- 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/EntityStatus.java diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java index 93f324e2..adf189c3 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java @@ -20,6 +20,7 @@ import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.protocol.packet.Respawn; import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.EncryptionResponse; +import net.md_5.bungee.protocol.packet.EntityStatus; import net.md_5.bungee.protocol.packet.LegacyHandshake; import net.md_5.bungee.protocol.packet.LegacyPing; import net.md_5.bungee.protocol.packet.LoginPayloadRequest; @@ -158,4 +159,8 @@ public abstract class AbstractPacketHandler public void handle(LoginPayloadResponse response) throws Exception { } + + public void handle(EntityStatus status) throws Exception + { + } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index c4dd00a5..c5234c18 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -16,6 +16,7 @@ import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.EncryptionResponse; +import net.md_5.bungee.protocol.packet.EntityStatus; import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.KeepAlive; import net.md_5.bungee.protocol.packet.Kick; @@ -171,6 +172,12 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_12_1, 0x4A ), map( ProtocolConstants.MINECRAFT_1_13, 0x4E ) ); + TO_CLIENT.registerPacket( + EntityStatus.class, + map( ProtocolConstants.MINECRAFT_1_8, 0x1A ), + map( ProtocolConstants.MINECRAFT_1_9, 0x1B ), + map( ProtocolConstants.MINECRAFT_1_13, 0x1C ) + ); TO_SERVER.registerPacket( KeepAlive.class, diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/EntityStatus.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EntityStatus.java new file mode 100644 index 00000000..a151c0fa --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/EntityStatus.java @@ -0,0 +1,43 @@ +package net.md_5.bungee.protocol.packet; + +import io.netty.buffer.ByteBuf; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import net.md_5.bungee.protocol.AbstractPacketHandler; +import net.md_5.bungee.protocol.DefinedPacket; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class EntityStatus extends DefinedPacket +{ + + public static final byte DEBUG_INFO_REDUCED = 22; + public static final byte DEBUG_INFO_NORMAL = 23; + // + private int entityId; + private byte status; + + @Override + public void read(ByteBuf buf) + { + entityId = buf.readInt(); + status = buf.readByte(); + } + + @Override + public void write(ByteBuf buf) + { + buf.writeInt( entityId ); + buf.writeByte( status ); + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 721444c5..03b45d14 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -35,6 +35,7 @@ import net.md_5.bungee.protocol.PacketWrapper; import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.EncryptionRequest; +import net.md_5.bungee.protocol.packet.EntityStatus; import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.protocol.packet.Login; @@ -206,7 +207,7 @@ public class ServerConnector extends PacketHandler user.setClientEntityId( login.getEntityId() ); user.setServerEntityId( login.getEntityId() ); - // Set tab list size, this sucks balls, TODO: what shall we do about packet mutability + // Set tab list size, TODO: what shall we do about packet mutability Login modLogin = new Login( login.getEntityId(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.isReducedDebugInfo() ); @@ -245,6 +246,9 @@ public class ServerConnector extends PacketHandler } user.getSentBossBars().clear(); + // Update debug info from login packet + user.unsafe().sendPacket( new EntityStatus( user.getClientEntityId(), login.isReducedDebugInfo() ? EntityStatus.DEBUG_INFO_REDUCED : EntityStatus.DEBUG_INFO_NORMAL ) ); + user.setDimensionChange( true ); if ( login.getDimension() == user.getDimension() ) {