Add server-id hash to LoginEvent (#1027)

This commit is contained in:
Rocco
2026-02-10 18:59:34 +00:00
committed by GitHub
parent 7e01491e2f
commit 2535751cd9
3 changed files with 33 additions and 5 deletions

View File

@@ -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
@@ -213,7 +215,7 @@ public class AuthSessionHandler implements MinecraftSessionHandler {
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,

View File

@@ -152,7 +152,7 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler {
} else {
mcConnection.setActiveSessionHandler(StateRegistry.LOGIN,
new AuthSessionHandler(server, inbound,
GameProfile.forOfflinePlayer(login.getUsername()), false));
GameProfile.forOfflinePlayer(login.getUsername()), false, null));
}
});
});
@@ -255,7 +255,7 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler {
}
// 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(