Don't require a GameProfileFetcher implementation by default

This commit is contained in:
RaphiMC 2023-04-28 21:25:58 +02:00
parent d622a45873
commit ab4d1a93ca
8 changed files with 35 additions and 47 deletions

View File

@ -102,6 +102,7 @@ If your platform supports online mode authentication you also should not always
#### GameProfileFetcher
The game profile fetcher is used to fetch the game profile of a player if the server version is <= 1.7.10.
This is required because the game profile or UUID of players is not sent by the server in <= 1.7.10.
The GameProfileFetcher is only used when ``legacy-skin-loading`` or ``legacy-skull-loading`` is set to ``true`` in the config. If you don't plan to use those options you don't need to implement this provider.
Here is an example implementation using the [Steveice10 AuthLib](https://github.com/GeyserMC/MCAuthLib):
```java
public class AuthLibGameProfileFetcher extends GameProfileFetcher {

View File

@ -50,7 +50,7 @@ public class ViaLegacyConfig extends Config implements net.raphimc.vialegacy.pla
private void loadFields() {
this.dynamicOnground = this.getBoolean("dynamic-onground", true);
this.ignoreLongChannelNames = this.getBoolean("ignore-long-1_8-channel-names", true);
this.legacySkullLoading = this.getBoolean("legacy-skull-loading", true);
this.legacySkullLoading = this.getBoolean("legacy-skull-loading", false);
this.legacySkinLoading = this.getBoolean("legacy-skin-loading", false);
this.soundEmulation = this.getBoolean("sound-emulation", true);
this.oldBiomes = this.getBoolean("old-biomes", true);

View File

@ -58,6 +58,7 @@ import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.types.Type
import net.raphimc.vialegacy.protocols.release.protocol1_7_6_10to1_7_2_5.ClientboundPackets1_7_2;
import net.raphimc.vialegacy.protocols.release.protocol1_7_6_10to1_7_2_5.ServerboundPackets1_7_2;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.Protocol1_8to1_7_6_10;
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;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Chunk1_7_6Type;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.ChunkBulk1_7_6Type;
@ -384,8 +385,7 @@ public class Protocol1_7_2_5to1_6_4 extends AbstractProtocol<ClientboundPackets1
map(Type.INT, Type.VAR_INT); // entity id
handler(wrapper -> {
final String name = wrapper.read(Types1_6_4.STRING); // name
final GameProfileFetcher gameProfileFetcher = Via.getManager().getProviders().get(GameProfileFetcher.class);
wrapper.write(Type.STRING, (ViaLegacy.getConfig().isLegacySkinLoading() ? gameProfileFetcher.getMojangUUID(name) : gameProfileFetcher.getOfflineUUID(name)).toString().replace("-", "")); // uuid
wrapper.write(Type.STRING, (ViaLegacy.getConfig().isLegacySkinLoading() ? Via.getManager().getProviders().get(GameProfileFetcher.class).getMojangUUID(name) : new GameProfile(name).uuid).toString().replace("-", "")); // uuid
wrapper.write(Type.STRING, name);
});
map(Type.INT); // x
@ -924,9 +924,8 @@ public class Protocol1_7_2_5to1_6_4 extends AbstractProtocol<ClientboundPackets1
final String name = wrapper.read(Type.STRING); // user name
final ProtocolInfo info = wrapper.user().getProtocolInfo();
final HandshakeStorage handshakeStorage = wrapper.user().get(HandshakeStorage.class);
final GameProfileFetcher gameProfileFetcher = Via.getManager().getProviders().get(GameProfileFetcher.class);
info.setUsername(name);
info.setUuid(ViaLegacy.getConfig().isLegacySkinLoading() ? gameProfileFetcher.getMojangUUID(info.getUsername()) : gameProfileFetcher.getOfflineUUID(info.getUsername()));
info.setUuid(ViaLegacy.getConfig().isLegacySkinLoading() ? Via.getManager().getProviders().get(GameProfileFetcher.class).getMojangUUID(name) : new GameProfile(name).uuid);
wrapper.write(Type.UNSIGNED_BYTE, (short) (-info.getServerProtocolVersion() >> 2)); // protocol id
wrapper.write(Types1_6_4.STRING, name); // user name

View File

@ -84,8 +84,6 @@ public class Protocol1_7_6_10to1_7_2_5 extends AbstractProtocol<ClientboundPacke
map(Type.UNSIGNED_BYTE); // type
map(Types1_7_6.COMPRESSED_NBT); // data
handler(wrapper -> {
final GameProfileFetcher gameProfileFetcher = Via.getManager().getProviders().get(GameProfileFetcher.class);
final Position pos = wrapper.get(Types1_7_6.POSITION_SHORT, 0);
final short type = wrapper.get(Type.UNSIGNED_BYTE, 0);
final CompoundTag tag = wrapper.get(Types1_7_6.COMPRESSED_NBT, 0);
@ -95,38 +93,40 @@ public class Protocol1_7_6_10to1_7_2_5 extends AbstractProtocol<ClientboundPacke
final StringTag extraType = tag.remove("ExtraType");
if (!ViaLegacy.getConfig().isLegacySkullLoading()) return;
if (ViaLegacy.getConfig().isLegacySkullLoading()) {
final GameProfileFetcher gameProfileFetcher = Via.getManager().getProviders().get(GameProfileFetcher.class);
final String skullName = extraType == null ? "" : extraType.getValue();
final CompoundTag newTag = tag.clone();
final String skullName = extraType == null ? "" : extraType.getValue();
final CompoundTag newTag = tag.clone();
if (gameProfileFetcher.isUUIDLoaded(skullName)) { // short cut if skull is already loaded
final UUID uuid = gameProfileFetcher.getMojangUUID(skullName);
if (gameProfileFetcher.isGameProfileLoaded(uuid)) {
if (gameProfileFetcher.isUUIDLoaded(skullName)) { // short cut if skull is already loaded
final UUID uuid = gameProfileFetcher.getMojangUUID(skullName);
if (gameProfileFetcher.isGameProfileLoaded(uuid)) {
final GameProfile skullProfile = gameProfileFetcher.getGameProfile(uuid);
if (skullProfile == null || skullProfile.isOffline()) return;
newTag.put("Owner", writeGameProfileToTag(skullProfile));
wrapper.set(Types1_7_6.COMPRESSED_NBT, 0, newTag);
return;
}
}
gameProfileFetcher.getMojangUUIDAsync(skullName).thenAccept(uuid -> {
final GameProfile skullProfile = gameProfileFetcher.getGameProfile(uuid);
if (skullProfile == null || skullProfile.isOffline()) return;
newTag.put("Owner", writeGameProfileToTag(skullProfile));
wrapper.set(Types1_7_6.COMPRESSED_NBT, 0, newTag);
return;
}
try {
final PacketWrapper updateSkull = PacketWrapper.create(ClientboundPackets1_7_2.BLOCK_ENTITY_DATA, wrapper.user());
updateSkull.write(Types1_7_6.POSITION_SHORT, pos);
updateSkull.write(Type.UNSIGNED_BYTE, type);
updateSkull.write(Types1_7_6.COMPRESSED_NBT, newTag);
updateSkull.send(Protocol1_7_6_10to1_7_2_5.class);
} catch (Throwable e) {
e.printStackTrace();
}
});
}
gameProfileFetcher.getMojangUUIDAsync(skullName).thenAccept(uuid -> {
final GameProfile skullProfile = gameProfileFetcher.getGameProfile(uuid);
if (skullProfile == null || skullProfile.isOffline()) return;
newTag.put("Owner", writeGameProfileToTag(skullProfile));
try {
final PacketWrapper updateSkull = PacketWrapper.create(ClientboundPackets1_7_2.BLOCK_ENTITY_DATA, wrapper.user());
updateSkull.write(Types1_7_6.POSITION_SHORT, pos);
updateSkull.write(Type.UNSIGNED_BYTE, type);
updateSkull.write(Types1_7_6.COMPRESSED_NBT, newTag);
updateSkull.send(Protocol1_7_6_10to1_7_2_5.class);
} catch (Throwable e) {
e.printStackTrace();
}
});
});
}
});

View File

@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
@ -60,7 +59,6 @@ import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.GameP
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.MapData;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.MapIcon;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.TabListEntry;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.rewriter.ChatItemRewriter;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.rewriter.ItemRewriter;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.rewriter.TranslationRewriter;
@ -1574,11 +1572,6 @@ public class Protocol1_8to1_7_6_10 extends AbstractProtocol<ClientboundPackets1_
return (int) Math.floor((yPos - yOffset) * 32F);
}
@Override
public void register(ViaProviders providers) {
providers.require(GameProfileFetcher.class);
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new TablistStorage(userConnection));

View File

@ -63,7 +63,7 @@ public abstract class GameProfileFetcher implements Provider {
while (e instanceof ExecutionException || e instanceof UncheckedExecutionException || e instanceof CompletionException) e = e.getCause();
ViaLegacy.getPlatform().getLogger().log(Level.WARNING, "Failed to load uuid for player '" + playerName + "' (" + e.getClass().getName() + ")");
}
final UUID uuid = this.getOfflineUUID(playerName);
final UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(StandardCharsets.UTF_8));
UUID_CACHE.put(playerName, uuid);
return uuid;
}
@ -109,10 +109,6 @@ public abstract class GameProfileFetcher implements Provider {
return future;
}
public UUID getOfflineUUID(final String playerName) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(StandardCharsets.UTF_8));
}
public abstract UUID loadMojangUUID(final String playerName) throws Exception;
public abstract GameProfile loadGameProfile(final UUID uuid) throws Exception;

View File

@ -83,9 +83,8 @@ public class ItemRewriter extends LegacyItemRewriter<Protocol1_8to1_7_6_10> {
}
}
if (skullOwnerName != null) {
if (skullOwnerName != null && ViaLegacy.getConfig().isLegacySkullLoading()) {
final GameProfileFetcher gameProfileFetcher = Via.getManager().getProviders().get(GameProfileFetcher.class);
if (!ViaLegacy.getConfig().isLegacySkullLoading()) return item;
if (gameProfileFetcher.isUUIDLoaded(skullOwnerName)) {
final UUID uuid = gameProfileFetcher.getMojangUUID(skullOwnerName);

View File

@ -7,7 +7,7 @@ dynamic-onground: true
ignore-long-1_8-channel-names: true
#
# Load <= 1.7.2 player skull skins
legacy-skull-loading: true
legacy-skull-loading: false
#
# Load <= 1.6.4 skins. (Adds max 500ms delay to player spawn packets)
legacy-skin-loading: false