Esempio n. 1
0
        public AvatarData(AvatarAppearance appearance)
        {
            AvatarType = 1; // SL avatars
            Data = new Dictionary<string, string>();

            Data["Serial"] = appearance.Serial.ToString();
            // Wearables
            Data["AvatarHeight"] = appearance.AvatarHeight.ToString();

            Data["Textures"] = OSDParser.SerializeJsonString(appearance.Texture.GetOSD());

            for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++)
            {
                for (int j = 0; j < appearance.Wearables[i].Count; j++)
                {
                    string fieldName = String.Format("Wearable {0}:{1}", i, j);
                    Data[fieldName] = String.Format("{0}:{1}",
                            appearance.Wearables[i][j].ItemID.ToString(),
                            appearance.Wearables[i][j].AssetID.ToString());
                }
            }

            // Visual Params
            string[] vps = new string[AvatarAppearance.VISUALPARAM_COUNT];
            byte[] binary = appearance.VisualParams;

            for (int i = 0; i < AvatarAppearance.VISUALPARAM_COUNT; i++)
            {
                vps[i] = binary[i].ToString();
            }

            Data["VisualParams"] = String.Join(",", vps);

            // Attachments
            List<AvatarAttachment> attachments = appearance.GetAttachments();
            foreach (AvatarAttachment attach in attachments)
            {
                Data["_ap_" + attach.AttachPoint] = attach.ItemID.ToString();
            }
        }
Esempio n. 2
0
        private AvatarAppearance CopyWearablesAndAttachments(UUID destination, UUID source,
            AvatarAppearance avatarAppearance,
            InventoryFolderBase destinationFolder, UUID agentid,
            OSDMap itemsMap,
            out List<InventoryItemBase> items)
        {
            if (destinationFolder == null)
                throw new Exception("Cannot locate folder(s)");
            items = new List<InventoryItemBase>();

            List<InventoryItemBase> litems = new List<InventoryItemBase>();
            foreach (KeyValuePair<string, OSD> kvp in itemsMap)
            {
                InventoryItemBase item = new InventoryItemBase();
                item.FromOSD((OSDMap)kvp.Value);
                MainConsole.Instance.Info("[AvatarArchive]: Loading item " + item.ID.ToString());
                litems.Add(item);
            }

            // Wearables
            AvatarWearable[] wearables = avatarAppearance.Wearables;

            for (int i = 0; i < wearables.Length; i++)
            {
                AvatarWearable wearable = wearables[i];
                for (int ii = 0; ii < wearable.Count; ii++)
                {
                    if (wearable[ii].ItemID != UUID.Zero)
                    {
                        // Get inventory item and copy it
                        InventoryItemBase item = InventoryService.GetItem(UUID.Zero, wearable[ii].ItemID);

                        if (item == null)
                        {
                            //Attempt to get from the map if it doesn't already exist on the grid
                            item = litems.First((itm) => itm.ID == wearable[ii].ItemID);
                        }
                        if (item != null)
                        {
                            InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination,
                                                                                                        destination,
                                                                                                        item,
                                                                                                        destinationFolder
                                                                                                            .ID,
                                                                                                        false, false);
                            items.Add(destinationItem);
                            MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}",
                                                             destinationItem.ID, destinationFolder.ID);

                            // Wear item
                            AvatarWearable newWearable = new AvatarWearable();
                            newWearable.Wear(destinationItem.ID, destinationItem.AssetID);
                            avatarAppearance.SetWearable(i, newWearable);
                        }
                        else
                        {
                            MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}",
                                                            wearable[ii].ItemID, destinationFolder.ID);
                        }
                    }
                }
            }

            // Attachments
            List<AvatarAttachment> attachments = avatarAppearance.GetAttachments();

            foreach (AvatarAttachment attachment in attachments)
            {
                int attachpoint = attachment.AttachPoint;
                UUID itemID = attachment.ItemID;

                if (itemID != UUID.Zero)
                {
                    // Get inventory item and copy it
                    InventoryItemBase item = InventoryService.GetItem(UUID.Zero, itemID);

                    if (item != null)
                    {
                        InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination,
                                                                                                    destination, item,
                                                                                                    destinationFolder.ID,
                                                                                                    false, false);
                        items.Add(destinationItem);
                        MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID,
                                                         destinationFolder.ID);

                        // Attach item
                        avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
                        MainConsole.Instance.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID);
                    }
                    else
                    {
                        MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID,
                                                        destinationFolder.ID);
                    }
                }
            }
            return avatarAppearance;
        }
