Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -11,6 +11,7 @@
import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.event.annotation.AwaitingEvent;
import com.velocitypowered.api.proxy.Player;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* This event is fired once the player has been authenticated, but before they connect to a server.
Expand All @@ -22,19 +23,33 @@
public final class LoginEvent implements ResultedEvent<ResultedEvent.ComponentResult> {

private final Player player;
private final String serverIdHash;
private ComponentResult result;

/**
* Constructs a new {@link LoginEvent}.
*
* @param player the player who has completed authentication
* @param serverIdHash the server ID hash sent to Mojang for authentication,
* or {@code null} if the connection is in offline-mode
*/
public LoginEvent(Player player) {
public LoginEvent(Player player, @Nullable String serverIdHash) {
this.player = Preconditions.checkNotNull(player, "player");
this.serverIdHash = serverIdHash;
this.result = ComponentResult.allowed();
}

/**
* Constructs a new {@link LoginEvent}.
*
* @param player the player who has completed authentication
* @deprecated Use {@link #LoginEvent(Player, String)}.
*/
@Deprecated(forRemoval = true)
public LoginEvent(Player player) {
this(player, null);
}

* Returns the player who has completed authentication.
*
* @return the authenticated player
Expand All @@ -43,6 +58,16 @@ public Player getPlayer() {
return player;
}

/**
* Returns the server ID hash that was sent to Mojang to authenticate the player.
* If the connection was in offline-mode, this returns {@code null}.
*
* @return the server ID hash that was sent to Mojang to authenticate the player
*/
public @Nullable String getServerIdHash() {
return serverIdHash;
}

@Override
public ComponentResult getResult() {
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ public class AuthSessionHandler implements MinecraftSessionHandler {
private @MonotonicNonNull ConnectedPlayer connectedPlayer;
private final boolean onlineMode;
private State loginState = State.START; // 1.20.2+
private final String serverIdHash;

AuthSessionHandler(VelocityServer server, LoginInboundConnection inbound,
GameProfile profile, boolean onlineMode) {
GameProfile profile, boolean onlineMode, String serverIdHash) {
this.server = Preconditions.checkNotNull(server, "server");
this.inbound = Preconditions.checkNotNull(inbound, "inbound");
this.profile = Preconditions.checkNotNull(profile, "profile");
this.onlineMode = onlineMode;
this.mcConnection = inbound.delegatedConnection();
this.serverIdHash = serverIdHash;
}

@Override
Expand Down Expand Up @@ -213,7 +215,7 @@ public boolean handle(ServerboundCookieResponsePacket packet) {
private void completeLoginProtocolPhaseAndInitialize(ConnectedPlayer player) {
mcConnection.setAssociation(player);

server.getEventManager().fire(new LoginEvent(player)).thenAcceptAsync(event -> {
server.getEventManager().fire(new LoginEvent(player, serverIdHash)).thenAcceptAsync(event -> {
if (mcConnection.isClosed()) {
// The player was disconnected
server.getEventManager().fireAndForget(new DisconnectEvent(player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public boolean handle(ServerLoginPacket packet) {
} else {
mcConnection.setActiveSessionHandler(StateRegistry.LOGIN,
new AuthSessionHandler(server, inbound,
GameProfile.forOfflinePlayer(login.getUsername()), false));
GameProfile.forOfflinePlayer(login.getUsername()), false, null));
}
});
});
Expand Down Expand Up @@ -255,7 +255,7 @@ public boolean handle(EncryptionResponsePacket packet) {
}
// All went well, initialize the session.
mcConnection.setActiveSessionHandler(StateRegistry.LOGIN,
new AuthSessionHandler(server, inbound, profile, true));
new AuthSessionHandler(server, inbound, profile, true, serverId));
} else if (response.statusCode() == 204) {
// Apparently an offline-mode user logged onto this online-mode proxy.
inbound.disconnect(
Expand Down
Loading