Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-06 00:00:47 +01:00
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:
Ursprung
53923ed857
Commit
e1f3b6b66f
@ -59,7 +59,7 @@ tasks {
|
||||
|
||||
val o = options as StandardJavadocDocletOptions
|
||||
o.encoding = "UTF-8"
|
||||
o.source = "8"
|
||||
o.source = "17"
|
||||
|
||||
o.links(
|
||||
"https://www.slf4j.org/apidocs/",
|
||||
|
@ -12,6 +12,7 @@ import com.velocitypowered.api.event.ResultedEvent;
|
||||
import com.velocitypowered.api.event.annotation.AwaitingEvent;
|
||||
import com.velocitypowered.api.proxy.InboundConnection;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
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 String username;
|
||||
private final @Nullable UUID uuid;
|
||||
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.
|
||||
*
|
||||
* @param connection the connection logging into the proxy
|
||||
* @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.username = Preconditions.checkNotNull(username, "username");
|
||||
this.uuid = uuid;
|
||||
this.result = PreLoginComponentResult.allowed();
|
||||
}
|
||||
|
||||
@ -55,13 +71,22 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
|
||||
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
|
||||
public PreLoginComponentResult getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResult(@NonNull PreLoginComponentResult result) {
|
||||
public void setResult(final @NonNull PreLoginComponentResult result) {
|
||||
this.result = Preconditions.checkNotNull(result, "result");
|
||||
}
|
||||
|
||||
@ -115,16 +140,12 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch (result) {
|
||||
case ALLOWED:
|
||||
return "allowed";
|
||||
case FORCE_OFFLINE:
|
||||
return "allowed with force offline mode";
|
||||
case FORCE_ONLINE:
|
||||
return "allowed with online mode";
|
||||
default:
|
||||
return "denied";
|
||||
}
|
||||
return switch (result) {
|
||||
case ALLOWED -> "allowed";
|
||||
case FORCE_OFFLINE -> "allowed with force offline mode";
|
||||
case FORCE_ONLINE -> "allowed with online mode";
|
||||
default -> "denied";
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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"));
|
||||
|
@ -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
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren