Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional Pack Detection Code #4806

Closed
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
private final Deque<String> packsToSent = new ArrayDeque<>();
private final CompressionStrategy compressionStrategy;

private boolean optionalPackLoaded = false;
private SessionLoadResourcePacksEventImpl resourcePackLoadEvent;

public UpstreamPacketHandler(GeyserImpl geyser, GeyserSession session) {
Expand Down Expand Up @@ -208,8 +209,8 @@ public PacketSignal handle(LoginPacket loginPacket) {
PackCodec codec = pack.codec();
ResourcePackManifest.Header header = pack.manifest().header();
resourcePacksInfo.getResourcePackInfos().add(new ResourcePacksInfoPacket.Entry(
header.uuid().toString(), header.version().toString(), codec.size(), pack.contentKey(),
"", header.uuid().toString(), false, false));
header.uuid().toString(), header.version().toString(), codec.size(), pack.contentKey(),
"", header.uuid().toString(), false, false));
}
resourcePacksInfo.setForcedToAccept(GeyserImpl.getInstance().getConfig().isForceResourcePacks());
session.sendUpstreamPacket(resourcePacksInfo);
Expand All @@ -218,10 +219,22 @@ public PacketSignal handle(LoginPacket loginPacket) {
return PacketSignal.HANDLED;
}

private boolean sendPacksRequested = false;
private boolean haveAllPacksRequested = false;
private boolean requestedPackData = false;

@Override
public PacketSignal handle(ResourcePackClientResponsePacket packet) {
switch (packet.getStatus()) {

case COMPLETED:
if (!sendPacksRequested && haveAllPacksRequested && GeyserImpl.getInstance().getConfig().isForceResourcePacks()) {
requestedPackData = true;
}
if (requestedPackData) {
session.setOptionalPackLoaded(this.optionalPackLoaded);
}
geyser.getLogger().debug("Geyser Optional Pack loaded: " + (session.isOptionalPackLoaded() ? "Yes" : "No"));
if (geyser.getConfig().getRemote().authType() != AuthType.ONLINE) {
session.authenticate(session.getAuthData().name());
} else if (!couldLoginUserByName(session.getAuthData().name())) {
Expand All @@ -232,11 +245,14 @@ public PacketSignal handle(ResourcePackClientResponsePacket packet) {
break;

case SEND_PACKS:
sendPacksRequested = true;
requestedPackData = true;
packsToSent.addAll(packet.getPackIds());
sendPackDataInfo(packsToSent.pop());
break;

case HAVE_ALL_PACKS:
haveAllPacksRequested = true;
ResourcePackStackPacket stackPacket = new ResourcePackStackPacket();
stackPacket.setExperimentsPreviouslyToggled(false);
stackPacket.setForcedToAccept(false); // Leaving this as false allows the player to choose to download or not
Expand All @@ -245,6 +261,9 @@ public PacketSignal handle(ResourcePackClientResponsePacket packet) {
for (ResourcePack pack : this.resourcePackLoadEvent.resourcePacks()) {
ResourcePackManifest.Header header = pack.manifest().header();
stackPacket.getResourcePacks().add(new ResourcePackStackPacket.Entry(header.uuid().toString(), header.version().toString(), ""));
if (pack.manifest().header().uuid().toString().equals("e5f5c938-a701-11eb-b2a3-047d7bb283ba")) {
this.optionalPackLoaded = true;
}
}

if (GeyserImpl.getInstance().getConfig().isAddNonBedrockItems()) {
Expand Down Expand Up @@ -308,10 +327,10 @@ public PacketSignal handle(MovePlayerPacket packet) {

@Override
public PacketSignal handle(ResourcePackChunkRequestPacket packet) {
requestedPackData = true;
ResourcePackChunkDataPacket data = new ResourcePackChunkDataPacket();
ResourcePack pack = this.resourcePackLoadEvent.getPacks().get(packet.getPackId().toString());
PackCodec codec = pack.codec();

data.setChunkIndex(packet.getChunkIndex());
data.setProgress((long) packet.getChunkIndex() * GeyserResourcePack.CHUNK_SIZE);
data.setPackVersion(packet.getPackVersion());
Expand Down Expand Up @@ -346,7 +365,9 @@ private void sendPackDataInfo(String id) {
ResourcePack pack = this.resourcePackLoadEvent.getPacks().get(packID[0]);
PackCodec codec = pack.codec();
ResourcePackManifest.Header header = pack.manifest().header();

if (header.uuid().toString().equals("e5f5c938-a701-11eb-b2a3-047d7bb283ba")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check doesn't need to be here; should be fine to have it above

this.optionalPackLoaded = true;
}
data.setPackId(header.uuid());
int chunkCount = (int) Math.ceil(codec.size() / (double) GeyserResourcePack.CHUNK_SIZE);
data.setChunkCount(chunkCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
@Setter
private float walkSpeed;

@Setter
private boolean optionalPackLoaded = false;
/**
* Caches current rain status.
*/
Expand Down