Add Virtualhost support for server list pings (#1265)
* Add virtualhost support for server list pings * Add virtualhost support to ping public API * Applied suggestions * fixed checkstyle * Added nullable annotation --------- Co-authored-by: Adrian <adriangonzalesval@gmail.com>
This commit is contained in:
@@ -63,7 +63,7 @@ public class ServerListPingHandler {
|
||||
}
|
||||
|
||||
private CompletableFuture<ServerPing> attemptPingPassthrough(VelocityInboundConnection connection,
|
||||
PingPassthroughMode mode, List<String> servers, ProtocolVersion responseProtocolVersion) {
|
||||
PingPassthroughMode mode, List<String> servers, ProtocolVersion responseProtocolVersion, String virtualHostStr) {
|
||||
ServerPing fallback = constructLocalPing(connection.getProtocolVersion());
|
||||
List<CompletableFuture<ServerPing>> pings = new ArrayList<>();
|
||||
for (String s : servers) {
|
||||
@@ -73,7 +73,7 @@ public class ServerListPingHandler {
|
||||
}
|
||||
VelocityRegisteredServer vrs = (VelocityRegisteredServer) rs.get();
|
||||
pings.add(vrs.ping(connection.getConnection().eventLoop(), PingOptions.builder()
|
||||
.version(responseProtocolVersion).build()));
|
||||
.version(responseProtocolVersion).virtualHost(virtualHostStr).build()));
|
||||
}
|
||||
if (pings.isEmpty()) {
|
||||
return CompletableFuture.completedFuture(fallback);
|
||||
@@ -155,7 +155,7 @@ public class ServerListPingHandler {
|
||||
.orElse("");
|
||||
List<String> serversToTry = server.getConfiguration().getForcedHosts().getOrDefault(
|
||||
virtualHostStr, server.getConfiguration().getAttemptConnectionOrder());
|
||||
return attemptPingPassthrough(connection, passthroughMode, serversToTry, shownVersion);
|
||||
return attemptPingPassthrough(connection, passthroughMode, serversToTry, shownVersion, virtualHostStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -43,20 +43,23 @@ public class PingSessionHandler implements MinecraftSessionHandler {
|
||||
private final MinecraftConnection connection;
|
||||
private final ProtocolVersion version;
|
||||
private boolean completed = false;
|
||||
private final String virtualHostString;
|
||||
|
||||
PingSessionHandler(CompletableFuture<ServerPing> result, RegisteredServer server,
|
||||
MinecraftConnection connection, ProtocolVersion version) {
|
||||
MinecraftConnection connection, ProtocolVersion version, String virtualHostString) {
|
||||
this.result = result;
|
||||
this.server = server;
|
||||
this.connection = connection;
|
||||
this.version = version;
|
||||
this.virtualHostString = virtualHostString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activated() {
|
||||
HandshakePacket handshake = new HandshakePacket();
|
||||
handshake.setIntent(HandshakeIntent.STATUS);
|
||||
handshake.setServerAddress(server.getServerInfo().getAddress().getHostString());
|
||||
handshake.setServerAddress(this.virtualHostString == null || this.virtualHostString.isEmpty()
|
||||
? server.getServerInfo().getAddress().getHostString() : this.virtualHostString);
|
||||
handshake.setPort(server.getServerInfo().getAddress().getPort());
|
||||
handshake.setProtocolVersion(version);
|
||||
connection.delayedWrite(handshake);
|
||||
|
@@ -129,7 +129,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
|
||||
if (future.isSuccess()) {
|
||||
MinecraftConnection conn = future.channel().pipeline().get(MinecraftConnection.class);
|
||||
PingSessionHandler handler = new PingSessionHandler(pingFuture,
|
||||
VelocityRegisteredServer.this, conn, pingOptions.getProtocolVersion());
|
||||
VelocityRegisteredServer.this, conn, pingOptions.getProtocolVersion(), pingOptions.getVirtualHost());
|
||||
conn.setActiveSessionHandler(StateRegistry.HANDSHAKE, handler);
|
||||
} else {
|
||||
pingFuture.completeExceptionally(future.cause());
|
||||
|
Reference in New Issue
Block a user