Exemplo n.º 1
0
        public AvatarAppearance LoadAvatarArchive(string FileName, string Name)
        {
            UserAccount account = UserAccountService.GetUserAccount(null, Name);

            MainConsole.Instance.Info("[AvatarArchive] Loading archive from " + FileName);
            if (account == null)
            {
                MainConsole.Instance.Error("[AvatarArchive] User not found!");
                return(null);
            }

            string archiveXML = "";

            if (FileName.EndsWith(".database"))
            {
                IAvatarArchiverConnector archiver = DataManager.DataManager.RequestPlugin <IAvatarArchiverConnector>();
                if (archiver != null)
                {
                    AvatarArchive archive = archiver.GetAvatarArchive(FileName.Substring(0, FileName.LastIndexOf(".database")));
                    archiveXML = archive.ArchiveXML;
                }
                else
                {
                    MainConsole.Instance.Error("[AvatarArchive] Unable to load from database!");
                    return(null);
                }
            }
            else
            {
                StreamReader reader = new StreamReader(FileName);
                archiveXML = reader.ReadToEnd();
                reader.Close();
                reader.Dispose();
            }

            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(null); //Bad people!
                }
            }

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

            string FolderNameToLoadInto = "";

            OSDMap map = ((OSDMap)OSDParser.DeserializeLLSDXml(archiveXML));

            OSDMap assetsMap = ((OSDMap)map["Assets"]);
            //OSDMap itemsMap = ((OSDMap)map["Items"]);
            OSDMap bodyMap = ((OSDMap)map["Body"]);

            AvatarAppearance appearance = ConvertXMLToAvatarAppearance(bodyMap, out FolderNameToLoadInto);

            appearance.Owner = account.PrincipalID;

            InventoryFolderBase AppearanceFolder = InventoryService.GetFolderForType(account.PrincipalID,
                                                                                     InventoryType.Wearable,
                                                                                     AssetType.Clothing);

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

            InventoryFolderBase folderForAppearance
                = new InventoryFolderBase(
                      UUID.Random(), FolderNameToLoadInto, account.PrincipalID,
                      -1, AppearanceFolder.ID, 1);

            InventoryService.AddFolder(folderForAppearance);

            folderForAppearance = InventoryService.GetFolder(folderForAppearance);

            try
            {
                LoadAssets(assetsMap);
                appearance = CopyWearablesAndAttachments(account.PrincipalID, UUID.Zero, appearance, folderForAppearance, account.PrincipalID, out items);
            }
            catch (Exception ex)
            {
                MainConsole.Instance.Warn("[AvatarArchiver]: Error loading assets and items, " + ex);
            }

            //Now update the client about the new items
            if (SP != null)
            {
                SP.ControllingClient.SendBulkUpdateInventory(folderForAppearance);
            }

            MainConsole.Instance.Info("[AvatarArchive] Loaded archive from " + FileName);
            return(appearance);
        }
Exemplo n.º 2
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]);
            }
        }