From d2e95e2f183b2816ccd8ecb977ae1696b0f05e0e Mon Sep 17 00:00:00 2001 From: TwistedAsylumMC Date: Mon, 3 Oct 2022 18:18:15 +0100 Subject: [PATCH] minecraft/conn.go: Remember which packs have been ignored --- minecraft/conn.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/minecraft/conn.go b/minecraft/conn.go index 518d8bff..3bad3761 100644 --- a/minecraft/conn.go +++ b/minecraft/conn.go @@ -122,6 +122,9 @@ type Conn struct { // downloadResourcePack is an optional function passed to a Dial() call. If set, each resource pack received // from the server will call this function to see if it should be downloaded or not. downloadResourcePack func(id uuid.UUID, version string) bool + // ignoredResourcePacks is a slice of resource packs that are not being downloaded due to the downloadResourcePack + // func returning false for the specific pack. + ignoredResourcePacks []exemptedResourcePack cacheEnabled bool @@ -808,6 +811,8 @@ func (conn *Conn) handleClientCacheStatus(pk *packet.ClientCacheStatus) error { // handleResourcePacksInfo handles a ResourcePacksInfo packet sent by the server. The client responds by // sending the packs it needs downloaded. func (conn *Conn) handleResourcePacksInfo(pk *packet.ResourcePacksInfo) error { + conn.packMu.Lock() + defer conn.packMu.Unlock() // First create a new resource pack queue with the information in the packet so we can download them // properly later. conn.packQueue = &resourcePackQueue{ @@ -824,6 +829,10 @@ func (conn *Conn) handleResourcePacksInfo(pk *packet.ResourcePacksInfo) error { continue } if conn.downloadResourcePack != nil && !conn.downloadResourcePack(uuid.MustParse(pack.UUID), pack.Version) { + conn.ignoredResourcePacks = append(conn.ignoredResourcePacks, exemptedResourcePack{ + uuid: pack.UUID, + version: pack.Version, + }) continue } // This UUID_Version is a hack Mojang put in place. @@ -842,6 +851,10 @@ func (conn *Conn) handleResourcePacksInfo(pk *packet.ResourcePacksInfo) error { continue } if conn.downloadResourcePack != nil && !conn.downloadResourcePack(uuid.MustParse(pack.UUID), pack.Version) { + conn.ignoredResourcePacks = append(conn.ignoredResourcePacks, exemptedResourcePack{ + uuid: pack.UUID, + version: pack.Version, + }) continue } // This UUID_Version is a hack Mojang put in place. @@ -909,6 +922,11 @@ func (conn *Conn) hasPack(uuid string, version string, hasBehaviours bool) bool conn.packMu.Lock() defer conn.packMu.Unlock() + for _, ignored := range conn.ignoredResourcePacks { + if ignored.uuid == uuid && ignored.version == version { + return true + } + } for _, pack := range conn.resourcePacks { if pack.UUID() == uuid && pack.Version() == version && pack.HasBehaviours() == hasBehaviours { return true