13
0
geforkt von Mirrors/Velocity

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>
Dieser Commit ist enthalten in:
Kezz 2024-02-09 16:23:47 +01:00 committet von GitHub
Ursprung 53923ed857
Commit e1f3b6b66f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
4 geänderte Dateien mit 43 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -59,7 +59,7 @@ tasks {
val o = options as StandardJavadocDocletOptions val o = options as StandardJavadocDocletOptions
o.encoding = "UTF-8" o.encoding = "UTF-8"
o.source = "8" o.source = "17"
o.links( o.links(
"https://www.slf4j.org/apidocs/", "https://www.slf4j.org/apidocs/",

Datei anzeigen

@ -12,6 +12,7 @@ import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.event.annotation.AwaitingEvent; import com.velocitypowered.api.event.annotation.AwaitingEvent;
import com.velocitypowered.api.proxy.InboundConnection; import com.velocitypowered.api.proxy.InboundConnection;
import java.util.Optional; import java.util.Optional;
import java.util.UUID;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -33,17 +34,32 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
private final InboundConnection connection; private final InboundConnection connection;
private final String username; private final String username;
private final @Nullable UUID uuid;
private PreLoginComponentResult result; private PreLoginComponentResult result;
/**
* Creates a new instance, without an associated UUID.
*
* @param connection the connection logging into the proxy
* @param username the player's username
* @deprecated use {@link #PreLoginEvent(InboundConnection, String, UUID)}
*/
@Deprecated
public PreLoginEvent(final InboundConnection connection, final String username) {
this(connection, username, null);
}
/** /**
* Creates a new instance. * Creates a new instance.
* *
* @param connection the connection logging into the proxy * @param connection the connection logging into the proxy
* @param username the player's username * @param username the player's username
* @param uuid the player's uuid, if known
*/ */
public PreLoginEvent(InboundConnection connection, String username) { public PreLoginEvent(final InboundConnection connection, final String username, final @Nullable UUID uuid) {
this.connection = Preconditions.checkNotNull(connection, "connection"); this.connection = Preconditions.checkNotNull(connection, "connection");
this.username = Preconditions.checkNotNull(username, "username"); this.username = Preconditions.checkNotNull(username, "username");
this.uuid = uuid;
this.result = PreLoginComponentResult.allowed(); this.result = PreLoginComponentResult.allowed();
} }
@ -55,13 +71,22 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
return username; return username;
} }
/**
* Returns the UUID of the connecting player. This value is {@code null} on 1.19.1 and lower.
*
* @return the uuid
*/
public @Nullable UUID getUniqueId() {
return uuid;
}
@Override @Override
public PreLoginComponentResult getResult() { public PreLoginComponentResult getResult() {
return result; return result;
} }
@Override @Override
public void setResult(@NonNull PreLoginComponentResult result) { public void setResult(final @NonNull PreLoginComponentResult result) {
this.result = Preconditions.checkNotNull(result, "result"); this.result = Preconditions.checkNotNull(result, "result");
} }
@ -115,16 +140,12 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
@Override @Override
public String toString() { public String toString() {
switch (result) { return switch (result) {
case ALLOWED: case ALLOWED -> "allowed";
return "allowed"; case FORCE_OFFLINE -> "allowed with force offline mode";
case FORCE_OFFLINE: case FORCE_ONLINE -> "allowed with online mode";
return "allowed with force offline mode"; default -> "denied";
case FORCE_ONLINE: };
return "allowed with online mode";
default:
return "denied";
}
} }
/** /**

Datei anzeigen

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

Datei anzeigen

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