29 using System.Collections.Generic;
31 using System.Reflection;
34 using OpenSim.Framework;
35 using OpenSim.Framework.Console;
37 using OpenSim.Services.Interfaces;
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 protected bool m_allowDuplicatePresences =
false;
51 m_log.Debug(
"[PRESENCE SERVICE]: Starting presence service");
53 IConfig presenceConfig = config.Configs[
"PresenceService"];
54 if (presenceConfig != null)
56 m_allowDuplicatePresences = presenceConfig.GetBoolean(
"AllowDuplicatePresences", m_allowDuplicatePresences);
60 public bool LoginAgent(
string userID, UUID sessionID, UUID secureSessionID)
64 if (!m_allowDuplicatePresences && (prevUser != null))
65 m_Database.Delete(
"UserID", userID.ToString());
70 data.RegionID = UUID.Zero;
71 data.SessionID = sessionID;
72 data.Data =
new Dictionary<string, string>();
73 data.Data[
"SecureSessionID"] = secureSessionID.ToString();
75 m_Database.Store(data);
77 string prevUserStr =
"";
79 prevUserStr = string.Format(
". This user was already logged-in: session {0}, region {1}", prevUser.SessionID, prevUser.RegionID);
81 m_log.DebugFormat(
"[PRESENCE SERVICE]: LoginAgent: session {0}, user {1}, region {2}, secure session {3}{4}",
82 data.SessionID, data.UserID, data.RegionID, secureSessionID, prevUserStr);
91 m_log.DebugFormat(
"[PRESENCE SERVICE]: LogoutAgent: session {0}, user {1}, region {2}",
93 (presence == null) ? null : presence.UserID,
94 (presence == null) ? null : presence.RegionID.ToString());
96 return m_Database.Delete(
"SessionID", sessionID.ToString());
101 PresenceData[] prevSessions = GetRegionAgents(regionID);
103 if ((prevSessions == null) || (prevSessions.Length == 0))
106 m_log.DebugFormat(
"[PRESENCE SERVICE]: Logout users in region {0}: {1}", regionID,
107 string.Join(
", ", Array.ConvertAll(prevSessions, session => session.UserID)));
112 m_Database.LogoutRegionAgents(regionID);
125 if (presence == null)
128 success = m_Database.ReportAgent(sessionID, regionID);
130 m_log.DebugFormat(
"[PRESENCE SERVICE]: ReportAgent{0}: session {1}, user {2}, region {3}. Previously: {4}",
131 success ?
"" :
" failed",
132 sessionID, (presence == null) ? null : presence.UserID, regionID,
133 (presence == null) ?
"not logged-in" :
"region " + presence.RegionID);
139 m_log.Debug(string.Format(
"[PRESENCE SERVICE]: ReportAgent for session {0} threw exception ", sessionID), e);
152 ret.UserID = data.UserID;
153 ret.RegionID = data.RegionID;
160 List<PresenceInfo> info =
new List<PresenceInfo>();
162 foreach (
string userIDStr
in userIDs)
164 PresenceData[] data = m_Database.Get(
"UserID", userIDStr);
170 ret.UserID = d.UserID;
171 ret.RegionID = d.RegionID;
180 return info.ToArray();
197 return m_Database.Get(
"RegionID", regionID.ToString());
PresenceService(IConfigSource config)
bool LogoutRegionAgents(UUID regionID)
Remove session information for all agents in the given region.
bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID)
Store session information.
Interactive OpenSim region server
OpenSim.Services.Interfaces.PresenceInfo PresenceInfo
PresenceInfo GetAgent(UUID sessionID)
Get session information for a given session ID.
bool ReportAgent(UUID sessionID, UUID regionID)
Update data for an existing session.
PresenceInfo[] GetAgents(string[] userIDs)
Get session information for a collection of users.
bool LogoutAgent(UUID sessionID)
Remove session information.