Esempio n. 3
0
        public AvatarAppearance WearFolder(AvatarAppearance avappearance, UUID user, UUID folderOwnerID)
        {
            InventoryFolderBase Folder2Wear = m_InventoryService.GetFolderByOwnerAndName(folderOwnerID,
                                                                                         m_forceUserToWearFolderName);
            if (Folder2Wear != null)
            {
                List<InventoryItemBase> itemsInFolder = m_InventoryService.GetFolderItems(UUID.Zero, Folder2Wear.ID);

                InventoryFolderBase appearanceFolder = m_InventoryService.GetFolderForType(user, InventoryType.Wearable,
                                                                                           AssetType.Clothing);

                InventoryFolderBase folderForAppearance = new InventoryFolderBase(UUID.Random(), "GridWear", user, -1,
                                                                                  appearanceFolder.ID, 1);
                List<InventoryFolderBase> userFolders = m_InventoryService.GetFolderFolders(user, appearanceFolder.ID);
                bool alreadyThere = false;
                List<UUID> items2RemoveFromAppearence = new List<UUID>();
                List<UUID> toDelete = new List<UUID>();
                foreach (InventoryFolderBase folder in userFolders)
                {
                    if (folder.Name == folderForAppearance.Name)
                    {
                        List<InventoryItemBase> itemsInCurrentFolder = m_InventoryService.GetFolderItems(UUID.Zero,
                                                                                                         folder.ID);
                        foreach (InventoryItemBase itemBase in itemsInCurrentFolder)
                        {
                            items2RemoveFromAppearence.Add(itemBase.AssetID);
                            items2RemoveFromAppearence.Add(itemBase.ID);
                            toDelete.Add(itemBase.ID);
                        }
                        folderForAppearance = folder;
                        alreadyThere = true;
                        m_InventoryService.DeleteItems(user, toDelete);
                        break;
                    }
                }

                if (!alreadyThere)
                    m_InventoryService.AddFolder(folderForAppearance);
                else
                {
                    // we have to remove all the old items if they are currently wearing them
                    for (int i = 0; i < avappearance.Wearables.Length; i++)
                    {
                        AvatarWearable wearable = avappearance.Wearables[i];
                        for (int ii = 0; ii < wearable.Count; ii++)
                        {
                            if (items2RemoveFromAppearence.Contains(wearable[ii].ItemID))
                            {
                                avappearance.Wearables[i] = AvatarWearable.DefaultWearables[i];
                                break;
                            }
                        }
                    }

                    List<AvatarAttachment> attachments = avappearance.GetAttachments();
                    foreach (AvatarAttachment attachment in attachments)
                    {
                        if ((items2RemoveFromAppearence.Contains(attachment.AssetID)) ||
                            (items2RemoveFromAppearence.Contains(attachment.ItemID)))
                        {
                            avappearance.DetachAttachment(attachment.ItemID);
                        }
                    }
                }

                // ok, now we have a empty folder, lets add the items
                foreach (InventoryItemBase itemBase in itemsInFolder)
                {
                    InventoryItemBase newcopy = m_InventoryService.InnerGiveInventoryItem(user, folderOwnerID, itemBase,
                                                                                          folderForAppearance.ID,
                                                                                          true, true);

                    if (newcopy.InvType == (int) InventoryType.Object)
                    {
                        byte[] attobj = m_AssetService.GetData(newcopy.AssetID.ToString());

                        if (attobj != null)
                        {
                            string xmlData = Utils.BytesToString(attobj);
                            XmlDocument doc = new XmlDocument();
                            try
                            {
                                doc.LoadXml(xmlData);
                            }
                            catch
                            {
                                continue;
                            }

                            if (doc.FirstChild.OuterXml.StartsWith("<groups>") ||
                                (doc.FirstChild.NextSibling != null &&
                                 doc.FirstChild.NextSibling.OuterXml.StartsWith("<groups>")))
                                continue;

                            string xml = "";
                            if ((doc.FirstChild.NodeType == XmlNodeType.XmlDeclaration) &&
                                (doc.FirstChild.NextSibling != null))
                                xml = doc.FirstChild.NextSibling.OuterXml;
                            else
                                xml = doc.FirstChild.OuterXml;
                            doc.LoadXml(xml);

                            if (doc.DocumentElement == null) continue;

                            XmlNodeList xmlNodeList = doc.DocumentElement.SelectNodes("//State");
                            int attchspot;
                            if ((xmlNodeList != null) && (int.TryParse(xmlNodeList[0].InnerText, out attchspot)))
                            {
                                AvatarAttachment a = new AvatarAttachment(attchspot, newcopy.ID, newcopy.AssetID);
                                Dictionary<int, List<AvatarAttachment>> ac = avappearance.Attachments;

                                if (!ac.ContainsKey(attchspot))
                                    ac[attchspot] = new List<AvatarAttachment>();

                                ac[attchspot].Add(a);
                                avappearance.Attachments = ac;
                            }
                        }
                    }
                    m_InventoryService.AddItem(newcopy);
                }
            }
            return avappearance;
        }
        private AvatarAppearance CopyWearablesAndAttachments(UUID destination, UUID source,
                                                             AvatarAppearance avatarAppearance,
                                                             InventoryFolderBase destinationFolder, UUID agentid,
                                                             out List<InventoryItemBase> items)
        {
            if (destinationFolder == null)
                throw new Exception("Cannot locate folder(s)");
            items = new List<InventoryItemBase>();

            // Wearables
            AvatarWearable[] wearables = avatarAppearance.Wearables;

            for (int i = 0; i < wearables.Length; i++)
            {
                AvatarWearable wearable = wearables[i];
                for (int ii = 0; ii < wearable.Count; ii++)
                {
                    if (wearable[ii].ItemID != UUID.Zero)
                    {
                        // Get inventory item and copy it
                        InventoryItemBase item = InventoryService.GetItem(agentid, wearable[ii].ItemID);

                        if (item != null)
                        {
                            InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination,
                                                                                                        destination,
                                                                                                        item,
                                                                                                        destinationFolder
                                                                                                            .ID,
                                                                                                        false);
                            items.Add(destinationItem);
                            MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}",
                                                             destinationItem.ID, destinationFolder.ID);

                            // Wear item
                            AvatarWearable newWearable = new AvatarWearable();
                            newWearable.Wear(destinationItem.ID, destinationItem.AssetID);
                            avatarAppearance.SetWearable(i, newWearable);
                        }
                        else
                        {
                            MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}",
                                                            wearable[ii].ItemID, destinationFolder.ID);
                        }
                    }
                }
            }

            // Attachments
            List<AvatarAttachment> attachments = avatarAppearance.GetAttachments();

            foreach (AvatarAttachment attachment in attachments)
            {
                int attachpoint = attachment.AttachPoint;
                UUID itemID = attachment.ItemID;

                if (itemID != UUID.Zero)
                {
                    // Get inventory item and copy it
                    InventoryItemBase item = InventoryService.GetItem(source, itemID);

                    if (item != null)
                    {
                        InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination,
                                                                                                    destination, item,
                                                                                                    destinationFolder.ID,
                                                                                                    false);
                        items.Add(destinationItem);
                        MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID,
                                                         destinationFolder.ID);

                        // Attach item
                        avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
                        MainConsole.Instance.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID);
                    }
                    else
                    {
                        MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID,
                                                        destinationFolder.ID);
                    }
                }
            }
            return avatarAppearance;
        }
