Expose connecting player's UUID in the PreLoginEvent (#1009)

* feature: Expose connecting player's UUID in the PreLoginEvent

* Applied suggestions

* Updated the javadocs compatible version to Java 17

---------

Co-authored-by: Adrian <adriangonzalesval@gmail.com>
This commit is contained in:
Kezz
2024-02-09 16:23:47 +01:00
committed by GitHub
parent 53923ed857
commit e1f3b6b66f
4 changed files with 43 additions and 20 deletions

View File

@@ -74,7 +74,7 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler {
private @MonotonicNonNull ServerLoginPacket login;
private byte[] verify = EMPTY_BYTE_ARRAY;
private LoginState currentState = LoginState.LOGIN_PACKET_EXPECTED;
private boolean forceKeyAuthentication;
private final boolean forceKeyAuthentication;
InitialLoginSessionHandler(VelocityServer server, MinecraftConnection mcConnection,
LoginInboundConnection inbound) {
@@ -100,8 +100,7 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler {
boolean isKeyValid;
if (playerKey.getKeyRevision() == IdentifiedKey.Revision.LINKED_V2
&& playerKey instanceof IdentifiedKeyImpl) {
IdentifiedKeyImpl keyImpl = (IdentifiedKeyImpl) playerKey;
&& playerKey instanceof final IdentifiedKeyImpl keyImpl) {
isKeyValid = keyImpl.internalAddHolder(packet.getHolderUuid());
} else {
isKeyValid = playerKey.isSignatureValid();
@@ -120,7 +119,7 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler {
inbound.setPlayerKey(playerKey);
this.login = packet;
PreLoginEvent event = new PreLoginEvent(inbound, login.getUsername());
final PreLoginEvent event = new PreLoginEvent(inbound, login.getUsername(), login.getHolderUuid());
server.getEventManager().fire(event).thenRunAsync(() -> {
if (mcConnection.isClosed()) {
// The player was disconnected
@@ -245,8 +244,7 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler {
// Not so fast, now we verify the public key for 1.19.1+
if (inbound.getIdentifiedKey() != null
&& inbound.getIdentifiedKey().getKeyRevision() == IdentifiedKey.Revision.LINKED_V2
&& inbound.getIdentifiedKey() instanceof IdentifiedKeyImpl) {
IdentifiedKeyImpl key = (IdentifiedKeyImpl) inbound.getIdentifiedKey();
&& inbound.getIdentifiedKey() instanceof final IdentifiedKeyImpl key) {
if (!key.internalAddHolder(profile.getId())) {
inbound.disconnect(
Component.translatable("multiplayer.disconnect.invalid_public_key"));

View File

@@ -74,7 +74,11 @@ public class ServerLoginPacket implements MinecraftPacket {
@Override
public String toString() {
return "ServerLogin{" + "username='" + username + '\'' + "playerKey='" + playerKey + '\'' + '}';
return "ServerLogin{"
+ "username='" + username + '\''
+ "uuid='" + holderUuid + '\''
+ "playerKey='" + playerKey + '\''
+ '}';
}
@Override