diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Services/UserAccountService/GridUserService.cs | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Services/UserAccountService/GridUserService.cs')
-rw-r--r-- | OpenSim/Services/UserAccountService/GridUserService.cs | 127 |
1 files changed, 117 insertions, 10 deletions
diff --git a/OpenSim/Services/UserAccountService/GridUserService.cs b/OpenSim/Services/UserAccountService/GridUserService.cs index 43fa04b..80a9d9d 100644 --- a/OpenSim/Services/UserAccountService/GridUserService.cs +++ b/OpenSim/Services/UserAccountService/GridUserService.cs | |||
@@ -43,15 +43,117 @@ namespace OpenSim.Services.UserAccountService | |||
43 | public class GridUserService : GridUserServiceBase, IGridUserService | 43 | public class GridUserService : GridUserServiceBase, IGridUserService |
44 | { | 44 | { |
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
46 | private static bool m_Initialized; | ||
46 | 47 | ||
47 | public GridUserService(IConfigSource config) : base(config) | 48 | public GridUserService(IConfigSource config) : base(config) |
48 | { | 49 | { |
49 | m_log.Debug("[USER GRID SERVICE]: Starting user grid service"); | 50 | m_log.Debug("[GRID USER SERVICE]: Starting user grid service"); |
51 | |||
52 | if (!m_Initialized) | ||
53 | { | ||
54 | m_Initialized = true; | ||
55 | |||
56 | MainConsole.Instance.Commands.AddCommand( | ||
57 | "Users", false, | ||
58 | "show grid user", | ||
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.", | ||
62 | HandleShowGridUser); | ||
63 | |||
64 | MainConsole.Instance.Commands.AddCommand( | ||
65 | "Users", false, | ||
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); | ||
72 | } | ||
73 | } | ||
74 | |||
75 | protected void HandleShowGridUser(string module, string[] cmdparams) | ||
76 | { | ||
77 | if (cmdparams.Length != 4) | ||
78 | { | ||
79 | MainConsole.Instance.Output("Usage: show grid user <UUID>"); | ||
80 | return; | ||
81 | } | ||
82 | |||
83 | GridUserData[] data = m_Database.GetAll(cmdparams[3]); | ||
84 | |||
85 | foreach (GridUserData gu in data) | ||
86 | { | ||
87 | ConsoleDisplayList cdl = new ConsoleDisplayList(); | ||
88 | |||
89 | cdl.AddRow("User ID", gu.UserID); | ||
90 | |||
91 | foreach (KeyValuePair<string,string> kvp in gu.Data) | ||
92 | cdl.AddRow(kvp.Key, kvp.Value); | ||
93 | |||
94 | MainConsole.Instance.Output(cdl.ToString()); | ||
95 | } | ||
96 | |||
97 | MainConsole.Instance.OutputFormat("Entries: {0}", data.Length); | ||
98 | } | ||
99 | |||
100 | protected void HandleShowGridUsersOnline(string module, string[] cmdparams) | ||
101 | { | ||
102 | // if (cmdparams.Length != 4) | ||
103 | // { | ||
104 | // MainConsole.Instance.Output("Usage: show grid users online"); | ||
105 | // return; | ||
106 | // } | ||
107 | |||
108 | // int onlineCount; | ||
109 | int onlineRecentlyCount = 0; | ||
110 | |||
111 | DateTime now = DateTime.UtcNow; | ||
112 | |||
113 | foreach (GridUserData gu in m_Database.GetAll("")) | ||
114 | { | ||
115 | if (bool.Parse(gu.Data["Online"])) | ||
116 | { | ||
117 | // onlineCount++; | ||
118 | |||
119 | int unixLoginTime = int.Parse(gu.Data["Login"]); | ||
120 | |||
121 | if ((now - Util.ToDateTime(unixLoginTime)).Days < 5) | ||
122 | onlineRecentlyCount++; | ||
123 | } | ||
124 | } | ||
125 | |||
126 | MainConsole.Instance.OutputFormat("Users online: {0}", onlineRecentlyCount); | ||
127 | } | ||
128 | |||
129 | private GridUserData GetGridUserData(string userID) | ||
130 | { | ||
131 | GridUserData d = null; | ||
132 | if (userID.Length > 36) // it's a UUI | ||
133 | { | ||
134 | d = m_Database.Get(userID); | ||
135 | } | ||
136 | else // it's a UUID | ||
137 | { | ||
138 | GridUserData[] ds = m_Database.GetAll(userID); | ||
139 | if (ds == null) | ||
140 | return null; | ||
141 | |||
142 | if (ds.Length > 0) | ||
143 | { | ||
144 | d = ds[0]; | ||
145 | foreach (GridUserData dd in ds) | ||
146 | if (dd.UserID.Length > d.UserID.Length) // find the longest | ||
147 | d = dd; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | return d; | ||
50 | } | 152 | } |
51 | 153 | ||
52 | public virtual GridUserInfo GetGridUserInfo(string userID) | 154 | public virtual GridUserInfo GetGridUserInfo(string userID) |
53 | { | 155 | { |
54 | GridUserData d = m_Database.Get(userID); | 156 | GridUserData d = GetGridUserData(userID); |
55 | 157 | ||
56 | if (d == null) | 158 | if (d == null) |
57 | return null; | 159 | return null; |
@@ -73,7 +175,7 @@ namespace OpenSim.Services.UserAccountService | |||
73 | return info; | 175 | return info; |
74 | } | 176 | } |
75 | 177 | ||
76 | public GridUserInfo[] GetGridUserInfo(string[] userIDs) | 178 | public virtual GridUserInfo[] GetGridUserInfo(string[] userIDs) |
77 | { | 179 | { |
78 | List<GridUserInfo> ret = new List<GridUserInfo>(); | 180 | List<GridUserInfo> ret = new List<GridUserInfo>(); |
79 | 181 | ||
@@ -86,7 +188,8 @@ namespace OpenSim.Services.UserAccountService | |||
86 | public GridUserInfo LoggedIn(string userID) | 188 | public GridUserInfo LoggedIn(string userID) |
87 | { | 189 | { |
88 | m_log.DebugFormat("[GRID USER SERVICE]: User {0} is online", userID); | 190 | m_log.DebugFormat("[GRID USER SERVICE]: User {0} is online", userID); |
89 | GridUserData d = m_Database.Get(userID); | 191 | |
192 | GridUserData d = GetGridUserData(userID); | ||
90 | 193 | ||
91 | if (d == null) | 194 | if (d == null) |
92 | { | 195 | { |
@@ -104,8 +207,9 @@ namespace OpenSim.Services.UserAccountService | |||
104 | 207 | ||
105 | public bool LoggedOut(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt) | 208 | public bool LoggedOut(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt) |
106 | { | 209 | { |
107 | m_log.DebugFormat("[GRID USER SERVICE]: User {0} is offline", userID); | 210 | m_log.InfoFormat("[GRID USER SERVICE]: User {0} is offline", userID); |
108 | GridUserData d = m_Database.Get(userID); | 211 | |
212 | GridUserData d = GetGridUserData(userID); | ||
109 | 213 | ||
110 | if (d == null) | 214 | if (d == null) |
111 | { | 215 | { |
@@ -124,7 +228,8 @@ namespace OpenSim.Services.UserAccountService | |||
124 | 228 | ||
125 | public bool SetHome(string userID, UUID homeID, Vector3 homePosition, Vector3 homeLookAt) | 229 | public bool SetHome(string userID, UUID homeID, Vector3 homePosition, Vector3 homeLookAt) |
126 | { | 230 | { |
127 | GridUserData d = m_Database.Get(userID); | 231 | GridUserData d = GetGridUserData(userID); |
232 | |||
128 | if (d == null) | 233 | if (d == null) |
129 | { | 234 | { |
130 | d = new GridUserData(); | 235 | d = new GridUserData(); |
@@ -140,8 +245,10 @@ namespace OpenSim.Services.UserAccountService | |||
140 | 245 | ||
141 | public bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt) | 246 | public bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt) |
142 | { | 247 | { |
143 | //m_log.DebugFormat("[Grid User Service]: SetLastPosition for {0}", userID); | 248 | // m_log.DebugFormat("[GRID USER SERVICE]: SetLastPosition for {0}", userID); |
144 | GridUserData d = m_Database.Get(userID); | 249 | |
250 | GridUserData d = GetGridUserData(userID); | ||
251 | |||
145 | if (d == null) | 252 | if (d == null) |
146 | { | 253 | { |
147 | d = new GridUserData(); | 254 | d = new GridUserData(); |
@@ -155,4 +262,4 @@ namespace OpenSim.Services.UserAccountService | |||
155 | return m_Database.Store(d); | 262 | return m_Database.Store(d); |
156 | } | 263 | } |
157 | } | 264 | } |
158 | } | 265 | } \ No newline at end of file |