Esempio n. 5
0
        private string MakeXMLFormat(AvatarAppearance appearance, string FolderNameToSaveInto)
        {
            string ArchiveXML = "";

            ArchiveXML += "<avatar>\n";
            ArchiveXML += "<" + appearance.AvatarHeight + ">\n";
            ArchiveXML += "<" + appearance.BodyAsset + ">\n";
            ArchiveXML += "<" + appearance.BodyItem + ">\n";
            ArchiveXML += "<" + appearance.EyesAsset + ">\n";
            ArchiveXML += "<" + appearance.EyesItem + ">\n";
            ArchiveXML += "<" + appearance.GlovesAsset + ">\n";
            ArchiveXML += "<" + appearance.GlovesItem + ">\n";
            ArchiveXML += "<" + appearance.HairAsset + ">\n";
            ArchiveXML += "<" + appearance.HairItem + ">\n";
            ArchiveXML += "<" + appearance.HipOffset + ">\n";
            ArchiveXML += "<" + appearance.JacketAsset + ">\n";
            ArchiveXML += "<" + appearance.JacketItem + ">\n";
            ArchiveXML += "<" + appearance.Owner + ">\n";
            ArchiveXML += "<" + appearance.PantsAsset + ">\n";
            ArchiveXML += "<" + appearance.PantsItem + ">\n";
            ArchiveXML += "<" + appearance.Serial + ">\n";
            ArchiveXML += "<" + appearance.ShirtAsset + ">\n";
            ArchiveXML += "<" + appearance.ShirtItem + ">\n";
            ArchiveXML += "<" + appearance.ShoesAsset + ">\n";
            ArchiveXML += "<" + appearance.ShoesItem + ">\n";
            ArchiveXML += "<" + appearance.SkinAsset + ">\n";
            ArchiveXML += "<" + appearance.SkinItem + ">\n";
            ArchiveXML += "<" + appearance.SkirtAsset + ">\n";
            ArchiveXML += "<" + appearance.SkirtItem + ">\n";
            ArchiveXML += "<" + appearance.SocksAsset + ">\n";
            ArchiveXML += "<" + appearance.SocksItem + ">\n";
            ArchiveXML += "<" + appearance.UnderPantsAsset + ">\n";
            ArchiveXML += "<" + appearance.UnderPantsItem + ">\n";
            ArchiveXML += "<" + appearance.UnderShirtAsset + ">\n";
            ArchiveXML += "<" + appearance.UnderShirtItem + ">\n";
            ArchiveXML += "<" + FolderNameToSaveInto + ">\n";
            ArchiveXML += "<VisualParams>\n";
            foreach (Byte Byte in appearance.VisualParams)
            {
                ArchiveXML += "</VP" + Convert.ToString(Byte) + ">\n";
            }
            ArchiveXML += "</VisualParams>\n";
            ArchiveXML += "<wearables>\n";
            foreach (AvatarWearable wear in appearance.Wearables)
            {
                ArchiveXML += "<WA" + wear.AssetID + ">\n";
                ArchiveXML += "<WI" + wear.ItemID + ">\n";
            }
            ArchiveXML += "</wearables>\n";
            ArchiveXML += "<TEXTURE" + appearance.Texture.ToString().Replace("\n", "") + "TEXTURE>\n";
            ArchiveXML += "</avatar>";
            Hashtable attachments = appearance.GetAttachments();
            ArchiveXML += "<attachments>\n";
            if (attachments != null)
            {
                foreach (DictionaryEntry element in attachments)
                {
                    Hashtable attachInfo = (Hashtable)element.Value;

                    InventoryItemBase IB = new InventoryItemBase(UUID.Parse(attachInfo["item"].ToString()));
                    IB = InventoryService.GetItem(IB);
                    ArchiveXML += "<AI" + attachInfo["item"] + ">\n";
                    ArchiveXML += "<AA" + IB.AssetID + ">\n";
                    ArchiveXML += "<AP" + (int)element.Key + ">\n";
                }
            }
            ArchiveXML += "</attachments>";
            return ArchiveXML;
        }
        protected void HandleSaveAvatarArchive(string[] cmdparams)
        {
            if (cmdparams.Length != 7)
            {
                MainConsole.Instance.Info("[AvatarArchive] Not enough parameters!");
            }
            UserAccount account = UserAccountService.GetUserAccount(UUID.Zero, cmdparams[3] + " " + cmdparams[4]);

            if (account == null)
            {
                MainConsole.Instance.Error("[AvatarArchive] User not found!");
                return;
            }

            IScenePresence SP      = null;
            SceneManager   manager = m_registry.RequestModuleInterface <SceneManager>();

            if (manager != null)
            {
                foreach (IScene scene in manager.Scenes)
                {
                    if (scene.TryGetScenePresence(account.PrincipalID, out SP))
                    {
                        break;
                    }
                }
                if (SP == null)
                {
                    return; //Bad people!
                }
            }

            if (SP != null)
            {
                SP.ControllingClient.SendAlertMessage("Appearance saving in progress...");
            }

            AvatarAppearance appearance = AvatarService.GetAppearance(SP.UUID);

            if (appearance == null)
            {
                IAvatarAppearanceModule appearancemod = SP.RequestModuleInterface <IAvatarAppearanceModule>();
                appearance = appearancemod.Appearance;
            }
            StreamWriter writer = new StreamWriter(cmdparams[5], false);
            OSDMap       map    = new OSDMap();
            OSDMap       body   = new OSDMap();
            OSDMap       assets = new OSDMap();
            OSDMap       items  = new OSDMap();

            body = appearance.Pack();
            body.Add("FolderName", OSD.FromString(cmdparams[6]));

            foreach (AvatarWearable wear in appearance.Wearables)
            {
                for (int i = 0; i < wear.Count; i++)
                {
                    WearableItem w = wear[i];
                    if (w.AssetID != UUID.Zero)
                    {
                        SaveItem(w.ItemID, items, assets);
                        SaveAsset(w.AssetID, assets);
                    }
                }
            }
            List <AvatarAttachment> attachments = appearance.GetAttachments();

#if (!ISWIN)
            foreach (AvatarAttachment a in attachments)
            {
                if (a.AssetID != UUID.Zero)
                {
                    SaveItem(a.ItemID, items, assets);
                    SaveAsset(a.AssetID, assets);
                }
            }
#else
            foreach (AvatarAttachment a in attachments.Where(a => a.AssetID != UUID.Zero))
            {
                SaveItem(a.ItemID, items, assets);
                SaveAsset(a.AssetID, assets);
            }
#endif
            map.Add("Body", body);
            map.Add("Assets", assets);
            map.Add("Items", items);
            //Write the map
            writer.Write(OSDParser.SerializeLLSDXmlString(map));
            writer.Close();
            writer.Dispose();
            MainConsole.Instance.Info("[AvatarArchive] Saved archive to " + cmdparams[5]);
        }
