Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -40,6 +40,16 @@ public interface ServerConnection extends ChannelMessageSource, ChannelMessageSi
*/
ServerInfo getServerInfo();

/**
* Returns the server info that this connection is currently connected to.
* Can be used for getting the resolved IP and port.
*
* @return the server info that this connection is currently connected to, if available;
* otherwise an empty {@link Optional} if the connection has not yet been established
* or has been closed
*/
Optional<ServerInfo> getConnectedServerInfo();

/**
* Returns the player that this connection is associated with.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Expand All @@ -67,6 +68,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
private final ConnectedPlayer proxyPlayer;
private final VelocityServer server;
private @Nullable MinecraftConnection connection;
private @Nullable ServerInfo connectedServerInfo;
private boolean hasCompletedJoin = false;
private boolean gracefulDisconnect = false;
private BackendConnectionPhase connectionPhase = BackendConnectionPhases.UNKNOWN;
Expand Down Expand Up @@ -106,6 +108,7 @@ public CompletableFuture<Impl> connect() {
.addListener((ChannelFutureListener) future -> {
if (future.isSuccess()) {
connection = new MinecraftConnection(future.channel(), server);
connectedServerInfo = new ServerInfo(registeredServer.getServerInfo().getName(), (InetSocketAddress) future.channel().remoteAddress());
connection.setAssociation(VelocityServerConnection.this);
future.channel().pipeline().addLast(HANDLER, connection);

Expand Down Expand Up @@ -235,6 +238,11 @@ public ServerInfo getServerInfo() {
return registeredServer.getServerInfo();
}

@Override
public Optional<ServerInfo> getConnectedServerInfo() {
return Optional.ofNullable(connectedServerInfo);
}

@Override
public ConnectedPlayer getPlayer() {
return proxyPlayer;
Expand All @@ -248,6 +256,7 @@ public void disconnect() {
gracefulDisconnect = true;
connection.close(false);
connection = null;
connectedServerInfo = null;
}
}

Expand Down