diff --git a/src/main/java/net/raphimc/vialegacy/api/util/UuidUtil.java b/src/main/java/net/raphimc/vialegacy/api/util/UuidUtil.java new file mode 100644 index 0000000..e8b8d10 --- /dev/null +++ b/src/main/java/net/raphimc/vialegacy/api/util/UuidUtil.java @@ -0,0 +1,29 @@ +/* + * This file is part of ViaLegacy - https://github.com/RaphiMC/ViaLegacy + * Copyright (C) 2020-2024 RK_01/RaphiMC and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.raphimc.vialegacy.api.util; + +import java.nio.charset.StandardCharsets; +import java.util.UUID; + +public class UuidUtil { + + public static UUID createOfflinePlayerUuid(final String name) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8)); + } + +} diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/Protocol1_7_2_5to1_6_4.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/Protocol1_7_2_5to1_6_4.java index f8a0742..933bf03 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/Protocol1_7_2_5to1_6_4.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/Protocol1_7_2_5to1_6_4.java @@ -856,14 +856,10 @@ public class Protocol1_7_2_5to1_6_4 extends StatelessTransitionProtocol { - final String name = wrapper.read(Type.STRING); // user name - final ProtocolInfo info = wrapper.user().getProtocolInfo(); final HandshakeStorage handshakeStorage = wrapper.user().get(HandshakeStorage.class); - info.setUsername(name); - info.setUuid(ViaLegacy.getConfig().isLegacySkinLoading() ? Via.getManager().getProviders().get(GameProfileFetcher.class).getMojangUUID(name) : new GameProfile(name).uuid); - wrapper.write(Type.UNSIGNED_BYTE, (short) LegacyProtocolVersion.getRealProtocolVersion(info.getServerProtocolVersion())); // protocol id - wrapper.write(Types1_6_4.STRING, name); // user name + wrapper.write(Type.UNSIGNED_BYTE, (short) LegacyProtocolVersion.getRealProtocolVersion(wrapper.user().getProtocolInfo().getServerProtocolVersion())); // protocol id + wrapper.write(Types1_6_4.STRING, wrapper.read(Type.STRING)); // user name wrapper.write(Types1_6_4.STRING, handshakeStorage.getHostname()); // hostname wrapper.write(Type.INT, handshakeStorage.getPort()); // port }); diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_6_10to1_7_2_5/Protocol1_7_6_10to1_7_2_5.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_6_10to1_7_2_5/Protocol1_7_6_10to1_7_2_5.java index d12643e..320b024 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_6_10to1_7_2_5/Protocol1_7_6_10to1_7_2_5.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_6_10to1_7_2_5/Protocol1_7_6_10to1_7_2_5.java @@ -31,6 +31,7 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.protocols.base.BaseProtocol1_7; import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; import net.raphimc.vialegacy.ViaLegacy; +import net.raphimc.vialegacy.api.util.UuidUtil; import net.raphimc.vialegacy.protocols.release.protocol1_7_6_10to1_7_2_5.rewriter.TranslationRewriter; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.GameProfile; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher; @@ -174,7 +175,7 @@ public class Protocol1_7_6_10to1_7_2_5 extends AbstractProtocol { // 1.7.10 ignores the data from the server + final ProtocolInfo protocolInfo = wrapper.user().getProtocolInfo(); + wrapper.write(Type.STRING, protocolInfo.getUuid().toString()); // uuid + wrapper.write(Type.STRING, protocolInfo.getUsername()); // name + }); + } + }); this.registerClientbound(ClientboundPackets1_7_2.KEEP_ALIVE, new PacketHandlers() { @Override public void register() { @@ -1146,6 +1160,18 @@ public class Protocol1_8to1_7_6_10 extends AbstractProtocol { + final String name = wrapper.passthrough(Type.STRING); // name + final ProtocolInfo info = wrapper.user().getProtocolInfo(); + // Set the information early + info.setUsername(name); + info.setUuid(ViaLegacy.getConfig().isLegacySkinLoading() ? Via.getManager().getProviders().get(GameProfileFetcher.class).getMojangUUID(name) : new GameProfile(name).uuid); + }); + } + }); this.registerServerbound(State.LOGIN, ServerboundLoginPackets.ENCRYPTION_KEY.getId(), ServerboundLoginPackets.ENCRYPTION_KEY.getId(), new PacketHandlers() { @Override public void register() { @@ -1504,6 +1530,11 @@ public class Protocol1_8to1_7_6_10 extends AbstractProtocol