Esempio n. 7
0
        private AvatarAppearance CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance, InventoryFolderBase destinationFolder)
        {
            if (destinationFolder == null)
            {
                throw new Exception("Cannot locate folder(s)");
            }


            // Wearables
            AvatarWearable[] wearables = avatarAppearance.Wearables;

            for (int i = 0; i < wearables.Length; i++)
            {
                AvatarWearable wearable = wearables[i];
                for (int ii = 0; ii < wearable.Count; ii++)
                {
                    if (wearable[ii].ItemID != UUID.Zero)
                    {
                        // Get inventory item and copy it
                        InventoryItemBase item = new InventoryItemBase(wearable[ii].ItemID);
                        item = InventoryService.GetItem(item);

                        if (item != null)
                        {
                            InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination)
                            {
                                Name                = item.Name,
                                Description         = item.Description,
                                InvType             = item.InvType,
                                CreatorId           = item.CreatorId,
                                CreatorData         = item.CreatorData,
                                CreatorIdAsUuid     = item.CreatorIdAsUuid,
                                NextPermissions     = item.NextPermissions,
                                CurrentPermissions  = item.CurrentPermissions,
                                BasePermissions     = item.BasePermissions,
                                EveryOnePermissions = item.EveryOnePermissions,
                                GroupPermissions    = item.GroupPermissions,
                                AssetType           = item.AssetType,
                                AssetID             = item.AssetID,
                                GroupID             = item.GroupID,
                                GroupOwned          = item.GroupOwned,
                                SalePrice           = item.SalePrice,
                                SaleType            = item.SaleType,
                                Flags               = item.Flags,
                                CreationDate        = item.CreationDate,
                                Folder              = destinationFolder.ID
                            };
                            if (InventoryService != null)
                            {
                                InventoryService.AddItem(destinationItem);
                            }
                            MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}",
                                                             destinationItem.ID, destinationFolder.ID);

                            // Wear item
                            AvatarWearable newWearable = new AvatarWearable();
                            newWearable.Wear(destinationItem.ID, wearable[ii].AssetID);
                            avatarAppearance.SetWearable(i, newWearable);
                        }
                        else
                        {
                            MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}",
                                                            wearable[ii].ItemID, destinationFolder.ID);
                        }
                    }
                }
            }

            // Attachments
            List <AvatarAttachment> attachments = avatarAppearance.GetAttachments();

            foreach (AvatarAttachment attachment in attachments)
            {
                int  attachpoint = attachment.AttachPoint;
                UUID itemID      = attachment.ItemID;

                if (itemID != UUID.Zero)
                {
                    // Get inventory item and copy it
                    InventoryItemBase item = new InventoryItemBase(itemID, source);
                    item = InventoryService.GetItem(item);

                    if (item != null)
                    {
                        InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination)
                        {
                            Name                = item.Name,
                            Description         = item.Description,
                            InvType             = item.InvType,
                            CreatorId           = item.CreatorId,
                            CreatorData         = item.CreatorData,
                            CreatorIdAsUuid     = item.CreatorIdAsUuid,
                            NextPermissions     = item.NextPermissions,
                            CurrentPermissions  = item.CurrentPermissions,
                            BasePermissions     = item.BasePermissions,
                            EveryOnePermissions = item.EveryOnePermissions,
                            GroupPermissions    = item.GroupPermissions,
                            AssetType           = item.AssetType,
                            AssetID             = item.AssetID,
                            GroupID             = item.GroupID,
                            GroupOwned          = item.GroupOwned,
                            SalePrice           = item.SalePrice,
                            SaleType            = item.SaleType,
                            Flags               = item.Flags,
                            CreationDate        = item.CreationDate,
                            Folder              = destinationFolder.ID
                        };
                        if (InventoryService != null)
                        {
                            InventoryService.AddItem(destinationItem);
                        }
                        MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID);

                        // Attach item
                        avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
                        MainConsole.Instance.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID);
                    }
                    else
                    {
                        MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID);
                    }
                }
            }
            return(avatarAppearance);
        }
