29 using System.Collections.Generic;
30 using System.Reflection;
33 using OpenSim.Services.Interfaces;
34 using OpenSim.Framework;
35 using OpenSim.Framework.Console;
41 namespace OpenSim.Services.UserAccountService
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 private static bool m_Initialized;
50 m_log.Debug(
"[GRID USER SERVICE]: Starting user grid service");
56 MainConsole.Instance.Commands.AddCommand(
59 "show grid user <ID>",
60 "Show grid user entry or entries that match or start with the given ID. This will normally be a UUID.",
61 "This is for debug purposes to see what data is found for a particular user id.",
64 MainConsole.Instance.Commands.AddCommand(
66 "show grid users online",
67 "show grid users online",
68 "Show number of grid users registered as online.",
69 "This number may not be accurate as a region may crash or not be cleanly shutdown and leave grid users shown as online\n."
70 +
"For this reason, users online for more than 5 days are not currently counted",
71 HandleShowGridUsersOnline);
77 if (cmdparams.Length != 4)
79 MainConsole.Instance.Output(
"Usage: show grid user <UUID>");
89 cdl.AddRow(
"User ID", gu.UserID);
91 foreach (KeyValuePair<string,string> kvp
in gu.
Data)
92 cdl.AddRow(kvp.Key, kvp.Value);
94 MainConsole.Instance.Output(cdl.ToString());
97 MainConsole.Instance.OutputFormat(
"Entries: {0}", data.Length);
109 int onlineRecentlyCount = 0;
111 DateTime now = DateTime.UtcNow;
115 if (
bool.Parse(gu.
Data[
"Online"]))
119 int unixLoginTime = int.Parse(gu.Data[
"Login"]);
121 if ((now - Util.ToDateTime(unixLoginTime)).Days < 5)
122 onlineRecentlyCount++;
126 MainConsole.Instance.OutputFormat(
"Users online: {0}", onlineRecentlyCount);
132 if (userID.Length > 36)
134 d = m_Database.Get(userID);
162 info.UserID = d.UserID;
163 info.HomeRegionID =
new UUID(d.
Data[
"HomeRegionID"]);
164 info.HomePosition = Vector3.Parse(d.Data[
"HomePosition"]);
165 info.HomeLookAt = Vector3.Parse(d.Data[
"HomeLookAt"]);
167 info.LastRegionID =
new UUID(d.
Data[
"LastRegionID"]);
168 info.LastPosition = Vector3.Parse(d.Data[
"LastPosition"]);
169 info.LastLookAt = Vector3.Parse(d.Data[
"LastLookAt"]);
171 info.Online = bool.Parse(d.Data[
"Online"]);
172 info.Login = Util.ToDateTime(Convert.ToInt32(d.Data[
"Login"]));
173 info.Logout = Util.ToDateTime(Convert.ToInt32(d.Data[
"Logout"]));
180 List<GridUserInfo> ret =
new List<GridUserInfo>();
182 foreach (
string id in userIDs)
183 ret.Add(GetGridUserInfo(
id));
185 return ret.ToArray();
190 m_log.DebugFormat(
"[GRID USER SERVICE]: User {0} is online", userID);
200 d.Data[
"Online"] = true.ToString();
201 d.Data[
"Login"] = Util.UnixTimeSinceEpoch().ToString();
205 return GetGridUserInfo(userID);
208 public bool LoggedOut(
string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
210 m_log.DebugFormat(
"[GRID USER SERVICE]: User {0} is offline", userID);
220 d.Data[
"Online"] = false.ToString();
221 d.Data[
"Logout"] = Util.UnixTimeSinceEpoch().ToString();
222 d.Data[
"LastRegionID"] = regionID.ToString();
223 d.Data[
"LastPosition"] = lastPosition.ToString();
224 d.Data[
"LastLookAt"] = lastLookAt.ToString();
226 return m_Database.Store(d);
229 public bool SetHome(
string userID, UUID homeID, Vector3 homePosition, Vector3 homeLookAt)
239 d.Data[
"HomeRegionID"] = homeID.ToString();
240 d.Data[
"HomePosition"] = homePosition.ToString();
241 d.Data[
"HomeLookAt"] = homeLookAt.ToString();
243 return m_Database.Store(d);
246 public bool SetLastPosition(
string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
258 d.Data[
"LastRegionID"] = regionID.ToString();
259 d.Data[
"LastPosition"] = lastPosition.ToString();
260 d.Data[
"LastLookAt"] = lastLookAt.ToString();
262 return m_Database.Store(d);
Used to generated a formatted table for the console.
virtual GridUserInfo[] GetGridUserInfo(string[] userIDs)
Dictionary< string, string > Data
void HandleShowGridUser(string module, string[] cmdparams)
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.
OpenSim.Services.Interfaces.GridRegion GridRegion
virtual GridUserInfo GetGridUserInfo(string userID)
bool SetHome(string userID, UUID homeID, Vector3 homePosition, Vector3 homeLookAt)
bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
Stores the last known user position at the grid level
void HandleShowGridUsersOnline(string module, string[] cmdparams)
GridUserInfo LoggedIn(string userID)
GridUserService(IConfigSource config)