From 3eeea8e8f8fbf3b5c324d41f47318d298671cc58 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 17 Nov 2019 11:14:56 -0500 Subject: [PATCH] Add limited flush consolidation, if the remote server supports it. --- .../proxy/connection/MinecraftConnection.java | 7 +++++++ .../proxy/connection/MinecraftSessionHandler.java | 4 ++++ .../connection/backend/BackendPlaySessionHandler.java | 9 +++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java index c1f15cc19..91d99ceea 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -124,6 +124,13 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { } } + @Override + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { + if (sessionHandler != null) { + sessionHandler.readCompleted(); + } + } + @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (ctx.channel().isActive()) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftSessionHandler.java index 2789e17f9..297e5f884 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftSessionHandler.java @@ -70,6 +70,10 @@ public interface MinecraftSessionHandler { } + default void readCompleted() { + + } + default boolean handle(AvailableCommands commands) { return false; } 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 ba6678b78..aaa7e3c3a 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 @@ -168,12 +168,17 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { if (packet instanceof PluginMessage) { ((PluginMessage) packet).retain(); } - playerConnection.write(packet); + playerConnection.delayedWrite(packet); } @Override public void handleUnknown(ByteBuf buf) { - playerConnection.write(buf.retain()); + playerConnection.delayedWrite(buf.retain()); + } + + @Override + public void readCompleted() { + playerConnection.flush(); } @Override