Only allow iar load/save if user is logged in to the region simulator

remotes/origin/0.6.7-post-fixes
Justin Clark-Casey (justincc) 2009-09-07 19:57:44 +01:00
parent 71f1628578
commit fa1d79533e
3 changed files with 116 additions and 32 deletions

View File

@ -51,6 +51,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
public string Name { get { return "Inventory Archiver Module"; } } public string Name { get { return "Inventory Archiver Module"; } }
public bool IsSharedModule { get { return true; } } public bool IsSharedModule { get { return true; } }
/// <value>
/// Enable or disable checking whether the iar user is actually logged in
/// </value>
public bool DisablePresenceChecks { get; set; }
public event InventoryArchiveSaved OnInventoryArchiveSaved; public event InventoryArchiveSaved OnInventoryArchiveSaved;
@ -70,6 +75,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
private Dictionary<UUID, Scene> m_scenes = new Dictionary<UUID, Scene>(); private Dictionary<UUID, Scene> m_scenes = new Dictionary<UUID, Scene>();
private Scene m_aScene; private Scene m_aScene;
public InventoryArchiverModule() {}
public InventoryArchiverModule(bool disablePresenceChecks)
{
DisablePresenceChecks = disablePresenceChecks;
}
public void Initialise(Scene scene, IConfigSource source) public void Initialise(Scene scene, IConfigSource source)
{ {
if (m_scenes.Count == 0) if (m_scenes.Count == 0)
@ -109,29 +121,57 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
handlerInventoryArchiveSaved(id, succeeded, userInfo, invPath, saveStream, reportedException); 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) if (m_scenes.Count > 0)
{ {
CachedUserInfo userInfo = GetUserInfo(firstName, lastName); CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
if (userInfo != null) 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) if (m_scenes.Count > 0)
{ {
CachedUserInfo userInfo = GetUserInfo(firstName, lastName); CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
if (userInfo != null) 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) if (m_scenes.Count > 0)
{ {
@ -139,14 +179,27 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
if (userInfo != null) if (userInfo != null)
{ {
InventoryArchiveReadRequest request = if (CheckPresence(userInfo.UserProfile.ID))
new InventoryArchiveReadRequest(m_aScene, userInfo, invPath, loadStream); {
UpdateClientWithLoadedNodes(userInfo, request.Execute()); 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) if (m_scenes.Count > 0)
{ {
@ -154,11 +207,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
if (userInfo != null) if (userInfo != null)
{ {
InventoryArchiveReadRequest request = if (CheckPresence(userInfo.UserProfile.ID))
new InventoryArchiveReadRequest(m_aScene, userInfo, invPath, loadPath); {
UpdateClientWithLoadedNodes(userInfo, request.Execute()); 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;
} }
/// <summary> /// <summary>
@ -183,11 +249,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
"[INVENTORY ARCHIVER]: Loading archive {0} to inventory path {1} for {2} {3}", "[INVENTORY ARCHIVER]: Loading archive {0} to inventory path {1} for {2} {3}",
loadPath, invPath, firstName, lastName); loadPath, invPath, firstName, lastName);
DearchiveInventory(firstName, lastName, invPath, loadPath); if (DearchiveInventory(firstName, lastName, invPath, loadPath))
m_log.InfoFormat(
m_log.InfoFormat( "[INVENTORY ARCHIVER]: Loaded archive {0} for {1} {2}",
"[INVENTORY ARCHIVER]: Loaded archive {0} for {1} {2}", loadPath, firstName, lastName);
loadPath, firstName, lastName);
} }
/// <summary> /// <summary>
@ -291,5 +356,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
} }
} }
} }
/// <summary>
/// Check if the given user is present in any of the scenes.
/// </summary>
/// <param name="userId">The user to check</param>
/// <returns>true if the user is in any of the scenes, false otherwise</returns>
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;
}
} }
} }

View File

@ -83,7 +83,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
TestHelper.InMethod(); TestHelper.InMethod();
log4net.Config.XmlConfigurator.Configure(); log4net.Config.XmlConfigurator.Configure();
InventoryArchiverModule archiverModule = new InventoryArchiverModule(); InventoryArchiverModule archiverModule = new InventoryArchiverModule(true);
Scene scene = SceneSetupHelpers.SetupScene("Inventory"); Scene scene = SceneSetupHelpers.SetupScene("Inventory");
SceneSetupHelpers.SetupSceneModules(scene, archiverModule); SceneSetupHelpers.SetupSceneModules(scene, archiverModule);
@ -100,9 +100,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
cm, userFirstName, userLastName, userId, InventoryReceived); cm, userFirstName, userLastName, userId, InventoryReceived);
Monitor.Wait(this, 60000); Monitor.Wait(this, 60000);
} }
Console.WriteLine("here");
// Create asset // Create asset
SceneObjectGroup object1; SceneObjectGroup object1;
SceneObjectPart part1; SceneObjectPart part1;
@ -248,7 +246,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());
SerialiserModule serialiserModule = new SerialiserModule(); 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 // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene
Scene scene = SceneSetupHelpers.SetupScene("inventory"); Scene scene = SceneSetupHelpers.SetupScene("inventory");
@ -318,7 +316,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());
SerialiserModule serialiserModule = new SerialiserModule(); 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 // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene
Scene scene = SceneSetupHelpers.SetupScene(); Scene scene = SceneSetupHelpers.SetupScene();

View File

@ -56,8 +56,9 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="firstName"></param> /// <param name="firstName"></param>
/// <param name="lastName"></param> /// <param name="lastName"></param>
/// <param name="invPath">The inventory path in which to place the loaded folders and items</param> /// <param name="invPath">The inventory path in which to place the loaded folders and items</param>
/// <param name="loadStream">The stream from which the inventory archive will be loaded</param> /// <param name="loadStream">The stream from which the inventory archive will be loaded</param>
void DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream); /// <returns>true if the first stage of the operation succeeded, false otherwise</returns>
bool DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream);
/// <summary> /// <summary>
/// Archive a user's inventory folder to the given stream /// Archive a user's inventory folder to the given stream
@ -67,6 +68,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="lastName"></param> /// <param name="lastName"></param>
/// <param name="invPath">The inventory path from which the inventory should be saved.</param> /// <param name="invPath">The inventory path from which the inventory should be saved.</param>
/// <param name="saveStream">The stream to which the inventory archive will be saved</param> /// <param name="saveStream">The stream to which the inventory archive will be saved</param>
void ArchiveInventory(Guid id, string firstName, string lastName, string invPath, Stream saveStream); /// <returns>true if the first stage of the operation succeeded, false otherwise</returns>
bool ArchiveInventory(Guid id, string firstName, string lastName, string invPath, Stream saveStream);
} }
} }