diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs | 423 |
1 files changed, 423 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs new file mode 100644 index 0000000..fac3d1f --- /dev/null +++ b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs | |||
@@ -0,0 +1,423 @@ | |||
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.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenMetaverse; | ||
41 | |||
42 | namespace OpenSim.Services.Connectors | ||
43 | { | ||
44 | public class PresenceServicesConnector : IPresenceService | ||
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 PresenceServicesConnector() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public PresenceServicesConnector(string serverURI) | ||
57 | { | ||
58 | m_ServerURI = serverURI.TrimEnd('/'); | ||
59 | } | ||
60 | |||
61 | public PresenceServicesConnector(IConfigSource source) | ||
62 | { | ||
63 | Initialise(source); | ||
64 | } | ||
65 | |||
66 | public virtual void Initialise(IConfigSource source) | ||
67 | { | ||
68 | IConfig gridConfig = source.Configs["PresenceService"]; | ||
69 | if (gridConfig == null) | ||
70 | { | ||
71 | m_log.Error("[PRESENCE CONNECTOR]: PresenceService missing from OpenSim.ini"); | ||
72 | throw new Exception("Presence connector init error"); | ||
73 | } | ||
74 | |||
75 | string serviceURI = gridConfig.GetString("PresenceServerURI", | ||
76 | String.Empty); | ||
77 | |||
78 | if (serviceURI == String.Empty) | ||
79 | { | ||
80 | m_log.Error("[PRESENCE CONNECTOR]: No Server URI named in section PresenceService"); | ||
81 | throw new Exception("Presence connector init error"); | ||
82 | } | ||
83 | m_ServerURI = serviceURI; | ||
84 | } | ||
85 | |||
86 | |||
87 | #region IPresenceService | ||
88 | |||
89 | public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID) | ||
90 | { | ||
91 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
92 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
93 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
94 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
95 | sendData["METHOD"] = "login"; | ||
96 | |||
97 | sendData["UserID"] = userID; | ||
98 | sendData["SessionID"] = sessionID.ToString(); | ||
99 | sendData["SecureSessionID"] = secureSessionID.ToString(); | ||
100 | |||
101 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
102 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
103 | try | ||
104 | { | ||
105 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
106 | m_ServerURI + "/presence", | ||
107 | reqString); | ||
108 | if (reply != string.Empty) | ||
109 | { | ||
110 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
111 | |||
112 | if (replyData.ContainsKey("result")) | ||
113 | { | ||
114 | if (replyData["result"].ToString().ToLower() == "success") | ||
115 | return true; | ||
116 | else | ||
117 | return false; | ||
118 | } | ||
119 | else | ||
120 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent reply data does not contain result field"); | ||
121 | |||
122 | } | ||
123 | else | ||
124 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent received empty reply"); | ||
125 | } | ||
126 | catch (Exception e) | ||
127 | { | ||
128 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
129 | } | ||
130 | |||
131 | return false; | ||
132 | |||
133 | } | ||
134 | |||
135 | public bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookat) | ||
136 | { | ||
137 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
138 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
139 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
140 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
141 | sendData["METHOD"] = "logout"; | ||
142 | |||
143 | sendData["SessionID"] = sessionID.ToString(); | ||
144 | sendData["Position"] = position.ToString(); | ||
145 | sendData["LookAt"] = lookat.ToString(); | ||
146 | |||
147 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
148 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
149 | try | ||
150 | { | ||
151 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
152 | m_ServerURI + "/presence", | ||
153 | reqString); | ||
154 | if (reply != string.Empty) | ||
155 | { | ||
156 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
157 | |||
158 | if (replyData.ContainsKey("result")) | ||
159 | { | ||
160 | if (replyData["result"].ToString().ToLower() == "success") | ||
161 | return true; | ||
162 | else | ||
163 | return false; | ||
164 | } | ||
165 | else | ||
166 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent reply data does not contain result field"); | ||
167 | |||
168 | } | ||
169 | else | ||
170 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent received empty reply"); | ||
171 | } | ||
172 | catch (Exception e) | ||
173 | { | ||
174 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
175 | } | ||
176 | |||
177 | return false; | ||
178 | } | ||
179 | |||
180 | public bool LogoutRegionAgents(UUID regionID) | ||
181 | { | ||
182 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
183 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
184 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
185 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
186 | sendData["METHOD"] = "logoutregion"; | ||
187 | |||
188 | sendData["RegionID"] = regionID.ToString(); | ||
189 | |||
190 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
191 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
192 | try | ||
193 | { | ||
194 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
195 | m_ServerURI + "/presence", | ||
196 | reqString); | ||
197 | if (reply != string.Empty) | ||
198 | { | ||
199 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
200 | |||
201 | if (replyData.ContainsKey("result")) | ||
202 | { | ||
203 | if (replyData["result"].ToString().ToLower() == "success") | ||
204 | return true; | ||
205 | else | ||
206 | return false; | ||
207 | } | ||
208 | else | ||
209 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents reply data does not contain result field"); | ||
210 | |||
211 | } | ||
212 | else | ||
213 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents received empty reply"); | ||
214 | } | ||
215 | catch (Exception e) | ||
216 | { | ||
217 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
218 | } | ||
219 | |||
220 | return false; | ||
221 | } | ||
222 | |||
223 | public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
224 | { | ||
225 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
226 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
227 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
228 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
229 | sendData["METHOD"] = "report"; | ||
230 | |||
231 | sendData["SessionID"] = sessionID.ToString(); | ||
232 | sendData["RegionID"] = regionID.ToString(); | ||
233 | sendData["position"] = position.ToString(); | ||
234 | sendData["lookAt"] = lookAt.ToString(); | ||
235 | |||
236 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
237 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
238 | try | ||
239 | { | ||
240 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
241 | m_ServerURI + "/presence", | ||
242 | reqString); | ||
243 | if (reply != string.Empty) | ||
244 | { | ||
245 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
246 | |||
247 | if (replyData.ContainsKey("result")) | ||
248 | { | ||
249 | if (replyData["result"].ToString().ToLower() == "success") | ||
250 | return true; | ||
251 | else | ||
252 | return false; | ||
253 | } | ||
254 | else | ||
255 | m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent reply data does not contain result field"); | ||
256 | |||
257 | } | ||
258 | else | ||
259 | m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent received empty reply"); | ||
260 | } | ||
261 | catch (Exception e) | ||
262 | { | ||
263 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
264 | } | ||
265 | |||
266 | return false; | ||
267 | } | ||
268 | |||
269 | public PresenceInfo GetAgent(UUID sessionID) | ||
270 | { | ||
271 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
272 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
273 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
274 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
275 | sendData["METHOD"] = "getagent"; | ||
276 | |||
277 | sendData["SessionID"] = sessionID.ToString(); | ||
278 | |||
279 | string reply = string.Empty; | ||
280 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
281 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
282 | try | ||
283 | { | ||
284 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
285 | m_ServerURI + "/presence", | ||
286 | reqString); | ||
287 | if (reply == null || (reply != null && reply == string.Empty)) | ||
288 | { | ||
289 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply"); | ||
290 | return null; | ||
291 | } | ||
292 | } | ||
293 | catch (Exception e) | ||
294 | { | ||
295 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
296 | } | ||
297 | |||
298 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
299 | PresenceInfo pinfo = null; | ||
300 | |||
301 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
302 | { | ||
303 | if (replyData["result"] is Dictionary<string, object>) | ||
304 | { | ||
305 | pinfo = new PresenceInfo((Dictionary<string, object>)replyData["result"]); | ||
306 | } | ||
307 | } | ||
308 | |||
309 | return pinfo; | ||
310 | } | ||
311 | |||
312 | public PresenceInfo[] GetAgents(string[] userIDs) | ||
313 | { | ||
314 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
315 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
316 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
317 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
318 | sendData["METHOD"] = "getagents"; | ||
319 | |||
320 | sendData["uuids"] = new List<string>(userIDs); | ||
321 | |||
322 | string reply = string.Empty; | ||
323 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
324 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
325 | try | ||
326 | { | ||
327 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
328 | m_ServerURI + "/presence", | ||
329 | reqString); | ||
330 | if (reply == null || (reply != null && reply == string.Empty)) | ||
331 | { | ||
332 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply"); | ||
333 | return null; | ||
334 | } | ||
335 | } | ||
336 | catch (Exception e) | ||
337 | { | ||
338 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
339 | } | ||
340 | |||
341 | List<PresenceInfo> rinfos = new List<PresenceInfo>(); | ||
342 | |||
343 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
344 | |||
345 | if (replyData != null) | ||
346 | { | ||
347 | if (replyData.ContainsKey("result") && | ||
348 | (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure")) | ||
349 | { | ||
350 | return new PresenceInfo[0]; | ||
351 | } | ||
352 | |||
353 | Dictionary<string, object>.ValueCollection pinfosList = replyData.Values; | ||
354 | //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); | ||
355 | foreach (object presence in pinfosList) | ||
356 | { | ||
357 | if (presence is Dictionary<string, object>) | ||
358 | { | ||
359 | PresenceInfo pinfo = new PresenceInfo((Dictionary<string, object>)presence); | ||
360 | rinfos.Add(pinfo); | ||
361 | } | ||
362 | else | ||
363 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received invalid response type {0}", | ||
364 | presence.GetType()); | ||
365 | } | ||
366 | } | ||
367 | else | ||
368 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null response"); | ||
369 | |||
370 | return rinfos.ToArray(); | ||
371 | } | ||
372 | |||
373 | |||
374 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
375 | { | ||
376 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
377 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
378 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
379 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
380 | sendData["METHOD"] = "sethome"; | ||
381 | |||
382 | sendData["UserID"] = userID; | ||
383 | sendData["RegionID"] = regionID.ToString(); | ||
384 | sendData["position"] = position.ToString(); | ||
385 | sendData["lookAt"] = lookAt.ToString(); | ||
386 | |||
387 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
388 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
389 | try | ||
390 | { | ||
391 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
392 | m_ServerURI + "/presence", | ||
393 | reqString); | ||
394 | if (reply != string.Empty) | ||
395 | { | ||
396 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
397 | |||
398 | if (replyData.ContainsKey("result")) | ||
399 | { | ||
400 | if (replyData["result"].ToString().ToLower() == "success") | ||
401 | return true; | ||
402 | else | ||
403 | return false; | ||
404 | } | ||
405 | else | ||
406 | m_log.DebugFormat("[PRESENCE CONNECTOR]: SetHomeLocation reply data does not contain result field"); | ||
407 | |||
408 | } | ||
409 | else | ||
410 | m_log.DebugFormat("[PRESENCE CONNECTOR]: SetHomeLocation received empty reply"); | ||
411 | } | ||
412 | catch (Exception e) | ||
413 | { | ||
414 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
415 | } | ||
416 | |||
417 | return false; | ||
418 | } | ||
419 | |||
420 | #endregion | ||
421 | |||
422 | } | ||
423 | } | ||