clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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.ServiceAuth;
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 : BaseServiceConnector, 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 base.Initialise(source, "PresenceService");
86 }
87  
88  
89 #region IPresenceService
90  
91 public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID)
92 {
93 Dictionary<string, object> sendData = new Dictionary<string, object>();
94 //sendData["SCOPEID"] = scopeID.ToString();
95 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
96 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
97 sendData["METHOD"] = "login";
98  
99 sendData["UserID"] = userID;
100 sendData["SessionID"] = sessionID.ToString();
101 sendData["SecureSessionID"] = secureSessionID.ToString();
102  
103 string reqString = ServerUtils.BuildQueryString(sendData);
104 string uri = m_ServerURI + "/presence";
105 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
106 try
107 {
108 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
109 uri,
110 reqString,
111 m_Auth);
112 if (reply != string.Empty)
113 {
114 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
115  
116 if (replyData.ContainsKey("result"))
117 {
118 if (replyData["result"].ToString().ToLower() == "success")
119 return true;
120 else
121 return false;
122 }
123 else
124 m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent reply data does not contain result field");
125  
126 }
127 else
128 m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent received empty reply");
129 }
130 catch (Exception e)
131 {
132 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
133 }
134  
135 return false;
136  
137 }
138  
139 public bool LogoutAgent(UUID sessionID)
140 {
141 Dictionary<string, object> sendData = new Dictionary<string, object>();
142 //sendData["SCOPEID"] = scopeID.ToString();
143 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
144 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
145 sendData["METHOD"] = "logout";
146  
147 sendData["SessionID"] = sessionID.ToString();
148  
149 string reqString = ServerUtils.BuildQueryString(sendData);
150 string uri = m_ServerURI + "/presence";
151 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
152 try
153 {
154 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
155 uri,
156 reqString,
157 m_Auth);
158 if (reply != string.Empty)
159 {
160 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
161  
162 if (replyData.ContainsKey("result"))
163 {
164 if (replyData["result"].ToString().ToLower() == "success")
165 return true;
166 else
167 return false;
168 }
169 else
170 m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent reply data does not contain result field");
171  
172 }
173 else
174 m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent received empty reply");
175 }
176 catch (Exception e)
177 {
178 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
179 }
180  
181 return false;
182 }
183  
184 public bool LogoutRegionAgents(UUID regionID)
185 {
186 Dictionary<string, object> sendData = new Dictionary<string, object>();
187 //sendData["SCOPEID"] = scopeID.ToString();
188 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
189 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
190 sendData["METHOD"] = "logoutregion";
191  
192 sendData["RegionID"] = regionID.ToString();
193  
194 string reqString = ServerUtils.BuildQueryString(sendData);
195 string uri = m_ServerURI + "/presence";
196 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
197 try
198 {
199 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
200 uri,
201 reqString,
202 m_Auth);
203 if (reply != string.Empty)
204 {
205 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
206  
207 if (replyData.ContainsKey("result"))
208 {
209 if (replyData["result"].ToString().ToLower() == "success")
210 return true;
211 else
212 return false;
213 }
214 else
215 m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents reply data does not contain result field");
216  
217 }
218 else
219 m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents received empty reply");
220 }
221 catch (Exception e)
222 {
223 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
224 }
225  
226 return false;
227 }
228  
229 public bool ReportAgent(UUID sessionID, UUID regionID)
230 {
231 Dictionary<string, object> sendData = new Dictionary<string, object>();
232 //sendData["SCOPEID"] = scopeID.ToString();
233 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
234 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
235 sendData["METHOD"] = "report";
236  
237 sendData["SessionID"] = sessionID.ToString();
238 sendData["RegionID"] = regionID.ToString();
239  
240 string reqString = ServerUtils.BuildQueryString(sendData);
241 string uri = m_ServerURI + "/presence";
242 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
243 try
244 {
245 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
246 uri,
247 reqString,
248 m_Auth);
249 if (reply != string.Empty)
250 {
251 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
252  
253 if (replyData.ContainsKey("result"))
254 {
255 if (replyData["result"].ToString().ToLower() == "success")
256 return true;
257 else
258 return false;
259 }
260 else
261 m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent reply data does not contain result field");
262  
263 }
264 else
265 m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent received empty reply");
266 }
267 catch (Exception e)
268 {
269 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
270 }
271  
272 return false;
273 }
274  
275 public PresenceInfo GetAgent(UUID sessionID)
276 {
277 Dictionary<string, object> sendData = new Dictionary<string, object>();
278 //sendData["SCOPEID"] = scopeID.ToString();
279 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
280 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
281 sendData["METHOD"] = "getagent";
282  
283 sendData["SessionID"] = sessionID.ToString();
284  
285 string reply = string.Empty;
286 string reqString = ServerUtils.BuildQueryString(sendData);
287 string uri = m_ServerURI + "/presence";
288 // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
289 try
290 {
291 reply = SynchronousRestFormsRequester.MakeRequest("POST",
292 uri,
293 reqString,
294 m_Auth);
295 if (reply == null || (reply != null && reply == string.Empty))
296 {
297 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply");
298 return null;
299 }
300 }
301 catch (Exception e)
302 {
303 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
304 }
305  
306 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
307 PresenceInfo pinfo = null;
308  
309 if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null))
310 {
311 if (replyData["result"] is Dictionary<string, object>)
312 {
313 pinfo = new PresenceInfo((Dictionary<string, object>)replyData["result"]);
314 }
315 }
316  
317 return pinfo;
318 }
319  
320 public PresenceInfo[] GetAgents(string[] userIDs)
321 {
322 Dictionary<string, object> sendData = new Dictionary<string, object>();
323 //sendData["SCOPEID"] = scopeID.ToString();
324 sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
325 sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
326 sendData["METHOD"] = "getagents";
327  
328 sendData["uuids"] = new List<string>(userIDs);
329  
330 string reply = string.Empty;
331 string reqString = ServerUtils.BuildQueryString(sendData);
332 string uri = m_ServerURI + "/presence";
333 //m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString);
334 try
335 {
336 reply = SynchronousRestFormsRequester.MakeRequest("POST",
337 uri,
338 reqString,
339 m_Auth);
340 if (reply == null || (reply != null && reply == string.Empty))
341 {
342 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null or empty reply");
343 return null;
344 }
345 }
346 catch (Exception e)
347 {
348 m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
349 }
350  
351 List<PresenceInfo> rinfos = new List<PresenceInfo>();
352  
353 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
354  
355 if (replyData != null)
356 {
357 if (replyData.ContainsKey("result") &&
358 (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure"))
359 {
360 return new PresenceInfo[0];
361 }
362  
363 Dictionary<string, object>.ValueCollection pinfosList = replyData.Values;
364 //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count);
365 foreach (object presence in pinfosList)
366 {
367 if (presence is Dictionary<string, object>)
368 {
369 PresenceInfo pinfo = new PresenceInfo((Dictionary<string, object>)presence);
370 rinfos.Add(pinfo);
371 }
372 else
373 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received invalid response type {0}",
374 presence.GetType());
375 }
376 }
377 else
378 m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null response");
379  
380 return rinfos.ToArray();
381 }
382  
383  
384 #endregion
385  
386 }
387 }