aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs389
1 files changed, 389 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs b/OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs
new file mode 100644
index 0000000..378aab6
--- /dev/null
+++ b/OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs
@@ -0,0 +1,389 @@
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 OpenSim.Server.Base;
39using OpenMetaverse;
40
41namespace OpenSim.Services.Connectors
42{
43 public class PresenceServicesConnector : IPresenceService
44 {
45 private static readonly ILog m_log =
46 LogManager.GetLogger(
47 MethodBase.GetCurrentMethod().DeclaringType);
48
49 private string m_ServerURI = String.Empty;
50
51 public PresenceServicesConnector()
52 {
53 }
54
55 public PresenceServicesConnector(string serverURI)
56 {
57 m_ServerURI = serverURI.TrimEnd('/');
58 }
59
60 public PresenceServicesConnector(IConfigSource source)
61 {
62 Initialise(source);
63 }
64
65 public virtual void Initialise(IConfigSource source)
66 {
67 IConfig gridConfig = source.Configs["PresenceService"];
68 if (gridConfig == null)
69 {
70 m_log.Error("[PRESENCE CONNECTOR]: PresenceService missing from OpenSim.ini");
71 throw new Exception("Presence connector init error");
72 }
73
74 string serviceURI = gridConfig.GetString("PresenceServerURI",
75 String.Empty);
76
77 if (serviceURI == String.Empty)
78 {
79 m_log.Error("[PRESENCE CONNECTOR]: No Server URI named in section PresenceService");
80 throw new Exception("Presence connector init error");
81 }
82 m_ServerURI = serviceURI;
83 }
84
85
86 #region IPresenceService
87
88 public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID)
89 {
90 Dictionary<string, object> sendData = new Dictionary<string, object>();
91 //sendData["SCOPEID"] = scopeID.ToString();
92 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
93 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
94 sendData["METHOD"] = "login";
95
96 sendData["UserID"] = userID;
97 sendData["SessionID"] = sessionID.ToString();
98 sendData["SecureSessionID"] = secureSessionID.ToString();
99
100 string reqString = ServerUtils.BuildQueryString(sendData);
101 string uri = m_ServerURI + "/presence";
102 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
103 try
104 {
105 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
106 uri,
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 at {0}: {1}", uri, e.Message);
129 }
130
131 return false;
132
133 }
134
135 public bool LogoutAgent(UUID sessionID)
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
145 string reqString = ServerUtils.BuildQueryString(sendData);
146 string uri = m_ServerURI + "/presence";
147 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
148 try
149 {
150 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
151 uri,
152 reqString);
153 if (reply != string.Empty)
154 {
155 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
156
157 if (replyData.ContainsKey("result"))
158 {
159 if (replyData["result"].ToString().ToLower() == "success")
160 return true;
161 else
162 return false;
163 }
164 else
165 m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent reply data does not contain result field");
166
167 }
168 else
169 m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent received empty reply");
170 }
171 catch (Exception e)
172 {
173 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
174 }
175
176 return false;
177 }
178
179 public bool LogoutRegionAgents(UUID regionID)
180 {
181 Dictionary<string, object> sendData = new Dictionary<string, object>();
182 //sendData["SCOPEID"] = scopeID.ToString();
183 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
184 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
185 sendData["METHOD"] = "logoutregion";
186
187 sendData["RegionID"] = regionID.ToString();
188
189 string reqString = ServerUtils.BuildQueryString(sendData);
190 string uri = m_ServerURI + "/presence";
191 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
192 try
193 {
194 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
195 uri,
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 at {0}: {1}", uri, e.Message);
218 }
219
220 return false;
221 }
222
223 public bool ReportAgent(UUID sessionID, UUID regionID)
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
234 string reqString = ServerUtils.BuildQueryString(sendData);
235 string uri = m_ServerURI + "/presence";
236 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
237 try
238 {
239 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
240 uri,
241 reqString);
242 if (reply != string.Empty)
243 {
244 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
245
246 if (replyData.ContainsKey("result"))
247 {
248 if (replyData["result"].ToString().ToLower() == "success")
249 return true;
250 else
251 return false;
252 }
253 else
254 m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent reply data does not contain result field");
255
256 }
257 else
258 m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent received empty reply");
259 }
260 catch (Exception e)
261 {
262 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
263 }
264
265 return false;
266 }
267
268 public PresenceInfo GetAgent(UUID sessionID)
269 {
270 Dictionary<string, object> sendData = new Dictionary<string, object>();
271 //sendData["SCOPEID"] = scopeID.ToString();
272 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
273 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
274 sendData["METHOD"] = "getagent";
275
276 sendData["SessionID"] = sessionID.ToString();
277
278 string reply = string.Empty;
279 string reqString = ServerUtils.BuildQueryString(sendData);
280 string uri = m_ServerURI + "/presence";
281 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
282 try
283 {
284 reply = SynchronousRestFormsRequester.MakeRequest("POST",
285 uri,
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 at {0}: {1}", uri, 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 else
308 {
309 if (replyData["result"].ToString() == "null")
310 return null;
311
312 m_log.DebugFormat("[PRESENCE CONNECTOR]: Invalid reply (result not dictionary) received from presence server when querying for sessionID {0}", sessionID.ToString());
313 }
314 }
315 else
316 {
317 m_log.DebugFormat("[PRESENCE CONNECTOR]: Invalid reply received from presence server when querying for sessionID {0}", sessionID.ToString());
318 }
319
320 return pinfo;
321 }
322
323 public PresenceInfo[] GetAgents(string[] userIDs)
324 {
325 Dictionary<string, object> sendData = new Dictionary<string, object>();
326 //sendData["SCOPEID"] = scopeID.ToString();
327 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
328 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
329 sendData["METHOD"] = "getagents";
330
331 sendData["uuids"] = new List<string>(userIDs);
332
333 string reply = string.Empty;
334 string reqString = ServerUtils.BuildQueryString(sendData);
335 string uri = m_ServerURI + "/presence";
336 //m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
337 try
338 {
339 reply = SynchronousRestFormsRequester.MakeRequest("POST",
340 uri,
341 reqString);
342 if (reply == null || (reply != null && reply == string.Empty))
343 {
344 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null or empty reply");
345 return null;
346 }
347 }
348 catch (Exception e)
349 {
350 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
351 }
352
353 List<PresenceInfo> rinfos = new List<PresenceInfo>();
354
355 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
356
357 if (replyData != null)
358 {
359 if (replyData.ContainsKey("result") &&
360 (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure"))
361 {
362 return new PresenceInfo[0];
363 }
364
365 Dictionary<string, object>.ValueCollection pinfosList = replyData.Values;
366 //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count);
367 foreach (object presence in pinfosList)
368 {
369 if (presence is Dictionary<string, object>)
370 {
371 PresenceInfo pinfo = new PresenceInfo((Dictionary<string, object>)presence);
372 rinfos.Add(pinfo);
373 }
374 else
375 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received invalid response type {0}",
376 presence.GetType());
377 }
378 }
379 else
380 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null response");
381
382 return rinfos.ToArray();
383 }
384
385
386 #endregion
387
388 }
389}