Skip to content

Commit

Permalink
minecraft/conn.go: Remember which packs have been ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Oct 3, 2022
1 parent 9f71fa2 commit d2e95e2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions minecraft/conn.go
Expand Up @@ -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

Expand Down Expand Up @@ -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()

This comment has been minimized.

Copy link
@Sandertv

Sandertv Oct 3, 2022

Owner

This locking/unlocking isn't necessary here.

// First create a new resource pack queue with the information in the packet so we can download them
// properly later.
conn.packQueue = &resourcePackQueue{
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d2e95e2

Please sign in to comment.