aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-05-09 23:25:01 +0100
committerJustin Clark-Casey (justincc)2012-05-09 23:25:01 +0100
commitd8a78374aa11c5460d6e58a6f4110fca61dfded4 (patch)
tree4214094c092eeff11f2dcd60f71cfc294ab887be /OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs
parentImprove logging on the prim inventory script asset request path for future use. (diff)
downloadopensim-SC-d8a78374aa11c5460d6e58a6f4110fca61dfded4.zip
opensim-SC-d8a78374aa11c5460d6e58a6f4110fca61dfded4.tar.gz
opensim-SC-d8a78374aa11c5460d6e58a6f4110fca61dfded4.tar.bz2
opensim-SC-d8a78374aa11c5460d6e58a6f4110fca61dfded4.tar.xz
Where necessary, rename OpenSim/Services/Connectors/*.cs files to reflect the actual class names.
This is usually because the file name was singular (*Service*) but the class name was plural (*Services*). This is to make configuration easier rather than having to look in the c# code itself to find the slightly different name of the connector. This does not affect existing configuration since the files are being renamed rather than the classes.
Diffstat (limited to 'OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs378
1 files changed, 378 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..f7d8c53
--- /dev/null
+++ b/OpenSim/Services/Connectors/Presence/PresenceServicesConnector.cs
@@ -0,0 +1,378 @@
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 }
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 string uri = m_ServerURI + "/presence";
325 //m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
326 try
327 {
328 reply = SynchronousRestFormsRequester.MakeRequest("POST",
329 uri,
330 reqString);
331 if (reply == null || (reply != null && reply == string.Empty))
332 {
333 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null or empty reply");
334 return null;
335 }
336 }
337 catch (Exception e)
338 {
339 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
340 }
341
342 List<PresenceInfo> rinfos = new List<PresenceInfo>();
343
344 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
345
346 if (replyData != null)
347 {
348 if (replyData.ContainsKey("result") &&
349 (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure"))
350 {
351 return new PresenceInfo[0];
352 }
353
354 Dictionary<string, object>.ValueCollection pinfosList = replyData.Values;
355 //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count);
356 foreach (object presence in pinfosList)
357 {
358 if (presence is Dictionary<string, object>)
359 {
360 PresenceInfo pinfo = new PresenceInfo((Dictionary<string, object>)presence);
361 rinfos.Add(pinfo);
362 }
363 else
364 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received invalid response type {0}",
365 presence.GetType());
366 }
367 }
368 else
369 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null response");
370
371 return rinfos.ToArray();
372 }
373
374
375 #endregion
376
377 }
378}