From c7469ec13c9ed3f1e2cc27b381222ee5173cb9c0 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 26 Aug 2018 23:58:35 -0400 Subject: [PATCH] Removed all entity ID rewriting logic. This was all a no-op anyway, and should the need for this arise again, it is trivial to re-add. However, Velocity does not need this, and probably will never need it. Let's have the complexity go away. --- .../backend/BackendPlaySessionHandler.java | 6 +--- .../client/ClientPlaySessionHandler.java | 11 +------ .../protocol/remap/EntityIdRemapper.java | 29 ----------------- .../protocol/remap/NoopEntityIdRemapper.java | 32 ------------------- 4 files changed, 2 insertions(+), 76 deletions(-) delete mode 100644 proxy/src/main/java/com/velocitypowered/proxy/protocol/remap/EntityIdRemapper.java delete mode 100644 proxy/src/main/java/com/velocitypowered/proxy/protocol/remap/NoopEntityIdRemapper.java diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index be62948cc..639fe070d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -86,11 +86,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { connection.getMinecraftConnection().close(); return; } - - ClientPlaySessionHandler playerHandler = - (ClientPlaySessionHandler) connection.getPlayer().getConnection().getSessionHandler(); - ByteBuf remapped = playerHandler.getIdRemapper().remap(buf, ProtocolConstants.Direction.CLIENTBOUND); - connection.getPlayer().getConnection().write(remapped); + connection.getPlayer().getConnection().write(buf.retain()); } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 9a60be7a4..1e011e5e8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -8,7 +8,6 @@ import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.packet.*; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.proxy.protocol.remap.EntityIdRemapper; import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; import com.velocitypowered.proxy.util.ThrowableUtils; import io.netty.buffer.ByteBuf; @@ -33,7 +32,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { private boolean spawned = false; private final List serverBossBars = new ArrayList<>(); private final Set clientPluginMsgChannels = new HashSet<>(); - private EntityIdRemapper idRemapper; public ClientPlaySessionHandler(ConnectedPlayer player) { this.player = player; @@ -127,8 +125,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { @Override public void handleUnknown(ByteBuf buf) { - ByteBuf remapped = idRemapper.remap(buf, ProtocolConstants.Direction.SERVERBOUND); - player.getConnectedServer().getMinecraftConnection().write(remapped); + player.getConnectedServer().getMinecraftConnection().write(buf.retain()); } @Override @@ -152,7 +149,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // nothing special to do here spawned = true; player.getConnection().delayedWrite(joinGame); - idRemapper = EntityIdRemapper.getMapper(joinGame.getEntityId(), player.getConnection().getProtocolVersion()); } else { // Ah, this is the meat and potatoes of the whole venture! // @@ -167,7 +163,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // Most notably, by having the client accept the join game packet, we can work around the need to perform // entity ID rewrites, eliminating potential issues from rewriting packets and improving compatibility with // mods. - idRemapper.setServerEntityId(joinGame.getEntityId()); player.getConnection().delayedWrite(joinGame); int tempDim = joinGame.getDimension() == 0 ? -1 : 0; player.getConnection().delayedWrite(new Respawn(tempDim, joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType())); @@ -250,10 +245,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { return clientPluginMsgChannels; } - public EntityIdRemapper getIdRemapper() { - return idRemapper; - } - public void setLastPing(long lastPing) { this.lastPingID = lastPing; this.lastPingSent = System.currentTimeMillis(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/remap/EntityIdRemapper.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/remap/EntityIdRemapper.java deleted file mode 100644 index c112b344f..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/remap/EntityIdRemapper.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.velocitypowered.proxy.protocol.remap; - -import com.velocitypowered.proxy.protocol.ProtocolConstants; -import io.netty.buffer.ByteBuf; - -/** - * Represents a protocol-specific entity ID remapper for certain Minecraft packets. This is mostly required to support - * old versions of Minecraft. For Minecraft 1.8 clients and above, Velocity can use a more efficient method based on - * sending JoinGame packets multiple times. - */ -public interface EntityIdRemapper { - /** - * Remaps the entity IDs in this packet so that they apply to the player. - * @param original the packet to remap - * @param direction the direction of the packet - * @return a remapped packet, which may either be a retained version of the original buffer or an entirely new buffer - */ - ByteBuf remap(ByteBuf original, ProtocolConstants.Direction direction); - - int getClientEntityId(); - - int getServerEntityId(); - - void setServerEntityId(int id); - - static EntityIdRemapper getMapper(int eid, int protocolVersion) { - return NoopEntityIdRemapper.INSTANCE; - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/remap/NoopEntityIdRemapper.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/remap/NoopEntityIdRemapper.java deleted file mode 100644 index f5a3b68f0..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/remap/NoopEntityIdRemapper.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.velocitypowered.proxy.protocol.remap; - -import com.velocitypowered.proxy.protocol.ProtocolConstants; -import io.netty.buffer.ByteBuf; - -public class NoopEntityIdRemapper implements EntityIdRemapper { - public static final NoopEntityIdRemapper INSTANCE = new NoopEntityIdRemapper(); - - private NoopEntityIdRemapper() { - - } - - @Override - public ByteBuf remap(ByteBuf original, ProtocolConstants.Direction direction) { - return original.retain(); - } - - @Override - public int getClientEntityId() { - return 0; - } - - @Override - public int getServerEntityId() { - return 0; - } - - @Override - public void setServerEntityId(int id) { - - } -}