Esempio n. 8
0
        public UUID CreateAvatar(string firstName, string lastName, IScene scene, AvatarAppearance avatarApp,
                                 UUID creatorID, Vector3 startPos)
        {
            // Add the circuit data so they can login
            AgentCircuitData m_aCircuitData = new AgentCircuitData
            {
                IsChildAgent = false,
                CircuitCode  = (uint)Util.RandomClass.Next()
            };

            // Create the new bot data
            BotClientAPI m_character = new BotClientAPI(scene, m_aCircuitData)
            {
                Name = firstName + " " + lastName
            };

            m_aCircuitData.AgentID = m_character.AgentId;

            // Set up appearance
            var origOwner = avatarApp.Owner;

            avatarApp.Owner = m_character.AgentId;
            List <AvatarAttachment> attachments = avatarApp.GetAttachments();

            avatarApp.ClearAttachments();
            // get original attachments
            foreach (AvatarAttachment t in attachments)
            {
                InventoryItemBase item = scene.InventoryService.GetItem(origOwner, t.ItemID);
                if (item != null)
                {
                    item.ID     = UUID.Random();
                    item.Owner  = m_character.AgentId;
                    item.Folder = UUID.Zero;
                    scene.InventoryService.AddCacheItemAsync(item);
                    // Now fix the ItemID
                    avatarApp.SetAttachment(t.AttachPoint, item.ID, t.AssetID);
                }
            }

            scene.AuthenticateHandler.AgentCircuits.Add(m_character.CircuitCode, m_aCircuitData);
            // This adds them to the scene and sets them in world
            AddAndWaitUntilAgentIsAdded(scene, m_character);

            IScenePresence SP = scene.GetScenePresence(m_character.AgentId);

            if (SP == null)
            {
                return(UUID.Zero);       // Failed!
            }
            // set this as a NPC character
            SP.IsNpcAgent = true;

            IAvatarAppearanceModule appearance = SP.RequestModuleInterface <IAvatarAppearanceModule>();

            appearance.Appearance = avatarApp;
            appearance.InitialHasWearablesBeenSent = true;
            Bot bot = new Bot();

            bot.Initialize(SP, creatorID);
            try {
                SP.MakeRootAgent(startPos, false, true);
            } catch {
                MainConsole.Instance.ErrorFormat("[BotManager]: Error creating bot {0} as root agent!", m_character.AgentId);
            }
            // Move them
            SP.Teleport(startPos);

            foreach (var presence in scene.GetScenePresences())
            {
                presence.SceneViewer.QueuePresenceForUpdate(SP, PrimUpdateFlags.ForcedFullUpdate);
            }
            IAttachmentsModule attModule = SP.Scene.RequestModuleInterface <IAttachmentsModule>();

            if (attModule != null)
            {
                foreach (AvatarAttachment att in attachments)
                {
                    attModule.RezSingleAttachmentFromInventory(SP.ControllingClient, att.ItemID, att.AssetID, 0, true);
                }
            }

            // Save them in the bots list
            m_bots.Add(m_character.AgentId, bot);
            AddTagToBot(m_character.AgentId, "AllBots", bot.AvatarCreatorID);

            MainConsole.Instance.InfoFormat("[BotManager]: Added bot {0} to region {1}",
                                            m_character.Name, scene.RegionInfo.RegionName);

            // Return their UUID
            return(m_character.AgentId);
        }
