From 1da51b8ffb3bf6cec7faef648becf2fe5781a351 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 29 Jul 2019 05:25:29 -0400 Subject: [PATCH] Batch handshake and server login/ping packets --- .../proxy/connection/backend/VelocityServerConnection.java | 5 +++-- .../velocitypowered/proxy/server/PingSessionHandler.java | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index 39e0bbd0c..5922238a1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -150,11 +150,12 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, handshake.setServerAddress(registeredServer.getServerInfo().getAddress().getHostString()); } handshake.setPort(registeredServer.getServerInfo().getAddress().getPort()); - mc.write(handshake); + mc.delayedWrite(handshake); mc.setProtocolVersion(protocolVersion); mc.setState(StateRegistry.LOGIN); - mc.write(new ServerLogin(proxyPlayer.getUsername())); + mc.delayedWrite(new ServerLogin(proxyPlayer.getUsername())); + mc.flush(); } public @Nullable MinecraftConnection getConnection() { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java index 63e7630c8..48875b988 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java @@ -34,10 +34,12 @@ public class PingSessionHandler implements MinecraftSessionHandler { handshake.setServerAddress(server.getServerInfo().getAddress().getHostString()); handshake.setPort(server.getServerInfo().getAddress().getPort()); handshake.setProtocolVersion(ProtocolVersion.MINIMUM_VERSION); - connection.write(handshake); + connection.delayedWrite(handshake); connection.setState(StateRegistry.STATUS); - connection.write(StatusRequest.INSTANCE); + connection.delayedWrite(StatusRequest.INSTANCE); + + connection.flush(); } @Override