예제 #1
0
        public void SLUtilTypeConvertTests()
        {
            int[] assettypes = new int[] { -1, 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
                                           , 23, 24, 25, 46, 47, 48 };
            string[] contenttypes = new string[]
            {
                "application/octet-stream",
                "image/x-j2c",
                "audio/ogg",
                "application/vnd.ll.callingcard",
                "application/vnd.ll.landmark",
                "application/vnd.ll.clothing",
                "application/vnd.ll.primitive",
                "application/vnd.ll.notecard",
                "application/vnd.ll.folder",
                "application/vnd.ll.rootfolder",
                "application/vnd.ll.lsltext",
                "application/vnd.ll.lslbyte",
                "image/tga",
                "application/vnd.ll.bodypart",
                "application/vnd.ll.trashfolder",
                "application/vnd.ll.snapshotfolder",
                "application/vnd.ll.lostandfoundfolder",
                "audio/x-wav",
                "image/tga",
                "image/jpeg",
                "application/vnd.ll.animation",
                "application/vnd.ll.gesture",
                "application/x-metaverse-simstate",
                "application/vnd.ll.favoritefolder",
                "application/vnd.ll.link",
                "application/vnd.ll.linkfolder",
                "application/vnd.ll.currentoutfitfolder",
                "application/vnd.ll.outfitfolder",
                "application/vnd.ll.myoutfitsfolder"
            };
            for (int i = 0; i < assettypes.Length; i++)
            {
                Assert.That(SLUtil.SLAssetTypeToContentType(assettypes[i]) == contenttypes[i], "Expecting {0} but got {1}", contenttypes[i], SLUtil.SLAssetTypeToContentType(assettypes[i]));
            }

            for (int i = 0; i < contenttypes.Length; i++)
            {
                int expected;
                if (contenttypes[i] == "image/tga")
                {
                    expected = 12;  // if we know only the content-type "image/tga", then we assume the asset type is TextureTGA; not ImageTGA
                }
                else
                {
                    expected = assettypes[i];
                }
                Assert.AreEqual(expected, SLUtil.ContentTypeToSLAssetType(contenttypes[i]),
                                String.Format("Incorrect AssetType mapped from Content-Type {0}", contenttypes[i]));
            }

            int[]    inventorytypes  = new int[] { -1, 0, 1, 2, 3, 6, 7, 8, 9, 10, 15, 17, 18, 20 };
            string[] invcontenttypes = new string[]
            {
                "application/octet-stream",
                "image/x-j2c",
                "audio/ogg",
                "application/vnd.ll.callingcard",
                "application/vnd.ll.landmark",
                "application/vnd.ll.primitive",
                "application/vnd.ll.notecard",
                "application/vnd.ll.folder",
                "application/vnd.ll.rootfolder",
                "application/vnd.ll.lsltext",
                "image/x-j2c",
                "application/vnd.ll.primitive",
                "application/vnd.ll.clothing",
                "application/vnd.ll.gesture"
            };

            for (int i = 0; i < inventorytypes.Length; i++)
            {
                Assert.AreEqual(invcontenttypes[i], SLUtil.SLInvTypeToContentType(inventorytypes[i]),
                                String.Format("Incorrect Content-Type mapped from InventoryType {0}", inventorytypes[i]));
            }

            invcontenttypes = new string[]
            {
                "image/x-j2c", "image/jp2", "image/tga",
                "image/jpeg", "application/ogg", "audio/ogg",
                "audio/x-wav", "application/vnd.ll.callingcard",
                "application/x-metaverse-callingcard",
                "application/vnd.ll.landmark",
                "application/x-metaverse-landmark",
                "application/vnd.ll.clothing",
                "application/x-metaverse-clothing", "application/vnd.ll.bodypart",
                "application/x-metaverse-bodypart", "application/vnd.ll.primitive",
                "application/x-metaverse-primitive", "application/vnd.ll.notecard",
                "application/x-metaverse-notecard", "application/vnd.ll.folder",
                "application/vnd.ll.rootfolder", "application/vnd.ll.lsltext",
                "application/x-metaverse-lsl", "application/vnd.ll.lslbyte",
                "application/x-metaverse-lso", "application/vnd.ll.trashfolder",
                "application/vnd.ll.snapshotfolder",
                "application/vnd.ll.lostandfoundfolder", "application/vnd.ll.animation",
                "application/x-metaverse-animation", "application/vnd.ll.gesture",
                "application/x-metaverse-gesture", "application/x-metaverse-simstate",
                "application/octet-stream"
            };
            sbyte[] invtypes = new sbyte[]
            {
                0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 18, 18, 18, 18, 6, 6, 7, 7, 8, 9, 10, 10, 10, 10
                , 8, 8, 8, 19, 19, 20, 20, 15, -1
            };

            for (int i = 0; i < invtypes.Length; i++)
            {
                Assert.AreEqual(invtypes[i], SLUtil.ContentTypeToSLInvType(invcontenttypes[i]),
                                String.Format("Incorrect InventoryType mapped from Content-Type {0}", invcontenttypes[i]));
            }
        }
        /// <summary>
        /// Add a new item to the user's inventory
        /// </summary>
        /// <param name="item"></param>
        /// <returns>true if the item was successfully added</returns>
        public bool AddItem(InventoryItemBase item)
        {
            // A folder of UUID.Zero means we need to find the most appropriate home for this item
            if (item.Folder == UUID.Zero)
            {
                InventoryFolderBase folder = GetFolderForType(item.Owner, (AssetType)item.AssetType);
                if (folder != null && folder.ID != UUID.Zero)
                {
                    item.Folder = folder.ID;
                }
                else
                {
                    item.Folder = item.Owner; // Root folder
                }
            }

            if ((AssetType)item.AssetType == AssetType.Gesture)
            {
                UpdateGesture(item.Owner, item.ID, item.Flags == 1);
            }

            if (item.BasePermissions == 0)
            {
                m_log.WarnFormat("[SIMIAN INVENTORY CONNECTOR]: Adding inventory item {0} ({1}) with no base permissions", item.Name, item.ID);
            }

            OSDMap permissions = new OSDMap
            {
                { "BaseMask", OSD.FromInteger(item.BasePermissions) },
                { "EveryoneMask", OSD.FromInteger(item.EveryOnePermissions) },
                { "GroupMask", OSD.FromInteger(item.GroupPermissions) },
                { "NextOwnerMask", OSD.FromInteger(item.NextPermissions) },
                { "OwnerMask", OSD.FromInteger(item.CurrentPermissions) }
            };

            OSDMap extraData = new OSDMap()
            {
                { "Flags", OSD.FromInteger(item.Flags) },
                { "GroupID", OSD.FromUUID(item.GroupID) },
                { "GroupOwned", OSD.FromBoolean(item.GroupOwned) },
                { "SalePrice", OSD.FromInteger(item.SalePrice) },
                { "SaleType", OSD.FromInteger(item.SaleType) },
                { "Permissions", permissions }
            };

            // Add different asset type only if it differs from inventory type
            // (needed for links)
            string invContentType   = SLUtil.SLInvTypeToContentType(item.InvType);
            string assetContentType = SLUtil.SLAssetTypeToContentType(item.AssetType);

            if (invContentType != assetContentType)
            {
                extraData["LinkedItemType"] = OSD.FromString(assetContentType);
            }

            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "AddInventoryItem" },
                { "ItemID", item.ID.ToString() },
                { "AssetID", item.AssetID.ToString() },
                { "ParentID", item.Folder.ToString() },
                { "OwnerID", item.Owner.ToString() },
                { "Name", item.Name },
                { "Description", item.Description },
                { "CreatorID", item.CreatorId },
                { "CreatorData", item.CreatorData },
                { "ContentType", invContentType },
                { "ExtraData", OSDParser.SerializeJsonString(extraData) }
            };

            OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
            bool   success  = response["Success"].AsBoolean();

            if (!success)
            {
                m_log.Warn("[SIMIAN INVENTORY CONNECTOR]: Error creating item " + item.Name + " for " + item.Owner + ": " +
                           response["Message"].AsString());
            }

            return(success);
        }
