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 InboundConnection#getHandshakeIntent #1493

Merged
merged 2 commits into from
Jan 15, 2025
Merged
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 @@ -7,6 +7,7 @@

package com.velocitypowered.api.proxy;

import com.velocitypowered.api.network.HandshakeIntent;
import com.velocitypowered.api.network.ProtocolState;
import com.velocitypowered.api.network.ProtocolVersion;
import java.net.InetSocketAddress;
Expand Down Expand Up @@ -60,4 +61,11 @@ public interface InboundConnection {
* @return the protocol state of the connection
*/
ProtocolState getProtocolState();

/**
* Returns the initial intent for the connection.
*
* @return the intent of the connection
*/
HandshakeIntent getHandshakeIntent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void activated() {
// Initiate a regular connection and move over to it.
ConnectedPlayer player = new ConnectedPlayer(server, profileEvent.getGameProfile(),
mcConnection, inbound.getVirtualHost().orElse(null), inbound.getRawVirtualHost().orElse(null), onlineMode,
inbound.getIdentifiedKey());
inbound.getHandshakeIntent(), inbound.getIdentifiedKey());
this.connectedPlayer = player;
if (!server.canRegisterConnection(player)) {
player.disconnect0(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.velocitypowered.api.event.player.PlayerSettingsChangedEvent;
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
import com.velocitypowered.api.event.player.configuration.PlayerEnterConfigurationEvent;
import com.velocitypowered.api.network.HandshakeIntent;
import com.velocitypowered.api.network.ProtocolState;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.permission.PermissionFunction;
Expand Down Expand Up @@ -156,6 +157,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
private final MinecraftConnection connection;
private final @Nullable InetSocketAddress virtualHost;
private final @Nullable String rawVirtualHost;
private final HandshakeIntent handshakeIntent;
private GameProfile profile;
private PermissionFunction permissionFunction;
private int tryIndex = 0;
Expand Down Expand Up @@ -193,12 +195,13 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,

ConnectedPlayer(VelocityServer server, GameProfile profile, MinecraftConnection connection,
@Nullable InetSocketAddress virtualHost, @Nullable String rawVirtualHost, boolean onlineMode,
@Nullable IdentifiedKey playerKey) {
HandshakeIntent handshakeIntent, @Nullable IdentifiedKey playerKey) {
this.server = server;
this.profile = profile;
this.connection = connection;
this.virtualHost = virtualHost;
this.rawVirtualHost = rawVirtualHost;
this.handshakeIntent = handshakeIntent;
this.permissionFunction = PermissionFunction.ALWAYS_UNDEFINED;
this.connectionPhase = connection.getType().getInitialClientPhase();
this.onlineMode = onlineMode;
Expand Down Expand Up @@ -1335,6 +1338,11 @@ public ProtocolState getProtocolState() {
return connection.getState().toProtocolState();
}

@Override
public HandshakeIntent getHandshakeIntent() {
return handshakeIntent;
}

private final class ConnectionRequestBuilderImpl implements ConnectionRequestBuilder {

private final RegisteredServer toConnect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,5 +277,10 @@ public MinecraftConnection getConnection() {
public ProtocolState getProtocolState() {
return connection.getState().toProtocolState();
}

@Override
public HandshakeIntent getHandshakeIntent() {
return HandshakeIntent.STATUS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.velocitypowered.proxy.connection.client;

import com.velocitypowered.api.network.HandshakeIntent;
import com.velocitypowered.api.network.ProtocolState;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.InboundConnection;
Expand Down Expand Up @@ -98,6 +99,11 @@ public ProtocolState getProtocolState() {
return connection.getState().toProtocolState();
}

@Override
public HandshakeIntent getHandshakeIntent() {
return handshake.getIntent();
}

/**
* Disconnects the connection from the server.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.velocitypowered.proxy.connection.client;

import com.velocitypowered.api.network.HandshakeIntent;
import com.velocitypowered.api.network.ProtocolState;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.LoginPhaseConnection;
Expand Down Expand Up @@ -177,4 +178,9 @@ public IdentifiedKey getIdentifiedKey() {
public ProtocolState getProtocolState() {
return delegate.getProtocolState();
}

@Override
public HandshakeIntent getHandshakeIntent() {
return delegate.getHandshakeIntent();
}
}