9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-25 09:59:20 +00:00

fix(auth): 修复获取不可信uuid

This commit is contained in:
jhqwqmc
2025-07-08 17:44:34 +08:00
parent 9cda66d675
commit cc640883b0
5 changed files with 20 additions and 27 deletions

View File

@@ -156,6 +156,7 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
registerNMSPacketConsumer(PacketConsumers.ROTATE_HEAD, NetworkReflections.clazz$ClientboundRotateHeadPacket);
registerNMSPacketConsumer(PacketConsumers.SET_ENTITY_MOTION, NetworkReflections.clazz$ClientboundSetEntityMotionPacket);
registerNMSPacketConsumer(PacketConsumers.FINISH_CONFIGURATION, NetworkReflections.clazz$ClientboundFinishConfigurationPacket);
registerNMSPacketConsumer(PacketConsumers.LOGIN_FINISHED, NetworkReflections.clazz$ClientboundLoginFinishedPacket);
registerS2CByteBufPacketConsumer(PacketConsumers.LEVEL_CHUNK_WITH_LIGHT, this.packetIds.clientboundLevelChunkWithLightPacket());
registerS2CByteBufPacketConsumer(PacketConsumers.SECTION_BLOCK_UPDATE, this.packetIds.clientboundSectionBlocksUpdatePacket());
registerS2CByteBufPacketConsumer(PacketConsumers.BLOCK_UPDATE, this.packetIds.clientboundBlockUpdatePacket());

View File

@@ -2406,11 +2406,6 @@ public class PacketConsumers {
CoreReflections.methodHandle$ServerCommonPacketListenerImpl$closedSetter.invokeExact(packetListener, false);
}
// 重新获取已验证的uuid
GameProfile gameProfile = (GameProfile) CoreReflections.methodHandle$ServerConfigurationPacketListenerImpl$gameProfileGetter.invokeExact(packetListener);
user.setName(gameProfile.getName());
user.setUUID(gameProfile.getId());
ResourcePackHost host = CraftEngine.instance().packManager().resourcePackHost();
host.requestResourcePackDownloadLink(user.uuid()).thenAccept(dataList -> {
if (dataList.isEmpty()) {
@@ -2438,4 +2433,15 @@ public class PacketConsumers {
CraftEngine.instance().logger().warn("Failed to handle ClientboundFinishConfigurationPacket", e);
}
};
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> LOGIN_FINISHED = (user, event, packet) -> {
try {
GameProfile gameProfile = FastNMS.INSTANCE.field$ClientboundLoginFinishedPacket$gameProfile(packet);
user.setName(gameProfile.getName());
user.setUUID(gameProfile.getId());
System.out.println("Login finished: " + user.name() + " " + user.uuid());
} catch (Exception e) {
CraftEngine.instance().logger().warn("Failed to handle ClientboundLoginFinishedPacket", e);
}
};
}

View File

@@ -2,7 +2,6 @@ package net.momirealms.craftengine.bukkit.plugin.reflection.minecraft;
import com.google.common.collect.ImmutableList;
import com.google.gson.JsonElement;
import com.mojang.authlib.GameProfile;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DynamicOps;
import io.netty.buffer.ByteBuf;
@@ -3765,24 +3764,4 @@ public final class CoreReflections {
clazz$Level, clazz$BlockPos, clazz$BlockState, clazz$Player
)
);
public static final Field field$ServerConfigurationPacketListenerImpl$gameProfile = Optional.ofNullable(clazz$ServerConfigurationPacketListenerImpl)
.map(it -> ReflectionUtils.getDeclaredField(it, GameProfile.class, 0))
.orElse(null);
public static final MethodHandle methodHandle$ServerConfigurationPacketListenerImpl$gameProfileGetter;
static {
try {
if (VersionHelper.isOrAbove1_20_2()) {
methodHandle$ServerConfigurationPacketListenerImpl$gameProfileGetter =
ReflectionUtils.unreflectGetter(field$ServerConfigurationPacketListenerImpl$gameProfile)
.asType(MethodType.methodType(GameProfile.class, Object.class));
} else {
methodHandle$ServerConfigurationPacketListenerImpl$gameProfileGetter = null;
}
} catch (ReflectiveOperationException e) {
throw new ReflectionInitException("Failed to initialize reflection", e);
}
}
}

View File

@@ -1554,4 +1554,11 @@ public final class NetworkReflections {
throw new ReflectionInitException("Failed to initialize ServerCommonPacketListener$handleResourcePackResponse", e);
}
}
public static final Class<?> clazz$ClientboundLoginFinishedPacket = requireNonNull(
BukkitReflectionUtils.findReobfOrMojmapClass(
"network.protocol.login.PacketLoginOutSuccess",
List.of("network.protocol.login.ClientboundLoginFinishedPacket", "network.protocol.login.ClientboundGameProfilePacket")
)
);
}

View File

@@ -50,7 +50,7 @@ byte_buddy_version=1.17.5
ahocorasick_version=0.6.3
snake_yaml_version=2.4
anti_grief_version=0.18
nms_helper_version=1.0.29
nms_helper_version=1.0.30
evalex_version=3.5.0
reactive_streams_version=1.0.4
amazon_awssdk_version=2.31.23