예제 #3
0
        public void SLUtilTypeConvertTests()
        {
            int[] assettypes = new int[] { -1, 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
                                           , 23, 24, 25, 46, 47, 48 };
            string[] contenttypes = new string[]
            {
                "application/octet-stream",
                "image/x-j2c",
                "audio/ogg",
                "application/vnd.ll.callingcard",
                "application/vnd.ll.landmark",
                "application/vnd.ll.clothing",
                "application/vnd.ll.primitive",
                "application/vnd.ll.notecard",
                "application/vnd.ll.folder",
                "application/vnd.ll.rootfolder",
                "application/vnd.ll.lsltext",
                "application/vnd.ll.lslbyte",
                "image/tga",
                "application/vnd.ll.bodypart",
                "application/vnd.ll.trashfolder",
                "application/vnd.ll.snapshotfolder",
                "application/vnd.ll.lostandfoundfolder",
                "audio/x-wav",
                "image/tga",
                "image/jpeg",
                "application/vnd.ll.animation",
                "application/vnd.ll.gesture",
                "application/x-metaverse-simstate",
                "application/vnd.ll.favoritefolder",
                "application/vnd.ll.link",
                "application/vnd.ll.linkfolder",
                "application/vnd.ll.currentoutfitfolder",
                "application/vnd.ll.outfitfolder",
                "application/vnd.ll.myoutfitsfolder"
            };
            for (int i = 0; i < assettypes.Length; i++)
            {
                Assert.That(SLUtil.SLAssetTypeToContentType(assettypes[i]) == contenttypes[i], "Expecting {0} but got {1}", contenttypes[i], SLUtil.SLAssetTypeToContentType(assettypes[i]));
            }

            for (int i = 0; i < contenttypes.Length; i++)
            {
                if (SLUtil.ContentTypeToSLAssetType(contenttypes[i]) == 18)
                {
                    Assert.That(contenttypes[i] == "image/tga");
                }
                else
                {
                    Assert.That(SLUtil.ContentTypeToSLAssetType(contenttypes[i]) == assettypes[i],
                                "Expecting {0} but got {1}", assettypes[i],
                                SLUtil.ContentTypeToSLAssetType(contenttypes[i]));
                }
            }

            int[]    inventorytypes  = new int[] { -1, 0, 1, 2, 3, 6, 7, 8, 9, 10, 15, 17, 18, 20 };
            string[] invcontenttypes = new string[]
            {
                "application/octet-stream",
                "image/x-j2c",
                "audio/ogg",
                "application/vnd.ll.callingcard",
                "application/vnd.ll.landmark",
                "application/vnd.ll.primitive",
                "application/vnd.ll.notecard",
                "application/vnd.ll.folder",
                "application/octet-stream",
                "application/vnd.ll.lsltext",
                "image/x-j2c",
                "application/vnd.ll.primitive",
                "application/vnd.ll.clothing",
                "application/vnd.ll.gesture"
            };

            for (int i = 0; i < inventorytypes.Length; i++)
            {
                Assert.That(SLUtil.SLInvTypeToContentType(inventorytypes[i]) == invcontenttypes[i], "Expected {0}, Got {1}", invcontenttypes[i], SLUtil.SLInvTypeToContentType(inventorytypes[i]));
            }

            invcontenttypes = new string[]
            {
                "image/x-j2c", "image/jp2", "image/tga",
                "image/jpeg", "application/ogg", "audio/ogg",
                "audio/x-wav", "application/vnd.ll.callingcard",
                "application/x-metaverse-callingcard",
                "application/vnd.ll.landmark",
                "application/x-metaverse-landmark",
                "application/vnd.ll.clothing",
                "application/x-metaverse-clothing", "application/vnd.ll.bodypart",
                "application/x-metaverse-bodypart", "application/vnd.ll.primitive",
                "application/x-metaverse-primitive", "application/vnd.ll.notecard",
                "application/x-metaverse-notecard", "application/vnd.ll.folder",
                "application/vnd.ll.rootfolder", "application/vnd.ll.lsltext",
                "application/x-metaverse-lsl", "application/vnd.ll.lslbyte",
                "application/x-metaverse-lso", "application/vnd.ll.trashfolder",
                "application/vnd.ll.snapshotfolder",
                "application/vnd.ll.lostandfoundfolder", "application/vnd.ll.animation",
                "application/x-metaverse-animation", "application/vnd.ll.gesture",
                "application/x-metaverse-gesture", "application/x-metaverse-simstate",
                "application/octet-stream"
            };
            sbyte[] invtypes = new sbyte[]
            {
                0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 18, 18, 18, 18, 6, 6, 7, 7, 8, 9, 10, 10, 10, 10
                , 8, 8, 8, 19, 19, 20, 20, 15, -1
            };

            for (int i = 0; i < invtypes.Length; i++)
            {
                Assert.That(SLUtil.ContentTypeToSLInvType(invcontenttypes[i]) == invtypes[i], "Expected {0}, Got {1}", invtypes[i], SLUtil.ContentTypeToSLInvType(invcontenttypes[i]));
            }
        }