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