Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Virtualhost support for server list pings #1265

Open
wants to merge 2 commits into
base: dev/3.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private ServerPing constructLocalPing(ProtocolVersion version) {
}

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) {
Expand All @@ -73,7 +73,7 @@ private CompletableFuture<ServerPing> attemptPingPassthrough(VelocityInboundConn
}
VelocityRegisteredServer vrs = (VelocityRegisteredServer) rs.get();
pings.add(vrs.ping(connection.getConnection().eventLoop(), PingOptions.builder()
.version(responseProtocolVersion).build()));
.version(responseProtocolVersion).build(), virtualHostStr));
}
if (pings.isEmpty()) {
return CompletableFuture.completedFuture(fallback);
Expand Down Expand Up @@ -155,7 +155,7 @@ public CompletableFuture<ServerPing> getInitialPing(VelocityInboundConnection co
.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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,22 @@ 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.setNextStatus(StateRegistry.STATUS_ID);
handshake.setServerAddress(server.getServerInfo().getAddress().getHostString());
handshake.setServerAddress(this.virtualHostString.isEmpty() ? server.getServerInfo().getAddress().getHostString() : this.virtualHostString);
handshake.setPort(server.getServerInfo().getAddress().getPort());
handshake.setProtocolVersion(version);
connection.delayedWrite(handshake);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public CompletableFuture<ServerPing> ping() {
return ping(null, PingOptions.DEFAULT);
}

public CompletableFuture<ServerPing> ping(@Nullable EventLoop loop, PingOptions pingOptions) {
return ping(loop, pingOptions, "");
}

/**
* Pings the specified server using the specified event {@code loop}, claiming to be {@code
* version}.
Expand All @@ -102,7 +106,7 @@ public CompletableFuture<ServerPing> ping() {
* @param pingOptions the options to apply to this ping
* @return the server list ping response
*/
public CompletableFuture<ServerPing> ping(@Nullable EventLoop loop, PingOptions pingOptions) {
public CompletableFuture<ServerPing> ping(@Nullable EventLoop loop, PingOptions pingOptions, String virtualHostString) {
if (server == null) {
throw new IllegalStateException("No Velocity proxy instance available");
}
Expand All @@ -125,7 +129,7 @@ protected void initChannel(Channel ch) throws Exception {
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(), virtualHostString);
conn.setActiveSessionHandler(StateRegistry.HANDSHAKE, handler);
} else {
pingFuture.completeExceptionally(future.cause());
Expand Down
Loading