diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs | 83 |
1 files changed, 17 insertions, 66 deletions
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 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | ||
29 | using System.Reflection; | 30 | using System.Reflection; |
30 | using System.IO; | 31 | using System.IO; |
31 | using log4net; | 32 | using log4net; |
@@ -33,8 +34,6 @@ using Mono.Addins; | |||
33 | using Nini.Config; | 34 | using Nini.Config; |
34 | using OpenMetaverse; | 35 | using OpenMetaverse; |
35 | using OpenMetaverse.StructuredData; | 36 | using OpenMetaverse.StructuredData; |
36 | using OpenSim.Data; | ||
37 | using OpenSim.Data.MySQL; | ||
38 | using OpenSim.Framework.Console; | 37 | using OpenSim.Framework.Console; |
39 | using OpenSim.Framework.Servers; | 38 | using OpenSim.Framework.Servers; |
40 | using OpenSim.Framework.Servers.HttpServer; | 39 | using OpenSim.Framework.Servers.HttpServer; |
@@ -47,68 +46,34 @@ using OpenSim.Capabilities.Handlers; | |||
47 | namespace OpenSim.Region.ClientStack.LindenCaps | 46 | namespace OpenSim.Region.ClientStack.LindenCaps |
48 | { | 47 | { |
49 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AgentPreferencesModule")] | 48 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AgentPreferencesModule")] |
50 | public class AgentPreferencesModule : ISharedRegionModule, IAgentPreferencesModule | 49 | public class AgentPreferencesModule : ISharedRegionModule |
51 | { | 50 | { |
52 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
53 | 52 | ||
54 | public bool m_enabled { get; private set; } | 53 | private List<Scene> m_scenes = new List<Scene>(); |
55 | private Scene m_Scene; | ||
56 | protected IAgentPreferencesData m_Database; | ||
57 | 54 | ||
58 | public void Initialise(IConfigSource source) | 55 | public void Initialise(IConfigSource source) |
59 | { | 56 | { |
60 | IConfig dbConfig = source.Configs["DatabaseService"]; | 57 | |
61 | if (dbConfig != null) | ||
62 | { | ||
63 | string dllName = String.Empty; | ||
64 | string connString = String.Empty; | ||
65 | |||
66 | dllName = dbConfig.GetString("StorageProvider", dllName); | ||
67 | connString = dbConfig.GetString("ConnectionString", connString); | ||
68 | |||
69 | // We tried, but this doesn't exist. We can't proceed | ||
70 | if (dllName == String.Empty) | ||
71 | throw new Exception("No StorageProvider configured"); | ||
72 | |||
73 | // *FIXME: This is a janky as hell, works for now. | ||
74 | if (dllName == "OpenSim.Data.MySQL.dll") | ||
75 | m_Database = new MySQLAgentPreferencesData(connString, "AgentPrefs"); | ||
76 | else | ||
77 | throw new Exception("Storage provider not supported!"); | ||
78 | |||
79 | if (m_Database == null) | ||
80 | { | ||
81 | m_enabled = false; | ||
82 | throw new Exception("Could not find a storage interface in the given module"); | ||
83 | } | ||
84 | m_log.Debug("[AgentPrefs] AgentPrefs is enabled"); | ||
85 | m_enabled = true; | ||
86 | } | ||
87 | } | 58 | } |
88 | 59 | ||
89 | #region Region module | 60 | #region Region module |
90 | public void AddRegion(Scene s) | ||
91 | { | ||
92 | if (!m_enabled) return; | ||
93 | 61 | ||
94 | s.RegisterModuleInterface<IAgentPreferencesModule>(this); | 62 | public void AddRegion(Scene scene) |
95 | m_Scene = s; | 63 | { |
64 | lock (m_scenes) m_scenes.Add(scene); | ||
96 | } | 65 | } |
97 | 66 | ||
98 | public void RemoveRegion(Scene s) | 67 | public void RemoveRegion(Scene scene) |
99 | { | 68 | { |
100 | if (!m_enabled) return; | 69 | lock (m_scenes) m_scenes.Remove(scene); |
101 | 70 | scene.EventManager.OnRegisterCaps -= RegisterCaps; | |
102 | m_Scene.UnregisterModuleInterface<IAgentPreferencesModule>(this); | 71 | scene = null; |
103 | m_Scene.EventManager.OnRegisterCaps -= RegisterCaps; | ||
104 | m_Scene = null; | ||
105 | } | 72 | } |
106 | 73 | ||
107 | public void RegionLoaded(Scene s) | 74 | public void RegionLoaded(Scene scene) |
108 | { | 75 | { |
109 | if (!m_enabled) return; | 76 | scene.EventManager.OnRegisterCaps += delegate(UUID agentID, OpenSim.Framework.Capabilities.Caps caps) |
110 | |||
111 | m_Scene.EventManager.OnRegisterCaps += delegate(UUID agentID, OpenSim.Framework.Capabilities.Caps caps) | ||
112 | { | 77 | { |
113 | RegisterCaps(agentID, caps); | 78 | RegisterCaps(agentID, caps); |
114 | }; | 79 | }; |
@@ -155,11 +120,10 @@ namespace OpenSim.Region.ClientStack.LindenCaps | |||
155 | { | 120 | { |
156 | m_log.DebugFormat("[AgentPrefs] UpdateAgentPreferences for {0}", agent.ToString()); | 121 | m_log.DebugFormat("[AgentPrefs] UpdateAgentPreferences for {0}", agent.ToString()); |
157 | OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); | 122 | OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); |
158 | AgentPreferencesData data = m_Database.GetPrefs(agent); | 123 | AgentPrefs data = m_scenes[0].AgentPreferencesService.GetAgentPreferences(agent); |
159 | if (data == null) | 124 | if (data == null) |
160 | { | 125 | { |
161 | data = new AgentPreferencesData(); | 126 | data = new AgentPrefs(agent); |
162 | data.PrincipalID = agent; | ||
163 | } | 127 | } |
164 | 128 | ||
165 | if (req.ContainsKey("access_prefs")) | 129 | if (req.ContainsKey("access_prefs")) |
@@ -186,7 +150,7 @@ namespace OpenSim.Region.ClientStack.LindenCaps | |||
186 | { | 150 | { |
187 | data.LanguageIsPublic = req["language_is_public"].AsBoolean(); | 151 | data.LanguageIsPublic = req["language_is_public"].AsBoolean(); |
188 | } | 152 | } |
189 | m_Database.StorePrefs(data); | 153 | m_scenes[0].AgentPreferencesService.StoreAgentPreferences(data); |
190 | OSDMap resp = new OSDMap(); | 154 | OSDMap resp = new OSDMap(); |
191 | OSDMap respAccessPrefs = new OSDMap(); | 155 | OSDMap respAccessPrefs = new OSDMap(); |
192 | respAccessPrefs["max"] = data.AccessPrefs; | 156 | respAccessPrefs["max"] = data.AccessPrefs; |
@@ -204,21 +168,8 @@ namespace OpenSim.Region.ClientStack.LindenCaps | |||
204 | string response = OSDParser.SerializeLLSDXmlString(resp); | 168 | string response = OSDParser.SerializeLLSDXmlString(resp); |
205 | return response; | 169 | return response; |
206 | } | 170 | } |
207 | #endregion Region module | ||
208 | 171 | ||
209 | #region IAgentPreferences | 172 | #endregion Region module |
210 | public string GetLang(UUID agentID) | ||
211 | { | ||
212 | AgentPreferencesData data = m_Database.GetPrefs(agentID); | ||
213 | if (data != null) | ||
214 | { | ||
215 | if (data.LanguageIsPublic) | ||
216 | return data.Language; | ||
217 | } | ||
218 | return "en-us"; | ||
219 | |||
220 | } | ||
221 | #endregion | ||
222 | } | 173 | } |
223 | } | 174 | } |
224 | 175 | ||