opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 1 /*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27  
28 using System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using Nini.Config;
32 using OpenSim.Data;
33 using OpenSim.Services.Interfaces;
34 using OpenSim.Framework;
35 using OpenSim.Framework.Console;
36 using GridRegion = OpenSim.Services.Interfaces.GridRegion;
37  
38 using OpenMetaverse;
39 using log4net;
40  
41 namespace OpenSim.Services.UserAccountService
42 {
43 public class GridUserService : GridUserServiceBase, IGridUserService
44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46  
47 public GridUserService(IConfigSource config) : base(config)
48 {
49 m_log.Debug("[GRID USER SERVICE]: Starting user grid service");
50  
51 MainConsole.Instance.Commands.AddCommand(
52 "Users", false,
53 "show grid user",
54 "show grid user <ID>",
55 "Show grid user entry or entries that match or start with the given ID. This will normally be a UUID.",
56 "This is for debug purposes to see what data is found for a particular user id.",
57 HandleShowGridUser);
58  
59 MainConsole.Instance.Commands.AddCommand(
60 "Users", false,
61 "show grid users online",
62 "show grid users online",
63 "Show number of grid users registered as online.",
64 "This number may not be accurate as a region may crash or not be cleanly shutdown and leave grid users shown as online\n."
65 + "For this reason, users online for more than 5 days are not currently counted",
66 HandleShowGridUsersOnline);
67 }
68  
69 protected void HandleShowGridUser(string module, string[] cmdparams)
70 {
71 if (cmdparams.Length != 4)
72 {
73 MainConsole.Instance.Output("Usage: show grid user <UUID>");
74 return;
75 }
76  
77 GridUserData[] data = m_Database.GetAll(cmdparams[3]);
78  
79 foreach (GridUserData gu in data)
80 {
81 ConsoleDisplayList cdl = new ConsoleDisplayList();
82  
83 cdl.AddRow("User ID", gu.UserID);
84  
85 foreach (KeyValuePair<string,string> kvp in gu.Data)
86 cdl.AddRow(kvp.Key, kvp.Value);
87  
88 MainConsole.Instance.Output(cdl.ToString());
89 }
90  
91 MainConsole.Instance.OutputFormat("Entries: {0}", data.Length);
92 }
93  
94 protected void HandleShowGridUsersOnline(string module, string[] cmdparams)
95 {
96 // if (cmdparams.Length != 4)
97 // {
98 // MainConsole.Instance.Output("Usage: show grid users online");
99 // return;
100 // }
101  
102 // int onlineCount;
103 int onlineRecentlyCount = 0;
104  
105 DateTime now = DateTime.UtcNow;
106  
107 foreach (GridUserData gu in m_Database.GetAll(""))
108 {
109 if (bool.Parse(gu.Data["Online"]))
110 {
111 // onlineCount++;
112  
113 int unixLoginTime = int.Parse(gu.Data["Login"]);
114  
115 if ((now - Util.ToDateTime(unixLoginTime)).Days < 5)
116 onlineRecentlyCount++;
117 }
118 }
119  
120 MainConsole.Instance.OutputFormat("Users online: {0}", onlineRecentlyCount);
121 }
122  
123 public virtual GridUserInfo GetGridUserInfo(string userID)
124 {
125 GridUserData d = null;
126 if (userID.Length > 36) // it's a UUI
127 d = m_Database.Get(userID);
128 else // it's a UUID
129 {
130 GridUserData[] ds = m_Database.GetAll(userID);
131 if (ds == null)
132 return null;
133  
134 if (ds.Length > 0)
135 {
136 d = ds[0];
137 foreach (GridUserData dd in ds)
138 if (dd.UserID.Length > d.UserID.Length) // find the longest
139 d = dd;
140 }
141 }
142  
143 if (d == null)
144 return null;
145  
146 GridUserInfo info = new GridUserInfo();
147 info.UserID = d.UserID;
148 info.HomeRegionID = new UUID(d.Data["HomeRegionID"]);
149 info.HomePosition = Vector3.Parse(d.Data["HomePosition"]);
150 info.HomeLookAt = Vector3.Parse(d.Data["HomeLookAt"]);
151  
152 info.LastRegionID = new UUID(d.Data["LastRegionID"]);
153 info.LastPosition = Vector3.Parse(d.Data["LastPosition"]);
154 info.LastLookAt = Vector3.Parse(d.Data["LastLookAt"]);
155  
156 info.Online = bool.Parse(d.Data["Online"]);
157 info.Login = Util.ToDateTime(Convert.ToInt32(d.Data["Login"]));
158 info.Logout = Util.ToDateTime(Convert.ToInt32(d.Data["Logout"]));
159  
160 return info;
161 }
162  
163 public virtual GridUserInfo[] GetGridUserInfo(string[] userIDs)
164 {
165 List<GridUserInfo> ret = new List<GridUserInfo>();
166  
167 foreach (string id in userIDs)
168 ret.Add(GetGridUserInfo(id));
169  
170 return ret.ToArray();
171 }
172  
173 public GridUserInfo LoggedIn(string userID)
174 {
175 m_log.DebugFormat("[GRID USER SERVICE]: User {0} is online", userID);
176 GridUserData d = m_Database.Get(userID);
177  
178 if (d == null)
179 {
180 d = new GridUserData();
181 d.UserID = userID;
182 }
183  
184 d.Data["Online"] = true.ToString();
185 d.Data["Login"] = Util.UnixTimeSinceEpoch().ToString();
186  
187 m_Database.Store(d);
188  
189 return GetGridUserInfo(userID);
190 }
191  
192 public bool LoggedOut(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
193 {
194 m_log.DebugFormat("[GRID USER SERVICE]: User {0} is offline", userID);
195 GridUserData d = m_Database.Get(userID);
196  
197 if (d == null)
198 {
199 d = new GridUserData();
200 d.UserID = userID;
201 }
202  
203 d.Data["Online"] = false.ToString();
204 d.Data["Logout"] = Util.UnixTimeSinceEpoch().ToString();
205 d.Data["LastRegionID"] = regionID.ToString();
206 d.Data["LastPosition"] = lastPosition.ToString();
207 d.Data["LastLookAt"] = lastLookAt.ToString();
208  
209 return m_Database.Store(d);
210 }
211  
212 public bool SetHome(string userID, UUID homeID, Vector3 homePosition, Vector3 homeLookAt)
213 {
214 GridUserData d = m_Database.Get(userID);
215 if (d == null)
216 {
217 d = new GridUserData();
218 d.UserID = userID;
219 }
220  
221 d.Data["HomeRegionID"] = homeID.ToString();
222 d.Data["HomePosition"] = homePosition.ToString();
223 d.Data["HomeLookAt"] = homeLookAt.ToString();
224  
225 return m_Database.Store(d);
226 }
227  
228 public bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
229 {
230 // m_log.DebugFormat("[GRID USER SERVICE]: SetLastPosition for {0}", userID);
231  
232 GridUserData d = m_Database.Get(userID);
233 if (d == null)
234 {
235 d = new GridUserData();
236 d.UserID = userID;
237 }
238  
239 d.Data["LastRegionID"] = regionID.ToString();
240 d.Data["LastPosition"] = lastPosition.ToString();
241 d.Data["LastLookAt"] = lastLookAt.ToString();
242  
243 return m_Database.Store(d);
244 }
245 }
246 }