diff options
Diffstat (limited to 'OpenSim/Services/UserAccountService')
7 files changed, 1322 insertions, 0 deletions
diff --git a/OpenSim/Services/UserAccountService/AgentPreferencesService.cs b/OpenSim/Services/UserAccountService/AgentPreferencesService.cs new file mode 100644 index 0000000..1808ee5 --- /dev/null +++ b/OpenSim/Services/UserAccountService/AgentPreferencesService.cs | |||
@@ -0,0 +1,82 @@ | |||
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 log4net; | ||
32 | using Nini.Config; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Data; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | |||
38 | namespace OpenSim.Services.UserAccountService | ||
39 | { | ||
40 | public class AgentPreferencesService : AgentPreferencesServiceBase, IAgentPreferencesService | ||
41 | { | ||
42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
44 | public AgentPreferencesService(IConfigSource config) : base(config) | ||
45 | { | ||
46 | m_log.Debug("[AGENT PREFERENCES SERVICE]: Starting agent preferences service"); | ||
47 | } | ||
48 | |||
49 | public AgentPrefs GetAgentPreferences(UUID principalID) | ||
50 | { | ||
51 | AgentPreferencesData d = m_Database.GetPrefs(principalID); | ||
52 | AgentPrefs prefs = (d == null) ? new AgentPrefs(principalID) : new AgentPrefs(d.Data); | ||
53 | return prefs; | ||
54 | } | ||
55 | |||
56 | public bool StoreAgentPreferences(AgentPrefs data) | ||
57 | { | ||
58 | AgentPreferencesData d = new AgentPreferencesData(); | ||
59 | d.Data = new Dictionary<string, string>(); | ||
60 | d.Data["PrincipalID"] = data.PrincipalID.ToString(); | ||
61 | d.Data["AccessPrefs"] = data.AccessPrefs; | ||
62 | d.Data["HoverHeight"] = data.HoverHeight.ToString(); | ||
63 | d.Data["Language"] = data.Language; | ||
64 | d.Data["LanguageIsPublic"] = (data.LanguageIsPublic ? "1" : "0"); | ||
65 | d.Data["PermEveryone"] = data.PermEveryone.ToString(); | ||
66 | d.Data["PermGroup"] = data.PermGroup.ToString(); | ||
67 | d.Data["PermNextOwner"] = data.PermNextOwner.ToString(); | ||
68 | return m_Database.Store(d); | ||
69 | } | ||
70 | |||
71 | public string GetLang(UUID principalID) | ||
72 | { | ||
73 | AgentPrefs data = GetAgentPreferences(principalID); | ||
74 | if (data != null) | ||
75 | { | ||
76 | if (data.LanguageIsPublic) | ||
77 | return data.Language; | ||
78 | } | ||
79 | return "en-us"; | ||
80 | } | ||
81 | } | ||
82 | } | ||
diff --git a/OpenSim/Services/UserAccountService/AgentPreferencesServiceBase.cs b/OpenSim/Services/UserAccountService/AgentPreferencesServiceBase.cs new file mode 100644 index 0000000..5974349 --- /dev/null +++ b/OpenSim/Services/UserAccountService/AgentPreferencesServiceBase.cs | |||
@@ -0,0 +1,73 @@ | |||
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.Reflection; | ||
30 | using Nini.Config; | ||
31 | using OpenSim.Data; | ||
32 | using OpenSim.Services.Interfaces; | ||
33 | using OpenSim.Services.Base; | ||
34 | |||
35 | namespace OpenSim.Services.UserAccountService | ||
36 | { | ||
37 | public class AgentPreferencesServiceBase: ServiceBase | ||
38 | { | ||
39 | protected IAgentPreferencesData m_Database = null; | ||
40 | |||
41 | public AgentPreferencesServiceBase(IConfigSource config) : base(config) | ||
42 | { | ||
43 | string dllName = String.Empty; | ||
44 | string connString = String.Empty; | ||
45 | string realm = "AgentPrefs"; | ||
46 | |||
47 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
48 | if (dbConfig != null) | ||
49 | { | ||
50 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
51 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
52 | } | ||
53 | |||
54 | IConfig userConfig = config.Configs["AgentPreferencesService"]; | ||
55 | if (userConfig == null) | ||
56 | throw new Exception("No AgentPreferencesService configuration"); | ||
57 | |||
58 | dllName = userConfig.GetString("StorageProvider", dllName); | ||
59 | |||
60 | if (dllName == String.Empty) | ||
61 | throw new Exception("No StorageProvider configured"); | ||
62 | |||
63 | connString = userConfig.GetString("ConnectionString", connString); | ||
64 | |||
65 | realm = userConfig.GetString("Realm", realm); | ||
66 | |||
67 | m_Database = LoadPlugin<IAgentPreferencesData>(dllName, new Object[] {connString, realm}); | ||
68 | |||
69 | if (m_Database == null) | ||
70 | throw new Exception("Could not find a storage interface in the given module"); | ||
71 | } | ||
72 | } | ||
73 | } | ||
diff --git a/OpenSim/Services/UserAccountService/GridUserService.cs b/OpenSim/Services/UserAccountService/GridUserService.cs new file mode 100644 index 0000000..e4bcf15 --- /dev/null +++ b/OpenSim/Services/UserAccountService/GridUserService.cs | |||
@@ -0,0 +1,265 @@ | |||
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 | private static bool m_Initialized; | ||
47 | |||
48 | public GridUserService(IConfigSource config) : base(config) | ||
49 | { | ||
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; | ||
152 | } | ||
153 | |||
154 | public virtual GridUserInfo GetGridUserInfo(string userID) | ||
155 | { | ||
156 | GridUserData d = GetGridUserData(userID); | ||
157 | |||
158 | if (d == null) | ||
159 | return null; | ||
160 | |||
161 | GridUserInfo info = new GridUserInfo(); | ||
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"]); | ||
166 | |||
167 | info.LastRegionID = new UUID(d.Data["LastRegionID"]); | ||
168 | info.LastPosition = Vector3.Parse(d.Data["LastPosition"]); | ||
169 | info.LastLookAt = Vector3.Parse(d.Data["LastLookAt"]); | ||
170 | |||
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"])); | ||
174 | |||
175 | return info; | ||
176 | } | ||
177 | |||
178 | public virtual GridUserInfo[] GetGridUserInfo(string[] userIDs) | ||
179 | { | ||
180 | List<GridUserInfo> ret = new List<GridUserInfo>(); | ||
181 | |||
182 | foreach (string id in userIDs) | ||
183 | ret.Add(GetGridUserInfo(id)); | ||
184 | |||
185 | return ret.ToArray(); | ||
186 | } | ||
187 | |||
188 | public GridUserInfo LoggedIn(string userID) | ||
189 | { | ||
190 | m_log.DebugFormat("[GRID USER SERVICE]: User {0} is online", userID); | ||
191 | |||
192 | GridUserData d = GetGridUserData(userID); | ||
193 | |||
194 | if (d == null) | ||
195 | { | ||
196 | d = new GridUserData(); | ||
197 | d.UserID = userID; | ||
198 | } | ||
199 | |||
200 | d.Data["Online"] = true.ToString(); | ||
201 | d.Data["Login"] = Util.UnixTimeSinceEpoch().ToString(); | ||
202 | |||
203 | m_Database.Store(d); | ||
204 | |||
205 | return GetGridUserInfo(userID); | ||
206 | } | ||
207 | |||
208 | public bool LoggedOut(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt) | ||
209 | { | ||
210 | m_log.DebugFormat("[GRID USER SERVICE]: User {0} is offline", userID); | ||
211 | |||
212 | GridUserData d = GetGridUserData(userID); | ||
213 | |||
214 | if (d == null) | ||
215 | { | ||
216 | d = new GridUserData(); | ||
217 | d.UserID = userID; | ||
218 | } | ||
219 | |||
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(); | ||
225 | |||
226 | return m_Database.Store(d); | ||
227 | } | ||
228 | |||
229 | public bool SetHome(string userID, UUID homeID, Vector3 homePosition, Vector3 homeLookAt) | ||
230 | { | ||
231 | GridUserData d = GetGridUserData(userID); | ||
232 | |||
233 | if (d == null) | ||
234 | { | ||
235 | d = new GridUserData(); | ||
236 | d.UserID = userID; | ||
237 | } | ||
238 | |||
239 | d.Data["HomeRegionID"] = homeID.ToString(); | ||
240 | d.Data["HomePosition"] = homePosition.ToString(); | ||
241 | d.Data["HomeLookAt"] = homeLookAt.ToString(); | ||
242 | |||
243 | return m_Database.Store(d); | ||
244 | } | ||
245 | |||
246 | public bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt) | ||
247 | { | ||
248 | // m_log.DebugFormat("[GRID USER SERVICE]: SetLastPosition for {0}", userID); | ||
249 | |||
250 | GridUserData d = GetGridUserData(userID); | ||
251 | |||
252 | if (d == null) | ||
253 | { | ||
254 | d = new GridUserData(); | ||
255 | d.UserID = userID; | ||
256 | } | ||
257 | |||
258 | d.Data["LastRegionID"] = regionID.ToString(); | ||
259 | d.Data["LastPosition"] = lastPosition.ToString(); | ||
260 | d.Data["LastLookAt"] = lastLookAt.ToString(); | ||
261 | |||
262 | return m_Database.Store(d); | ||
263 | } | ||
264 | } | ||
265 | } \ No newline at end of file | ||
diff --git a/OpenSim/Services/UserAccountService/GridUserServiceBase.cs b/OpenSim/Services/UserAccountService/GridUserServiceBase.cs new file mode 100644 index 0000000..8c5f5df --- /dev/null +++ b/OpenSim/Services/UserAccountService/GridUserServiceBase.cs | |||
@@ -0,0 +1,82 @@ | |||
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.Reflection; | ||
30 | using Nini.Config; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Data; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using OpenSim.Services.Base; | ||
35 | |||
36 | namespace OpenSim.Services.UserAccountService | ||
37 | { | ||
38 | public class GridUserServiceBase : ServiceBase | ||
39 | { | ||
40 | protected IGridUserData m_Database = null; | ||
41 | |||
42 | public GridUserServiceBase(IConfigSource config) : base(config) | ||
43 | { | ||
44 | string dllName = String.Empty; | ||
45 | string connString = String.Empty; | ||
46 | string realm = "GridUser"; | ||
47 | |||
48 | // | ||
49 | // Try reading the [DatabaseService] section, if it exists | ||
50 | // | ||
51 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
52 | if (dbConfig != null) | ||
53 | { | ||
54 | if (dllName == String.Empty) | ||
55 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
56 | if (connString == String.Empty) | ||
57 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
58 | } | ||
59 | |||
60 | // | ||
61 | // [GridUsetService] section overrides [DatabaseService], if it exists | ||
62 | // | ||
63 | IConfig usersConfig = config.Configs["GridUserService"]; | ||
64 | if (usersConfig != null) | ||
65 | { | ||
66 | dllName = usersConfig.GetString("StorageProvider", dllName); | ||
67 | connString = usersConfig.GetString("ConnectionString", connString); | ||
68 | realm = usersConfig.GetString("Realm", realm); | ||
69 | } | ||
70 | |||
71 | // | ||
72 | // We tried, but this doesn't exist. We can't proceed. | ||
73 | // | ||
74 | if (dllName.Equals(String.Empty)) | ||
75 | throw new Exception("No StorageProvider configured"); | ||
76 | |||
77 | m_Database = LoadPlugin<IGridUserData>(dllName, new Object[] { connString, realm }); | ||
78 | if (m_Database == null) | ||
79 | throw new Exception("Could not find a storage interface in the given module " + dllName); | ||
80 | } | ||
81 | } | ||
82 | } \ No newline at end of file | ||
diff --git a/OpenSim/Services/UserAccountService/Properties/AssemblyInfo.cs b/OpenSim/Services/UserAccountService/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..33933a0 --- /dev/null +++ b/OpenSim/Services/UserAccountService/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,33 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.Services.UserAccountService")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
12 | [assembly: AssemblyProduct("OpenSim")] | ||
13 | [assembly: AssemblyCopyright("OpenSimulator developers")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("fdb4771d-9928-4db4-aeb5-90cac2976584")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | [assembly: AssemblyVersion("0.8.2.*")] | ||
33 | |||
diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs new file mode 100644 index 0000000..2e19ece --- /dev/null +++ b/OpenSim/Services/UserAccountService/UserAccountService.cs | |||
@@ -0,0 +1,714 @@ | |||
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 log4net; | ||
32 | using Nini.Config; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Data; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using OpenSim.Framework.Console; | ||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
39 | using PermissionMask = OpenSim.Framework.PermissionMask; | ||
40 | |||
41 | namespace OpenSim.Services.UserAccountService | ||
42 | { | ||
43 | public class UserAccountService : UserAccountServiceBase, IUserAccountService | ||
44 | { | ||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | private static UserAccountService m_RootInstance; | ||
47 | |||
48 | /// <summary> | ||
49 | /// Should we create default entries (minimum body parts/clothing, avatar wearable entries) for a new avatar? | ||
50 | /// </summary> | ||
51 | private bool m_CreateDefaultAvatarEntries; | ||
52 | |||
53 | protected IGridService m_GridService; | ||
54 | protected IAuthenticationService m_AuthenticationService; | ||
55 | protected IGridUserService m_GridUserService; | ||
56 | protected IInventoryService m_InventoryService; | ||
57 | protected IAvatarService m_AvatarService; | ||
58 | |||
59 | public UserAccountService(IConfigSource config) | ||
60 | : base(config) | ||
61 | { | ||
62 | IConfig userConfig = config.Configs["UserAccountService"]; | ||
63 | if (userConfig == null) | ||
64 | throw new Exception("No UserAccountService configuration"); | ||
65 | |||
66 | string gridServiceDll = userConfig.GetString("GridService", string.Empty); | ||
67 | if (gridServiceDll != string.Empty) | ||
68 | m_GridService = LoadPlugin<IGridService>(gridServiceDll, new Object[] { config }); | ||
69 | |||
70 | string authServiceDll = userConfig.GetString("AuthenticationService", string.Empty); | ||
71 | if (authServiceDll != string.Empty) | ||
72 | m_AuthenticationService = LoadPlugin<IAuthenticationService>(authServiceDll, new Object[] { config }); | ||
73 | |||
74 | string presenceServiceDll = userConfig.GetString("GridUserService", string.Empty); | ||
75 | if (presenceServiceDll != string.Empty) | ||
76 | m_GridUserService = LoadPlugin<IGridUserService>(presenceServiceDll, new Object[] { config }); | ||
77 | |||
78 | string invServiceDll = userConfig.GetString("InventoryService", string.Empty); | ||
79 | if (invServiceDll != string.Empty) | ||
80 | m_InventoryService = LoadPlugin<IInventoryService>(invServiceDll, new Object[] { config }); | ||
81 | |||
82 | string avatarServiceDll = userConfig.GetString("AvatarService", string.Empty); | ||
83 | if (avatarServiceDll != string.Empty) | ||
84 | m_AvatarService = LoadPlugin<IAvatarService>(avatarServiceDll, new Object[] { config }); | ||
85 | |||
86 | m_CreateDefaultAvatarEntries = userConfig.GetBoolean("CreateDefaultAvatarEntries", false); | ||
87 | |||
88 | // In case there are several instances of this class in the same process, | ||
89 | // the console commands are only registered for the root instance | ||
90 | if (m_RootInstance == null && MainConsole.Instance != null) | ||
91 | { | ||
92 | m_RootInstance = this; | ||
93 | MainConsole.Instance.Commands.AddCommand("Users", false, | ||
94 | "create user", | ||
95 | "create user [<first> [<last> [<pass> [<email> [<user id>]]]]]", | ||
96 | "Create a new user", HandleCreateUser); | ||
97 | |||
98 | MainConsole.Instance.Commands.AddCommand("Users", false, | ||
99 | "reset user password", | ||
100 | "reset user password [<first> [<last> [<password>]]]", | ||
101 | "Reset a user password", HandleResetUserPassword); | ||
102 | |||
103 | MainConsole.Instance.Commands.AddCommand("Users", false, | ||
104 | "reset user email", | ||
105 | "reset user email [<first> [<last> [<email>]]]", | ||
106 | "Reset a user email address", HandleResetUserEmail); | ||
107 | |||
108 | MainConsole.Instance.Commands.AddCommand("Users", false, | ||
109 | "set user level", | ||
110 | "set user level [<first> [<last> [<level>]]]", | ||
111 | "Set user level. If >= 200 and 'allow_grid_gods = true' in OpenSim.ini, " | ||
112 | + "this account will be treated as god-moded. " | ||
113 | + "It will also affect the 'login level' command. ", | ||
114 | HandleSetUserLevel); | ||
115 | |||
116 | MainConsole.Instance.Commands.AddCommand("Users", false, | ||
117 | "show account", | ||
118 | "show account <first> <last>", | ||
119 | "Show account details for the given user", HandleShowAccount); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | #region IUserAccountService | ||
124 | |||
125 | public UserAccount GetUserAccount(UUID scopeID, string firstName, | ||
126 | string lastName) | ||
127 | { | ||
128 | // m_log.DebugFormat( | ||
129 | // "[USER ACCOUNT SERVICE]: Retrieving account by username for {0} {1}, scope {2}", | ||
130 | // firstName, lastName, scopeID); | ||
131 | |||
132 | UserAccountData[] d; | ||
133 | |||
134 | if (scopeID != UUID.Zero) | ||
135 | { | ||
136 | d = m_Database.Get( | ||
137 | new string[] { "ScopeID", "FirstName", "LastName" }, | ||
138 | new string[] { scopeID.ToString(), firstName, lastName }); | ||
139 | if (d.Length < 1) | ||
140 | { | ||
141 | d = m_Database.Get( | ||
142 | new string[] { "ScopeID", "FirstName", "LastName" }, | ||
143 | new string[] { UUID.Zero.ToString(), firstName, lastName }); | ||
144 | } | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | d = m_Database.Get( | ||
149 | new string[] { "FirstName", "LastName" }, | ||
150 | new string[] { firstName, lastName }); | ||
151 | } | ||
152 | |||
153 | if (d.Length < 1) | ||
154 | return null; | ||
155 | |||
156 | return MakeUserAccount(d[0]); | ||
157 | } | ||
158 | |||
159 | private UserAccount MakeUserAccount(UserAccountData d) | ||
160 | { | ||
161 | UserAccount u = new UserAccount(); | ||
162 | u.FirstName = d.FirstName; | ||
163 | u.LastName = d.LastName; | ||
164 | u.PrincipalID = d.PrincipalID; | ||
165 | u.ScopeID = d.ScopeID; | ||
166 | if (d.Data.ContainsKey("Email") && d.Data["Email"] != null) | ||
167 | u.Email = d.Data["Email"].ToString(); | ||
168 | else | ||
169 | u.Email = string.Empty; | ||
170 | u.Created = Convert.ToInt32(d.Data["Created"].ToString()); | ||
171 | if (d.Data.ContainsKey("UserTitle") && d.Data["UserTitle"] != null) | ||
172 | u.UserTitle = d.Data["UserTitle"].ToString(); | ||
173 | else | ||
174 | u.UserTitle = string.Empty; | ||
175 | if (d.Data.ContainsKey("UserLevel") && d.Data["UserLevel"] != null) | ||
176 | Int32.TryParse(d.Data["UserLevel"], out u.UserLevel); | ||
177 | if (d.Data.ContainsKey("UserFlags") && d.Data["UserFlags"] != null) | ||
178 | Int32.TryParse(d.Data["UserFlags"], out u.UserFlags); | ||
179 | |||
180 | if (d.Data.ContainsKey("ServiceURLs") && d.Data["ServiceURLs"] != null) | ||
181 | { | ||
182 | string[] URLs = d.Data["ServiceURLs"].ToString().Split(new char[] { ' ' }); | ||
183 | u.ServiceURLs = new Dictionary<string, object>(); | ||
184 | |||
185 | foreach (string url in URLs) | ||
186 | { | ||
187 | string[] parts = url.Split(new char[] { '=' }); | ||
188 | |||
189 | if (parts.Length != 2) | ||
190 | continue; | ||
191 | |||
192 | string name = System.Web.HttpUtility.UrlDecode(parts[0]); | ||
193 | string val = System.Web.HttpUtility.UrlDecode(parts[1]); | ||
194 | |||
195 | u.ServiceURLs[name] = val; | ||
196 | } | ||
197 | } | ||
198 | else | ||
199 | u.ServiceURLs = new Dictionary<string, object>(); | ||
200 | |||
201 | return u; | ||
202 | } | ||
203 | |||
204 | public UserAccount GetUserAccount(UUID scopeID, string email) | ||
205 | { | ||
206 | UserAccountData[] d; | ||
207 | |||
208 | if (scopeID != UUID.Zero) | ||
209 | { | ||
210 | d = m_Database.Get( | ||
211 | new string[] { "ScopeID", "Email" }, | ||
212 | new string[] { scopeID.ToString(), email }); | ||
213 | if (d.Length < 1) | ||
214 | { | ||
215 | d = m_Database.Get( | ||
216 | new string[] { "ScopeID", "Email" }, | ||
217 | new string[] { UUID.Zero.ToString(), email }); | ||
218 | } | ||
219 | } | ||
220 | else | ||
221 | { | ||
222 | d = m_Database.Get( | ||
223 | new string[] { "Email" }, | ||
224 | new string[] { email }); | ||
225 | } | ||
226 | |||
227 | if (d.Length < 1) | ||
228 | return null; | ||
229 | |||
230 | return MakeUserAccount(d[0]); | ||
231 | } | ||
232 | |||
233 | public UserAccount GetUserAccount(UUID scopeID, UUID principalID) | ||
234 | { | ||
235 | UserAccountData[] d; | ||
236 | |||
237 | if (scopeID != UUID.Zero) | ||
238 | { | ||
239 | d = m_Database.Get( | ||
240 | new string[] { "ScopeID", "PrincipalID" }, | ||
241 | new string[] { scopeID.ToString(), principalID.ToString() }); | ||
242 | if (d.Length < 1) | ||
243 | { | ||
244 | d = m_Database.Get( | ||
245 | new string[] { "ScopeID", "PrincipalID" }, | ||
246 | new string[] { UUID.Zero.ToString(), principalID.ToString() }); | ||
247 | } | ||
248 | } | ||
249 | else | ||
250 | { | ||
251 | d = m_Database.Get( | ||
252 | new string[] { "PrincipalID" }, | ||
253 | new string[] { principalID.ToString() }); | ||
254 | } | ||
255 | |||
256 | if (d.Length < 1) | ||
257 | { | ||
258 | return null; | ||
259 | } | ||
260 | |||
261 | return MakeUserAccount(d[0]); | ||
262 | } | ||
263 | |||
264 | public void InvalidateCache(UUID userID) | ||
265 | { | ||
266 | } | ||
267 | |||
268 | public bool StoreUserAccount(UserAccount data) | ||
269 | { | ||
270 | // m_log.DebugFormat( | ||
271 | // "[USER ACCOUNT SERVICE]: Storing user account for {0} {1} {2}, scope {3}", | ||
272 | // data.FirstName, data.LastName, data.PrincipalID, data.ScopeID); | ||
273 | |||
274 | UserAccountData d = new UserAccountData(); | ||
275 | |||
276 | d.FirstName = data.FirstName; | ||
277 | d.LastName = data.LastName; | ||
278 | d.PrincipalID = data.PrincipalID; | ||
279 | d.ScopeID = data.ScopeID; | ||
280 | d.Data = new Dictionary<string, string>(); | ||
281 | d.Data["Email"] = data.Email; | ||
282 | d.Data["Created"] = data.Created.ToString(); | ||
283 | d.Data["UserLevel"] = data.UserLevel.ToString(); | ||
284 | d.Data["UserFlags"] = data.UserFlags.ToString(); | ||
285 | if (data.UserTitle != null) | ||
286 | d.Data["UserTitle"] = data.UserTitle.ToString(); | ||
287 | |||
288 | List<string> parts = new List<string>(); | ||
289 | |||
290 | foreach (KeyValuePair<string, object> kvp in data.ServiceURLs) | ||
291 | { | ||
292 | string key = System.Web.HttpUtility.UrlEncode(kvp.Key); | ||
293 | string val = System.Web.HttpUtility.UrlEncode(kvp.Value.ToString()); | ||
294 | parts.Add(key + "=" + val); | ||
295 | } | ||
296 | |||
297 | d.Data["ServiceURLs"] = string.Join(" ", parts.ToArray()); | ||
298 | |||
299 | return m_Database.Store(d); | ||
300 | } | ||
301 | |||
302 | public List<UserAccount> GetUserAccounts(UUID scopeID, string query) | ||
303 | { | ||
304 | UserAccountData[] d = m_Database.GetUsers(scopeID, query); | ||
305 | |||
306 | if (d == null) | ||
307 | return new List<UserAccount>(); | ||
308 | |||
309 | List<UserAccount> ret = new List<UserAccount>(); | ||
310 | |||
311 | foreach (UserAccountData data in d) | ||
312 | ret.Add(MakeUserAccount(data)); | ||
313 | |||
314 | return ret; | ||
315 | } | ||
316 | |||
317 | #endregion | ||
318 | |||
319 | #region Console commands | ||
320 | |||
321 | /// <summary> | ||
322 | /// Handle the create user command from the console. | ||
323 | /// </summary> | ||
324 | /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param> | ||
325 | protected void HandleCreateUser(string module, string[] cmdparams) | ||
326 | { | ||
327 | string firstName; | ||
328 | string lastName; | ||
329 | string password; | ||
330 | string email; | ||
331 | string rawPrincipalId; | ||
332 | |||
333 | List<char> excluded = new List<char>(new char[]{' '}); | ||
334 | |||
335 | if (cmdparams.Length < 3) | ||
336 | firstName = MainConsole.Instance.CmdPrompt("First name", "Default", excluded); | ||
337 | else firstName = cmdparams[2]; | ||
338 | |||
339 | if (cmdparams.Length < 4) | ||
340 | lastName = MainConsole.Instance.CmdPrompt("Last name", "User", excluded); | ||
341 | else lastName = cmdparams[3]; | ||
342 | |||
343 | if (cmdparams.Length < 5) | ||
344 | password = MainConsole.Instance.PasswdPrompt("Password"); | ||
345 | else password = cmdparams[4]; | ||
346 | |||
347 | if (cmdparams.Length < 6) | ||
348 | email = MainConsole.Instance.CmdPrompt("Email", ""); | ||
349 | else email = cmdparams[5]; | ||
350 | |||
351 | if (cmdparams.Length < 7) | ||
352 | rawPrincipalId = MainConsole.Instance.CmdPrompt("User ID", UUID.Random().ToString()); | ||
353 | else | ||
354 | rawPrincipalId = cmdparams[6]; | ||
355 | |||
356 | UUID principalId = UUID.Zero; | ||
357 | if (!UUID.TryParse(rawPrincipalId, out principalId)) | ||
358 | throw new Exception(string.Format("ID {0} is not a valid UUID", rawPrincipalId)); | ||
359 | |||
360 | CreateUser(UUID.Zero, principalId, firstName, lastName, password, email); | ||
361 | } | ||
362 | |||
363 | protected void HandleShowAccount(string module, string[] cmdparams) | ||
364 | { | ||
365 | if (cmdparams.Length != 4) | ||
366 | { | ||
367 | MainConsole.Instance.Output("Usage: show account <first-name> <last-name>"); | ||
368 | return; | ||
369 | } | ||
370 | |||
371 | string firstName = cmdparams[2]; | ||
372 | string lastName = cmdparams[3]; | ||
373 | |||
374 | UserAccount ua = GetUserAccount(UUID.Zero, firstName, lastName); | ||
375 | |||
376 | if (ua == null) | ||
377 | { | ||
378 | MainConsole.Instance.OutputFormat("No user named {0} {1}", firstName, lastName); | ||
379 | return; | ||
380 | } | ||
381 | |||
382 | MainConsole.Instance.OutputFormat("Name: {0}", ua.Name); | ||
383 | MainConsole.Instance.OutputFormat("ID: {0}", ua.PrincipalID); | ||
384 | MainConsole.Instance.OutputFormat("Title: {0}", ua.UserTitle); | ||
385 | MainConsole.Instance.OutputFormat("E-mail: {0}", ua.Email); | ||
386 | MainConsole.Instance.OutputFormat("Created: {0}", Utils.UnixTimeToDateTime(ua.Created)); | ||
387 | MainConsole.Instance.OutputFormat("Level: {0}", ua.UserLevel); | ||
388 | MainConsole.Instance.OutputFormat("Flags: {0}", ua.UserFlags); | ||
389 | foreach (KeyValuePair<string, Object> kvp in ua.ServiceURLs) | ||
390 | MainConsole.Instance.OutputFormat("{0}: {1}", kvp.Key, kvp.Value); | ||
391 | } | ||
392 | |||
393 | protected void HandleResetUserPassword(string module, string[] cmdparams) | ||
394 | { | ||
395 | string firstName; | ||
396 | string lastName; | ||
397 | string newPassword; | ||
398 | |||
399 | if (cmdparams.Length < 4) | ||
400 | firstName = MainConsole.Instance.CmdPrompt("First name"); | ||
401 | else firstName = cmdparams[3]; | ||
402 | |||
403 | if (cmdparams.Length < 5) | ||
404 | lastName = MainConsole.Instance.CmdPrompt("Last name"); | ||
405 | else lastName = cmdparams[4]; | ||
406 | |||
407 | if (cmdparams.Length < 6) | ||
408 | newPassword = MainConsole.Instance.PasswdPrompt("New password"); | ||
409 | else newPassword = cmdparams[5]; | ||
410 | |||
411 | UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName); | ||
412 | if (account == null) | ||
413 | { | ||
414 | MainConsole.Instance.OutputFormat("No such user as {0} {1}", firstName, lastName); | ||
415 | return; | ||
416 | } | ||
417 | |||
418 | bool success = false; | ||
419 | if (m_AuthenticationService != null) | ||
420 | success = m_AuthenticationService.SetPassword(account.PrincipalID, newPassword); | ||
421 | |||
422 | if (!success) | ||
423 | MainConsole.Instance.OutputFormat("Unable to reset password for account {0} {1}.", firstName, lastName); | ||
424 | else | ||
425 | MainConsole.Instance.OutputFormat("Password reset for user {0} {1}", firstName, lastName); | ||
426 | } | ||
427 | |||
428 | protected void HandleResetUserEmail(string module, string[] cmdparams) | ||
429 | { | ||
430 | string firstName; | ||
431 | string lastName; | ||
432 | string newEmail; | ||
433 | |||
434 | if (cmdparams.Length < 4) | ||
435 | firstName = MainConsole.Instance.CmdPrompt("First name"); | ||
436 | else firstName = cmdparams[3]; | ||
437 | |||
438 | if (cmdparams.Length < 5) | ||
439 | lastName = MainConsole.Instance.CmdPrompt("Last name"); | ||
440 | else lastName = cmdparams[4]; | ||
441 | |||
442 | if (cmdparams.Length < 6) | ||
443 | newEmail = MainConsole.Instance.PasswdPrompt("New Email"); | ||
444 | else newEmail = cmdparams[5]; | ||
445 | |||
446 | UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName); | ||
447 | if (account == null) | ||
448 | { | ||
449 | MainConsole.Instance.OutputFormat("No such user as {0} {1}", firstName, lastName); | ||
450 | return; | ||
451 | } | ||
452 | |||
453 | bool success = false; | ||
454 | |||
455 | account.Email = newEmail; | ||
456 | |||
457 | success = StoreUserAccount(account); | ||
458 | if (!success) | ||
459 | MainConsole.Instance.OutputFormat("Unable to set Email for account {0} {1}.", firstName, lastName); | ||
460 | else | ||
461 | MainConsole.Instance.OutputFormat("User Email set for user {0} {1} to {2}", firstName, lastName, account.Email); | ||
462 | } | ||
463 | |||
464 | |||
465 | protected void HandleSetUserLevel(string module, string[] cmdparams) | ||
466 | { | ||
467 | string firstName; | ||
468 | string lastName; | ||
469 | string rawLevel; | ||
470 | int level; | ||
471 | |||
472 | if (cmdparams.Length < 4) | ||
473 | firstName = MainConsole.Instance.CmdPrompt("First name"); | ||
474 | else firstName = cmdparams[3]; | ||
475 | |||
476 | if (cmdparams.Length < 5) | ||
477 | lastName = MainConsole.Instance.CmdPrompt("Last name"); | ||
478 | else lastName = cmdparams[4]; | ||
479 | |||
480 | UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName); | ||
481 | if (account == null) { | ||
482 | MainConsole.Instance.OutputFormat("No such user"); | ||
483 | return; | ||
484 | } | ||
485 | |||
486 | if (cmdparams.Length < 6) | ||
487 | rawLevel = MainConsole.Instance.CmdPrompt("User level"); | ||
488 | else rawLevel = cmdparams[5]; | ||
489 | |||
490 | if(int.TryParse(rawLevel, out level) == false) { | ||
491 | MainConsole.Instance.OutputFormat("Invalid user level"); | ||
492 | return; | ||
493 | } | ||
494 | |||
495 | account.UserLevel = level; | ||
496 | |||
497 | bool success = StoreUserAccount(account); | ||
498 | if (!success) | ||
499 | MainConsole.Instance.OutputFormat("Unable to set user level for account {0} {1}.", firstName, lastName); | ||
500 | else | ||
501 | MainConsole.Instance.OutputFormat("User level set for user {0} {1} to {2}", firstName, lastName, level); | ||
502 | } | ||
503 | |||
504 | #endregion | ||
505 | |||
506 | /// <summary> | ||
507 | /// Create a user | ||
508 | /// </summary> | ||
509 | /// <param name="scopeID">Allows hosting of multiple grids in a single database. Normally left as UUID.Zero</param> | ||
510 | /// <param name="principalID">ID of the user</param> | ||
511 | /// <param name="firstName"></param> | ||
512 | /// <param name="lastName"></param> | ||
513 | /// <param name="password"></param> | ||
514 | /// <param name="email"></param> | ||
515 | public UserAccount CreateUser(UUID scopeID, UUID principalID, string firstName, string lastName, string password, string email) | ||
516 | { | ||
517 | UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName); | ||
518 | if (null == account) | ||
519 | { | ||
520 | account = new UserAccount(UUID.Zero, principalID, firstName, lastName, email); | ||
521 | if (account.ServiceURLs == null || (account.ServiceURLs != null && account.ServiceURLs.Count == 0)) | ||
522 | { | ||
523 | account.ServiceURLs = new Dictionary<string, object>(); | ||
524 | account.ServiceURLs["HomeURI"] = string.Empty; | ||
525 | account.ServiceURLs["InventoryServerURI"] = string.Empty; | ||
526 | account.ServiceURLs["AssetServerURI"] = string.Empty; | ||
527 | } | ||
528 | |||
529 | if (StoreUserAccount(account)) | ||
530 | { | ||
531 | bool success; | ||
532 | if (m_AuthenticationService != null) | ||
533 | { | ||
534 | success = m_AuthenticationService.SetPassword(account.PrincipalID, password); | ||
535 | if (!success) | ||
536 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set password for account {0} {1}.", | ||
537 | firstName, lastName); | ||
538 | } | ||
539 | |||
540 | GridRegion home = null; | ||
541 | if (m_GridService != null) | ||
542 | { | ||
543 | List<GridRegion> defaultRegions = m_GridService.GetDefaultRegions(UUID.Zero); | ||
544 | if (defaultRegions != null && defaultRegions.Count >= 1) | ||
545 | home = defaultRegions[0]; | ||
546 | |||
547 | if (m_GridUserService != null && home != null) | ||
548 | m_GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); | ||
549 | else | ||
550 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.", | ||
551 | firstName, lastName); | ||
552 | } | ||
553 | else | ||
554 | { | ||
555 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to retrieve home region for account {0} {1}.", | ||
556 | firstName, lastName); | ||
557 | } | ||
558 | |||
559 | if (m_InventoryService != null) | ||
560 | { | ||
561 | success = m_InventoryService.CreateUserInventory(account.PrincipalID); | ||
562 | if (!success) | ||
563 | { | ||
564 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to create inventory for account {0} {1}.", | ||
565 | firstName, lastName); | ||
566 | } | ||
567 | else | ||
568 | { | ||
569 | m_log.DebugFormat( | ||
570 | "[USER ACCOUNT SERVICE]: Created user inventory for {0} {1}", firstName, lastName); | ||
571 | } | ||
572 | |||
573 | if (m_CreateDefaultAvatarEntries) | ||
574 | CreateDefaultAppearanceEntries(account.PrincipalID); | ||
575 | } | ||
576 | |||
577 | m_log.InfoFormat( | ||
578 | "[USER ACCOUNT SERVICE]: Account {0} {1} {2} created successfully", | ||
579 | firstName, lastName, account.PrincipalID); | ||
580 | } | ||
581 | else | ||
582 | { | ||
583 | m_log.ErrorFormat("[USER ACCOUNT SERVICE]: Account creation failed for account {0} {1}", firstName, lastName); | ||
584 | } | ||
585 | } | ||
586 | else | ||
587 | { | ||
588 | m_log.ErrorFormat("[USER ACCOUNT SERVICE]: A user with the name {0} {1} already exists!", firstName, lastName); | ||
589 | } | ||
590 | |||
591 | return account; | ||
592 | } | ||
593 | |||
594 | protected void CreateDefaultAppearanceEntries(UUID principalID) | ||
595 | { | ||
596 | m_log.DebugFormat("[USER ACCOUNT SERVICE]: Creating default appearance items for {0}", principalID); | ||
597 | |||
598 | InventoryFolderBase bodyPartsFolder = m_InventoryService.GetFolderForType(principalID, FolderType.BodyPart); | ||
599 | |||
600 | InventoryItemBase eyes = new InventoryItemBase(UUID.Random(), principalID); | ||
601 | eyes.AssetID = new UUID("4bb6fa4d-1cd2-498a-a84c-95c1a0e745a7"); | ||
602 | eyes.Name = "Default Eyes"; | ||
603 | eyes.CreatorId = principalID.ToString(); | ||
604 | eyes.AssetType = (int)AssetType.Bodypart; | ||
605 | eyes.InvType = (int)InventoryType.Wearable; | ||
606 | eyes.Folder = bodyPartsFolder.ID; | ||
607 | eyes.BasePermissions = (uint)PermissionMask.All; | ||
608 | eyes.CurrentPermissions = (uint)PermissionMask.All; | ||
609 | eyes.EveryOnePermissions = (uint)PermissionMask.All; | ||
610 | eyes.GroupPermissions = (uint)PermissionMask.All; | ||
611 | eyes.NextPermissions = (uint)PermissionMask.All; | ||
612 | eyes.Flags = (uint)WearableType.Eyes; | ||
613 | m_InventoryService.AddItem(eyes); | ||
614 | |||
615 | InventoryItemBase shape = new InventoryItemBase(UUID.Random(), principalID); | ||
616 | shape.AssetID = AvatarWearable.DEFAULT_BODY_ASSET; | ||
617 | shape.Name = "Default Shape"; | ||
618 | shape.CreatorId = principalID.ToString(); | ||
619 | shape.AssetType = (int)AssetType.Bodypart; | ||
620 | shape.InvType = (int)InventoryType.Wearable; | ||
621 | shape.Folder = bodyPartsFolder.ID; | ||
622 | shape.BasePermissions = (uint)PermissionMask.All; | ||
623 | shape.CurrentPermissions = (uint)PermissionMask.All; | ||
624 | shape.EveryOnePermissions = (uint)PermissionMask.All; | ||
625 | shape.GroupPermissions = (uint)PermissionMask.All; | ||
626 | shape.NextPermissions = (uint)PermissionMask.All; | ||
627 | shape.Flags = (uint)WearableType.Shape; | ||
628 | m_InventoryService.AddItem(shape); | ||
629 | |||
630 | InventoryItemBase skin = new InventoryItemBase(UUID.Random(), principalID); | ||
631 | skin.AssetID = AvatarWearable.DEFAULT_SKIN_ASSET; | ||
632 | skin.Name = "Default Skin"; | ||
633 | skin.CreatorId = principalID.ToString(); | ||
634 | skin.AssetType = (int)AssetType.Bodypart; | ||
635 | skin.InvType = (int)InventoryType.Wearable; | ||
636 | skin.Folder = bodyPartsFolder.ID; | ||
637 | skin.BasePermissions = (uint)PermissionMask.All; | ||
638 | skin.CurrentPermissions = (uint)PermissionMask.All; | ||
639 | skin.EveryOnePermissions = (uint)PermissionMask.All; | ||
640 | skin.GroupPermissions = (uint)PermissionMask.All; | ||
641 | skin.NextPermissions = (uint)PermissionMask.All; | ||
642 | skin.Flags = (uint)WearableType.Skin; | ||
643 | m_InventoryService.AddItem(skin); | ||
644 | |||
645 | InventoryItemBase hair = new InventoryItemBase(UUID.Random(), principalID); | ||
646 | hair.AssetID = AvatarWearable.DEFAULT_HAIR_ASSET; | ||
647 | hair.Name = "Default Hair"; | ||
648 | hair.CreatorId = principalID.ToString(); | ||
649 | hair.AssetType = (int)AssetType.Bodypart; | ||
650 | hair.InvType = (int)InventoryType.Wearable; | ||
651 | hair.Folder = bodyPartsFolder.ID; | ||
652 | hair.BasePermissions = (uint)PermissionMask.All; | ||
653 | hair.CurrentPermissions = (uint)PermissionMask.All; | ||
654 | hair.EveryOnePermissions = (uint)PermissionMask.All; | ||
655 | hair.GroupPermissions = (uint)PermissionMask.All; | ||
656 | hair.NextPermissions = (uint)PermissionMask.All; | ||
657 | hair.Flags = (uint)WearableType.Hair; | ||
658 | m_InventoryService.AddItem(hair); | ||
659 | |||
660 | InventoryFolderBase clothingFolder = m_InventoryService.GetFolderForType(principalID, FolderType.Clothing); | ||
661 | |||
662 | InventoryItemBase shirt = new InventoryItemBase(UUID.Random(), principalID); | ||
663 | shirt.AssetID = AvatarWearable.DEFAULT_SHIRT_ASSET; | ||
664 | shirt.Name = "Default Shirt"; | ||
665 | shirt.CreatorId = principalID.ToString(); | ||
666 | shirt.AssetType = (int)AssetType.Clothing; | ||
667 | shirt.InvType = (int)InventoryType.Wearable; | ||
668 | shirt.Folder = clothingFolder.ID; | ||
669 | shirt.BasePermissions = (uint)PermissionMask.All; | ||
670 | shirt.CurrentPermissions = (uint)PermissionMask.All; | ||
671 | shirt.EveryOnePermissions = (uint)PermissionMask.All; | ||
672 | shirt.GroupPermissions = (uint)PermissionMask.All; | ||
673 | shirt.NextPermissions = (uint)PermissionMask.All; | ||
674 | shirt.Flags = (uint)WearableType.Shirt; | ||
675 | m_InventoryService.AddItem(shirt); | ||
676 | |||
677 | InventoryItemBase pants = new InventoryItemBase(UUID.Random(), principalID); | ||
678 | pants.AssetID = AvatarWearable.DEFAULT_PANTS_ASSET; | ||
679 | pants.Name = "Default Pants"; | ||
680 | pants.CreatorId = principalID.ToString(); | ||
681 | pants.AssetType = (int)AssetType.Clothing; | ||
682 | pants.InvType = (int)InventoryType.Wearable; | ||
683 | pants.Folder = clothingFolder.ID; | ||
684 | pants.BasePermissions = (uint)PermissionMask.All; | ||
685 | pants.CurrentPermissions = (uint)PermissionMask.All; | ||
686 | pants.EveryOnePermissions = (uint)PermissionMask.All; | ||
687 | pants.GroupPermissions = (uint)PermissionMask.All; | ||
688 | pants.NextPermissions = (uint)PermissionMask.All; | ||
689 | pants.Flags = (uint)WearableType.Pants; | ||
690 | m_InventoryService.AddItem(pants); | ||
691 | |||
692 | if (m_AvatarService != null) | ||
693 | { | ||
694 | m_log.DebugFormat("[USER ACCOUNT SERVICE]: Creating default avatar entries for {0}", principalID); | ||
695 | |||
696 | AvatarWearable[] wearables = new AvatarWearable[6]; | ||
697 | wearables[AvatarWearable.EYES] = new AvatarWearable(eyes.ID, eyes.AssetID); | ||
698 | wearables[AvatarWearable.BODY] = new AvatarWearable(shape.ID, shape.AssetID); | ||
699 | wearables[AvatarWearable.SKIN] = new AvatarWearable(skin.ID, skin.AssetID); | ||
700 | wearables[AvatarWearable.HAIR] = new AvatarWearable(hair.ID, hair.AssetID); | ||
701 | wearables[AvatarWearable.SHIRT] = new AvatarWearable(shirt.ID, shirt.AssetID); | ||
702 | wearables[AvatarWearable.PANTS] = new AvatarWearable(pants.ID, pants.AssetID); | ||
703 | |||
704 | AvatarAppearance ap = new AvatarAppearance(); | ||
705 | for (int i = 0; i < 6; i++) | ||
706 | { | ||
707 | ap.SetWearable(i, wearables[i]); | ||
708 | } | ||
709 | |||
710 | m_AvatarService.SetAppearance(principalID, ap); | ||
711 | } | ||
712 | } | ||
713 | } | ||
714 | } | ||
diff --git a/OpenSim/Services/UserAccountService/UserAccountServiceBase.cs b/OpenSim/Services/UserAccountService/UserAccountServiceBase.cs new file mode 100644 index 0000000..c1a7b76 --- /dev/null +++ b/OpenSim/Services/UserAccountService/UserAccountServiceBase.cs | |||
@@ -0,0 +1,73 @@ | |||
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.Reflection; | ||
30 | using Nini.Config; | ||
31 | using OpenSim.Data; | ||
32 | using OpenSim.Services.Interfaces; | ||
33 | using OpenSim.Services.Base; | ||
34 | |||
35 | namespace OpenSim.Services.UserAccountService | ||
36 | { | ||
37 | public class UserAccountServiceBase: ServiceBase | ||
38 | { | ||
39 | protected IUserAccountData m_Database = null; | ||
40 | |||
41 | public UserAccountServiceBase(IConfigSource config) : base(config) | ||
42 | { | ||
43 | string dllName = String.Empty; | ||
44 | string connString = String.Empty; | ||
45 | string realm = "UserAccounts"; | ||
46 | |||
47 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
48 | if (dbConfig != null) | ||
49 | { | ||
50 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
51 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
52 | } | ||
53 | |||
54 | IConfig userConfig = config.Configs["UserAccountService"]; | ||
55 | if (userConfig == null) | ||
56 | throw new Exception("No UserAccountService configuration"); | ||
57 | |||
58 | dllName = userConfig.GetString("StorageProvider", dllName); | ||
59 | |||
60 | if (dllName == String.Empty) | ||
61 | throw new Exception("No StorageProvider configured"); | ||
62 | |||
63 | connString = userConfig.GetString("ConnectionString", connString); | ||
64 | |||
65 | realm = userConfig.GetString("Realm", realm); | ||
66 | |||
67 | m_Database = LoadPlugin<IUserAccountData>(dllName, new Object[] {connString, realm}); | ||
68 | |||
69 | if (m_Database == null) | ||
70 | throw new Exception("Could not find a storage interface in the given module"); | ||
71 | } | ||
72 | } | ||
73 | } | ||