@Test void cleanVhostHandlesOctetsAndForge() { assertEquals("localhost", cleanVhost("localhost." + HANDSHAKE_HOSTNAME_TOKEN)); assertEquals("mc.example.com", cleanVhost("mc.example.com." + HANDSHAKE_HOSTNAME_TOKEN)); }
@VisibleForTesting static String cleanVhost(String hostname) { String cleaned = hostname; int zeroIdx = cleaned.indexOf('\0'); if (zeroIdx > -1) { cleaned = hostname.substring(0, zeroIdx); } if (!cleaned.isEmpty() && cleaned.charAt(cleaned.length() - 1) == '.') { cleaned = cleaned.substring(0, cleaned.length() - 1); } return cleaned; }
HandshakeSessionHandler implements MinecraftSessionHandler { @VisibleForTesting static String cleanVhost(String hostname) { String cleaned = hostname; int zeroIdx = cleaned.indexOf('\0'); if (zeroIdx > -1) { cleaned = hostname.substring(0, zeroIdx); } if (!cleaned.isEmpty() && cleaned.charAt(cleaned.length() - 1) == '.') { cleaned = cleaned.substring(0, cleaned.length() - 1); } return cleaned; } }
HandshakeSessionHandler implements MinecraftSessionHandler { @VisibleForTesting static String cleanVhost(String hostname) { String cleaned = hostname; int zeroIdx = cleaned.indexOf('\0'); if (zeroIdx > -1) { cleaned = hostname.substring(0, zeroIdx); } if (!cleaned.isEmpty() && cleaned.charAt(cleaned.length() - 1) == '.') { cleaned = cleaned.substring(0, cleaned.length() - 1); } return cleaned; } HandshakeSessionHandler(MinecraftConnection connection, VelocityServer server); }
HandshakeSessionHandler implements MinecraftSessionHandler { @VisibleForTesting static String cleanVhost(String hostname) { String cleaned = hostname; int zeroIdx = cleaned.indexOf('\0'); if (zeroIdx > -1) { cleaned = hostname.substring(0, zeroIdx); } if (!cleaned.isEmpty() && cleaned.charAt(cleaned.length() - 1) == '.') { cleaned = cleaned.substring(0, cleaned.length() - 1); } return cleaned; } HandshakeSessionHandler(MinecraftConnection connection, VelocityServer server); @Override boolean handle(LegacyPing packet); @Override boolean handle(LegacyHandshake packet); @Override boolean handle(Handshake handshake); @Override void handleGeneric(MinecraftPacket packet); @Override void handleUnknown(ByteBuf buf); }
HandshakeSessionHandler implements MinecraftSessionHandler { @VisibleForTesting static String cleanVhost(String hostname) { String cleaned = hostname; int zeroIdx = cleaned.indexOf('\0'); if (zeroIdx > -1) { cleaned = hostname.substring(0, zeroIdx); } if (!cleaned.isEmpty() && cleaned.charAt(cleaned.length() - 1) == '.') { cleaned = cleaned.substring(0, cleaned.length() - 1); } return cleaned; } HandshakeSessionHandler(MinecraftConnection connection, VelocityServer server); @Override boolean handle(LegacyPing packet); @Override boolean handle(LegacyHandshake packet); @Override boolean handle(Handshake handshake); @Override void handleGeneric(MinecraftPacket packet); @Override void handleUnknown(ByteBuf buf);  }