From a0d79e621cc8ee4935dfc2816da75db9c23c1b84 Mon Sep 17 00:00:00 2001
From: Diva Canto
Date: Sat, 30 Jan 2010 15:43:10 -0800
Subject: Bug fix: change HGBroker to a INonSharedRegionModule

---
 .../InventoryAccess/HGInventoryAccessModule.cs     |   7 +-
 .../Inventory/BaseInventoryConnector.cs            |  11 +-
 .../Inventory/HGInventoryBroker.cs                 | 135 +++++++++++----------
 3 files changed, 82 insertions(+), 71 deletions(-)

(limited to 'OpenSim/Region')

diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs
index ecd7002..09798aa 100644
--- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs
@@ -183,7 +183,10 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
         public bool IsForeignUser(UUID userID, out string assetServerURL)
         {
             assetServerURL = string.Empty;
-            UserAccount account = m_Scene.UserAccountService.GetUserAccount(m_Scene.RegionInfo.ScopeID, userID);
+            UserAccount account = null;
+            if (m_Scene.UserAccountService != null)
+                account = m_Scene.UserAccountService.GetUserAccount(m_Scene.RegionInfo.ScopeID, userID);
+
             if (account == null) // foreign
             {
                 ScenePresence sp = null;
@@ -193,7 +196,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
                     if (aCircuit.ServiceURLs.ContainsKey("AssetServerURI"))
                     {
                         assetServerURL = aCircuit.ServiceURLs["AssetServerURI"].ToString();
-                        return true;
+                        assetServerURL = assetServerURL.Trim(new char[] { '/' }); return true;
                     }
                 }
             }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs
