aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs')
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs225
1 files changed, 225 insertions, 0 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs
new file mode 100644
index 0000000..a738fba
--- /dev/null
+++ b/OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs
@@ -0,0 +1,225 @@
1/*
2 * @brief AgentPreferences capability module
3 *
4 * Copyright (C) 2015, Cinder Roxley <cinder@sdf.org>
5 *
6 * Permission is hereby granted, free of charge, to any person or organization
7 * obtaining a copy of the software and accompanying documentation covered by
8 * this license (the "Software") to use, reproduce, display, distribute,
9 * execute, and transmit the Software, and to prepare derivative works of the
10 * Software, and to permit third-parties to whom the Software is furnished to
11 * do so, all subject to the following:
12 *
13 * The copyright notices in the Software and this entire statement, including
14 * the above license grant, this restriction and the following disclaimer,
15 * must be included in all copies of the Software, in whole or in part, and
16 * all derivative works of the Software, unless such copies or derivative
17 * works are solely in the form of machine-executable object code generated by
18 * a source language processor.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
23 * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
24 * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 */
28
29using System;
30using System.Reflection;
31using System.IO;
32using log4net;
33using Mono.Addins;
34using Nini.Config;
35using OpenMetaverse;
36using OpenMetaverse.StructuredData;
37using OpenSim.Data;
38using OpenSim.Data.MySQL;
39using OpenSim.Framework.Console;
40using OpenSim.Framework.Servers;
41using OpenSim.Framework.Servers.HttpServer;
42using OpenSim.Region.Framework.Interfaces;
43using OpenSim.Region.Framework.Scenes;
44using OpenSim.Services.Interfaces;
45using Caps = OpenSim.Framework.Capabilities.Caps;
46using OpenSim.Capabilities.Handlers;
47
48namespace OpenSim.Region.ClientStack.LindenCaps
49{
50 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AgentPreferencesModule")]
51 public class AgentPreferencesModule : ISharedRegionModule, IAgentPreferencesModule
52 {
53 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54
55 public bool m_enabled { get; private set; }
56 private Scene m_Scene;
57 protected IAgentPreferencesData m_Database;
58
59 public void Initialise(IConfigSource source)
60 {
61 IConfig dbConfig = source.Configs["DatabaseService"];
62 if (dbConfig != null)
63 {
64 string dllName = String.Empty;
65 string connString = String.Empty;
66
67 dllName = dbConfig.GetString("StorageProvider", dllName);
68 connString = dbConfig.GetString("ConnectionString", connString);
69
70 // We tried, but this doesn't exist. We can't proceed
71 if (dllName == String.Empty)
72 throw new Exception("No StorageProvider configured");
73
74 // *FIXME: This is a janky as hell, works for now.
75 if (dllName == "OpenSim.Data.MySQL.dll")
76 m_Database = new MySQLAgentPreferencesData(connString, "AgentPrefs");
77 else
78 throw new Exception("Storage provider not supported!");
79
80 if (m_Database == null)
81 {
82 m_enabled = false;
83 throw new Exception("Could not find a storage interface in the given module");
84 }
85 m_log.Debug("[AgentPrefs] AgentPrefs is enabled");
86 m_enabled = true;
87 }
88 }
89
90 #region Region module
91 public void AddRegion(Scene s)
92 {
93 if (!m_enabled) return;
94
95 s.RegisterModuleInterface<IAgentPreferencesModule>(this);
96 m_Scene = s;
97 }
98
99 public void RemoveRegion(Scene s)
100 {
101 if (!m_enabled) return;
102
103 m_Scene.UnregisterModuleInterface<IAgentPreferencesModule>(this);
104 m_Scene.EventManager.OnRegisterCaps -= RegisterCaps;
105 m_Scene = null;
106 }
107
108 public void RegionLoaded(Scene s)
109 {
110 if (!m_enabled) return;
111
112 m_Scene.EventManager.OnRegisterCaps += delegate(UUID agentID, OpenSim.Framework.Capabilities.Caps caps)
113 {
114 RegisterCaps(agentID, caps);
115 };
116 }
117
118 public void PostInitialise() {}
119
120 public void Close() {}
121
122 public string Name { get { return "AgentPreferencesModule"; } }
123
124 public Type ReplaceableInterface
125 {
126 get { return null; }
127 }
128
129 public void RegisterCaps(UUID agent, Caps caps)
130 {
131 UUID capId = UUID.Random();
132 caps.RegisterHandler("AgentPreferences",
133 new RestStreamHandler("POST", "/CAPS/" + capId,
134 delegate(string request, string path, string param,
135 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
136 {
137 return UpdateAgentPreferences(request, path, param, agent);
138 }));
139 caps.RegisterHandler("UpdateAgentLanguage",
140 new RestStreamHandler("POST", "/CAPS/" + capId,
141 delegate(string request, string path, string param,
142 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
143 {
144 return UpdateAgentPreferences(request, path, param, agent);
145 }));
146 caps.RegisterHandler("UpdateAgentInformation",
147 new RestStreamHandler("POST", "/CAPS/" + capId,
148 delegate(string request, string path, string param,
149 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
150 {
151 return UpdateAgentPreferences(request, path, param, agent);
152 }));
153 }
154
155 public string UpdateAgentPreferences(string request, string path, string param, UUID agent)
156 {
157 m_log.DebugFormat("[AgentPrefs] UpdateAgentPreferences for {0}", agent.ToString());
158 OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request);
159 AgentPreferencesData data = m_Database.GetPrefs(agent);
160 if (data == null)
161 {
162 data = new AgentPreferencesData();
163 data.PrincipalID = agent;
164 }
165
166 if (req.ContainsKey("access_prefs"))
167 {
168 OSDMap accessPrefs = (OSDMap)req["access_prefs"]; // We could check with ContainsKey...
169 data.AccessPrefs = accessPrefs["max"].AsString();
170 }
171 if (req.ContainsKey("default_object_perm_masks"))
172 {
173 OSDMap permsMap = (OSDMap)req["default_object_perm_masks"];
174 data.PermEveryone = permsMap["Everyone"].AsInteger();
175 data.PermGroup = permsMap["Group"].AsInteger();
176 data.PermNextOwner = permsMap["NextOwner"].AsInteger();
177 }
178 if (req.ContainsKey("hover_height"))
179 {
180 data.HoverHeight = req["hover_height"].AsReal();
181 }
182 if (req.ContainsKey("language"))
183 {
184 data.Language = req["language"].AsString();
185 }
186 if (req.ContainsKey("language_is_public"))
187 {
188 data.LanguageIsPublic = req["language_is_public"].AsBoolean();
189 }
190 m_Database.StorePrefs(data);
191 OSDMap resp = new OSDMap();
192 OSDMap respAccessPrefs = new OSDMap();
193 respAccessPrefs["max"] = data.AccessPrefs;
194 resp["access_prefs"] = respAccessPrefs;
195 OSDMap respDefaultPerms = new OSDMap();
196 respDefaultPerms["Everyone"] = data.PermEveryone;
197 respDefaultPerms["Group"] = data.PermGroup;
198 respDefaultPerms["NextOwner"] = data.PermNextOwner;
199 resp["default_object_perm_masks"] = respDefaultPerms;
200 resp["god_level"] = 0; // *TODO: Add this
201 resp["hover_height"] = data.HoverHeight;
202 resp["language"] = data.Language;
203 resp["language_is_public"] = data.LanguageIsPublic;
204
205 string response = OSDParser.SerializeLLSDXmlString(resp);
206 return response;
207 }
208 #endregion Region module
209
210 #region IAgentPreferences
211 public string GetLang(UUID agentID)
212 {
213 AgentPreferencesData data = m_Database.GetPrefs(agentID);
214 if (data != null)
215 {
216 if (data.LanguageIsPublic)
217 return data.Language;
218 }
219 return "en-us";
220
221 }
222 #endregion
223 }
224}
225