diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs index 3869de2b43..2340fad548 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs @@ -51,6 +51,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver public string Name { get { return "Inventory Archiver Module"; } } public bool IsSharedModule { get { return true; } } + + /// + /// Enable or disable checking whether the iar user is actually logged in + /// + public bool DisablePresenceChecks { get; set; } public event InventoryArchiveSaved OnInventoryArchiveSaved; @@ -70,6 +75,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver private Dictionary m_scenes = new Dictionary(); private Scene m_aScene; + public InventoryArchiverModule() {} + + public InventoryArchiverModule(bool disablePresenceChecks) + { + DisablePresenceChecks = disablePresenceChecks; + } + public void Initialise(Scene scene, IConfigSource source) { if (m_scenes.Count == 0) @@ -109,29 +121,57 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver handlerInventoryArchiveSaved(id, succeeded, userInfo, invPath, saveStream, reportedException); } - public void ArchiveInventory(Guid id, string firstName, string lastName, string invPath, Stream saveStream) + public bool ArchiveInventory(Guid id, string firstName, string lastName, string invPath, Stream saveStream) { if (m_scenes.Count > 0) { CachedUserInfo userInfo = GetUserInfo(firstName, lastName); if (userInfo != null) - new InventoryArchiveWriteRequest(id, this, m_aScene, userInfo, invPath, saveStream).Execute(); - } + { + if (CheckPresence(userInfo.UserProfile.ID)) + { + new InventoryArchiveWriteRequest(id, this, m_aScene, userInfo, invPath, saveStream).Execute(); + return true; + } + else + { + m_log.ErrorFormat( + "[INVENTORY ARCHIVER]: User {0} {1} not logged in to this region simulator", + userInfo.UserProfile.Name, userInfo.UserProfile.ID); + } + } + } + + return false; } - public void ArchiveInventory(Guid id, string firstName, string lastName, string invPath, string savePath) + public bool ArchiveInventory(Guid id, string firstName, string lastName, string invPath, string savePath) { if (m_scenes.Count > 0) { CachedUserInfo userInfo = GetUserInfo(firstName, lastName); if (userInfo != null) - new InventoryArchiveWriteRequest(id, this, m_aScene, userInfo, invPath, savePath).Execute(); - } + { + if (CheckPresence(userInfo.UserProfile.ID)) + { + new InventoryArchiveWriteRequest(id, this, m_aScene, userInfo, invPath, savePath).Execute(); + return true; + } + else + { + m_log.ErrorFormat( + "[INVENTORY ARCHIVER]: User {0} {1} not logged in to this region simulator", + userInfo.UserProfile.Name, userInfo.UserProfile.ID); + } + } + } + + return false; } - public void DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream) + public bool DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream) { if (m_scenes.Count > 0) { @@ -139,14 +179,27 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver if (userInfo != null) { - InventoryArchiveReadRequest request = - new InventoryArchiveReadRequest(m_aScene, userInfo, invPath, loadStream); - UpdateClientWithLoadedNodes(userInfo, request.Execute()); + if (CheckPresence(userInfo.UserProfile.ID)) + { + InventoryArchiveReadRequest request = + new InventoryArchiveReadRequest(m_aScene, userInfo, invPath, loadStream); + UpdateClientWithLoadedNodes(userInfo, request.Execute()); + + return true; + } + else + { + m_log.ErrorFormat( + "[INVENTORY ARCHIVER]: User {0} {1} not logged in to this region simulator", + userInfo.UserProfile.Name, userInfo.UserProfile.ID); + } } - } + } + + return false; } - public void DearchiveInventory(string firstName, string lastName, string invPath, string loadPath) + public bool DearchiveInventory(string firstName, string lastName, string invPath, string loadPath) { if (m_scenes.Count > 0) { @@ -154,11 +207,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver if (userInfo != null) { - InventoryArchiveReadRequest request = - new InventoryArchiveReadRequest(m_aScene, userInfo, invPath, loadPath); - UpdateClientWithLoadedNodes(userInfo, request.Execute()); - } - } + if (CheckPresence(userInfo.UserProfile.ID)) + { + InventoryArchiveReadRequest request = + new InventoryArchiveReadRequest(m_aScene, userInfo, invPath, loadPath); + UpdateClientWithLoadedNodes(userInfo, request.Execute()); + + return true; + } + else + { + m_log.ErrorFormat( + "[INVENTORY ARCHIVER]: User {0} {1} not logged in to this region simulator", + userInfo.UserProfile.Name, userInfo.UserProfile.ID); + } + } + } + + return false; } /// @@ -183,11 +249,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver "[INVENTORY ARCHIVER]: Loading archive {0} to inventory path {1} for {2} {3}", loadPath, invPath, firstName, lastName); - DearchiveInventory(firstName, lastName, invPath, loadPath); - - m_log.InfoFormat( - "[INVENTORY ARCHIVER]: Loaded archive {0} for {1} {2}", - loadPath, firstName, lastName); + if (DearchiveInventory(firstName, lastName, invPath, loadPath)) + m_log.InfoFormat( + "[INVENTORY ARCHIVER]: Loaded archive {0} for {1} {2}", + loadPath, firstName, lastName); } /// @@ -291,5 +356,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver } } } + + /// + /// Check if the given user is present in any of the scenes. + /// + /// The user to check + /// true if the user is in any of the scenes, false otherwise + protected bool CheckPresence(UUID userId) + { + if (DisablePresenceChecks) + return true; + + foreach (Scene scene in m_scenes.Values) + { + if (scene.GetScenePresence(userId) != null) + return true; + } + + return false; + } } } diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index c21adef074..d579a81d6d 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs @@ -83,7 +83,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests TestHelper.InMethod(); log4net.Config.XmlConfigurator.Configure(); - InventoryArchiverModule archiverModule = new InventoryArchiverModule(); + InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); Scene scene = SceneSetupHelpers.SetupScene("Inventory"); SceneSetupHelpers.SetupSceneModules(scene, archiverModule); @@ -100,9 +100,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests cm, userFirstName, userLastName, userId, InventoryReceived); Monitor.Wait(this, 60000); } - - Console.WriteLine("here"); - + // Create asset SceneObjectGroup object1; SceneObjectPart part1; @@ -248,7 +246,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); SerialiserModule serialiserModule = new SerialiserModule(); - InventoryArchiverModule archiverModule = new InventoryArchiverModule(); + InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene Scene scene = SceneSetupHelpers.SetupScene("inventory"); @@ -318,7 +316,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); SerialiserModule serialiserModule = new SerialiserModule(); - InventoryArchiverModule archiverModule = new InventoryArchiverModule(); + InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene Scene scene = SceneSetupHelpers.SetupScene(); diff --git a/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs b/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs index 457b5b84e9..ca7abf8327 100644 --- a/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IInventoryArchiverModule.cs @@ -56,8 +56,9 @@ namespace OpenSim.Region.Framework.Interfaces /// /// /// The inventory path in which to place the loaded folders and items - /// The stream from which the inventory archive will be loaded - void DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream); + /// The stream from which the inventory archive will be loaded + /// true if the first stage of the operation succeeded, false otherwise + bool DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream); /// /// Archive a user's inventory folder to the given stream @@ -67,6 +68,7 @@ namespace OpenSim.Region.Framework.Interfaces /// /// The inventory path from which the inventory should be saved. /// The stream to which the inventory archive will be saved - void ArchiveInventory(Guid id, string firstName, string lastName, string invPath, Stream saveStream); + /// true if the first stage of the operation succeeded, false otherwise + bool ArchiveInventory(Guid id, string firstName, string lastName, string invPath, Stream saveStream); } -} +} \ No newline at end of file