index 811569f..1e51187 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs
@@ -40,12 +40,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
 {
     public abstract class BaseInventoryConnector : IInventoryService
     {
-        protected InventoryCache m_cache;
+        protected static InventoryCache m_cache;
+        private static bool m_Initialized;
 
         protected virtual void Init(IConfigSource source)
         {
-            m_cache = new InventoryCache();
-            m_cache.Init(source, this);
+            if (!m_Initialized)
+            {
+                m_cache = new InventoryCache();
+                m_cache.Init(source, this);
+                m_Initialized = true;
+            }
         }
 
         /// <summary>
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
index b6718a8..c6312e0 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
@@ -41,20 +41,21 @@ using OpenMetaverse;
 
 namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
 {
-    public class HGInventoryBroker : BaseInventoryConnector, ISharedRegionModule, IInventoryService
+    public class HGInventoryBroker : BaseInventoryConnector, INonSharedRegionModule, IInventoryService
     {
         private static readonly ILog m_log =
                 LogManager.GetLogger(
                 MethodBase.GetCurrentMethod().DeclaringType);
 
-        private bool m_Enabled = false;
-        private bool m_Initialized = false;
+        private static bool m_Initialized = false;
+        private static bool m_Enabled = false;
+
+        private static IInventoryService m_GridService;
+        private static ISessionAuthInventoryService m_HGService;
+
         private Scene m_Scene;
         private IUserAccountService m_UserAccountService; 
 
-        private IInventoryService m_GridService;
-        private ISessionAuthInventoryService m_HGService;
-
         public Type ReplaceableInterface 
         {
             get { return null; }
@@ -67,63 +68,67 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
 
         public void Initialise(IConfigSource source)
         {
-            IConfig moduleConfig = source.Configs["Modules"];
-            if (moduleConfig != null)
+            if (!m_Initialized)
             {
-                string name = moduleConfig.GetString("InventoryServices", "");
-                if (name == Name)
+                IConfig moduleConfig = source.Configs["Modules"];
+                if (moduleConfig != null)
                 {
-                    IConfig inventoryConfig = source.Configs["InventoryService"];
-                    if (inventoryConfig == null)
-                    {
-                        m_log.Error("[HG INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini");
-                        return;
-                    }
-
-                    string localDll = inventoryConfig.GetString("LocalGridInventoryService",
-                            String.Empty);
-                    string HGDll = inventoryConfig.GetString("HypergridInventoryService",
-                            String.Empty);
-
-                    if (localDll == String.Empty)
-                    {
-                        m_log.Error("[HG INVENTORY CONNECTOR]: No LocalGridInventoryService named in section InventoryService");
-                        //return;
-                        throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
-                    }
-
-                    if (HGDll == String.Empty)
+                    string name = moduleConfig.GetString("InventoryServices", "");
+                    if (name == Name)
                     {
-                        m_log.Error("[HG INVENTORY CONNECTOR]: No HypergridInventoryService named in section InventoryService");
-                        //return;
-                        throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
+                        IConfig inventoryConfig = source.Configs["InventoryService"];
+                        if (inventoryConfig == null)
+                        {
+                            m_log.Error("[HG INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini");
+                            return;
+                        }
+
+                        string localDll = inventoryConfig.GetString("LocalGridInventoryService",
+                                String.Empty);
+                        string HGDll = inventoryConfig.GetString("HypergridInventoryService",
+                                String.Empty);
+
+                        if (localDll == String.Empty)
+                        {
+                            m_log.Error("[HG INVENTORY CONNECTOR]: No LocalGridInventoryService named in section InventoryService");
+                            //return;
+                            throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
+                        }
+
+                        if (HGDll == String.Empty)
+                        {
+                            m_log.Error("[HG INVENTORY CONNECTOR]: No HypergridInventoryService named in section InventoryService");
+                            //return;
+                            throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
+                        }
+
+                        Object[] args = new Object[] { source };
+                        m_GridService =
+                                ServerUtils.LoadPlugin<IInventoryService>(localDll,
+                                args);
+
+                        m_HGService =
+                                ServerUtils.LoadPlugin<ISessionAuthInventoryService>(HGDll,
+                                args);
+
+                        if (m_GridService == null)
+                        {
+                            m_log.Error("[HG INVENTORY CONNECTOR]: Can't load local inventory service");
+                            return;
+                        }
+                        if (m_HGService == null)
+                        {
+                            m_log.Error("[HG INVENTORY CONNECTOR]: Can't load hypergrid inventory service");
+                            return;
+                        }
+
+                        Init(source);
+
+                        m_Enabled = true;
+                        m_log.Info("[HG INVENTORY CONNECTOR]: HG inventory broker enabled");
                     }
-
-                    Object[] args = new Object[] { source };
-                    m_GridService =
-                            ServerUtils.LoadPlugin<IInventoryService>(localDll,
-                            args);
-
-                    m_HGService =
-                            ServerUtils.LoadPlugin<ISessionAuthInventoryService>(HGDll,
-                            args);
-
-                    if (m_GridService == null)
-                    {
-                        m_log.Error("[HG INVENTORY CONNECTOR]: Can't load local inventory service");
-                        return;
-                    }
-                    if (m_HGService == null)
-                    {
-                        m_log.Error("[HG INVENTORY CONNECTOR]: Can't load hypergrid inventory service");
-                        return;
-                    }
-
-                    Init(source);
-
-                    m_Enabled = true;
-                    m_log.Info("[HG INVENTORY CONNECTOR]: HG inventory broker enabled");
                 }
+                m_Initialized = true;
             }
         }
 
@@ -140,13 +145,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
             if (!m_Enabled)
                 return;
 
-            if (!m_Initialized)
-            {
-                m_Scene = scene;
-                m_UserAccountService = m_Scene.UserAccountService;
-
-                m_Initialized = true;
-            }
+            m_Scene = scene;
+            m_UserAccountService = m_Scene.UserAccountService;
 
             scene.RegisterModuleInterface<IInventoryService>(this);
             m_cache.AddRegion(scene);
@@ -514,7 +514,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
         private bool IsForeignUser(UUID userID, out string inventoryURL)
         {
             inventoryURL = string.Empty;
-            UserAccount account = m_Scene.UserAccountService.GetUserAccount(m_Scene.RegionInfo.ScopeID, userID);
+            UserAccount account = null;
+            if (m_Scene.UserAccountService != null)
+                account = m_Scene.UserAccountService.GetUserAccount(m_Scene.RegionInfo.ScopeID, userID);
+
             if (account == null) // foreign user
             {
                 ScenePresence sp = null;
-- 
cgit v1.1