29 using System.Collections.Generic;
30 using System.Collections.Specialized;
31 using System.Reflection;
35 using OpenSim.Framework;
36 using OpenSim.Region.Framework.Interfaces;
37 using OpenSim.Region.Framework.Scenes;
38 using OpenSim.Services.Interfaces;
40 using OpenMetaverse.StructuredData;
44 namespace OpenSim.Services.Connectors.SimianGrid
50 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"SimianPresenceServiceConnector")]
53 private static readonly ILog m_log =
55 MethodBase.GetCurrentMethod().DeclaringType);
57 private string m_serverUrl = String.Empty;
59 private bool m_Enabled =
false;
61 #region ISharedRegionModule
63 public Type ReplaceableInterface {
get {
return null; } }
69 public string Name {
get {
return "SimianPresenceServiceConnector"; } }
77 m_activityDetector.AddRegion(scene);
89 m_activityDetector.RemoveRegion(scene);
95 #endregion ISharedRegionModule
104 IConfig moduleConfig = source.Configs[
"Modules"];
105 if (moduleConfig != null)
107 string name = moduleConfig.GetString(
"PresenceServices",
"");
113 private void CommonInit(IConfigSource source)
115 IConfig gridConfig = source.Configs[
"PresenceService"];
116 if (gridConfig != null)
118 string serviceUrl = gridConfig.GetString(
"PresenceServerURI");
119 if (!
String.IsNullOrEmpty(serviceUrl))
121 if (!serviceUrl.EndsWith(
"/") && !serviceUrl.EndsWith(
"="))
122 serviceUrl = serviceUrl +
'/';
123 m_serverUrl = serviceUrl;
129 if (
String.IsNullOrEmpty(m_serverUrl))
130 m_log.Info(
"[SIMIAN PRESENCE CONNECTOR]: No PresenceServerURI specified, disabling connector");
133 #region IPresenceService
135 public bool LoginAgent(
string userID, UUID sessionID, UUID secureSessionID)
137 m_log.ErrorFormat(
"[SIMIAN PRESENCE CONNECTOR]: Login requested, UserID={0}, SessionID={1}, SecureSessionID={2}",
138 userID, sessionID, secureSessionID);
140 NameValueCollection requestArgs =
new NameValueCollection
142 {
"RequestMethod",
"AddSession" },
143 {
"UserID", userID.ToString() }
146 if (sessionID !=
UUID.Zero)
148 requestArgs[
"SessionID"] = sessionID.ToString();
149 requestArgs[
"SecureSessionID"] = secureSessionID.ToString();
152 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
153 bool success = response[
"Success"].AsBoolean();
156 m_log.Warn(
"[SIMIAN PRESENCE CONNECTOR]: Failed to login agent " + userID +
": " + response[
"Message"].AsString());
165 NameValueCollection requestArgs =
new NameValueCollection
167 {
"RequestMethod",
"RemoveSession" },
168 {
"SessionID", sessionID.ToString() }
171 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
172 bool success = response[
"Success"].AsBoolean();
175 m_log.Warn(
"[SIMIAN PRESENCE CONNECTOR]: Failed to logout agent with sessionID " + sessionID +
": " + response[
"Message"].AsString());
184 NameValueCollection requestArgs =
new NameValueCollection
186 {
"RequestMethod",
"RemoveSessions" },
187 {
"SceneID", regionID.ToString() }
190 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
191 bool success = response[
"Success"].AsBoolean();
194 m_log.Warn(
"[SIMIAN PRESENCE CONNECTOR]: Failed to logout agents from region " + regionID +
": " + response[
"Message"].AsString());
207 OSDMap sessionResponse = GetSessionDataFromSessionID(sessionID);
208 if (sessionResponse == null)
210 m_log.WarnFormat(
"[SIMIAN PRESENCE CONNECTOR]: Failed to retrieve session {0}: {1}",sessionID.ToString(),sessionResponse[
"Message"].AsString());
214 UUID userID = sessionResponse[
"UserID"].AsUUID();
215 OSDMap userResponse = GetUserData(userID);
216 if (userResponse == null)
218 m_log.WarnFormat(
"[SIMIAN PRESENCE CONNECTOR]: Failed to retrieve user data for {0}: {1}",userID.ToString(),userResponse[
"Message"].AsString());
222 return ResponseToPresenceInfo(sessionResponse);
227 List<PresenceInfo> presences =
new List<PresenceInfo>();
229 NameValueCollection requestArgs =
new NameValueCollection
231 {
"RequestMethod",
"GetSessions" },
232 {
"UserIDList", String.Join(
",",userIDs) }
235 OSDMap sessionListResponse = SimianGrid.PostToService(m_serverUrl, requestArgs);
236 if (! sessionListResponse[
"Success"].AsBoolean())
238 m_log.WarnFormat(
"[SIMIAN PRESENCE CONNECTOR]: Failed to retrieve sessions: {0}",sessionListResponse[
"Message"].AsString());
243 for (
int i = 0; i < sessionList.Count; i++)
246 presences.Add(ResponseToPresenceInfo(sessionInfo));
249 return presences.ToArray();
252 #endregion IPresenceService
254 #region IGridUserService
262 public bool LoggedOut(
string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
267 if (!LogoutAgent(sessionID))
271 NameValueCollection requestArgs =
new NameValueCollection
273 {
"RequestMethod",
"AddUserData" },
274 {
"UserID", userID.ToString() },
275 {
"LastLocation", SerializeLocation(regionID, lastPosition, lastLookAt) }
278 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
279 bool success = response[
"Success"].AsBoolean();
282 m_log.Warn(
"[SIMIAN PRESENCE CONNECTOR]: Failed to set last location for " + userID +
": " + response[
"Message"].AsString());
287 public bool SetHome(
string userID, UUID regionID, Vector3 position, Vector3 lookAt)
291 NameValueCollection requestArgs =
new NameValueCollection
293 {
"RequestMethod",
"AddUserData" },
294 {
"UserID", userID.ToString() },
295 {
"HomeLocation", SerializeLocation(regionID, position, lookAt) }
298 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
299 bool success = response[
"Success"].AsBoolean();
302 m_log.Warn(
"[SIMIAN PRESENCE CONNECTOR]: Failed to set home location for " + userID +
": " + response[
"Message"].AsString());
307 public bool SetLastPosition(
string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
309 return UpdateSession(sessionID, regionID, lastPosition, lastLookAt);
317 OSDMap userResponse = GetUserData(userID);
319 if (userResponse == null)
321 m_log.WarnFormat(
"[SIMIAN PRESENCE CONNECTOR]: Failed to retrieve user data for {0}", userID);
325 return ResponseToGridUserInfo(userResponse);
333 private OSDMap GetUserData(UUID userID)
337 NameValueCollection requestArgs =
new NameValueCollection
339 {
"RequestMethod",
"GetUser" },
340 {
"UserID", userID.ToString() }
343 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
344 if (response[
"Success"].AsBoolean() && response[
"User"] is
OSDMap)
347 m_log.WarnFormat(
"[SIMIAN PRESENCE CONNECTOR]: Failed to retrieve user data for {0}; {1}",userID.ToString(),response[
"Message"].AsString());
351 private OSDMap GetSessionDataFromSessionID(UUID sessionID)
353 NameValueCollection requestArgs =
new NameValueCollection
355 {
"RequestMethod",
"GetSession" },
356 {
"SessionID", sessionID.ToString() }
359 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
360 if (response[
"Success"].AsBoolean())
363 m_log.WarnFormat(
"[SIMIAN PRESENCE CONNECTOR]: Failed to retrieve session data for {0}; {1}",sessionID.ToString(),response[
"Message"].AsString());
367 private bool UpdateSession(UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
370 NameValueCollection requestArgs =
new NameValueCollection
372 {
"RequestMethod",
"UpdateSession" },
373 {
"SessionID", sessionID.ToString() },
374 {
"SceneID", regionID.ToString() },
375 {
"ScenePosition", lastPosition.ToString() },
376 {
"SceneLookAt", lastLookAt.ToString() }
379 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
380 bool success = response[
"Success"].AsBoolean();
383 m_log.Warn(
"[SIMIAN PRESENCE CONNECTOR]: Failed to update agent session " + sessionID +
": " + response[
"Message"].AsString());
390 if (sessionResponse == null)
395 info.UserID = sessionResponse[
"UserID"].AsUUID().ToString();
396 info.RegionID = sessionResponse[
"SceneID"].AsUUID();
403 if (userResponse != null && userResponse[
"User"] is
OSDMap)
408 info.UserID = userResponse[
"UserID"].AsUUID().ToString();
409 info.LastRegionID = userResponse[
"SceneID"].AsUUID();
410 info.LastPosition = userResponse[
"ScenePosition"].AsVector3();
411 info.LastLookAt = userResponse[
"SceneLookAt"].AsVector3();
413 OSDMap user = (
OSDMap)userResponse[
"User"];
415 info.Login = user[
"LastLoginDate"].AsDate();
416 info.Logout = user[
"LastLogoutDate"].AsDate();
425 private string SerializeLocation(UUID regionID, Vector3 position, Vector3 lookAt)
427 return "{" + String.Format(
"\"SceneID\":\"{0}\",\"Position\":\"{1}\",\"LookAt\":\"{2}\"", regionID, position, lookAt) +
"}";
430 private bool DeserializeLocation(
string location, out UUID regionID, out Vector3 position, out Vector3 lookAt)
434 try { map = OSDParser.DeserializeJson(location) as OSDMap; }
439 regionID = map[
"SceneID"].AsUUID();
440 if (Vector3.TryParse(map[
"Position"].AsString(), out position) &&
441 Vector3.TryParse(map[
"LookAt"].AsString(), out lookAt))
447 regionID = UUID.Zero;
448 position = Vector3.Zero;
449 lookAt = Vector3.Zero;
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
Connects avatar presence information (for tracking current location and message routing) to the Simia...
bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
Stores the last known user position at the grid level
OpenSim.Services.Interfaces.PresenceInfo PresenceInfo
OpenMetaverse.StructuredData.OSDArray OSDArray
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
GridUserInfo[] GetGridUserInfo(string[] userIDs)
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
OpenMetaverse.StructuredData.OSDMap OSDMap
PresenceInfo GetAgent(UUID sessionID)
Get session information for a given session ID.
SimianPresenceServiceConnector()
bool LoggedOut(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
Informs the grid that a user is logged out and to remove any session data for them ...
Records user information specific to a grid but which is not part of a user's account.
bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID)
Store session information.
bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
bool LogoutRegionAgents(UUID regionID)
Remove session information for all agents in the given region.
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
bool ReportAgent(UUID sessionID, UUID regionID)
Update data for an existing session.
GridUserInfo LoggedIn(string userID)
bool LogoutAgent(UUID sessionID)
Remove session information.
virtual RegionInfo RegionInfo
GridUserInfo GetGridUserInfo(string user)
SimianPresenceServiceConnector(IConfigSource source)
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
PresenceInfo[] GetAgents(string[] userIDs)
Get session information for a collection of users.
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...