From ac9cc82e4d4e96d2d8aa0ae0306a47cfb639f5d7 Mon Sep 17 00:00:00 2001 From: olebeck <31539311+olebeck@users.noreply.github.com> Date: Mon, 22 Jul 2024 02:20:49 +0200 Subject: [PATCH] fix issue with http --- utils/proxy/resourcepacks.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/utils/proxy/resourcepacks.go b/utils/proxy/resourcepacks.go index 9b066a1..774dfb4 100644 --- a/utils/proxy/resourcepacks.go +++ b/utils/proxy/resourcepacks.go @@ -178,13 +178,11 @@ func (r *rpHandler) OnResourcePacksInfo(pk *packet.ResourcePacksInfo) error { idxURL := slices.IndexFunc(pk.PackURLs, func(pu protocol.PackURL) bool { return pu.UUIDVersion == packID }) if idxURL != -1 { - url := pk.PackURLs[idxURL] - r.dlwg.Add(1) - go func() { + go func(url string) { defer r.dlwg.Done() - r.log.Infof("Downloading Resourcepack: %s", url.URL) - newPack, err := resource.ReadURL(url.URL) + r.log.Infof("Downloading Resourcepack: %s", url) + newPack, err := resource.ReadURL(url) if err != nil { r.log.Error(err) return @@ -217,7 +215,7 @@ func (r *rpHandler) OnResourcePacksInfo(pk *packet.ResourcePacksInfo) error { r.nextPackToClient <- newPack } } - }() + }(pk.PackURLs[idxURL].URL) return nil } @@ -267,6 +265,7 @@ func (r *rpHandler) OnResourcePacksInfo(pk *packet.ResourcePacksInfo) error { } if len(packsToDownload) == 0 { + r.dlwg.Wait() r.Server.Expect(packet.IDResourcePackStack) return r.Server.WritePacket(&packet.ResourcePackClientResponse{Response: packet.PackResponseAllPacksDownloaded}) } @@ -453,6 +452,7 @@ func (r *rpHandler) downloadResourcePack(pk *packet.ResourcePackDataInfo) error // finished downloading if len(r.downloadingPacks) == 0 { + r.dlwg.Wait() if r.nextPackToClient != nil { close(r.nextPackToClient) } @@ -545,6 +545,7 @@ func (r *rpHandler) OnResourcePackStack(pk *packet.ResourcePackStack) error { } } + r.dlwg.Wait() r.log.Debug("starting game") r.Server.Expect(packet.IDStartGame) _ = r.Server.WritePacket(&packet.ResourcePackClientResponse{Response: packet.PackResponseCompleted})