Refactor AgentPreferences so that database operations happen centrally. the opensim way.
Signed-off-by: Diva Canto <diva@metaverseink.com>fsassets
							parent
							
								
									c1ddb7f05e
								
							
						
					
					
						commit
						0fa94f222d
					
				| 
						 | 
				
			
			@ -34,22 +34,13 @@ namespace OpenSim.Data
 | 
			
		|||
{
 | 
			
		||||
    public class AgentPreferencesData
 | 
			
		||||
    {
 | 
			
		||||
        public UUID PrincipalID = UUID.Zero;
 | 
			
		||||
        public string AccessPrefs = "M";
 | 
			
		||||
        //public int GodLevel;
 | 
			
		||||
        public double HoverHeight = 0.0;
 | 
			
		||||
        public string Language = "en-us";
 | 
			
		||||
        public bool LanguageIsPublic = true;
 | 
			
		||||
        // DefaultObjectPermMasks
 | 
			
		||||
        public int PermEveryone = 0;
 | 
			
		||||
        public int PermGroup = 0;
 | 
			
		||||
        public int PermNextOwner = 532480;
 | 
			
		||||
        public Dictionary<string, string> Data;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public interface IAgentPreferencesData
 | 
			
		||||
    {
 | 
			
		||||
        bool Store(AgentPreferencesData data);
 | 
			
		||||
        AgentPreferencesData GetPrefs(UUID agentID);
 | 
			
		||||
        void StorePrefs(AgentPreferencesData data);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -52,22 +52,9 @@ namespace OpenSim.Data.MySQL
 | 
			
		|||
            return ret[0];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void StorePrefs(AgentPreferencesData data)
 | 
			
		||||
        public void Store(AgentPreferencesData data)
 | 
			
		||||
        {
 | 
			
		||||
            using (MySqlCommand cmd = new MySqlCommand())
 | 
			
		||||
            {
 | 
			
		||||
                cmd.CommandText = String.Format("replace into `{0}` (`PrincipalID`, `AccessPrefs`, `HoverHeight`, `Language`, `LanguageIsPublic`, `PermEveryone`, `PermGroup`, `PermNextOwner`) VALUES (?Principal, ?AP, ?HH, ?Lang, ?LIP, ?PE, ?PG, ?PNO)", m_Realm);
 | 
			
		||||
                cmd.Parameters.AddWithValue("?Principal", data.PrincipalID.ToString());
 | 
			
		||||
                cmd.Parameters.AddWithValue("?AP", data.AccessPrefs);
 | 
			
		||||
                cmd.Parameters.AddWithValue("?HH", data.HoverHeight);
 | 
			
		||||
                cmd.Parameters.AddWithValue("?Lang", data.Language);
 | 
			
		||||
                cmd.Parameters.AddWithValue("?LIP", data.LanguageIsPublic);
 | 
			
		||||
                cmd.Parameters.AddWithValue("?PE", data.PermEveryone);
 | 
			
		||||
                cmd.Parameters.AddWithValue("?PG", data.PermGroup);
 | 
			
		||||
                cmd.Parameters.AddWithValue("?PNO", data.PermNextOwner);
 | 
			
		||||
 | 
			
		||||
                ExecuteNonQuery(cmd);
 | 
			
		||||
            }
 | 
			
		||||
            base.Store(data);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<Scene> m_scenes = new List<Scene>();
 | 
			
		||||
 | 
			
		||||
        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<IAgentPreferencesModule>(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<IAgentPreferencesModule>(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
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<IAgentPreferencesService>(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<IAgentPreferencesService>(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
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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<IAgentPreferencesService>(this);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void RemoveRegion(Scene scene)
 | 
			
		||||
        {
 | 
			
		||||
            /* no op */
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void RegionLoaded(Scene scene)
 | 
			
		||||
        {
 | 
			
		||||
            /* no op */
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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<IAgentPreferencesService>();
 | 
			
		||||
                return m_AgentPreferencesService;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IAttachmentsModule AttachmentsModule { get; set; }
 | 
			
		||||
        public IEntityTransferModule EntityTransferModule { get; private set; }
 | 
			
		||||
        public IAgentAssetTransactions AgentTransactionsModule { get; private set; }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<IAgentPreferencesModule>();
 | 
			
		||||
            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");
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,206 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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 Nini.Config;
 | 
			
		||||
using log4net;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Net;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Text.RegularExpressions;
 | 
			
		||||
using System.Xml;
 | 
			
		||||
using System.Xml.Serialization;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using OpenSim.Server.Base;
 | 
			
		||||
using OpenSim.Services.Interfaces;
 | 
			
		||||
using OpenSim.Framework;
 | 
			
		||||
using OpenSim.Framework.ServiceAuth;
 | 
			
		||||
using OpenSim.Framework.Servers.HttpServer;
 | 
			
		||||
using OpenMetaverse;
 | 
			
		||||
 | 
			
		||||
namespace OpenSim.Server.Handlers.AgentPreferences
 | 
			
		||||
{
 | 
			
		||||
    public class AgentPreferencesServerPostHandler : BaseStreamHandler
 | 
			
		||||
    {
 | 
			
		||||
        private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 | 
			
		||||
 | 
			
		||||
        private IAgentPreferencesService m_AgentPreferencesService;
 | 
			
		||||
 | 
			
		||||
        public AgentPreferencesServerPostHandler(IAgentPreferencesService service, IServiceAuth auth) :
 | 
			
		||||
        base("POST", "/agentprefs", auth)
 | 
			
		||||
        {
 | 
			
		||||
            m_AgentPreferencesService = service;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected override byte[] ProcessRequest(string path, Stream requestData,
 | 
			
		||||
            IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
 | 
			
		||||
        {
 | 
			
		||||
            StreamReader sr = new StreamReader(requestData);
 | 
			
		||||
            string body = sr.ReadToEnd();
 | 
			
		||||
            sr.Close();
 | 
			
		||||
            body = body.Trim();
 | 
			
		||||
 | 
			
		||||
            //m_log.DebugFormat("[XXX]: query String: {0}", body);
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                Dictionary<string, object> request =
 | 
			
		||||
                    ServerUtils.ParseQueryString(body);
 | 
			
		||||
 | 
			
		||||
                if (!request.ContainsKey("METHOD"))
 | 
			
		||||
                    return FailureResult();
 | 
			
		||||
 | 
			
		||||
                string method = request["METHOD"].ToString();
 | 
			
		||||
 | 
			
		||||
                switch (method)
 | 
			
		||||
                {
 | 
			
		||||
                    case "getagentprefs":
 | 
			
		||||
                        return GetAgentPrefs(request);
 | 
			
		||||
                    case "setagentprefs":
 | 
			
		||||
                        return SetAgentPrefs(request);
 | 
			
		||||
                    case "getagentlang":
 | 
			
		||||
                        return GetAgentLang(request);
 | 
			
		||||
                }
 | 
			
		||||
                m_log.DebugFormat("[AGENT PREFERENCES HANDLER]: unknown method request: {0}", method);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e)
 | 
			
		||||
            {
 | 
			
		||||
                m_log.DebugFormat("[AGENT PREFERENCES HANDLER]: Exception {0}", e);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return FailureResult();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        byte[] GetAgentPrefs(Dictionary<string, object> request)
 | 
			
		||||
        {
 | 
			
		||||
            if (!request.ContainsKey("UserID"))
 | 
			
		||||
                return FailureResult();
 | 
			
		||||
 | 
			
		||||
            UUID userID;
 | 
			
		||||
            if (!UUID.TryParse(request["UserID"].ToString(), out userID))
 | 
			
		||||
                return FailureResult();
 | 
			
		||||
            AgentPrefs prefs = m_AgentPreferencesService.GetAgentPreferences(userID);
 | 
			
		||||
            Dictionary<string, object> result = new Dictionary<string, object>();
 | 
			
		||||
            result = prefs.ToKeyValuePairs();
 | 
			
		||||
 | 
			
		||||
            string xmlString = ServerUtils.BuildXmlResponse(result);
 | 
			
		||||
 | 
			
		||||
            return Util.UTF8NoBomEncoding.GetBytes(xmlString);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        byte[] SetAgentPrefs(Dictionary<string, object> request)
 | 
			
		||||
        {
 | 
			
		||||
            if (!request.ContainsKey("PrincipalID") || !request.ContainsKey("AccessPrefs") || !request.ContainsKey("HoverHeight")
 | 
			
		||||
                || !request.ContainsKey("Language") || !request.ContainsKey("LanguageIsPublic") || !request.ContainsKey("PermEveryone")
 | 
			
		||||
                || !request.ContainsKey("PermGroup") || !request.ContainsKey("PermNextOwner"))
 | 
			
		||||
            {
 | 
			
		||||
                return FailureResult();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            UUID userID;
 | 
			
		||||
            if (!UUID.TryParse(request["PrincipalID"].ToString(), out userID))
 | 
			
		||||
                return FailureResult();
 | 
			
		||||
 | 
			
		||||
            AgentPrefs data = new AgentPrefs(userID);
 | 
			
		||||
            data.AccessPrefs = request["AccessPrefs"].ToString();
 | 
			
		||||
            data.HoverHeight = double.Parse(request["HoverHeight"].ToString());
 | 
			
		||||
            data.Language = request["Language"].ToString();
 | 
			
		||||
            data.LanguageIsPublic = bool.Parse(request["LanguageIsPublic"].ToString());
 | 
			
		||||
            data.PermEveryone = int.Parse(request["PermEveryone"].ToString());
 | 
			
		||||
            data.PermGroup = int.Parse(request["PermGroup"].ToString());
 | 
			
		||||
            data.PermNextOwner = int.Parse(request["PermNextOwner"].ToString());
 | 
			
		||||
 | 
			
		||||
            return m_AgentPreferencesService.StoreAgentPreferences(data) ? SuccessResult() : FailureResult();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        byte[] GetAgentLang(Dictionary<string, object> request)
 | 
			
		||||
        {
 | 
			
		||||
            if (!request.ContainsKey("UserID"))
 | 
			
		||||
                return FailureResult();
 | 
			
		||||
            UUID userID;
 | 
			
		||||
            if (!UUID.TryParse(request["UserID"].ToString(), out userID))
 | 
			
		||||
                return FailureResult();
 | 
			
		||||
 | 
			
		||||
            string lang = "en-us";
 | 
			
		||||
            AgentPrefs prefs = m_AgentPreferencesService.GetAgentPreferences(userID);
 | 
			
		||||
            if (prefs != null)
 | 
			
		||||
            {
 | 
			
		||||
                if (prefs.LanguageIsPublic)
 | 
			
		||||
                    lang = prefs.Language;
 | 
			
		||||
            }
 | 
			
		||||
            Dictionary<string, object> result = new Dictionary<string, object>();
 | 
			
		||||
            result["Language"] = lang;
 | 
			
		||||
            string xmlString = ServerUtils.BuildXmlResponse(result);
 | 
			
		||||
            return Util.UTF8NoBomEncoding.GetBytes(xmlString);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private byte[] SuccessResult()
 | 
			
		||||
        {
 | 
			
		||||
            XmlDocument doc = new XmlDocument();
 | 
			
		||||
 | 
			
		||||
            XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
 | 
			
		||||
                "", "");
 | 
			
		||||
 | 
			
		||||
            doc.AppendChild(xmlnode);
 | 
			
		||||
 | 
			
		||||
            XmlElement rootElement = doc.CreateElement("", "ServerResponse",
 | 
			
		||||
                "");
 | 
			
		||||
 | 
			
		||||
            doc.AppendChild(rootElement);
 | 
			
		||||
 | 
			
		||||
            XmlElement result = doc.CreateElement("", "result", "");
 | 
			
		||||
            result.AppendChild(doc.CreateTextNode("Success"));
 | 
			
		||||
 | 
			
		||||
            rootElement.AppendChild(result);
 | 
			
		||||
 | 
			
		||||
            return Util.DocToBytes(doc);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private byte[] FailureResult()
 | 
			
		||||
        {
 | 
			
		||||
            XmlDocument doc = new XmlDocument();
 | 
			
		||||
 | 
			
		||||
            XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
 | 
			
		||||
                "", "");
 | 
			
		||||
 | 
			
		||||
            doc.AppendChild(xmlnode);
 | 
			
		||||
 | 
			
		||||
            XmlElement rootElement = doc.CreateElement("", "ServerResponse",
 | 
			
		||||
                "");
 | 
			
		||||
 | 
			
		||||
            doc.AppendChild(rootElement);
 | 
			
		||||
 | 
			
		||||
            XmlElement result = doc.CreateElement("", "result", "");
 | 
			
		||||
            result.AppendChild(doc.CreateTextNode("Failure"));
 | 
			
		||||
 | 
			
		||||
            rootElement.AppendChild(result);
 | 
			
		||||
 | 
			
		||||
            return Util.DocToBytes(doc);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
/*
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) Contributors, http://opensimulator.org/
 | 
			
		||||
 * See CONTRIBUTORS.TXT for a full list of copyright holders.
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			@ -25,13 +25,40 @@
 | 
			
		|||
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
using OpenMetaverse;
 | 
			
		||||
 | 
			
		||||
namespace OpenSim.Region.Framework.Interfaces
 | 
			
		||||
using System;
 | 
			
		||||
using Nini.Config;
 | 
			
		||||
using OpenSim.Server.Base;
 | 
			
		||||
using OpenSim.Services.Interfaces;
 | 
			
		||||
using OpenSim.Framework.ServiceAuth;
 | 
			
		||||
using OpenSim.Framework.Servers.HttpServer;
 | 
			
		||||
using OpenSim.Server.Handlers.Base;
 | 
			
		||||
 | 
			
		||||
namespace OpenSim.Server.Handlers.AgentPreferences
 | 
			
		||||
{
 | 
			
		||||
    public interface IAgentPreferencesModule
 | 
			
		||||
    public class AgentPreferencesServiceConnector : ServiceConnector
 | 
			
		||||
    {
 | 
			
		||||
        string GetLang(UUID agentID);
 | 
			
		||||
        private IAgentPreferencesService m_AgentPreferencesService;
 | 
			
		||||
        private string m_ConfigName = "AgentPreferencesService";
 | 
			
		||||
 | 
			
		||||
        public AgentPreferencesServiceConnector(IConfigSource config, IHttpServer server, string configName) :
 | 
			
		||||
                base(config, server, configName)
 | 
			
		||||
        {
 | 
			
		||||
            IConfig serverConfig = config.Configs[m_ConfigName];
 | 
			
		||||
            if (serverConfig == null)
 | 
			
		||||
                throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
 | 
			
		||||
 | 
			
		||||
            string service = serverConfig.GetString("LocalServiceModule", String.Empty);
 | 
			
		||||
 | 
			
		||||
            if (String.IsNullOrWhiteSpace(service))
 | 
			
		||||
                throw new Exception("No LocalServiceModule in config file");
 | 
			
		||||
 | 
			
		||||
            Object[] args = new Object[] { config };
 | 
			
		||||
            m_AgentPreferencesService = ServerUtils.LoadPlugin<IAgentPreferencesService>(service, args);
 | 
			
		||||
 | 
			
		||||
            IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); ;
 | 
			
		||||
 | 
			
		||||
            server.AddStreamHandler(new AgentPreferencesServerPostHandler(m_AgentPreferencesService, auth));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,230 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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 log4net;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using Nini.Config;
 | 
			
		||||
using OpenSim.Framework;
 | 
			
		||||
using OpenSim.Framework.ServiceAuth;
 | 
			
		||||
using OpenSim.Services.Interfaces;
 | 
			
		||||
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
 | 
			
		||||
using IAvatarService = OpenSim.Services.Interfaces.IAvatarService;
 | 
			
		||||
using OpenSim.Server.Base;
 | 
			
		||||
using OpenMetaverse;
 | 
			
		||||
 | 
			
		||||
namespace OpenSim.Services.Connectors
 | 
			
		||||
{
 | 
			
		||||
    public class AgentPreferencesServicesConnector : BaseServiceConnector, IAgentPreferencesService
 | 
			
		||||
    {
 | 
			
		||||
        private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 | 
			
		||||
 | 
			
		||||
        private string m_ServerURI = String.Empty;
 | 
			
		||||
 | 
			
		||||
        public AgentPreferencesServicesConnector()
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public AgentPreferencesServicesConnector(string serverURI)
 | 
			
		||||
        {
 | 
			
		||||
            m_ServerURI = serverURI.TrimEnd('/');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public AgentPreferencesServicesConnector(IConfigSource source)
 | 
			
		||||
            : base(source, "AgentPreferencesService")
 | 
			
		||||
        {
 | 
			
		||||
            Initialise(source);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public virtual void Initialise(IConfigSource source)
 | 
			
		||||
        {
 | 
			
		||||
            IConfig gridConfig = source.Configs["AgentPreferencesService"];
 | 
			
		||||
            if (gridConfig == null)
 | 
			
		||||
            {
 | 
			
		||||
                m_log.Error("[AGENT PREFERENCES CONNECTOR]: AgentPreferencesService missing from OpenSim.ini");
 | 
			
		||||
                throw new Exception("Agent Preferences connector init error");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            string serviceURI = gridConfig.GetString("AgentPreferencesServerURI", String.Empty);
 | 
			
		||||
 | 
			
		||||
            if (serviceURI == String.Empty)
 | 
			
		||||
            {
 | 
			
		||||
                m_log.Error("[AGENT PREFERENCES CONNECTOR]: No Server URI named in section AgentPreferences");
 | 
			
		||||
                throw new Exception("Agent Preferences connector init error");
 | 
			
		||||
            }
 | 
			
		||||
            m_ServerURI = serviceURI;
 | 
			
		||||
 | 
			
		||||
            base.Initialise(source, "AgentPreferencesService");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #region IAgentPreferencesService
 | 
			
		||||
 | 
			
		||||
        public AgentPrefs GetAgentPreferences(UUID principalID)
 | 
			
		||||
        {
 | 
			
		||||
            Dictionary<string, object> sendData = new Dictionary<string, object>();
 | 
			
		||||
 | 
			
		||||
            string reply = string.Empty;
 | 
			
		||||
            string uri = String.Concat(m_ServerURI, "/agentprefs");
 | 
			
		||||
 | 
			
		||||
            sendData["METHOD"] = "getagentprefs";
 | 
			
		||||
            sendData["UserID"] = principalID;
 | 
			
		||||
            string reqString = ServerUtils.BuildQueryString(sendData);
 | 
			
		||||
            // m_log.DebugFormat("[AGENT PREFS CONNECTOR]: queryString = {0}", reqString);
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString, m_Auth);
 | 
			
		||||
                if (String.IsNullOrEmpty(reply))
 | 
			
		||||
                {
 | 
			
		||||
                    m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: GetAgentPreferences received null or empty reply");
 | 
			
		||||
                    return null;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e)
 | 
			
		||||
            {
 | 
			
		||||
                m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: Exception when contacting agent preferences server at {0}: {1}", uri, e.Message);
 | 
			
		||||
            }
 | 
			
		||||
                
 | 
			
		||||
            Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
 | 
			
		||||
            if (replyData != null)
 | 
			
		||||
            {
 | 
			
		||||
                if (replyData.ContainsKey("result") &&
 | 
			
		||||
                    (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure"))
 | 
			
		||||
                {
 | 
			
		||||
                    m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: GetAgentPreferences received Failure response");
 | 
			
		||||
                    return null;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: GetAgentPreferences received null response");
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
            AgentPrefs prefs = new AgentPrefs(replyData);
 | 
			
		||||
            return prefs;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool StoreAgentPreferences(AgentPrefs data)
 | 
			
		||||
        {
 | 
			
		||||
            Dictionary<string, object> sendData = new Dictionary<string, object>();
 | 
			
		||||
 | 
			
		||||
            sendData["METHOD"] = "setagentprefs";
 | 
			
		||||
 | 
			
		||||
            sendData["PrincipalID"] = data.PrincipalID.ToString();
 | 
			
		||||
            sendData["AccessPrefs"] = data.AccessPrefs;
 | 
			
		||||
            sendData["HoverHeight"] = data.HoverHeight.ToString();
 | 
			
		||||
            sendData["Language"] = data.Language;
 | 
			
		||||
            sendData["LanguageIsPublic"] = data.LanguageIsPublic.ToString();
 | 
			
		||||
            sendData["PermEveryone"] = data.PermEveryone.ToString();
 | 
			
		||||
            sendData["PermGroup"] = data.PermGroup.ToString();
 | 
			
		||||
            sendData["PermNextOwner"] = data.PermNextOwner.ToString();
 | 
			
		||||
 | 
			
		||||
            string uri = String.Concat(m_ServerURI, "/agentprefs");
 | 
			
		||||
            string reqString = ServerUtils.BuildQueryString(sendData);
 | 
			
		||||
            // m_log.DebugFormat("[AGENT PREFS CONNECTOR]: queryString = {0}", reqString);
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString, m_Auth);
 | 
			
		||||
                if (reply != string.Empty)
 | 
			
		||||
                {
 | 
			
		||||
                    Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
 | 
			
		||||
 | 
			
		||||
                    if (replyData.ContainsKey("result"))
 | 
			
		||||
                    {
 | 
			
		||||
                        if (replyData["result"].ToString().ToLower() == "success")
 | 
			
		||||
                            return true;
 | 
			
		||||
                        else
 | 
			
		||||
                            return false;
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: StoreAgentPreferences reply data does not contain result field");
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                    m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: StoreAgentPreferences received empty reply");
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e)
 | 
			
		||||
            {
 | 
			
		||||
                m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: Exception when contacting agent preferences server at {0}: {1}", uri, e.Message);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public string GetLang(UUID principalID)
 | 
			
		||||
        {
 | 
			
		||||
            Dictionary<string, object> sendData = new Dictionary<string, object>();
 | 
			
		||||
            string reply = string.Empty;
 | 
			
		||||
 | 
			
		||||
            sendData["METHOD"] = "getagentlang";
 | 
			
		||||
            sendData["UserID"] = principalID.ToString();
 | 
			
		||||
 | 
			
		||||
            string uri = String.Concat(m_ServerURI, "/agentprefs");
 | 
			
		||||
            string reqString = ServerUtils.BuildQueryString(sendData);
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString, m_Auth);
 | 
			
		||||
                if (String.IsNullOrEmpty(reply))
 | 
			
		||||
                {
 | 
			
		||||
                    m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: GetLang received null or empty reply");
 | 
			
		||||
                    return "en-us"; // I guess? Gotta return somethin'!
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e)
 | 
			
		||||
            {
 | 
			
		||||
                m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: Exception when contacting agent preferences server at {0}: {1}", uri, e.Message);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
 | 
			
		||||
            if (replyData != null)
 | 
			
		||||
            {
 | 
			
		||||
                if (replyData.ContainsKey("result") &&
 | 
			
		||||
                    (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure"))
 | 
			
		||||
                {
 | 
			
		||||
                    m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: GetLang received Failure response");
 | 
			
		||||
                    return "en-us";
 | 
			
		||||
                }
 | 
			
		||||
                if (replyData.ContainsKey("Language"))
 | 
			
		||||
                    return replyData["Language"].ToString();
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: GetLang received null response");
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            return "en-us";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion IAgentPreferencesService
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,115 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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 OpenMetaverse;
 | 
			
		||||
 | 
			
		||||
namespace OpenSim.Services.Interfaces
 | 
			
		||||
{
 | 
			
		||||
    public class AgentPrefs
 | 
			
		||||
    {
 | 
			
		||||
        public AgentPrefs(UUID principalID) 
 | 
			
		||||
        {
 | 
			
		||||
            principalID = PrincipalID;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public AgentPrefs(Dictionary<string, string> kvp)
 | 
			
		||||
        {
 | 
			
		||||
            if (kvp.ContainsKey("PrincipalID"))
 | 
			
		||||
                UUID.TryParse(kvp["PrincipalID"], out PrincipalID);
 | 
			
		||||
            if (kvp.ContainsKey("AccessPrefs"))
 | 
			
		||||
                AccessPrefs = kvp["AccessPrefs"];
 | 
			
		||||
            if (kvp.ContainsKey("HoverHeight"))
 | 
			
		||||
                HoverHeight = double.Parse(kvp["HoverHeight"]);
 | 
			
		||||
            if (kvp.ContainsKey("Language"))
 | 
			
		||||
                Language = kvp["Language"];
 | 
			
		||||
            if (kvp.ContainsKey("LanguageIsPublic"))
 | 
			
		||||
                LanguageIsPublic = bool.Parse(kvp["LanguageIsPublic"]);
 | 
			
		||||
            if (kvp.ContainsKey("PermEveryone"))
 | 
			
		||||
                PermEveryone = int.Parse(kvp["PermEveryone"]);
 | 
			
		||||
            if (kvp.ContainsKey("PermGroup"))
 | 
			
		||||
                PermGroup = int.Parse(kvp["PermGroup"]);
 | 
			
		||||
            if (kvp.ContainsKey("PermNextOwner"))
 | 
			
		||||
                PermNextOwner = int.Parse(kvp["PermNextOwner"]);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public AgentPrefs(Dictionary<string, object> kvp)
 | 
			
		||||
        {
 | 
			
		||||
            if (kvp.ContainsKey("PrincipalID"))
 | 
			
		||||
                UUID.TryParse(kvp["PrincipalID"].ToString(), out PrincipalID);
 | 
			
		||||
            if (kvp.ContainsKey("AccessPrefs"))
 | 
			
		||||
                AccessPrefs = kvp["AccessPrefs"].ToString();
 | 
			
		||||
            if (kvp.ContainsKey("HoverHeight"))
 | 
			
		||||
                HoverHeight = double.Parse(kvp["HoverHeight"].ToString());
 | 
			
		||||
            if (kvp.ContainsKey("Language"))
 | 
			
		||||
                Language = kvp["Language"].ToString();
 | 
			
		||||
            if (kvp.ContainsKey("LanguageIsPublic"))
 | 
			
		||||
                LanguageIsPublic = bool.Parse(kvp["LanguageIsPublic"].ToString());
 | 
			
		||||
            if (kvp.ContainsKey("PermEveryone"))
 | 
			
		||||
                PermEveryone = int.Parse(kvp["PermEveryone"].ToString());
 | 
			
		||||
            if (kvp.ContainsKey("PermGroup"))
 | 
			
		||||
                PermGroup = int.Parse(kvp["PermGroup"].ToString());
 | 
			
		||||
            if (kvp.ContainsKey("PermNextOwner"))
 | 
			
		||||
                PermNextOwner = int.Parse(kvp["PermNextOwner"].ToString());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Dictionary<string, object> ToKeyValuePairs()
 | 
			
		||||
        {
 | 
			
		||||
            Dictionary<string, object> result = new Dictionary<string, object>();
 | 
			
		||||
            result["PrincipalID"] = PrincipalID.ToString();
 | 
			
		||||
            result["AccessPrefs"] = AccessPrefs.ToString();
 | 
			
		||||
            result["HoverHeight"] = HoverHeight.ToString();
 | 
			
		||||
            result["Language"] = Language.ToString();
 | 
			
		||||
            result["LanguageIsPublic"] = LanguageIsPublic.ToString();
 | 
			
		||||
            result["PermEveryone"] = PermEveryone.ToString();
 | 
			
		||||
            result["PermGroup"] = PermGroup.ToString();
 | 
			
		||||
            result["PermNextOwner"] = PermNextOwner.ToString();
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public UUID PrincipalID = UUID.Zero;
 | 
			
		||||
        public string AccessPrefs = "M";
 | 
			
		||||
        //public int GodLevel; // *TODO: Implement GodLevel (Unused by the viewer, afaict - 6/11/2015)
 | 
			
		||||
        public double HoverHeight = 0.0;
 | 
			
		||||
        public string Language = "en-us";
 | 
			
		||||
        public bool LanguageIsPublic = true;
 | 
			
		||||
        // DefaultObjectPermMasks
 | 
			
		||||
        public int PermEveryone = 0;
 | 
			
		||||
        public int PermGroup = 0;
 | 
			
		||||
        public int PermNextOwner = 532480;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public interface IAgentPreferencesService
 | 
			
		||||
    {
 | 
			
		||||
        AgentPrefs GetAgentPreferences(UUID principalID);
 | 
			
		||||
        bool StoreAgentPreferences(AgentPrefs data);
 | 
			
		||||
 | 
			
		||||
        string GetLang(UUID principalID);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,80 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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.Reflection;
 | 
			
		||||
using log4net;
 | 
			
		||||
using Nini.Config;
 | 
			
		||||
using OpenMetaverse;
 | 
			
		||||
using OpenSim.Data;
 | 
			
		||||
using OpenSim.Framework;
 | 
			
		||||
using OpenSim.Services.Interfaces;
 | 
			
		||||
 | 
			
		||||
namespace OpenSim.Services.UserAccountService
 | 
			
		||||
{
 | 
			
		||||
    public class AgentPreferencesService : AgentPreferencesServiceBase, IAgentPreferencesService
 | 
			
		||||
    {
 | 
			
		||||
        private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 | 
			
		||||
 | 
			
		||||
        public AgentPreferencesService(IConfigSource config) : base(config) 
 | 
			
		||||
        {
 | 
			
		||||
            m_log.Debug("[AGENT PREFERENCES SERVICE]: Starting agent preferences service");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public AgentPrefs GetAgentPreferences(UUID principalID)
 | 
			
		||||
        {
 | 
			
		||||
            AgentPreferencesData d = m_Database.GetPrefs(principalID);
 | 
			
		||||
            AgentPrefs prefs = (d == null) ? new AgentPrefs(principalID) : new AgentPrefs(d.Data);
 | 
			
		||||
            return prefs;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool StoreAgentPreferences(AgentPrefs data)
 | 
			
		||||
        {
 | 
			
		||||
            AgentPreferencesData d = new AgentPreferencesData();
 | 
			
		||||
            d.Data["PrincipalID"] = data.PrincipalID.ToString();
 | 
			
		||||
            d.Data["AccessPrefs"] = data.AccessPrefs;
 | 
			
		||||
            d.Data["HoverHeight"] = data.HoverHeight.ToString();
 | 
			
		||||
            d.Data["Language"] = data.Language;
 | 
			
		||||
            d.Data["LanguageIsPublic"] = data.LanguageIsPublic.ToString();
 | 
			
		||||
            d.Data["PermEveryone"] = data.PermEveryone.ToString();
 | 
			
		||||
            d.Data["PermGroup"] = data.PermGroup.ToString();
 | 
			
		||||
            d.Data["PermNextOwner"] = data.PermNextOwner.ToString();
 | 
			
		||||
            return m_Database.Store(d);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public string GetLang(UUID principalID)
 | 
			
		||||
        {
 | 
			
		||||
            AgentPrefs data = GetAgentPreferences(principalID);
 | 
			
		||||
            if (data != null)
 | 
			
		||||
            {
 | 
			
		||||
                if (data.LanguageIsPublic)
 | 
			
		||||
                    return data.Language;
 | 
			
		||||
            }
 | 
			
		||||
            return "en-us";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,73 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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.Reflection;
 | 
			
		||||
using Nini.Config;
 | 
			
		||||
using OpenSim.Data;
 | 
			
		||||
using OpenSim.Services.Interfaces;
 | 
			
		||||
using OpenSim.Services.Base;
 | 
			
		||||
 | 
			
		||||
namespace OpenSim.Services.UserAccountService
 | 
			
		||||
{
 | 
			
		||||
    public class AgentPreferencesServiceBase: ServiceBase
 | 
			
		||||
    {
 | 
			
		||||
        protected IAgentPreferencesData m_Database = null;
 | 
			
		||||
 | 
			
		||||
        public AgentPreferencesServiceBase(IConfigSource config) : base(config)
 | 
			
		||||
        {
 | 
			
		||||
            string dllName = String.Empty;
 | 
			
		||||
            string connString = String.Empty;
 | 
			
		||||
            string realm = "AgentPrefs";
 | 
			
		||||
 | 
			
		||||
            IConfig dbConfig = config.Configs["DatabaseService"];
 | 
			
		||||
            if (dbConfig != null)
 | 
			
		||||
            {
 | 
			
		||||
                dllName = dbConfig.GetString("StorageProvider", String.Empty);
 | 
			
		||||
                connString = dbConfig.GetString("ConnectionString", String.Empty);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            IConfig userConfig = config.Configs["AgentPreferencesService"];
 | 
			
		||||
            if (userConfig == null)
 | 
			
		||||
                throw new Exception("No AgentPreferencesService configuration");
 | 
			
		||||
 | 
			
		||||
            dllName = userConfig.GetString("StorageProvider", dllName);
 | 
			
		||||
 | 
			
		||||
            if (dllName == String.Empty)
 | 
			
		||||
                throw new Exception("No StorageProvider configured");
 | 
			
		||||
 | 
			
		||||
            connString = userConfig.GetString("ConnectionString", connString);
 | 
			
		||||
 | 
			
		||||
            realm = userConfig.GetString("Realm", realm);
 | 
			
		||||
 | 
			
		||||
            m_Database = LoadPlugin<IAgentPreferencesData>(dllName, new Object[] {connString, realm});
 | 
			
		||||
 | 
			
		||||
            if (m_Database == null)
 | 
			
		||||
                throw new Exception("Could not find a storage interface in the given module");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -85,6 +85,7 @@
 | 
			
		|||
    PresenceServiceConnector = "${Const|PrivatePort}/OpenSim.Server.Handlers.dll:PresenceServiceConnector"
 | 
			
		||||
    UserAccountServiceConnector = "${Const|PrivatePort}/OpenSim.Server.Handlers.dll:UserAccountServiceConnector"
 | 
			
		||||
    GridUserServiceConnector = "${Const|PrivatePort}/OpenSim.Server.Handlers.dll:GridUserServiceConnector"
 | 
			
		||||
    AgentPreferencesServiceConnector = "${Const|PrivatePort}/OpenSim.Server.Handlers.dll:AgentPreferencesServiceConnector"
 | 
			
		||||
    FriendsServiceConnector = "${Const|PrivatePort}/OpenSim.Server.Handlers.dll:FriendsServiceConnector"
 | 
			
		||||
    MapAddServiceConnector = "${Const|PrivatePort}/OpenSim.Server.Handlers.dll:MapAddServiceConnector"
 | 
			
		||||
    MapGetServiceConnector = "${Const|PublicPort}/OpenSim.Server.Handlers.dll:MapGetServiceConnector"
 | 
			
		||||
| 
						 | 
				
			
			@ -374,6 +375,11 @@
 | 
			
		|||
    LocalServiceModule = "OpenSim.Services.UserAccountService.dll:GridUserService"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
[AgentPreferencesService]
 | 
			
		||||
    ; for the server connector
 | 
			
		||||
    LocalServiceModule = "Opensim.Services.UserAccountService.dll:AgentPreferencesService"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
[PresenceService]
 | 
			
		||||
    ; for the server connector
 | 
			
		||||
    LocalServiceModule = "OpenSim.Services.PresenceService.dll:PresenceService"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -76,6 +76,7 @@
 | 
			
		|||
    PresenceServiceConnector = "${Const|PrivatePort}/OpenSim.Server.Handlers.dll:PresenceServiceConnector"
 | 
			
		||||
    UserAccountServiceConnector = "${Const|PrivatePort}/OpenSim.Server.Handlers.dll:UserAccountServiceConnector"
 | 
			
		||||
    GridUserServiceConnector = "${Const|PrivatePort}/OpenSim.Server.Handlers.dll:GridUserServiceConnector"
 | 
			
		||||
    AgentPreferencesServiceConnector = "${Const|PrivatePort}/OpenSim.Server.Handlers.dll:AgentPreferencesServiceConnector"
 | 
			
		||||
    FriendsServiceConnector = "${Const|PrivatePort}/OpenSim.Server.Handlers.dll:FriendsServiceConnector"
 | 
			
		||||
    MapAddServiceConnector = "${Const|PrivatePort}/OpenSim.Server.Handlers.dll:MapAddServiceConnector"
 | 
			
		||||
    MapGetServiceConnector = "${Const|PublicPort}/OpenSim.Server.Handlers.dll:MapGetServiceConnector"
 | 
			
		||||
| 
						 | 
				
			
			@ -332,6 +333,11 @@
 | 
			
		|||
    LocalServiceModule = "OpenSim.Services.UserAccountService.dll:GridUserService"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
[AgentPreferencesService]
 | 
			
		||||
    ; for the server connector
 | 
			
		||||
    LocalServiceModule = "Opensim.Services.UserAccountService.dll:AgentPreferencesService"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
[PresenceService]
 | 
			
		||||
    ; for the server connector
 | 
			
		||||
    LocalServiceModule = "OpenSim.Services.PresenceService.dll:PresenceService"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@
 | 
			
		|||
    AuthorizationServices   = "LocalAuthorizationServicesConnector"
 | 
			
		||||
    PresenceServices        = "RemotePresenceServicesConnector"
 | 
			
		||||
    UserAccountServices     = "RemoteUserAccountServicesConnector"
 | 
			
		||||
    AgentPreferencesServices= "RemoteAgentPreferencesServicesConnector"
 | 
			
		||||
    GridUserServices        = "RemoteGridUserServicesConnector"
 | 
			
		||||
    SimulationServices      = "RemoteSimulationConnectorModule"
 | 
			
		||||
    EntityTransferModule    = "BasicEntityTransferModule"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -131,6 +131,12 @@
 | 
			
		|||
    ;
 | 
			
		||||
    AvatarServerURI = "${Const|BaseURL}:${Const|PrivatePort}"
 | 
			
		||||
 | 
			
		||||
[AgentPreferencesService]
 | 
			
		||||
    ;
 | 
			
		||||
    ; Change this to your grid-wide avatar prefs server
 | 
			
		||||
    ;
 | 
			
		||||
    AgentPreferencesServerURI = "${Const|BaseURL}:${Const|PrivatePort}"
 | 
			
		||||
 | 
			
		||||
[PresenceService]
 | 
			
		||||
    ;
 | 
			
		||||
    ; Change this to your grid-wide presence server
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,6 +20,7 @@
 | 
			
		|||
    AuthorizationServices   = "LocalAuthorizationServicesConnector"
 | 
			
		||||
    PresenceServices        = "RemotePresenceServicesConnector"
 | 
			
		||||
    UserAccountServices     = "RemoteUserAccountServicesConnector"
 | 
			
		||||
    AgentPreferencesServices= "RemoteAgentPreferencesServicesConnector"
 | 
			
		||||
    GridUserServices        = "RemoteGridUserServicesConnector"
 | 
			
		||||
    SimulationServices      = "RemoteSimulationConnectorModule"
 | 
			
		||||
    EntityTransferModule    = "HGEntityTransferModule"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,7 @@
 | 
			
		|||
    PresenceServices        = "LocalPresenceServicesConnector"
 | 
			
		||||
    UserProfilesServices    = "LocalUserProfilesServicesConnector"
 | 
			
		||||
    UserAccountServices     = "LocalUserAccountServicesConnector"
 | 
			
		||||
    AgentPreferencesServices= "LocalAgentPreferencesServicesConnector"
 | 
			
		||||
    GridUserServices        = "LocalGridUserServicesConnector"
 | 
			
		||||
    SimulationServices      = "LocalSimulationConnectorModule"
 | 
			
		||||
    AvatarServices          = "LocalAvatarServicesConnector"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,6 +16,7 @@
 | 
			
		|||
    GridServices            = "LocalGridServicesConnector"
 | 
			
		||||
    PresenceServices        = "LocalPresenceServicesConnector"
 | 
			
		||||
    UserAccountServices     = "LocalUserAccountServicesConnector"
 | 
			
		||||
    AgentPreferencesServices= "LocalAgentPreferencesServicesConnector"
 | 
			
		||||
    GridUserServices        = "LocalGridUserServicesConnector"
 | 
			
		||||
    SimulationServices      = "RemoteSimulationConnectorModule"
 | 
			
		||||
    AvatarServices          = "LocalAvatarServicesConnector"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue