aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Data/IAgentPreferencesData.cs13
-rw-r--r--OpenSim/Data/MySQL/MySQLAgentPreferencesData.cs17
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/AgentPreferencesModule.cs83
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/LocalAgentPreferencesServiceConnector.cs153
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/RemoteAgentPreferencesServiceConnector.cs116
-rwxr-xr-xOpenSim/Region/Framework/Scenes/Scene.cs11
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs10
-rw-r--r--OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs206
-rw-r--r--OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServiceConnector.cs (renamed from OpenSim/Region/Framework/Interfaces/IAgentPreferencesModule.cs)37
-rw-r--r--OpenSim/Services/Connectors/AgentPreferences/AgentPreferencesConnector.cs230
-rw-r--r--OpenSim/Services/Interfaces/IAgentPreferencesService.cs115
-rw-r--r--OpenSim/Services/UserAccountService/AgentPreferencesService.cs80
-rw-r--r--OpenSim/Services/UserAccountService/AgentPreferencesServiceBase.cs73
13 files changed, 1040 insertions, 104 deletions
diff --git a/OpenSim/Data/IAgentPreferencesData.cs b/OpenSim/Data/IAgentPreferencesData.cs
index f8261e2..8763299 100644
--- a/OpenSim/Data/IAgentPreferencesData.cs
+++ b/OpenSim/Data/IAgentPreferencesData.cs
@@ -34,22 +34,13 @@ namespace OpenSim.Data
34{ 34{
35 public class AgentPreferencesData 35 public class AgentPreferencesData
36 { 36 {
37 public UUID PrincipalID = UUID.Zero; 37 public Dictionary<string, string> Data;
38 public string AccessPrefs = "M";
39 //public int GodLevel;
40 public double HoverHeight = 0.0;
41 public string Language = "en-us";
42 public bool LanguageIsPublic = true;
43 // DefaultObjectPermMasks
44 public int PermEveryone = 0;
45 public int PermGroup = 0;
46 public int PermNextOwner = 532480;
47 } 38 }
48 39
49 public interface IAgentPreferencesData 40 public interface IAgentPreferencesData
50 { 41 {
42 bool Store(AgentPreferencesData data);
51 AgentPreferencesData GetPrefs(UUID agentID); 43 AgentPreferencesData GetPrefs(UUID agentID);
52 void StorePrefs(AgentPreferencesData data);
53 } 44 }
54} 45}
55 46
diff --git a/OpenSim/Data/MySQL/MySQLAgentPreferencesData.cs b/OpenSim/Data/MySQL/MySQLAgentPreferencesData.cs
index cd9004a..bf188ee 100644
--- a/OpenSim/Data/MySQL/MySQLAgentPreferencesData.cs
+++ b/OpenSim/Data/MySQL/MySQLAgentPreferencesData.cs
@@ -52,22 +52,9 @@ namespace OpenSim.Data.MySQL
52 return ret[0]; 52 return ret[0];
53 } 53 }
54 54
55 public void StorePrefs(AgentPreferencesData data) 55 public void Store(AgentPreferencesData data)
56 { 56 {
57 using (MySqlCommand cmd = new MySqlCommand()) 57 base.Store(data);
58 {
59 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);
60 cmd.Parameters.AddWithValue("?Principal", data.PrincipalID.ToString());
61 cmd.Parameters.AddWithValue("?AP", data.AccessPrefs);
62 cmd.Parameters.AddWithValue("?HH", data.HoverHeight);
63 cmd.Parameters.AddWithValue("?Lang", data.Language);
64 cmd.Parameters.AddWithValue("?LIP", data.LanguageIsPublic);
65 cmd.Parameters.AddWithValue("?PE", data.PermEveryone);
66 cmd.Parameters.AddWithValue("?PG", data.PermGroup);
67 cmd.Parameters.AddWithValue("?PNO", data.PermNextOwner);
68
69 ExecuteNonQuery(cmd);
70 }
71 } 58 }
72 } 59 }
73} 60}
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
28using System; 28using System;
29using System.Collections.Generic;
29using System.Reflection; 30using System.Reflection;
30using System.IO; 31using System.IO;
31using log4net; 32using log4net;
@@ -33,8 +34,6 @@ using Mono.Addins;
33using Nini.Config; 34using Nini.Config;
34using OpenMetaverse; 35using OpenMetaverse;
35using OpenMetaverse.StructuredData; 36using OpenMetaverse.StructuredData;
36using OpenSim.Data;
37using OpenSim.Data.MySQL;
38using OpenSim.Framework.Console; 37using OpenSim.Framework.Console;
39using OpenSim.Framework.Servers; 38using OpenSim.Framework.Servers;
40using OpenSim.Framework.Servers.HttpServer; 39using OpenSim.Framework.Servers.HttpServer;
@@ -47,68 +46,34 @@ using OpenSim.Capabilities.Handlers;
47namespace OpenSim.Region.ClientStack.LindenCaps 46namespace 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
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/LocalAgentPreferencesServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/LocalAgentPreferencesServiceConnector.cs
new file mode 100644
index 0000000..9d8367d
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/LocalAgentPreferencesServiceConnector.cs
@@ -0,0 +1,153 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using log4net;
32using Mono.Addins;
33using Nini.Config;
34using OpenSim.Region.Framework.Interfaces;
35using OpenSim.Region.Framework.Scenes;
36using OpenSim.Server.Base;
37using OpenSim.Services.Interfaces;
38
39using OpenMetaverse;
40
41namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.AgentPreferences
42{
43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalAgentPreferencesServicesConnector")]
44 public class LocalAgentPreferencesServicesConnector : ISharedRegionModule, IAgentPreferencesService
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 private IAgentPreferencesService m_AgentPreferencesService;
49 private bool m_Enabled = false;
50
51 #region ISharedRegionModule
52
53 public Type ReplaceableInterface
54 {
55 get { return null; }
56 }
57
58 public string Name
59 {
60 get { return "LocalAgentPreferencesServicesConnector"; }
61 }
62
63 public void Initialise(IConfigSource source)
64 {
65 IConfig moduleConfig = source.Configs["Modules"];
66 if (moduleConfig != null)
67 {
68 string name = moduleConfig.GetString("AgentPreferencesServices", "");
69 if (name == Name)
70 {
71 IConfig userConfig = source.Configs["AgentPreferencesService"];
72 if (userConfig == null)
73 {
74 m_log.Error("[AGENT PREFERENCES CONNECTOR]: AgentPreferencesService missing from OpenSim.ini");
75 return;
76 }
77
78 string serviceDll = userConfig.GetString("LocalServiceModule", String.Empty);
79
80 if (String.IsNullOrEmpty(serviceDll))
81 {
82 m_log.Error("[AGENT PREFERENCES CONNECTOR]: No AgentPreferencesModule named in section AgentPreferencesService");
83 return;
84 }
85
86 Object[] args = new Object[] { source };
87 m_AgentPreferencesService = ServerUtils.LoadPlugin<IAgentPreferencesService>(serviceDll, args);
88
89 if (m_AgentPreferencesService == null)
90 {
91 m_log.Error("[AGENT PREFERENCES CONNECTOR]: Can't load user account service");
92 return;
93 }
94 m_Enabled = true;
95 m_log.Info("[AGENT PREFERENCES CONNECTOR]: Local agent preferences connector enabled");
96 }
97 }
98 }
99
100 public void PostInitialise()
101 {
102 if (!m_Enabled)
103 return;
104 }
105
106 public void Close()
107 {
108 if (!m_Enabled)
109 return;
110 }
111
112 public void AddRegion(Scene scene)
113 {
114 if (!m_Enabled)
115 return;
116
117 scene.RegisterModuleInterface<IAgentPreferencesService>(this);
118 }
119
120 public void RemoveRegion(Scene scene)
121 {
122 if (!m_Enabled)
123 return;
124 }
125
126 public void RegionLoaded(Scene scene)
127 {
128 if (!m_Enabled)
129 return;
130 }
131
132 #endregion ISharedRegionModule
133
134 #region IAgentPreferencesService
135
136 public AgentPrefs GetAgentPreferences(UUID principalID)
137 {
138 return m_AgentPreferencesService.GetAgentPreferences(principalID);
139 }
140
141 public bool StoreAgentPreferences(AgentPrefs data)
142 {
143 return m_AgentPreferencesService.StoreAgentPreferences(data);
144 }
145
146 public string GetLang(UUID principalID)
147 {
148 return m_AgentPreferencesService.GetLang(principalID);
149 }
150
151 #endregion IAgentPreferencesService
152 }
153}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/RemoteAgentPreferencesServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/RemoteAgentPreferencesServiceConnector.cs
new file mode 100644
index 0000000..ad9544a
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/RemoteAgentPreferencesServiceConnector.cs
@@ -0,0 +1,116 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28
29using System;
30using System.Collections.Generic;
31using System.Reflection;
32
33using OpenSim.Region.Framework.Interfaces;
34using OpenSim.Region.Framework.Scenes;
35using OpenSim.Server.Base;
36using OpenSim.Services.Interfaces;
37using OpenSim.Services.Connectors;
38
39using OpenMetaverse;
40using log4net;
41using Mono.Addins;
42using Nini.Config;
43
44namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.AgentPreferences
45{
46 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteAgentPreferencesServicesConnector")]
47 public class RemoteAgentPreferencesServicesConnector : AgentPreferencesServicesConnector,
48 ISharedRegionModule, IAgentPreferencesService
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private bool m_Enabled = false;
53
54 public Type ReplaceableInterface
55 {
56 get { return null; }
57 }
58
59 public string Name
60 {
61 get { return "RemoteAgentPreferencesServicesConnector"; }
62 }
63
64 public override void Initialise(IConfigSource source)
65 {
66 IConfig moduleConfig = source.Configs["Modules"];
67 if (moduleConfig != null)
68 {
69 string name = moduleConfig.GetString("AgentPreferencesServices", "");
70 if (name == Name)
71 {
72 IConfig userConfig = source.Configs["AgentPreferencesService"];
73 if (userConfig == null)
74 {
75 m_log.Error("[AGENT PREFERENCES CONNECTOR]: AgentPreferencesService missing from OpenSim.ini");
76 return;
77 }
78
79 m_Enabled = true;
80
81 base.Initialise(source);
82
83 m_log.Info("[AGENT PREFERENCES CONNECTOR]: Remote agent preferences enabled");
84 }
85 }
86 }
87
88 public void PostInitialise()
89 {
90 /* no op */
91 }
92
93 public void Close()
94 {
95 /* no op */
96 }
97
98 public void AddRegion(Scene scene)
99 {
100 if (!m_Enabled)
101 return;
102
103 scene.RegisterModuleInterface<IAgentPreferencesService>(this);
104 }
105
106 public void RemoveRegion(Scene scene)
107 {
108 /* no op */
109 }
110
111 public void RegionLoaded(Scene scene)
112 {
113 /* no op */
114 }
115 }
116} \ No newline at end of file
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index c539f1f..23b2e90 100755
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -325,6 +325,7 @@ namespace OpenSim.Region.Framework.Scenes
325 protected IUserAccountService m_UserAccountService; 325 protected IUserAccountService m_UserAccountService;
326 protected IAvatarService m_AvatarService; 326 protected IAvatarService m_AvatarService;
327 protected IGridUserService m_GridUserService; 327 protected IGridUserService m_GridUserService;
328 protected IAgentPreferencesService m_AgentPreferencesService;
328 329
329 protected IXMLRPC m_xmlrpcModule; 330 protected IXMLRPC m_xmlrpcModule;
330 protected IWorldComm m_worldCommModule; 331 protected IWorldComm m_worldCommModule;
@@ -728,6 +729,16 @@ namespace OpenSim.Region.Framework.Scenes
728 } 729 }
729 } 730 }
730 731
732 public IAgentPreferencesService AgentPreferencesService
733 {
734 get
735 {
736 if (m_AgentPreferencesService == null)
737 m_AgentPreferencesService = RequestModuleInterface<IAgentPreferencesService>();
738 return m_AgentPreferencesService;
739 }
740 }
741
731 public IAttachmentsModule AttachmentsModule { get; set; } 742 public IAttachmentsModule AttachmentsModule { get; set; }
732 public IEntityTransferModule EntityTransferModule { get; private set; } 743 public IEntityTransferModule EntityTransferModule { get; private set; }
733 public IAgentAssetTransactions AgentTransactionsModule { get; private set; } 744 public IAgentAssetTransactions AgentTransactionsModule { get; private set; }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index b50f429..75b40af 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -6149,14 +6149,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6149 { 6149 {
6150 // This should only return a value if the avatar is in the same region, but eh. idc. 6150 // This should only return a value if the avatar is in the same region, but eh. idc.
6151 m_host.AddScriptLPS(1); 6151 m_host.AddScriptLPS(1);
6152 IAgentPreferencesModule ap = World.RequestModuleInterface<IAgentPreferencesModule>(); 6152 UUID key = new UUID();
6153 if (ap != null) 6153 if (UUID.TryParse(id, out key))
6154 { 6154 {
6155 UUID key = new UUID(); 6155 return new LSL_String(World.AgentPreferencesService.GetLang(key));
6156 if (UUID.TryParse(id, out key))
6157 {
6158 return ap.GetLang(key);
6159 }
6160 } 6156 }
6161 return new LSL_String("en-us"); 6157 return new LSL_String("en-us");
6162 } 6158 }
diff --git a/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs
new file mode 100644
index 0000000..713b755
--- /dev/null
+++ b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs
@@ -0,0 +1,206 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using System.Collections.Generic;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenSim.Framework;
42using OpenSim.Framework.ServiceAuth;
43using OpenSim.Framework.Servers.HttpServer;
44using OpenMetaverse;
45
46namespace OpenSim.Server.Handlers.AgentPreferences
47{
48 public class AgentPreferencesServerPostHandler : BaseStreamHandler
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private IAgentPreferencesService m_AgentPreferencesService;
53
54 public AgentPreferencesServerPostHandler(IAgentPreferencesService service, IServiceAuth auth) :
55 base("POST", "/agentprefs", auth)
56 {
57 m_AgentPreferencesService = service;
58 }
59
60 protected override byte[] ProcessRequest(string path, Stream requestData,
61 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
62 {
63 StreamReader sr = new StreamReader(requestData);
64 string body = sr.ReadToEnd();
65 sr.Close();
66 body = body.Trim();
67
68 //m_log.DebugFormat("[XXX]: query String: {0}", body);
69
70 try
71 {
72 Dictionary<string, object> request =
73 ServerUtils.ParseQueryString(body);
74
75 if (!request.ContainsKey("METHOD"))
76 return FailureResult();
77
78 string method = request["METHOD"].ToString();
79
80 switch (method)
81 {
82 case "getagentprefs":
83 return GetAgentPrefs(request);
84 case "setagentprefs":
85 return SetAgentPrefs(request);
86 case "getagentlang":
87 return GetAgentLang(request);
88 }
89 m_log.DebugFormat("[AGENT PREFERENCES HANDLER]: unknown method request: {0}", method);
90 }
91 catch (Exception e)
92 {
93 m_log.DebugFormat("[AGENT PREFERENCES HANDLER]: Exception {0}", e);
94 }
95
96 return FailureResult();
97 }
98
99 byte[] GetAgentPrefs(Dictionary<string, object> request)
100 {
101 if (!request.ContainsKey("UserID"))
102 return FailureResult();
103
104 UUID userID;
105 if (!UUID.TryParse(request["UserID"].ToString(), out userID))
106 return FailureResult();
107 AgentPrefs prefs = m_AgentPreferencesService.GetAgentPreferences(userID);
108 Dictionary<string, object> result = new Dictionary<string, object>();
109 result = prefs.ToKeyValuePairs();
110
111 string xmlString = ServerUtils.BuildXmlResponse(result);
112
113 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
114 }
115
116 byte[] SetAgentPrefs(Dictionary<string, object> request)
117 {
118 if (!request.ContainsKey("PrincipalID") || !request.ContainsKey("AccessPrefs") || !request.ContainsKey("HoverHeight")
119 || !request.ContainsKey("Language") || !request.ContainsKey("LanguageIsPublic") || !request.ContainsKey("PermEveryone")
120 || !request.ContainsKey("PermGroup") || !request.ContainsKey("PermNextOwner"))
121 {
122 return FailureResult();
123 }
124
125 UUID userID;
126 if (!UUID.TryParse(request["PrincipalID"].ToString(), out userID))
127 return FailureResult();
128
129 AgentPrefs data = new AgentPrefs(userID);
130 data.AccessPrefs = request["AccessPrefs"].ToString();
131 data.HoverHeight = double.Parse(request["HoverHeight"].ToString());
132 data.Language = request["Language"].ToString();
133 data.LanguageIsPublic = bool.Parse(request["LanguageIsPublic"].ToString());
134 data.PermEveryone = int.Parse(request["PermEveryone"].ToString());
135 data.PermGroup = int.Parse(request["PermGroup"].ToString());
136 data.PermNextOwner = int.Parse(request["PermNextOwner"].ToString());
137
138 return m_AgentPreferencesService.StoreAgentPreferences(data) ? SuccessResult() : FailureResult();
139 }
140
141 byte[] GetAgentLang(Dictionary<string, object> request)
142 {
143 if (!request.ContainsKey("UserID"))
144 return FailureResult();
145 UUID userID;
146 if (!UUID.TryParse(request["UserID"].ToString(), out userID))
147 return FailureResult();
148
149 string lang = "en-us";
150 AgentPrefs prefs = m_AgentPreferencesService.GetAgentPreferences(userID);
151 if (prefs != null)
152 {
153 if (prefs.LanguageIsPublic)
154 lang = prefs.Language;
155 }
156 Dictionary<string, object> result = new Dictionary<string, object>();
157 result["Language"] = lang;
158 string xmlString = ServerUtils.BuildXmlResponse(result);
159 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
160 }
161
162 private byte[] SuccessResult()
163 {
164 XmlDocument doc = new XmlDocument();
165
166 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
167 "", "");
168
169 doc.AppendChild(xmlnode);
170
171 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
172 "");
173
174 doc.AppendChild(rootElement);
175
176 XmlElement result = doc.CreateElement("", "result", "");
177 result.AppendChild(doc.CreateTextNode("Success"));
178
179 rootElement.AppendChild(result);
180
181 return Util.DocToBytes(doc);
182 }
183
184 private byte[] FailureResult()
185 {
186 XmlDocument doc = new XmlDocument();
187
188 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
189 "", "");
190
191 doc.AppendChild(xmlnode);
192
193 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
194 "");
195
196 doc.AppendChild(rootElement);
197
198 XmlElement result = doc.CreateElement("", "result", "");
199 result.AppendChild(doc.CreateTextNode("Failure"));
200
201 rootElement.AppendChild(result);
202
203 return Util.DocToBytes(doc);
204 }
205 }
206}
diff --git a/OpenSim/Region/Framework/Interfaces/IAgentPreferencesModule.cs b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServiceConnector.cs
index 4975b96..a581ea2 100644
--- a/OpenSim/Region/Framework/Interfaces/IAgentPreferencesModule.cs
+++ b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServiceConnector.cs
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
@@ -25,13 +25,40 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28
28using System; 29using System;
29using OpenMetaverse; 30using Nini.Config;
31using OpenSim.Server.Base;
32using OpenSim.Services.Interfaces;
33using OpenSim.Framework.ServiceAuth;
34using OpenSim.Framework.Servers.HttpServer;
35using OpenSim.Server.Handlers.Base;
30 36
31namespace OpenSim.Region.Framework.Interfaces 37namespace OpenSim.Server.Handlers.AgentPreferences
32{ 38{
33 public interface IAgentPreferencesModule 39 public class AgentPreferencesServiceConnector : ServiceConnector
34 { 40 {
35 string GetLang(UUID agentID); 41 private IAgentPreferencesService m_AgentPreferencesService;
42 private string m_ConfigName = "AgentPreferencesService";
43
44 public AgentPreferencesServiceConnector(IConfigSource config, IHttpServer server, string configName) :
45 base(config, server, configName)
46 {
47 IConfig serverConfig = config.Configs[m_ConfigName];
48 if (serverConfig == null)
49 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
50
51 string service = serverConfig.GetString("LocalServiceModule", String.Empty);
52
53 if (String.IsNullOrWhiteSpace(service))
54 throw new Exception("No LocalServiceModule in config file");
55
56 Object[] args = new Object[] { config };
57 m_AgentPreferencesService = ServerUtils.LoadPlugin<IAgentPreferencesService>(service, args);
58
59 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); ;
60
61 server.AddStreamHandler(new AgentPreferencesServerPostHandler(m_AgentPreferencesService, auth));
62 }
36 } 63 }
37} 64}
diff --git a/OpenSim/Services/Connectors/AgentPreferences/AgentPreferencesConnector.cs b/OpenSim/Services/Connectors/AgentPreferences/AgentPreferencesConnector.cs
new file mode 100644
index 0000000..1dbc0c8
--- /dev/null
+++ b/OpenSim/Services/Connectors/AgentPreferences/AgentPreferencesConnector.cs
@@ -0,0 +1,230 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.ServiceAuth;
36using OpenSim.Services.Interfaces;
37using GridRegion = OpenSim.Services.Interfaces.GridRegion;
38using IAvatarService = OpenSim.Services.Interfaces.IAvatarService;
39using OpenSim.Server.Base;
40using OpenMetaverse;
41
42namespace OpenSim.Services.Connectors
43{
44 public class AgentPreferencesServicesConnector : BaseServiceConnector, IAgentPreferencesService
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 private string m_ServerURI = String.Empty;
49
50 public AgentPreferencesServicesConnector()
51 {
52 }
53
54 public AgentPreferencesServicesConnector(string serverURI)
55 {
56 m_ServerURI = serverURI.TrimEnd('/');
57 }
58
59 public AgentPreferencesServicesConnector(IConfigSource source)
60 : base(source, "AgentPreferencesService")
61 {
62 Initialise(source);
63 }
64
65 public virtual void Initialise(IConfigSource source)
66 {
67 IConfig gridConfig = source.Configs["AgentPreferencesService"];
68 if (gridConfig == null)
69 {
70 m_log.Error("[AGENT PREFERENCES CONNECTOR]: AgentPreferencesService missing from OpenSim.ini");
71 throw new Exception("Agent Preferences connector init error");
72 }
73
74 string serviceURI = gridConfig.GetString("AgentPreferencesServerURI", String.Empty);
75
76 if (serviceURI == String.Empty)
77 {
78 m_log.Error("[AGENT PREFERENCES CONNECTOR]: No Server URI named in section AgentPreferences");
79 throw new Exception("Agent Preferences connector init error");
80 }
81 m_ServerURI = serviceURI;
82
83 base.Initialise(source, "AgentPreferencesService");
84 }
85
86 #region IAgentPreferencesService
87
88 public AgentPrefs GetAgentPreferences(UUID principalID)
89 {
90 Dictionary<string, object> sendData = new Dictionary<string, object>();
91
92 string reply = string.Empty;
93 string uri = String.Concat(m_ServerURI, "/agentprefs");
94
95 sendData["METHOD"] = "getagentprefs";
96 sendData["UserID"] = principalID;
97 string reqString = ServerUtils.BuildQueryString(sendData);
98 // m_log.DebugFormat("[AGENT PREFS CONNECTOR]: queryString = {0}", reqString);
99
100 try
101 {
102 reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString, m_Auth);
103 if (String.IsNullOrEmpty(reply))
104 {
105 m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: GetAgentPreferences received null or empty reply");
106 return null;
107 }
108 }
109 catch (Exception e)
110 {
111 m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: Exception when contacting agent preferences server at {0}: {1}", uri, e.Message);
112 }
113
114 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
115 if (replyData != null)
116 {
117 if (replyData.ContainsKey("result") &&
118 (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure"))
119 {
120 m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: GetAgentPreferences received Failure response");
121 return null;
122 }
123 }
124 else
125 {
126 m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: GetAgentPreferences received null response");
127 return null;
128 }
129 AgentPrefs prefs = new AgentPrefs(replyData);
130 return prefs;
131 }
132
133 public bool StoreAgentPreferences(AgentPrefs data)
134 {
135 Dictionary<string, object> sendData = new Dictionary<string, object>();
136
137 sendData["METHOD"] = "setagentprefs";
138
139 sendData["PrincipalID"] = data.PrincipalID.ToString();
140 sendData["AccessPrefs"] = data.AccessPrefs;
141 sendData["HoverHeight"] = data.HoverHeight.ToString();
142 sendData["Language"] = data.Language;
143 sendData["LanguageIsPublic"] = data.LanguageIsPublic.ToString();
144 sendData["PermEveryone"] = data.PermEveryone.ToString();
145 sendData["PermGroup"] = data.PermGroup.ToString();
146 sendData["PermNextOwner"] = data.PermNextOwner.ToString();
147
148 string uri = String.Concat(m_ServerURI, "/agentprefs");
149 string reqString = ServerUtils.BuildQueryString(sendData);
150 // m_log.DebugFormat("[AGENT PREFS CONNECTOR]: queryString = {0}", reqString);
151
152 try
153 {
154 string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString, m_Auth);
155 if (reply != string.Empty)
156 {
157 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
158
159 if (replyData.ContainsKey("result"))
160 {
161 if (replyData["result"].ToString().ToLower() == "success")
162 return true;
163 else
164 return false;
165 }
166 else
167 {
168 m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: StoreAgentPreferences reply data does not contain result field");
169 }
170
171 }
172 else
173 m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: StoreAgentPreferences received empty reply");
174 }
175 catch (Exception e)
176 {
177 m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: Exception when contacting agent preferences server at {0}: {1}", uri, e.Message);
178 }
179
180 return false;
181 }
182
183 public string GetLang(UUID principalID)
184 {
185 Dictionary<string, object> sendData = new Dictionary<string, object>();
186 string reply = string.Empty;
187
188 sendData["METHOD"] = "getagentlang";
189 sendData["UserID"] = principalID.ToString();
190
191 string uri = String.Concat(m_ServerURI, "/agentprefs");
192 string reqString = ServerUtils.BuildQueryString(sendData);
193
194 try
195 {
196 reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString, m_Auth);
197 if (String.IsNullOrEmpty(reply))
198 {
199 m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: GetLang received null or empty reply");
200 return "en-us"; // I guess? Gotta return somethin'!
201 }
202 }
203 catch (Exception e)
204 {
205 m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: Exception when contacting agent preferences server at {0}: {1}", uri, e.Message);
206 }
207
208 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
209 if (replyData != null)
210 {
211 if (replyData.ContainsKey("result") &&
212 (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure"))
213 {
214 m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: GetLang received Failure response");
215 return "en-us";
216 }
217 if (replyData.ContainsKey("Language"))
218 return replyData["Language"].ToString();
219 }
220 else
221 {
222 m_log.DebugFormat("[AGENT PREFERENCES CONNECTOR]: GetLang received null response");
223
224 }
225 return "en-us";
226 }
227
228 #endregion IAgentPreferencesService
229 }
230}
diff --git a/OpenSim/Services/Interfaces/IAgentPreferencesService.cs b/OpenSim/Services/Interfaces/IAgentPreferencesService.cs
new file mode 100644
index 0000000..b74b580
--- /dev/null
+++ b/OpenSim/Services/Interfaces/IAgentPreferencesService.cs
@@ -0,0 +1,115 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31
32namespace OpenSim.Services.Interfaces
33{
34 public class AgentPrefs
35 {
36 public AgentPrefs(UUID principalID)
37 {
38 principalID = PrincipalID;
39 }
40
41 public AgentPrefs(Dictionary<string, string> kvp)
42 {
43 if (kvp.ContainsKey("PrincipalID"))
44 UUID.TryParse(kvp["PrincipalID"], out PrincipalID);
45 if (kvp.ContainsKey("AccessPrefs"))
46 AccessPrefs = kvp["AccessPrefs"];
47 if (kvp.ContainsKey("HoverHeight"))
48 HoverHeight = double.Parse(kvp["HoverHeight"]);
49 if (kvp.ContainsKey("Language"))
50 Language = kvp["Language"];
51 if (kvp.ContainsKey("LanguageIsPublic"))
52 LanguageIsPublic = bool.Parse(kvp["LanguageIsPublic"]);
53 if (kvp.ContainsKey("PermEveryone"))
54 PermEveryone = int.Parse(kvp["PermEveryone"]);
55 if (kvp.ContainsKey("PermGroup"))
56 PermGroup = int.Parse(kvp["PermGroup"]);
57 if (kvp.ContainsKey("PermNextOwner"))
58 PermNextOwner = int.Parse(kvp["PermNextOwner"]);
59 }
60
61 public AgentPrefs(Dictionary<string, object> kvp)
62 {
63 if (kvp.ContainsKey("PrincipalID"))
64 UUID.TryParse(kvp["PrincipalID"].ToString(), out PrincipalID);
65 if (kvp.ContainsKey("AccessPrefs"))
66 AccessPrefs = kvp["AccessPrefs"].ToString();
67 if (kvp.ContainsKey("HoverHeight"))
68 HoverHeight = double.Parse(kvp["HoverHeight"].ToString());
69 if (kvp.ContainsKey("Language"))
70 Language = kvp["Language"].ToString();
71 if (kvp.ContainsKey("LanguageIsPublic"))
72 LanguageIsPublic = bool.Parse(kvp["LanguageIsPublic"].ToString());
73 if (kvp.ContainsKey("PermEveryone"))
74 PermEveryone = int.Parse(kvp["PermEveryone"].ToString());
75 if (kvp.ContainsKey("PermGroup"))
76 PermGroup = int.Parse(kvp["PermGroup"].ToString());
77 if (kvp.ContainsKey("PermNextOwner"))
78 PermNextOwner = int.Parse(kvp["PermNextOwner"].ToString());
79 }
80
81 public Dictionary<string, object> ToKeyValuePairs()
82 {
83 Dictionary<string, object> result = new Dictionary<string, object>();
84 result["PrincipalID"] = PrincipalID.ToString();
85 result["AccessPrefs"] = AccessPrefs.ToString();
86 result["HoverHeight"] = HoverHeight.ToString();
87 result["Language"] = Language.ToString();
88 result["LanguageIsPublic"] = LanguageIsPublic.ToString();
89 result["PermEveryone"] = PermEveryone.ToString();
90 result["PermGroup"] = PermGroup.ToString();
91 result["PermNextOwner"] = PermNextOwner.ToString();
92 return result;
93 }
94
95 public UUID PrincipalID = UUID.Zero;
96 public string AccessPrefs = "M";
97 //public int GodLevel; // *TODO: Implement GodLevel (Unused by the viewer, afaict - 6/11/2015)
98 public double HoverHeight = 0.0;
99 public string Language = "en-us";
100 public bool LanguageIsPublic = true;
101 // DefaultObjectPermMasks
102 public int PermEveryone = 0;
103 public int PermGroup = 0;
104 public int PermNextOwner = 532480;
105 }
106
107 public interface IAgentPreferencesService
108 {
109 AgentPrefs GetAgentPreferences(UUID principalID);
110 bool StoreAgentPreferences(AgentPrefs data);
111
112 string GetLang(UUID principalID);
113 }
114}
115
diff --git a/OpenSim/Services/UserAccountService/AgentPreferencesService.cs b/OpenSim/Services/UserAccountService/AgentPreferencesService.cs
new file mode 100644
index 0000000..f8d2e29
--- /dev/null
+++ b/OpenSim/Services/UserAccountService/AgentPreferencesService.cs
@@ -0,0 +1,80 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Reflection;
30using log4net;
31using Nini.Config;
32using OpenMetaverse;
33using OpenSim.Data;
34using OpenSim.Framework;
35using OpenSim.Services.Interfaces;
36
37namespace OpenSim.Services.UserAccountService
38{
39 public class AgentPreferencesService : AgentPreferencesServiceBase, IAgentPreferencesService
40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42
43 public AgentPreferencesService(IConfigSource config) : base(config)
44 {
45 m_log.Debug("[AGENT PREFERENCES SERVICE]: Starting agent preferences service");
46 }
47
48 public AgentPrefs GetAgentPreferences(UUID principalID)
49 {
50 AgentPreferencesData d = m_Database.GetPrefs(principalID);
51 AgentPrefs prefs = (d == null) ? new AgentPrefs(principalID) : new AgentPrefs(d.Data);
52 return prefs;
53 }
54
55 public bool StoreAgentPreferences(AgentPrefs data)
56 {
57 AgentPreferencesData d = new AgentPreferencesData();
58 d.Data["PrincipalID"] = data.PrincipalID.ToString();
59 d.Data["AccessPrefs"] = data.AccessPrefs;
60 d.Data["HoverHeight"] = data.HoverHeight.ToString();
61 d.Data["Language"] = data.Language;
62 d.Data["LanguageIsPublic"] = data.LanguageIsPublic.ToString();
63 d.Data["PermEveryone"] = data.PermEveryone.ToString();
64 d.Data["PermGroup"] = data.PermGroup.ToString();
65 d.Data["PermNextOwner"] = data.PermNextOwner.ToString();
66 return m_Database.Store(d);
67 }
68
69 public string GetLang(UUID principalID)
70 {
71 AgentPrefs data = GetAgentPreferences(principalID);
72 if (data != null)
73 {
74 if (data.LanguageIsPublic)
75 return data.Language;
76 }
77 return "en-us";
78 }
79 }
80}
diff --git a/OpenSim/Services/UserAccountService/AgentPreferencesServiceBase.cs b/OpenSim/Services/UserAccountService/AgentPreferencesServiceBase.cs
new file mode 100644
index 0000000..5974349
--- /dev/null
+++ b/OpenSim/Services/UserAccountService/AgentPreferencesServiceBase.cs
@@ -0,0 +1,73 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Reflection;
30using Nini.Config;
31using OpenSim.Data;
32using OpenSim.Services.Interfaces;
33using OpenSim.Services.Base;
34
35namespace OpenSim.Services.UserAccountService
36{
37 public class AgentPreferencesServiceBase: ServiceBase
38 {
39 protected IAgentPreferencesData m_Database = null;
40
41 public AgentPreferencesServiceBase(IConfigSource config) : base(config)
42 {
43 string dllName = String.Empty;
44 string connString = String.Empty;
45 string realm = "AgentPrefs";
46
47 IConfig dbConfig = config.Configs["DatabaseService"];
48 if (dbConfig != null)
49 {
50 dllName = dbConfig.GetString("StorageProvider", String.Empty);
51 connString = dbConfig.GetString("ConnectionString", String.Empty);
52 }
53
54 IConfig userConfig = config.Configs["AgentPreferencesService"];
55 if (userConfig == null)
56 throw new Exception("No AgentPreferencesService configuration");
57
58 dllName = userConfig.GetString("StorageProvider", dllName);
59
60 if (dllName == String.Empty)
61 throw new Exception("No StorageProvider configured");
62
63 connString = userConfig.GetString("ConnectionString", connString);
64
65 realm = userConfig.GetString("Realm", realm);
66
67 m_Database = LoadPlugin<IAgentPreferencesData>(dllName, new Object[] {connString, realm});
68
69 if (m_Database == null)
70 throw new Exception("Could not find a storage interface in the given module");
71 }
72 }
73}