Ejemplo n.º 1
0
        /// <summary>
        /// Hot patches inventory items that may have the wrong flags set and thus will not wear in the viewer
        /// </summary>
        /// <param name="baseItem"></param>
        /// <param name="uinfo"></param>
        /// <param name="clientView"></param>
        /// <returns></returns>
        private bool FixupItemFlagsOnWearableTypeMismatch(InventoryItemBase baseItem, CachedUserInfo uinfo, IClientAPI clientView)
        {
            if (baseItem.InvType != (int)InventoryType.Wearable) return false;

            //download the asset and extract the type. make sure the type matches the lower byte
            //of the inventory item flags

            AssetBase asset;
            try
            {
                asset = CommsManager.AssetCache.GetAsset(baseItem.AssetID, AssetRequestInfo.InternalRequest());
                if (asset == null) return false;    // not found
            }
            catch
            {
                //we couldnt get the asset, cant apply fixups
                return false;
            }

            //do we have the correct asset type to parse?
            if (asset.Type != (sbyte)AssetType.Clothing && asset.Type != (sbyte)AssetType.Bodypart) return false;

            try
            {
                uint wearableTypeInAsset = this.ParseWearableAndGetType(asset);

                //do they match?
                if (wearableTypeInAsset != (baseItem.Flags & 0xFF))
                {
                    //no. we need a fixup
                    m_log.ErrorFormat("[APPEARANCE]: Hotpatching item {0} due to flags mismatch: Got {1}, should be {2}",
                        baseItem.ID, baseItem.Flags & 0xFF, wearableTypeInAsset);

                    //remove the first byte
                    baseItem.Flags = baseItem.Flags & 0xFFFFFF00;
                    //combine our type
                    baseItem.Flags = baseItem.Flags | (wearableTypeInAsset & 0xFF);

                    //save back the inventory item with updated flags
                    uinfo.UpdateItem(baseItem);

                    //inform viewer
                    clientView.SendBulkUpdateInventory(baseItem);

                    return true;
                }

                return false;
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[APPEARANCE]: Error when attempting to parse wearable and update item for Flags hotpatch {0}", e);

                //couldnt parse wearable
                return false;
            }
        }