From 9637e509567efe512d4b29ea925c10011cdbe99e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 6 Apr 2012 20:34:31 -0700 Subject: [PATCH] Moved the inventory manipulation from HGEntityTransferModule to HGInventoryAccessModule where it belongs. They need to exchange some events, so added those to EventManager. Those events (TeleportStart and TeleportFail) are nice to have anyway. --- .../EntityTransfer/EntityTransferModule.cs | 8 +- .../EntityTransfer/HGEntityTransferModule.cs | 149 +---------------- .../HGInventoryAccessModule.cs | 152 +++++++++++++++++- .../Region/Framework/Scenes/EventManager.cs | 49 ++++++ 4 files changed, 208 insertions(+), 150 deletions(-) diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index 86e10d491f..fa9cd551ad 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -561,12 +561,18 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer // Finally, kill the agent we just created at the destination. m_aScene.SimulationService.CloseAgent(finalDestination, sp.UUID); + sp.Scene.EventManager.TriggerTeleportFail(sp.ControllingClient, logout); } protected virtual bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason, out bool logout) { logout = false; - return m_aScene.SimulationService.CreateAgent(finalDestination, agentCircuit, teleportFlags, out reason); + bool success = m_aScene.SimulationService.CreateAgent(finalDestination, agentCircuit, teleportFlags, out reason); + + if (success) + sp.Scene.EventManager.TriggerTeleportStart(sp.ControllingClient, reg, finalDestination, teleportFlags, logout); + + return success; } protected virtual bool UpdateAgent(GridRegion reg, GridRegion finalDestination, AgentData agent) diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs index 0f422ae1ce..7f9175d2fc 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs @@ -51,8 +51,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer private bool m_Initialized = false; - private bool m_RestrictInventoryAccessAbroad = false; - private GatekeeperServiceConnector m_GatekeeperConnector; #region ISharedRegionModule @@ -71,10 +69,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer if (name == Name) { InitialiseCommon(source); - IConfig transferConfig = source.Configs["HGEntityTransferModule"]; - if (transferConfig != null) - m_RestrictInventoryAccessAbroad = transferConfig.GetBoolean("RestrictInventoryAccessAbroad", false); - m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: {0} enabled.", Name); } } @@ -94,44 +88,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer client.OnTeleportHomeRequest += TeleportHome; client.OnTeleportLandmarkRequest += RequestTeleportLandmark; client.OnConnectionClosed += new Action(OnConnectionClosed); - client.OnCompleteMovementToRegion += new Action(OnCompleteMovementToRegion); } - protected void OnCompleteMovementToRegion(IClientAPI client, bool arg2) - { - // HACK HACK -- just seeing how the viewer responds - // Let's send the Suitcase or the real root folder folder for incoming HG agents - // Visiting agents get their suitcase contents; incoming local users get their real root folder's content - m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: OnCompleteMovementToRegion of user {0}", client.AgentId); - object sp = null; - if (client.Scene.TryGetScenePresence(client.AgentId, out sp)) - { - if (sp is ScenePresence) - { - AgentCircuitData aCircuit = ((ScenePresence)sp).Scene.AuthenticateHandler.GetAgentCircuitData(client.AgentId); - if ((aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0) - { - m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: ViaHGLogin"); - if (m_RestrictInventoryAccessAbroad) - { - IUserManagement uMan = m_Scenes[0].RequestModuleInterface(); - if (uMan.IsLocalGridUser(client.AgentId)) - { - m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is local"); - RestoreRootFolderContents(client); - } - else - { - m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is foreign"); - RestoreSuitcaseFolderContents(client); - } - } - } - } - } - } - - public override void RegionLoaded(Scene scene) { base.RegionLoaded(scene); @@ -141,12 +99,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer m_GatekeeperConnector = new GatekeeperServiceConnector(scene.AssetService); m_Initialized = true; - scene.AddCommand( - "HG", this, "send inventory", - "send inventory", - "Don't use this", - HandleSendInventory); - } } @@ -219,21 +171,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer bool success = connector.LoginAgentToGrid(agentCircuit, reg, finalDestination, out reason); logout = success; // flag for later logout from this grid; this is an HG TP - if (success && m_RestrictInventoryAccessAbroad) - { - IUserManagement uMan = m_aScene.RequestModuleInterface(); - if (uMan != null && uMan.IsLocalGridUser(sp.UUID)) - { - // local grid user - m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is local"); - RemoveRootFolderContents(sp.ControllingClient); - } - else - { - m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is foreign"); - RemoveSuitcaseFolderContents(sp.ControllingClient); - } - } + if (success) + sp.Scene.EventManager.TriggerTeleportStart(sp.ControllingClient, reg, finalDestination, teleportFlags, logout); return success; } @@ -244,7 +183,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer } } - return m_aScene.SimulationService.CreateAgent(reg, agentCircuit, teleportFlags, out reason); + return base.CreateAgent(sp, reg, finalDestination, agentCircuit, teleportFlags, out reason, out logout); } public override void TeleportHome(UUID id, IClientAPI client) @@ -348,15 +287,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer } - protected override void Fail(ScenePresence sp, GridRegion finalDestination, bool logout) - { - base.Fail(sp, finalDestination, logout); - if (logout && m_RestrictInventoryAccessAbroad) - { - RestoreRootFolderContents(sp.ControllingClient); - } - } - #endregion #region IUserAgentVerificationModule @@ -411,71 +341,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer #endregion - private void RemoveRootFolderContents(IClientAPI client) - { - // TODO tell the viewer to remove the root folder's content - if (client is IClientCore) - { - IClientCore core = (IClientCore)client; - IClientInventory inv; - - if (core.TryGet(out inv)) - { - InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId); - if (root != null) - { - m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Removing root inventory for user {0}", client.Name); - InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID); - List fids = new List(); - List iids = new List(); - List keep = new List(); - - foreach (InventoryFolderBase f in content.Folders) - { - if (f.Name != "My Suitcase") - { - f.Name = f.Name + " (Unavailable)"; - keep.Add(f); - } - } - - // items directly under the root folder - foreach (InventoryItemBase it in content.Items) - it.Name = it.Name + " (Unavailable)"; ; - - // Send the new names - inv.SendBulkUpdateInventory(keep.ToArray(), content.Items.ToArray()); - - } - } - } - } - - private void RemoveSuitcaseFolderContents(IClientAPI client) - { - } - - private void RestoreRootFolderContents(IClientAPI client) - { - m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Restoring root folder"); - if (client is IClientCore) - { - IClientCore core = (IClientCore)client; - IClientInventory inv; - - if (core.TryGet(out inv)) - { - InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId); - InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID); - - inv.SendBulkUpdateInventory(content.Folders.ToArray(), content.Items.ToArray()); - } - } - } - - private void RestoreSuitcaseFolderContents(IClientAPI client) - { - } private GridRegion MakeRegion(AgentCircuitData aCircuit) { @@ -494,13 +359,5 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer return region; } - protected void HandleSendInventory(string module, string[] cmd) - { - m_Scenes[0].ForEachClient(delegate(IClientAPI client) - { - RestoreRootFolderContents(client); - }); - } - } } diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs index d2fe3888fa..a71584a91b 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs @@ -30,6 +30,7 @@ using System.Collections.Generic; using System.Reflection; using OpenSim.Framework; +using OpenSim.Framework.Client; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Services.Connectors.Hypergrid; @@ -57,6 +58,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess private string m_HomeURI; private bool m_OutboundPermission; private string m_ThisGatekeeper; + private bool m_RestrictInventoryAccessAbroad; // private bool m_Initialized = false; @@ -90,6 +92,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess m_HomeURI = thisModuleConfig.GetString("HomeURI", m_HomeURI); m_OutboundPermission = thisModuleConfig.GetBoolean("OutboundPermission", true); m_ThisGatekeeper = thisModuleConfig.GetString("Gatekeeper", string.Empty); + m_RestrictInventoryAccessAbroad = thisModuleConfig.GetBoolean("RestrictInventoryAccessAbroad", false); } else m_log.Warn("[HG INVENTORY ACCESS MODULE]: HGInventoryAccessModule configs not found. ProfileServerURI not set!"); @@ -105,13 +108,79 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess base.AddRegion(scene); m_assMapper = new HGAssetMapper(scene, m_HomeURI); scene.EventManager.OnNewInventoryItemUploadComplete += UploadInventoryItem; - + scene.EventManager.OnTeleportStart += TeleportStart; + scene.EventManager.OnTeleportFail += TeleportFail; } #endregion #region Event handlers + protected override void OnNewClient(IClientAPI client) + { + base.OnNewClient(client); + client.OnCompleteMovementToRegion += new Action(OnCompleteMovementToRegion); + } + + protected void OnCompleteMovementToRegion(IClientAPI client, bool arg2) + { + //m_log.DebugFormat("[HG INVENTORY ACCESS MODULE]: OnCompleteMovementToRegion of user {0}", client.Name); + object sp = null; + if (client.Scene.TryGetScenePresence(client.AgentId, out sp)) + { + if (sp is ScenePresence) + { + AgentCircuitData aCircuit = ((ScenePresence)sp).Scene.AuthenticateHandler.GetAgentCircuitData(client.AgentId); + if ((aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0) + { + if (m_RestrictInventoryAccessAbroad) + { + IUserManagement uMan = m_Scene.RequestModuleInterface(); + if (uMan.IsLocalGridUser(client.AgentId)) + ProcessInventoryForComingHome(client); + else + ProcessInventoryForArriving(client); + } + } + } + } + } + + protected void TeleportStart(IClientAPI client, GridRegion destination, GridRegion finalDestination, uint teleportFlags, bool gridLogout) + { + if (gridLogout && m_RestrictInventoryAccessAbroad) + { + IUserManagement uMan = m_Scene.RequestModuleInterface(); + if (uMan != null && uMan.IsLocalGridUser(client.AgentId)) + { + // local grid user + ProcessInventoryForHypergriding(client); + } + else + { + // Foreigner + ProcessInventoryForLeaving(client); + } + } + + } + + protected void TeleportFail(IClientAPI client, bool gridLogout) + { + if (gridLogout && m_RestrictInventoryAccessAbroad) + { + IUserManagement uMan = m_Scene.RequestModuleInterface(); + if (uMan.IsLocalGridUser(client.AgentId)) + { + ProcessInventoryForComingHome(client); + } + else + { + ProcessInventoryForArriving(client); + } + } + } + public void UploadInventoryItem(UUID avatarID, UUID assetID, string name, int userlevel) { string userAssetServer = string.Empty; @@ -236,8 +305,6 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess return false; } - #endregion - protected override InventoryItemBase GetItem(UUID agentID, UUID itemID) { InventoryItemBase item = base.GetItem(agentID, itemID); @@ -248,5 +315,84 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess return item; } + + #endregion + + #region Inventory manipulation upon arriving/leaving + + // + // These 2 are for local and foreign users coming back, respectively + // + + private void ProcessInventoryForComingHome(IClientAPI client) + { + m_log.DebugFormat("[HG INVENTORY ACCESS MODULE]: Restoring root folder for local user {0}", client.Name); + if (client is IClientCore) + { + IClientCore core = (IClientCore)client; + IClientInventory inv; + + if (core.TryGet(out inv)) + { + InventoryFolderBase root = m_Scene.InventoryService.GetRootFolder(client.AgentId); + InventoryCollection content = m_Scene.InventoryService.GetFolderContent(client.AgentId, root.ID); + + inv.SendBulkUpdateInventory(content.Folders.ToArray(), content.Items.ToArray()); + } + } + } + + private void ProcessInventoryForArriving(IClientAPI client) + { + } + + // + // These 2 are for local and foreign users going away respectively + // + + private void ProcessInventoryForHypergriding(IClientAPI client) + { + if (client is IClientCore) + { + IClientCore core = (IClientCore)client; + IClientInventory inv; + + if (core.TryGet(out inv)) + { + InventoryFolderBase root = m_Scene.InventoryService.GetRootFolder(client.AgentId); + if (root != null) + { + m_log.DebugFormat("[HG INVENTORY ACCESS MODULE]: Changing root inventory for user {0}", client.Name); + InventoryCollection content = m_Scene.InventoryService.GetFolderContent(client.AgentId, root.ID); + List fids = new List(); + List iids = new List(); + List keep = new List(); + + foreach (InventoryFolderBase f in content.Folders) + { + if (f.Name != "My Suitcase") + { + f.Name = f.Name + " (Unavailable)"; + keep.Add(f); + } + } + + // items directly under the root folder + foreach (InventoryItemBase it in content.Items) + it.Name = it.Name + " (Unavailable)"; ; + + // Send the new names + inv.SendBulkUpdateInventory(keep.ToArray(), content.Items.ToArray()); + + } + } + } + } + + private void ProcessInventoryForLeaving(IClientAPI client) + { + } + + #endregion } } diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index fe3438e175..b3debb0296 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs @@ -502,6 +502,12 @@ namespace OpenSim.Region.Framework.Scenes public delegate void PrimsLoaded(Scene s); public event PrimsLoaded OnPrimsLoaded; + public delegate void TeleportStart(IClientAPI client, GridRegion destination, GridRegion finalDestination, uint teleportFlags, bool gridLogout); + public event TeleportStart OnTeleportStart; + + public delegate void TeleportFail(IClientAPI client, bool gridLogout); + public event TeleportFail OnTeleportFail; + public class MoneyTransferArgs : EventArgs { public UUID sender; @@ -2463,5 +2469,48 @@ namespace OpenSim.Region.Framework.Scenes } } } + + public void TriggerTeleportStart(IClientAPI client, GridRegion destination, GridRegion finalDestination, uint teleportFlags, bool gridLogout) + { + TeleportStart handler = OnTeleportStart; + + if (handler != null) + { + foreach (TeleportStart d in handler.GetInvocationList()) + { + try + { + d(client, destination, finalDestination, teleportFlags, gridLogout); + } + catch (Exception e) + { + m_log.ErrorFormat("[EVENT MANAGER]: Delegate for TeleportStart failed - continuing {0} - {1}", + e.Message, e.StackTrace); + } + } + } + } + + public void TriggerTeleportFail(IClientAPI client, bool gridLogout) + { + TeleportFail handler = OnTeleportFail; + + if (handler != null) + { + foreach (TeleportFail d in handler.GetInvocationList()) + { + try + { + d(client, gridLogout); + } + catch (Exception e) + { + m_log.ErrorFormat("[EVENT MANAGER]: Delegate for TeleportFail failed - continuing {0} - {1}", + e.Message, e.StackTrace); + } + } + } + } + } }