aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs373
1 files changed, 373 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..41ebeaf
--- /dev/null
+++ b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs
@@ -0,0 +1,373 @@
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.Framework.Servers.HttpServer;
37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using OpenSim.Server.Base;
40using OpenMetaverse;
41
42namespace 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)
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 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
147 try
148 {
149 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
150 m_ServerURI + "/presence",
151 reqString);
152 if (reply != string.Empty)
153 {
154 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
155
156 if (replyData.ContainsKey("result"))
157 {
158 if (replyData["result"].ToString().ToLower() == "success")
159 return true;
160 else
161 return false;
162 }
163 else
164 m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent reply data does not contain result field");
165
166 }
167 else
168 m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent received empty reply");
169 }
170 catch (Exception e)
171 {
172 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
173 }
174
175 return false;
176 }
177
178 public bool LogoutRegionAgents(UUID regionID)
179 {
180 Dictionary<string, object> sendData = new Dictionary<string, object>();
181 //sendData["SCOPEID"] = scopeID.ToString();
182 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
183 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
184 sendData["METHOD"] = "logoutregion";
185
186 sendData["RegionID"] = regionID.ToString();
187
188 string reqString = ServerUtils.BuildQueryString(sendData);
189 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
190 try
191 {
192 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
193 m_ServerURI + "/presence",
194 reqString);
195 if (reply != string.Empty)
196 {
197 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
198
199 if (replyData.ContainsKey("result"))
200 {
201 if (replyData["result"].ToString().ToLower() == "success")
202 return true;
203 else
204 return false;
205 }
206 else
207 m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents reply data does not contain result field");
208
209 }
210 else
211 m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents received empty reply");
212 }
213 catch (Exception e)
214 {
215 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
216 }
217
218 return false;
219 }
220
221 public bool ReportAgent(UUID sessionID, UUID regionID)
222 {
223 Dictionary<string, object> sendData = new Dictionary<string, object>();
224 //sendData["SCOPEID"] = scopeID.ToString();
225 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
226 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
227 sendData["METHOD"] = "report";
228
229 sendData["SessionID"] = sessionID.ToString();
230 sendData["RegionID"] = regionID.ToString();
231
232 string reqString = ServerUtils.BuildQueryString(sendData);
233 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
234 try
235 {
236 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
237 m_ServerURI + "/presence",
238 reqString);
239 if (reply != string.Empty)
240 {
241 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
242
243 if (replyData.ContainsKey("result"))
244 {
245 if (replyData["result"].ToString().ToLower() == "success")
246 return true;
247 else
248 return false;
249 }
250 else
251 m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent reply data does not contain result field");
252
253 }
254 else
255 m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent received empty reply");
256 }
257 catch (Exception e)
258 {
259 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
260 }
261
262 return false;
263 }
264
265 public PresenceInfo GetAgent(UUID sessionID)
266 {
267 Dictionary<string, object> sendData = new Dictionary<string, object>();
268 //sendData["SCOPEID"] = scopeID.ToString();
269 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
270 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
271 sendData["METHOD"] = "getagent";
272
273 sendData["SessionID"] = sessionID.ToString();
274
275 string reply = string.Empty;
276 string reqString = ServerUtils.BuildQueryString(sendData);
277 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
278 try
279 {
280 reply = SynchronousRestFormsRequester.MakeRequest("POST",
281 m_ServerURI + "/presence",
282 reqString);
283 if (reply == null || (reply != null && reply == string.Empty))
284 {
285 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply");
286 return null;
287 }
288 }
289 catch (Exception e)
290 {
291 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
292 }
293
294 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
295 PresenceInfo pinfo = null;
296
297 if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null))
298 {
299 if (replyData["result"] is Dictionary<string, object>)
300 {
301 pinfo = new PresenceInfo((Dictionary<string, object>)replyData["result"]);
302 }
303 }
304
305 return pinfo;
306 }
307
308 public PresenceInfo[] GetAgents(string[] userIDs)
309 {
310 Dictionary<string, object> sendData = new Dictionary<string, object>();
311 //sendData["SCOPEID"] = scopeID.ToString();
312 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
313 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
314 sendData["METHOD"] = "getagents";
315
316 sendData["uuids"] = new List<string>(userIDs);
317
318 string reply = string.Empty;
319 string reqString = ServerUtils.BuildQueryString(sendData);
320 //m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
321 try
322 {
323 reply = SynchronousRestFormsRequester.MakeRequest("POST",
324 m_ServerURI + "/presence",
325 reqString);
326 if (reply == null || (reply != null && reply == string.Empty))
327 {
328 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null or empty reply");
329 return null;
330 }
331 }
332 catch (Exception e)
333 {
334 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message);
335 }
336
337 List<PresenceInfo> rinfos = new List<PresenceInfo>();
338
339 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
340
341 if (replyData != null)
342 {
343 if (replyData.ContainsKey("result") &&
344 (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure"))
345 {
346 return new PresenceInfo[0];
347 }
348
349 Dictionary<string, object>.ValueCollection pinfosList = replyData.Values;
350 //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count);
351 foreach (object presence in pinfosList)
352 {
353 if (presence is Dictionary<string, object>)
354 {
355 PresenceInfo pinfo = new PresenceInfo((Dictionary<string, object>)presence);
356 rinfos.Add(pinfo);
357 }
358 else
359 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received invalid response type {0}",
360 presence.GetType());
361 }
362 }
363 else
364 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null response");
365
366 return rinfos.ToArray();
367 }
368
369
370 #endregion
371
372 }
373}