aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/AgentPreferences
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Services/Connectors/AgentPreferences
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Services/Connectors/AgentPreferences')
-rw-r--r--OpenSim/Services/Connectors/AgentPreferences/AgentPreferencesConnector.cs230
1 files changed, 230 insertions, 0 deletions
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}