Esempio n. 9
0
        protected void HandleSaveAvatarArchive(string[] cmdparams)
        {
            if (cmdparams.Length < 7)
            {
                MainConsole.Instance.Info("[AvatarArchive] Not enough parameters!");
            }
            UserAccount account = UserAccountService.GetUserAccount(null, cmdparams[3] + " " + cmdparams[4]);

            if (account == null)
            {
                MainConsole.Instance.Error("[AvatarArchive] User not found!");
                return;
            }

            IScenePresence SP      = null;
            ISceneManager  manager = m_registry.RequestModuleInterface <ISceneManager>();

            if (manager != null)
            {
                foreach (IScene scene in manager.GetAllScenes())
                {
                    if (scene.TryGetScenePresence(account.PrincipalID, out SP))
                    {
                        break;
                    }
                }
                if (SP == null)
                {
                    return; //Bad people!
                }
            }

            if (SP != null)
            {
                SP.ControllingClient.SendAlertMessage("Appearance saving in progress...");
            }

            AvatarAppearance appearance = AvatarService.GetAppearance(account.PrincipalID);

            if (appearance == null)
            {
                IAvatarAppearanceModule appearancemod = m_registry.RequestModuleInterface <IAvatarAppearanceModule>();
                appearance = appearancemod.Appearance;
            }
            OSDMap map    = new OSDMap();
            OSDMap body   = new OSDMap();
            OSDMap assets = new OSDMap();
            OSDMap items  = new OSDMap();

            body = appearance.Pack();
            body.Add("FolderName", OSD.FromString(cmdparams[6]));

            foreach (AvatarWearable wear in appearance.Wearables)
            {
                for (int i = 0; i < wear.Count; i++)
                {
                    WearableItem w = wear[i];
                    if (w.AssetID != UUID.Zero)
                    {
                        SaveItem(w.ItemID, items, assets);
                        SaveAsset(w.AssetID, assets);
                    }
                }
            }
            List <AvatarAttachment> attachments = appearance.GetAttachments();

#if (!ISWIN)
            foreach (AvatarAttachment a in attachments)
            {
                if (a.AssetID != UUID.Zero)
                {
                    SaveItem(a.ItemID, items, assets);
                    SaveAsset(a.AssetID, assets);
                }
            }
#else
            foreach (AvatarAttachment a in attachments.Where(a => a.AssetID != UUID.Zero))
            {
                SaveItem(a.ItemID, items, assets);
                SaveAsset(a.AssetID, assets);
            }
#endif
            map.Add("Body", body);
            map.Add("Assets", assets);
            map.Add("Items", items);

            //Write the map
            if (cmdparams[5].EndsWith(".database"))
            {
                IAvatarArchiverConnector archiver = DataManager.DataManager.RequestPlugin <IAvatarArchiverConnector>();
                if (archiver != null)
                {
                    AvatarArchive archive = new AvatarArchive();
                    archive.ArchiveXML = OSDParser.SerializeLLSDXmlString(map);

                    // Add the extra details for archives
                    archive.Name = cmdparams[5].Substring(0, cmdparams[5].LastIndexOf(".database"));
                    if (cmdparams.Length > 7)
                    {
                        if (cmdparams.Contains("--snapshot"))
                        {
                            UUID snapshot;
                            int  index = 0;
                            for (; index < cmdparams.Length; index++)
                            {
                                if (cmdparams[index] == "--snapshot")
                                {
                                    index++;
                                    break;
                                }
                            }
                            if (index < cmdparams.Length && UUID.TryParse(cmdparams[index], out snapshot))
                            {
                                archive.Snapshot = snapshot.ToString();
                            }
                        }
                        else
                        {
                            archive.Snapshot = UUID.Zero.ToString();
                        }
                        if (cmdparams.Contains("--public"))
                        {
                            archive.IsPublic = 1;
                        }
                    }
                    else
                    {
                        archive.Snapshot = UUID.Zero.ToString();
                        archive.IsPublic = 0;
                    }

                    // Save the archive
                    archiver.SaveAvatarArchive(archive);
                    MainConsole.Instance.Info("[AvatarArchive] Saved archive to database as: " + archive.Name);
                }
                else
                {
                    MainConsole.Instance.Error("[AvatarArchive] Unable to save to database!");
                    return;
                }
            }
            else
            {
                StreamWriter writer = new StreamWriter(cmdparams[5], false);
                writer.Write(OSDParser.SerializeLLSDXmlString(map));
                writer.Close();
                writer.Dispose();
                MainConsole.Instance.Info("[AvatarArchive] Saved archive to " + cmdparams[5]);
            }
        }
