aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Data/IAgentPreferencesData.cs56
-rw-r--r--OpenSim/Data/MySQL/MySQLAgentPreferencesData.cs73
-rw-r--r--OpenSim/Data/MySQL/Resources/AgentPrefs.migrations18
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs225
-rw-r--r--OpenSim/Region/Framework/Interfaces/IAgentPreferencesModule.cs36
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs16
6 files changed, 419 insertions, 5 deletions
diff --git a/OpenSim/Data/IAgentPreferencesData.cs b/OpenSim/Data/IAgentPreferencesData.cs
new file mode 100644
index 0000000..18bf337
--- /dev/null
+++ b/OpenSim/Data/IAgentPreferencesData.cs
@@ -0,0 +1,56 @@
1/*
2 * @brief Data store for AgentPreferences capability
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.Collections.Generic;
31using OpenMetaverse;
32using OpenSim.Framework;
33
34namespace OpenSim.Data
35{
36 public class AgentPreferencesData
37 {
38 public UUID PrincipalID = UUID.Zero;
39 public string AccessPrefs = "M";
40 //public int GodLevel;
41 public double HoverHeight = 0.0;
42 public string Language = "en-us";
43 public bool LanguageIsPublic = true;
44 // DefaultObjectPermMasks
45 public int PermEveryone = 0;
46 public int PermGroup = 0;
47 public int PermNextOwner = 532480;
48 }
49
50 public interface IAgentPreferencesData
51 {
52 AgentPreferencesData GetPrefs(UUID agentID);
53 void StorePrefs(AgentPreferencesData data);
54 }
55}
56
diff --git a/OpenSim/Data/MySQL/MySQLAgentPreferencesData.cs b/OpenSim/Data/MySQL/MySQLAgentPreferencesData.cs
new file mode 100644
index 0000000..0ea2f64
--- /dev/null
+++ b/OpenSim/Data/MySQL/MySQLAgentPreferencesData.cs
@@ -0,0 +1,73 @@
1/*
2 * Copyright (C) 2015, Cinder Roxley <cinder@sdf.org>
3 *
4 * Permission is hereby granted, free of charge, to any person or organization
5 * obtaining a copy of the software and accompanying documentation covered by
6 * this license (the "Software") to use, reproduce, display, distribute,
7 * execute, and transmit the Software, and to prepare derivative works of the
8 * Software, and to permit third-parties to whom the Software is furnished to
9 * do so, all subject to the following:
10 *
11 * The copyright notices in the Software and this entire statement, including
12 * the above license grant, this restriction and the following disclaimer,
13 * must be included in all copies of the Software, in whole or in part, and
14 * all derivative works of the Software, unless such copies or derivative
15 * works are solely in the form of machine-executable object code generated by
16 * a source language processor.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21 * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22 * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 */
26
27using System;
28using System.Collections;
29using System.Collections.Generic;
30using System.Data;
31using OpenMetaverse;
32using OpenSim.Framework;
33using MySql.Data.MySqlClient;
34
35namespace OpenSim.Data.MySQL
36{
37 public class MySQLAgentPreferencesData : MySQLGenericTableHandler<AgentPreferencesData>, IAgentPreferencesData
38 {
39 public MySQLAgentPreferencesData(string connectionString, string realm)
40 : base(connectionString, realm, "AgentPrefs")
41 {
42 }
43
44 public AgentPreferencesData GetPrefs(UUID agentID)
45 {
46 AgentPreferencesData[] ret = Get("PrincipalID", agentID.ToString());
47
48 if (ret.Length == 0)
49 return null;
50
51 return ret[0];
52 }
53
54 public void StorePrefs(AgentPreferencesData data)
55 {
56 using (MySqlCommand cmd = new MySqlCommand())
57 {
58 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);
59 cmd.Parameters.AddWithValue("?Principal", data.PrincipalID.ToString());
60 cmd.Parameters.AddWithValue("?AP", data.AccessPrefs);
61 cmd.Parameters.AddWithValue("?HH", data.HoverHeight);
62 cmd.Parameters.AddWithValue("?Lang", data.Language);
63 cmd.Parameters.AddWithValue("?LIP", data.LanguageIsPublic);
64 cmd.Parameters.AddWithValue("?PE", data.PermEveryone);
65 cmd.Parameters.AddWithValue("?PG", data.PermGroup);
66 cmd.Parameters.AddWithValue("?PNO", data.PermNextOwner);
67
68 ExecuteNonQuery(cmd);
69 }
70 }
71 }
72}
73
diff --git a/OpenSim/Data/MySQL/Resources/AgentPrefs.migrations b/OpenSim/Data/MySQL/Resources/AgentPrefs.migrations
new file mode 100644
index 0000000..e496f72
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/AgentPrefs.migrations
@@ -0,0 +1,18 @@
1:VERSION 1 # -------------------------
2
3BEGIN;
4
5CREATE TABLE `AgentPrefs` (
6 `PrincipalID` CHAR(36) NOT NULL,
7 `AccessPrefs` CHAR(2) NOT NULL DEFAULT 'M',
8 `HoverHeight` DOUBLE(30, 27) NOT NULL DEFAULT 0,
9 `Language` CHAR(5) NOT NULL DEFAULT 'en-us',
10 `LanguageIsPublic` BOOLEAN NOT NULL DEFAULT 1,
11 `PermEveryone` INT(6) NOT NULL DEFAULT 0,
12 `PermGroup` INT(6) NOT NULL DEFAULT 0,
13 `PermNextOwner` INT(6) NOT NULL DEFAULT 532480,
14 UNIQUE KEY `PrincipalID` (`PrincipalID`),
15 PRIMARY KEY(`PrincipalID`)
16) ENGINE=InnoDB DEFAULT CHARSET=utf8;
17
18COMMIT;
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
diff --git a/OpenSim/Region/Framework/Interfaces/IAgentPreferencesModule.cs b/OpenSim/Region/Framework/Interfaces/IAgentPreferencesModule.cs
new file mode 100644
index 0000000..f2930ac
--- /dev/null
+++ b/OpenSim/Region/Framework/Interfaces/IAgentPreferencesModule.cs
@@ -0,0 +1,36 @@
1/*
2 * Copyright (C) 2015, Cinder Roxley <cinder@sdf.org>
3 *
4 * Permission is hereby granted, free of charge, to any person or organization
5 * obtaining a copy of the software and accompanying documentation covered by
6 * this license (the "Software") to use, reproduce, display, distribute,
7 * execute, and transmit the Software, and to prepare derivative works of the
8 * Software, and to permit third-parties to whom the Software is furnished to
9 * do so, all subject to the following:
10 *
11 * The copyright notices in the Software and this entire statement, including
12 * the above license grant, this restriction and the following disclaimer,
13 * must be included in all copies of the Software, in whole or in part, and
14 * all derivative works of the Software, unless such copies or derivative
15 * works are solely in the form of machine-executable object code generated by
16 * a source language processor.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21 * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22 * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 */
26
27using System;
28using OpenMetaverse;
29
30namespace OpenSim.Region.Framework.Interfaces
31{
32 public interface IAgentPreferencesModule
33 {
34 string GetLang(UUID agentID);
35 }
36}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 53c198e..b50f429 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -6147,12 +6147,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6147 6147
6148 public LSL_String llGetAgentLanguage(string id) 6148 public LSL_String llGetAgentLanguage(string id)
6149 { 6149 {
6150 // This should only return a value if the avatar is in the same region 6150 // This should only return a value if the avatar is in the same region, but eh. idc.
6151 //ckrinke 1-30-09 : This needs to parse the XMLRPC language field supplied
6152 //by the client at login. Currently returning only en-us until our I18N
6153 //effort gains momentum
6154 m_host.AddScriptLPS(1); 6151 m_host.AddScriptLPS(1);
6155 return "en-us"; 6152 IAgentPreferencesModule ap = World.RequestModuleInterface<IAgentPreferencesModule>();
6153 if (ap != null)
6154 {
6155 UUID key = new UUID();
6156 if (UUID.TryParse(id, out key))
6157 {
6158 return ap.GetLang(key);
6159 }
6160 }
6161 return new LSL_String("en-us");
6156 } 6162 }
6157 /// <summary> 6163 /// <summary>
6158 /// http://wiki.secondlife.com/wiki/LlGetAgentList 6164 /// http://wiki.secondlife.com/wiki/LlGetAgentList