From 65ff9ebb393a065efb4997fe9a2ad30b956282ca Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 28 Oct 2018 01:10:23 -0400 Subject: [PATCH] Tiny legacy player info forwarding forwarding micro-optimization. --- .../backend/VelocityServerConnection.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 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 bed0f611d..2e0bf3aa9 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 @@ -100,14 +100,19 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, return result; } - private String createBungeeForwardingAddress() { + private String createLegacyForwardingAddress() { // BungeeCord IP forwarding is simply a special injection after the "address" in the handshake, // separated by \0 (the null byte). In order, you send the original host, the player's IP, their // UUID (undashed), and if you are in online-mode, their login properties (from Mojang). - return registeredServer.getServerInfo().getAddress().getHostString() + "\0" - + proxyPlayer.getRemoteAddress().getHostString() + "\0" - + proxyPlayer.getProfile().getId() + "\0" - + GSON.toJson(proxyPlayer.getProfile().getProperties()); + StringBuilder data = new StringBuilder(2048) + .append(registeredServer.getServerInfo().getAddress().getHostString()) + .append('\0') + .append(proxyPlayer.getRemoteAddress().getHostString()) + .append('\0') + .append(proxyPlayer.getProfile().getId()) + .append('\0'); + GSON.toJson(proxyPlayer.getProfile().getProperties(), data); + return data.toString(); } private void startHandshake() { @@ -123,7 +128,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, handshake.setNextStatus(StateRegistry.LOGIN_ID); handshake.setProtocolVersion(proxyPlayer.getConnection().getNextProtocolVersion()); if (forwardingMode == PlayerInfoForwarding.LEGACY) { - handshake.setServerAddress(createBungeeForwardingAddress()); + handshake.setServerAddress(createLegacyForwardingAddress()); } else if (proxyPlayer.getConnection().isLegacyForge()) { handshake.setServerAddress(handshake.getServerAddress() + "\0FML\0"); } else {