From 0fa94f222df8ed7f308730c3692bf2a774138718 Mon Sep 17 00:00:00 2001 From: Cinder Date: Fri, 12 Jun 2015 18:48:07 -0600 Subject: Refactor AgentPreferences so that database operations happen centrally. the opensim way. Signed-off-by: Diva Canto --- .../Linden/Caps/AgentPreferencesModule.cs | 83 +++-------- .../LocalAgentPreferencesServiceConnector.cs | 153 +++++++++++++++++++++ .../RemoteAgentPreferencesServiceConnector.cs | 116 ++++++++++++++++ .../Interfaces/IAgentPreferencesModule.cs | 37 ----- OpenSim/Region/Framework/Scenes/Scene.cs | 11 ++ .../Shared/Api/Implementation/LSL_Api.cs | 10 +- 6 files changed, 300 insertions(+), 110 deletions(-) create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/LocalAgentPreferencesServiceConnector.cs create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/RemoteAgentPreferencesServiceConnector.cs delete mode 100644 OpenSim/Region/Framework/Interfaces/IAgentPreferencesModule.cs (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs index 58d9f7d..509004d 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs @@ -26,6 +26,7 @@ */ using System; +using System.Collections.Generic; using System.Reflection; using System.IO; using log4net; @@ -33,8 +34,6 @@ using Mono.Addins; using Nini.Config; using OpenMetaverse; using OpenMetaverse.StructuredData; -using OpenSim.Data; -using OpenSim.Data.MySQL; using OpenSim.Framework.Console; using OpenSim.Framework.Servers; using OpenSim.Framework.Servers.HttpServer; @@ -47,68 +46,34 @@ using OpenSim.Capabilities.Handlers; namespace OpenSim.Region.ClientStack.LindenCaps { [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AgentPreferencesModule")] - public class AgentPreferencesModule : ISharedRegionModule, IAgentPreferencesModule + public class AgentPreferencesModule : ISharedRegionModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - public bool m_enabled { get; private set; } - private Scene m_Scene; - protected IAgentPreferencesData m_Database; + private List m_scenes = new List(); public void Initialise(IConfigSource source) { - IConfig dbConfig = source.Configs["DatabaseService"]; - if (dbConfig != null) - { - string dllName = String.Empty; - string connString = String.Empty; - - dllName = dbConfig.GetString("StorageProvider", dllName); - connString = dbConfig.GetString("ConnectionString", connString); - - // We tried, but this doesn't exist. We can't proceed - if (dllName == String.Empty) - throw new Exception("No StorageProvider configured"); - - // *FIXME: This is a janky as hell, works for now. - if (dllName == "OpenSim.Data.MySQL.dll") - m_Database = new MySQLAgentPreferencesData(connString, "AgentPrefs"); - else - throw new Exception("Storage provider not supported!"); - - if (m_Database == null) - { - m_enabled = false; - throw new Exception("Could not find a storage interface in the given module"); - } - m_log.Debug("[AgentPrefs] AgentPrefs is enabled"); - m_enabled = true; - } + } #region Region module - public void AddRegion(Scene s) - { - if (!m_enabled) return; - s.RegisterModuleInterface(this); - m_Scene = s; + public void AddRegion(Scene scene) + { + lock (m_scenes) m_scenes.Add(scene); } - public void RemoveRegion(Scene s) + public void RemoveRegion(Scene scene) { - if (!m_enabled) return; - - m_Scene.UnregisterModuleInterface(this); - m_Scene.EventManager.OnRegisterCaps -= RegisterCaps; - m_Scene = null; + lock (m_scenes) m_scenes.Remove(scene); + scene.EventManager.OnRegisterCaps -= RegisterCaps; + scene = null; } - public void RegionLoaded(Scene s) + public void RegionLoaded(Scene scene) { - if (!m_enabled) return; - - m_Scene.EventManager.OnRegisterCaps += delegate(UUID agentID, OpenSim.Framework.Capabilities.Caps caps) + scene.EventManager.OnRegisterCaps += delegate(UUID agentID, OpenSim.Framework.Capabilities.Caps caps) { RegisterCaps(agentID, caps); }; @@ -155,11 +120,10 @@ namespace OpenSim.Region.ClientStack.LindenCaps { m_log.DebugFormat("[AgentPrefs] UpdateAgentPreferences for {0}", agent.ToString()); OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); - AgentPreferencesData data = m_Database.GetPrefs(agent); + AgentPrefs data = m_scenes[0].AgentPreferencesService.GetAgentPreferences(agent); if (data == null) { - data = new AgentPreferencesData(); - data.PrincipalID = agent; + data = new AgentPrefs(agent); } if (req.ContainsKey("access_prefs")) @@ -186,7 +150,7 @@ namespace OpenSim.Region.ClientStack.LindenCaps { data.LanguageIsPublic = req["language_is_public"].AsBoolean(); } - m_Database.StorePrefs(data); + m_scenes[0].AgentPreferencesService.StoreAgentPreferences(data); OSDMap resp = new OSDMap(); OSDMap respAccessPrefs = new OSDMap(); respAccessPrefs["max"] = data.AccessPrefs; @@ -204,21 +168,8 @@ namespace OpenSim.Region.ClientStack.LindenCaps string response = OSDParser.SerializeLLSDXmlString(resp); return response; } - #endregion Region module - #region IAgentPreferences - public string GetLang(UUID agentID) - { - AgentPreferencesData data = m_Database.GetPrefs(agentID); - if (data != null) - { - if (data.LanguageIsPublic) - return data.Language; - } - return "en-us"; - - } - #endregion + #endregion Region module } } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/LocalAgentPreferencesServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/LocalAgentPreferencesServiceConnector.cs new file mode 100644 index 0000000..9d8367d --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/LocalAgentPreferencesServiceConnector.cs @@ -0,0 +1,153 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Reflection; +using log4net; +using Mono.Addins; +using Nini.Config; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; + +using OpenMetaverse; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.AgentPreferences +{ + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalAgentPreferencesServicesConnector")] + public class LocalAgentPreferencesServicesConnector : ISharedRegionModule, IAgentPreferencesService + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private IAgentPreferencesService m_AgentPreferencesService; + private bool m_Enabled = false; + + #region ISharedRegionModule + + public Type ReplaceableInterface + { + get { return null; } + } + + public string Name + { + get { return "LocalAgentPreferencesServicesConnector"; } + } + + public void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("AgentPreferencesServices", ""); + if (name == Name) + { + IConfig userConfig = source.Configs["AgentPreferencesService"]; + if (userConfig == null) + { + m_log.Error("[AGENT PREFERENCES CONNECTOR]: AgentPreferencesService missing from OpenSim.ini"); + return; + } + + string serviceDll = userConfig.GetString("LocalServiceModule", String.Empty); + + if (String.IsNullOrEmpty(serviceDll)) + { + m_log.Error("[AGENT PREFERENCES CONNECTOR]: No AgentPreferencesModule named in section AgentPreferencesService"); + return; + } + + Object[] args = new Object[] { source }; + m_AgentPreferencesService = ServerUtils.LoadPlugin(serviceDll, args); + + if (m_AgentPreferencesService == null) + { + m_log.Error("[AGENT PREFERENCES CONNECTOR]: Can't load user account service"); + return; + } + m_Enabled = true; + m_log.Info("[AGENT PREFERENCES CONNECTOR]: Local agent preferences connector enabled"); + } + } + } + + public void PostInitialise() + { + if (!m_Enabled) + return; + } + + public void Close() + { + if (!m_Enabled) + return; + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + scene.RegisterModuleInterface(this); + } + + public void RemoveRegion(Scene scene) + { + if (!m_Enabled) + return; + } + + public void RegionLoaded(Scene scene) + { + if (!m_Enabled) + return; + } + + #endregion ISharedRegionModule + + #region IAgentPreferencesService + + public AgentPrefs GetAgentPreferences(UUID principalID) + { + return m_AgentPreferencesService.GetAgentPreferences(principalID); + } + + public bool StoreAgentPreferences(AgentPrefs data) + { + return m_AgentPreferencesService.StoreAgentPreferences(data); + } + + public string GetLang(UUID principalID) + { + return m_AgentPreferencesService.GetLang(principalID); + } + + #endregion IAgentPreferencesService + } +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/RemoteAgentPreferencesServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/RemoteAgentPreferencesServiceConnector.cs new file mode 100644 index 0000000..ad9544a --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/RemoteAgentPreferencesServiceConnector.cs @@ -0,0 +1,116 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +using System; +using System.Collections.Generic; +using System.Reflection; + +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; +using OpenSim.Services.Connectors; + +using OpenMetaverse; +using log4net; +using Mono.Addins; +using Nini.Config; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.AgentPreferences +{ + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteAgentPreferencesServicesConnector")] + public class RemoteAgentPreferencesServicesConnector : AgentPreferencesServicesConnector, + ISharedRegionModule, IAgentPreferencesService + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private bool m_Enabled = false; + + public Type ReplaceableInterface + { + get { return null; } + } + + public string Name + { + get { return "RemoteAgentPreferencesServicesConnector"; } + } + + public override void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + if (moduleConfig != null) + { + string name = moduleConfig.GetString("AgentPreferencesServices", ""); + if (name == Name) + { + IConfig userConfig = source.Configs["AgentPreferencesService"]; + if (userConfig == null) + { + m_log.Error("[AGENT PREFERENCES CONNECTOR]: AgentPreferencesService missing from OpenSim.ini"); + return; + } + + m_Enabled = true; + + base.Initialise(source); + + m_log.Info("[AGENT PREFERENCES CONNECTOR]: Remote agent preferences enabled"); + } + } + } + + public void PostInitialise() + { + /* no op */ + } + + public void Close() + { + /* no op */ + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + scene.RegisterModuleInterface(this); + } + + public void RemoveRegion(Scene scene) + { + /* no op */ + } + + public void RegionLoaded(Scene scene) + { + /* no op */ + } + } +} \ No newline at end of file diff --git a/OpenSim/Region/Framework/Interfaces/IAgentPreferencesModule.cs b/OpenSim/Region/Framework/Interfaces/IAgentPreferencesModule.cs deleted file mode 100644 index 4975b96..0000000 --- a/OpenSim/Region/Framework/Interfaces/IAgentPreferencesModule.cs +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using OpenMetaverse; - -namespace OpenSim.Region.Framework.Interfaces -{ - public interface IAgentPreferencesModule - { - string GetLang(UUID agentID); - } -} diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index c539f1f..23b2e90 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -325,6 +325,7 @@ namespace OpenSim.Region.Framework.Scenes protected IUserAccountService m_UserAccountService; protected IAvatarService m_AvatarService; protected IGridUserService m_GridUserService; + protected IAgentPreferencesService m_AgentPreferencesService; protected IXMLRPC m_xmlrpcModule; protected IWorldComm m_worldCommModule; @@ -728,6 +729,16 @@ namespace OpenSim.Region.Framework.Scenes } } + public IAgentPreferencesService AgentPreferencesService + { + get + { + if (m_AgentPreferencesService == null) + m_AgentPreferencesService = RequestModuleInterface(); + return m_AgentPreferencesService; + } + } + public IAttachmentsModule AttachmentsModule { get; set; } public IEntityTransferModule EntityTransferModule { get; private set; } public IAgentAssetTransactions AgentTransactionsModule { get; private set; } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index b50f429..75b40af 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -6149,14 +6149,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { // This should only return a value if the avatar is in the same region, but eh. idc. m_host.AddScriptLPS(1); - IAgentPreferencesModule ap = World.RequestModuleInterface(); - if (ap != null) + UUID key = new UUID(); + if (UUID.TryParse(id, out key)) { - UUID key = new UUID(); - if (UUID.TryParse(id, out key)) - { - return ap.GetLang(key); - } + return new LSL_String(World.AgentPreferencesService.GetLang(key)); } return new LSL_String("en-us"); } -- cgit v1.1