aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Avatar/AvatarServicesConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Connectors/Avatar/AvatarServicesConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/Avatar/AvatarServicesConnector.cs326
1 files changed, 326 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Avatar/AvatarServicesConnector.cs b/OpenSim/Services/Connectors/Avatar/AvatarServicesConnector.cs
new file mode 100644
index 0000000..ddfca57
--- /dev/null
+++ b/OpenSim/Services/Connectors/Avatar/AvatarServicesConnector.cs
@@ -0,0 +1,326 @@
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.Communications;
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 AvatarServicesConnector : IAvatarService
45 {
46 private static readonly ILog m_log =
47 LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType);
49
50 private string m_ServerURI = String.Empty;
51
52 public AvatarServicesConnector()
53 {
54 }
55
56 public AvatarServicesConnector(string serverURI)
57 {
58 m_ServerURI = serverURI.TrimEnd('/');
59 }
60
61 public AvatarServicesConnector(IConfigSource source)
62 {
63 Initialise(source);
64 }
65
66 public virtual void Initialise(IConfigSource source)
67 {
68 IConfig gridConfig = source.Configs["AvatarService"];
69 if (gridConfig == null)
70 {
71 m_log.Error("[AVATAR CONNECTOR]: AvatarService missing from OpenSim.ini");
72 throw new Exception("Avatar connector init error");
73 }
74
75 string serviceURI = gridConfig.GetString("AvatarServerURI",
76 String.Empty);
77
78 if (serviceURI == String.Empty)
79 {
80 m_log.Error("[AVATAR CONNECTOR]: No Server URI named in section AvatarService");
81 throw new Exception("Avatar connector init error");
82 }
83 m_ServerURI = serviceURI;
84 }
85
86
87 #region IAvatarService
88
89 public AvatarAppearance GetAppearance(UUID userID)
90 {
91 AvatarData avatar = GetAvatar(userID);
92 return avatar.ToAvatarAppearance();
93 }
94
95 public bool SetAppearance(UUID userID, AvatarAppearance appearance)
96 {
97 AvatarData avatar = new AvatarData(appearance);
98 return SetAvatar(userID,avatar);
99 }
100
101 public AvatarData GetAvatar(UUID userID)
102 {
103 Dictionary<string, object> sendData = new Dictionary<string, object>();
104 //sendData["SCOPEID"] = scopeID.ToString();
105 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
106 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
107 sendData["METHOD"] = "getavatar";
108
109 sendData["UserID"] = userID;
110
111 string reply = string.Empty;
112 string reqString = ServerUtils.BuildQueryString(sendData);
113 string uri = m_ServerURI + "/avatar";
114 // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
115 try
116 {
117 reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString);
118 if (reply == null || (reply != null && reply == string.Empty))
119 {
120 m_log.DebugFormat("[AVATAR CONNECTOR]: GetAgent received null or empty reply");
121 return null;
122 }
123 }
124 catch (Exception e)
125 {
126 m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
127 }
128
129 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
130 AvatarData avatar = null;
131
132 if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null))
133 {
134 if (replyData["result"] is Dictionary<string, object>)
135 {
136 avatar = new AvatarData((Dictionary<string, object>)replyData["result"]);
137 }
138 }
139
140 return avatar;
141
142 }
143
144 public bool SetAvatar(UUID userID, AvatarData avatar)
145 {
146 Dictionary<string, object> sendData = new Dictionary<string, object>();
147 //sendData["SCOPEID"] = scopeID.ToString();
148 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
149 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
150 sendData["METHOD"] = "setavatar";
151
152 sendData["UserID"] = userID.ToString();
153
154 Dictionary<string, object> structData = avatar.ToKeyValuePairs();
155
156 foreach (KeyValuePair<string, object> kvp in structData)
157 sendData[kvp.Key] = kvp.Value.ToString();
158
159
160 string reqString = ServerUtils.BuildQueryString(sendData);
161 string uri = m_ServerURI + "/avatar";
162 //m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
163 try
164 {
165 string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString);
166 if (reply != string.Empty)
167 {
168 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
169
170 if (replyData.ContainsKey("result"))
171 {
172 if (replyData["result"].ToString().ToLower() == "success")
173 return true;
174 else
175 return false;
176 }
177 else
178 {
179 m_log.DebugFormat("[AVATAR CONNECTOR]: SetAvatar reply data does not contain result field");
180 }
181 }
182 else
183 {
184 m_log.DebugFormat("[AVATAR CONNECTOR]: SetAvatar received empty reply");
185 }
186 }
187 catch (Exception e)
188 {
189 m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
190 }
191
192 return false;
193 }
194
195 public bool ResetAvatar(UUID userID)
196 {
197 Dictionary<string, object> sendData = new Dictionary<string, object>();
198 //sendData["SCOPEID"] = scopeID.ToString();
199 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
200 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
201 sendData["METHOD"] = "resetavatar";
202
203 sendData["UserID"] = userID.ToString();
204
205 string reqString = ServerUtils.BuildQueryString(sendData);
206 string uri = m_ServerURI + "/avatar";
207 // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
208 try
209 {
210 string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString);
211 if (reply != string.Empty)
212 {
213 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
214
215 if (replyData.ContainsKey("result"))
216 {
217 if (replyData["result"].ToString().ToLower() == "success")
218 return true;
219 else
220 return false;
221 }
222 else
223 m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems reply data does not contain result field");
224
225 }
226 else
227 m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems received empty reply");
228 }
229 catch (Exception e)
230 {
231 m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
232 }
233
234 return false;
235 }
236
237 public bool SetItems(UUID userID, string[] names, string[] values)
238 {
239 Dictionary<string, object> sendData = new Dictionary<string, object>();
240 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
241 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
242 sendData["METHOD"] = "setitems";
243
244 sendData["UserID"] = userID.ToString();
245 sendData["Names"] = new List<string>(names);
246 sendData["Values"] = new List<string>(values);
247
248 string reqString = ServerUtils.BuildQueryString(sendData);
249 string uri = m_ServerURI + "/avatar";
250 // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
251 try
252 {
253 string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString);
254 if (reply != string.Empty)
255 {
256 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
257
258 if (replyData.ContainsKey("result"))
259 {
260 if (replyData["result"].ToString().ToLower() == "success")
261 return true;
262 else
263 return false;
264 }
265 else
266 m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems reply data does not contain result field");
267
268 }
269 else
270 m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems received empty reply");
271 }
272 catch (Exception e)
273 {
274 m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
275 }
276
277 return false;
278 }
279
280 public bool RemoveItems(UUID userID, string[] names)
281 {
282 Dictionary<string, object> sendData = new Dictionary<string, object>();
283 //sendData["SCOPEID"] = scopeID.ToString();
284 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
285 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
286 sendData["METHOD"] = "removeitems";
287
288 sendData["UserID"] = userID.ToString();
289 sendData["Names"] = new List<string>(names);
290
291 string reqString = ServerUtils.BuildQueryString(sendData);
292 string uri = m_ServerURI + "/avatar";
293 // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString);
294 try
295 {
296 string reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString);
297 if (reply != string.Empty)
298 {
299 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
300
301 if (replyData.ContainsKey("result"))
302 {
303 if (replyData["result"].ToString().ToLower() == "success")
304 return true;
305 else
306 return false;
307 }
308 else
309 m_log.DebugFormat("[AVATAR CONNECTOR]: RemoveItems reply data does not contain result field");
310
311 }
312 else
313 m_log.DebugFormat("[AVATAR CONNECTOR]: RemoveItems received empty reply");
314 }
315 catch (Exception e)
316 {
317 m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
318 }
319
320 return false;
321 }
322
323 #endregion
324
325 }
326}