Esempio n. 10
0
        private AvatarAppearance CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance, InventoryFolderBase destinationFolder, UUID agentid, out List <InventoryItemBase> items)
        {
            if (destinationFolder == null)
            {
                throw new Exception("Cannot locate folder(s)");
            }
            items = new List <InventoryItemBase>();

            // Wearables
            AvatarWearable[] wearables = avatarAppearance.Wearables;

            for (int i = 0; i < wearables.Length; i++)
            {
                AvatarWearable wearable = wearables[i];
                for (int ii = 0; ii < wearable.Count; ii++)
                {
                    if (wearable[ii].ItemID != UUID.Zero)
                    {
                        // Get inventory item and copy it
                        InventoryItemBase item = new InventoryItemBase(wearable[ii].ItemID);
                        item = InventoryService.GetItem(item);

                        if (item != null)
                        {
                            InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination,
                                                                                                        destination, item,
                                                                                                        destinationFolder.ID,
                                                                                                        false);
                            items.Add(destinationItem);
                            MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}",
                                                             destinationItem.ID, destinationFolder.ID);

                            // Wear item
                            AvatarWearable newWearable = new AvatarWearable();
                            newWearable.Wear(destinationItem.ID, wearable[ii].AssetID);
                            avatarAppearance.SetWearable(i, newWearable);
                        }
                        else
                        {
                            MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}",
                                                            wearable[ii].ItemID, destinationFolder.ID);
                        }
                    }
                }
            }

            // Attachments
            List <AvatarAttachment> attachments = avatarAppearance.GetAttachments();

            foreach (AvatarAttachment attachment in attachments)
            {
                int  attachpoint = attachment.AttachPoint;
                UUID itemID      = attachment.ItemID;

                if (itemID != UUID.Zero)
                {
                    // Get inventory item and copy it
                    InventoryItemBase item = new InventoryItemBase(itemID, source);
                    item = InventoryService.GetItem(item);

                    if (item != null)
                    {
                        InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination,
                                                                                                    destination, item,
                                                                                                    destinationFolder.ID,
                                                                                                    false);
                        items.Add(destinationItem);
                        MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID);

                        // Attach item
                        avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
                        MainConsole.Instance.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID);
                    }
                    else
                    {
                        MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID);
                    }
                }
            }
            return(avatarAppearance);
        }
