30 using System.Collections.Generic;
32 using System.Reflection;
34 using OpenSim.Framework;
36 using OpenSim.Framework.ServiceAuth;
37 using OpenSim.Services.Interfaces;
39 using OpenSim.Server.Base;
42 namespace OpenSim.Services.Connectors
46 private static readonly ILog m_log =
48 MethodBase.GetCurrentMethod().DeclaringType);
50 private string m_ServerURI = String.Empty;
58 m_ServerURI = serverURI.TrimEnd(
'/');
68 IConfig gridConfig = source.Configs[
"PresenceService"];
69 if (gridConfig == null)
71 m_log.Error(
"[PRESENCE CONNECTOR]: PresenceService missing from OpenSim.ini");
72 throw new Exception(
"Presence connector init error");
75 string serviceURI = gridConfig.GetString(
"PresenceServerURI",
78 if (serviceURI == String.Empty)
80 m_log.Error(
"[PRESENCE CONNECTOR]: No Server URI named in section PresenceService");
81 throw new Exception(
"Presence connector init error");
83 m_ServerURI = serviceURI;
85 base.Initialise(source,
"PresenceService");
89 #region IPresenceService
91 public bool LoginAgent(
string userID, UUID sessionID, UUID secureSessionID)
93 Dictionary<string, object> sendData =
new Dictionary<string, object>();
95 sendData[
"VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
96 sendData[
"VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
97 sendData[
"METHOD"] =
"login";
99 sendData[
"UserID"] = userID;
100 sendData[
"SessionID"] = sessionID.ToString();
101 sendData[
"SecureSessionID"] = secureSessionID.ToString();
103 string reqString = ServerUtils.BuildQueryString(sendData);
104 string uri = m_ServerURI +
"/presence";
108 string reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
112 if (reply !=
string.Empty)
114 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
116 if (replyData.ContainsKey(
"result"))
118 if (replyData[
"result"].ToString().ToLower() ==
"success")
124 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: LoginAgent reply data does not contain result field");
128 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: LoginAgent received empty reply");
132 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
141 Dictionary<string, object> sendData =
new Dictionary<string, object>();
143 sendData[
"VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
144 sendData[
"VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
145 sendData[
"METHOD"] =
"logout";
147 sendData[
"SessionID"] = sessionID.ToString();
149 string reqString = ServerUtils.BuildQueryString(sendData);
150 string uri = m_ServerURI +
"/presence";
154 string reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
158 if (reply !=
string.Empty)
160 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
162 if (replyData.ContainsKey(
"result"))
164 if (replyData[
"result"].ToString().ToLower() ==
"success")
170 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: LogoutAgent reply data does not contain result field");
174 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: LogoutAgent received empty reply");
178 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
186 Dictionary<string, object> sendData =
new Dictionary<string, object>();
188 sendData[
"VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
189 sendData[
"VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
190 sendData[
"METHOD"] =
"logoutregion";
192 sendData[
"RegionID"] = regionID.ToString();
194 string reqString = ServerUtils.BuildQueryString(sendData);
195 string uri = m_ServerURI +
"/presence";
199 string reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
203 if (reply !=
string.Empty)
205 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
207 if (replyData.ContainsKey(
"result"))
209 if (replyData[
"result"].ToString().ToLower() ==
"success")
215 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: LogoutRegionAgents reply data does not contain result field");
219 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: LogoutRegionAgents received empty reply");
223 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
231 Dictionary<string, object> sendData =
new Dictionary<string, object>();
233 sendData[
"VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
234 sendData[
"VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
235 sendData[
"METHOD"] =
"report";
237 sendData[
"SessionID"] = sessionID.ToString();
238 sendData[
"RegionID"] = regionID.ToString();
240 string reqString = ServerUtils.BuildQueryString(sendData);
241 string uri = m_ServerURI +
"/presence";
245 string reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
249 if (reply !=
string.Empty)
251 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
253 if (replyData.ContainsKey(
"result"))
255 if (replyData[
"result"].ToString().ToLower() ==
"success")
261 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: ReportAgent reply data does not contain result field");
265 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: ReportAgent received empty reply");
269 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
277 Dictionary<string, object> sendData =
new Dictionary<string, object>();
279 sendData[
"VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
280 sendData[
"VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
281 sendData[
"METHOD"] =
"getagent";
283 sendData[
"SessionID"] = sessionID.ToString();
285 string reply = string.Empty;
286 string reqString = ServerUtils.BuildQueryString(sendData);
287 string uri = m_ServerURI +
"/presence";
291 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
295 if (reply == null || (reply != null && reply ==
string.Empty))
297 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: GetAgent received null or empty reply");
303 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
307 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
310 if ((replyData != null) && replyData.ContainsKey(
"result") && (replyData[
"result"] != null))
312 if (replyData[
"result"] is Dictionary<string, object>)
314 pinfo =
new PresenceInfo((Dictionary<string, object>)replyData[
"result"]);
318 if (replyData[
"result"].ToString() ==
"null")
321 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: Invalid reply (result not dictionary) received from presence server when querying for sessionID {0}", sessionID.ToString());
326 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: Invalid reply received from presence server when querying for sessionID {0}", sessionID.ToString());
334 Dictionary<string, object> sendData =
new Dictionary<string, object>();
336 sendData[
"VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString();
337 sendData[
"VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString();
338 sendData[
"METHOD"] =
"getagents";
340 sendData[
"uuids"] =
new List<string>(userIDs);
342 string reply = string.Empty;
343 string reqString = ServerUtils.BuildQueryString(sendData);
344 string uri = m_ServerURI +
"/presence";
348 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
352 if (reply == null || (reply != null && reply ==
string.Empty))
354 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: GetAgents received null or empty reply");
360 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: Exception when contacting presence server at {0}: {1}", uri, e.Message);
363 List<PresenceInfo> rinfos =
new List<PresenceInfo>();
365 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
367 if (replyData != null)
369 if (replyData.ContainsKey(
"result") &&
370 (replyData[
"result"].ToString() ==
"null" || replyData[
"result"].ToString() ==
"Failure"))
375 Dictionary<string, object>.ValueCollection pinfosList = replyData.Values;
377 foreach (
object presence
in pinfosList)
379 if (presence is Dictionary<string, object>)
385 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: GetAgents received invalid response type {0}",
390 m_log.DebugFormat(
"[PRESENCE CONNECTOR]: GetAgents received null response");
392 return rinfos.ToArray();
PresenceServicesConnector()
OpenSim.Services.Interfaces.GridRegion GridRegion
PresenceServicesConnector(IConfigSource source)
bool LogoutAgent(UUID sessionID)
Remove session information.
PresenceInfo GetAgent(UUID sessionID)
Get session information for a given session ID.
bool LogoutRegionAgents(UUID regionID)
Remove session information for all agents in the given region.
PresenceServicesConnector(string serverURI)
bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID)
Store session information.
PresenceInfo[] GetAgents(string[] userIDs)
Get session information for a collection of users.
OpenSim.Services.Interfaces.PresenceInfo PresenceInfo
virtual void Initialise(IConfigSource source)
bool ReportAgent(UUID sessionID, UUID regionID)
Update data for an existing session.