Esempio n. 11
0
        /// <summary>
        /// This method is called by EstablishAppearance to do a copy all inventory items
        /// worn or attached to the Clothing inventory folder of the receiving avatar.
        /// In parallel the avatar wearables and attachments are updated.
        /// </summary>
        private void CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance)
        {
            // Get Clothing folder of receiver
            InventoryFolderBase destinationFolder = m_InventoryService.GetFolderForType(destination, FolderType.Clothing);

            if (destinationFolder == null)
            {
                throw new Exception("Cannot locate folder(s)");
            }

            // Missing destination folder? This should *never* be the case
            if (destinationFolder.Type != (short)FolderType.Clothing)
            {
                destinationFolder = new InventoryFolderBase();

                destinationFolder.ID       = UUID.Random();
                destinationFolder.Name     = "Clothing";
                destinationFolder.Owner    = destination;
                destinationFolder.Type     = (short)AssetType.Clothing;
                destinationFolder.ParentID = m_InventoryService.GetRootFolder(destination).ID;
                destinationFolder.Version  = 1;
                m_InventoryService.AddFolder(destinationFolder);     // store base record
                m_log.ErrorFormat("[USER ACCOUNT SERVICE]: Created folder for destination {0}", source);
            }

            // Wearables
            AvatarWearable[] wearables = avatarAppearance.Wearables;
            AvatarWearable   wearable;

            for (int i = 0; i < wearables.Length; i++)
            {
                wearable = wearables[i];
                if (wearable[0].ItemID != UUID.Zero)
                {
                    // Get inventory item and copy it
                    InventoryItemBase item = m_InventoryService.GetItem(source, wearable[0].ItemID);

                    if (item != null)
                    {
                        InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination);
                        destinationItem.Name                = item.Name;
                        destinationItem.Owner               = destination;
                        destinationItem.Description         = item.Description;
                        destinationItem.InvType             = item.InvType;
                        destinationItem.CreatorId           = item.CreatorId;
                        destinationItem.CreatorData         = item.CreatorData;
                        destinationItem.NextPermissions     = item.NextPermissions;
                        destinationItem.CurrentPermissions  = item.CurrentPermissions;
                        destinationItem.BasePermissions     = item.BasePermissions;
                        destinationItem.EveryOnePermissions = item.EveryOnePermissions;
                        destinationItem.GroupPermissions    = item.GroupPermissions;
                        destinationItem.AssetType           = item.AssetType;
                        destinationItem.AssetID             = item.AssetID;
                        destinationItem.GroupID             = item.GroupID;
                        destinationItem.GroupOwned          = item.GroupOwned;
                        destinationItem.SalePrice           = item.SalePrice;
                        destinationItem.SaleType            = item.SaleType;
                        destinationItem.Flags               = item.Flags;
                        destinationItem.CreationDate        = item.CreationDate;
                        destinationItem.Folder              = destinationFolder.ID;
                        ApplyNextOwnerPermissions(destinationItem);

                        m_InventoryService.AddItem(destinationItem);
                        m_log.DebugFormat("[USER ACCOUNT SERVICE]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID);

                        // Wear item
                        AvatarWearable newWearable = new AvatarWearable();
                        newWearable.Wear(destinationItem.ID, wearable[0].AssetID);
                        avatarAppearance.SetWearable(i, newWearable);
                    }
                    else
                    {
                        m_log.WarnFormat("[USER ACCOUNT SERVICE]: Error transferring {0} to folder {1}", wearable[0].ItemID, destinationFolder.ID);
                    }
                }
            }

            // Attachments
            List <AvatarAttachment> attachments = avatarAppearance.GetAttachments();

            foreach (AvatarAttachment attachment in attachments)
            {
                int  attachpoint = attachment.AttachPoint;
                UUID itemID      = attachment.ItemID;

                if (itemID != UUID.Zero)
                {
                    // Get inventory item and copy it
                    InventoryItemBase item = m_InventoryService.GetItem(source, itemID);

                    if (item != null)
                    {
                        InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination);
                        destinationItem.Name                = item.Name;
                        destinationItem.Owner               = destination;
                        destinationItem.Description         = item.Description;
                        destinationItem.InvType             = item.InvType;
                        destinationItem.CreatorId           = item.CreatorId;
                        destinationItem.CreatorData         = item.CreatorData;
                        destinationItem.NextPermissions     = item.NextPermissions;
                        destinationItem.CurrentPermissions  = item.CurrentPermissions;
                        destinationItem.BasePermissions     = item.BasePermissions;
                        destinationItem.EveryOnePermissions = item.EveryOnePermissions;
                        destinationItem.GroupPermissions    = item.GroupPermissions;
                        destinationItem.AssetType           = item.AssetType;
                        destinationItem.AssetID             = item.AssetID;
                        destinationItem.GroupID             = item.GroupID;
                        destinationItem.GroupOwned          = item.GroupOwned;
                        destinationItem.SalePrice           = item.SalePrice;
                        destinationItem.SaleType            = item.SaleType;
                        destinationItem.Flags               = item.Flags;
                        destinationItem.CreationDate        = item.CreationDate;
                        destinationItem.Folder              = destinationFolder.ID;
                        ApplyNextOwnerPermissions(destinationItem);

                        m_InventoryService.AddItem(destinationItem);
                        m_log.DebugFormat("[USER ACCOUNT SERVICE]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID);

                        // Attach item
                        avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
                        m_log.DebugFormat("[USER ACCOUNT SERVICE]: Attached {0}", destinationItem.ID);
                    }
                    else
                    {
                        m_log.WarnFormat("[USER ACCOUNT SERVICE]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID);
                    }
                }
            }
        }
Esempio n. 12
0
        private AvatarAppearance CopyWearablesAndAttachments(UUID destination, UUID source,
                                                             AvatarAppearance avatarAppearance,
                                                             InventoryFolderBase destinationFolder, UUID agentid,
                                                             OSDMap itemsMap,
                                                             out List <InventoryItemBase> items)
        {
            if (destinationFolder == null)
            {
                throw new Exception("Cannot locate folder(s)");
            }
            items = new List <InventoryItemBase>();

            List <InventoryItemBase> litems = new List <InventoryItemBase>();

            foreach (KeyValuePair <string, OSD> kvp in itemsMap)
            {
                InventoryItemBase item = new InventoryItemBase();
                item.FromOSD((OSDMap)kvp.Value);
                MainConsole.Instance.Info("[AvatarArchive]: Loading item " + item.ID.ToString());
                litems.Add(item);
            }

            // Wearables
            AvatarWearable[] wearables = avatarAppearance.Wearables;

            for (int i = 0; i < wearables.Length; i++)
            {
                AvatarWearable wearable = wearables[i];
                for (int ii = 0; ii < wearable.Count; ii++)
                {
                    if (wearable[ii].ItemID != UUID.Zero)
                    {
                        // Get inventory item and copy it
                        InventoryItemBase item = InventoryService.GetItem(UUID.Zero, wearable[ii].ItemID);

                        if (item == null)
                        {
                            //Attempt to get from the map if it doesn't already exist on the grid
                            item = litems.First((itm) => itm.ID == wearable[ii].ItemID);
                        }
                        if (item != null)
                        {
                            InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination,
                                                                                                        destination,
                                                                                                        item,
                                                                                                        destinationFolder
                                                                                                        .ID,
                                                                                                        false, false);
                            items.Add(destinationItem);
                            MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}",
                                                             destinationItem.ID, destinationFolder.ID);

                            // Wear item
                            AvatarWearable newWearable = new AvatarWearable();
                            newWearable.Wear(destinationItem.ID, destinationItem.AssetID);
                            avatarAppearance.SetWearable(i, newWearable);
                        }
                        else
                        {
                            MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}",
                                                            wearable[ii].ItemID, destinationFolder.ID);
                        }
                    }
                }
            }

            // Attachments
            List <AvatarAttachment> attachments = avatarAppearance.GetAttachments();

            foreach (AvatarAttachment attachment in attachments)
            {
                int  attachpoint = attachment.AttachPoint;
                UUID itemID      = attachment.ItemID;

                if (itemID != UUID.Zero)
                {
                    // Get inventory item and copy it
                    InventoryItemBase item = InventoryService.GetItem(UUID.Zero, itemID);

                    if (item != null)
                    {
                        InventoryItemBase destinationItem = InventoryService.InnerGiveInventoryItem(destination,
                                                                                                    destination, item,
                                                                                                    destinationFolder.ID,
                                                                                                    false, false);
                        items.Add(destinationItem);
                        MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID,
                                                         destinationFolder.ID);

                        // Attach item
                        avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
                        MainConsole.Instance.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID);
                    }
                    else
                    {
                        MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID,
                                                        destinationFolder.ID);
                    }
                }
            }
            return(avatarAppearance);
        }