diff options
author | lbsa71 | 2007-09-24 07:30:30 +0000 |
---|---|---|
committer | lbsa71 | 2007-09-24 07:30:30 +0000 |
commit | 1302ef44e3c632159378bc4042c753bcf36e9c63 (patch) | |
tree | 6b6295ac233ecb05afe6432a903ec616e4fa079a /OpenSim/Framework/Communications/UserManagerBase.cs | |
parent | * Trying to streamline CommunicationsManager (diff) | |
download | opensim-SC_OLD-1302ef44e3c632159378bc4042c753bcf36e9c63.zip opensim-SC_OLD-1302ef44e3c632159378bc4042c753bcf36e9c63.tar.gz opensim-SC_OLD-1302ef44e3c632159378bc4042c753bcf36e9c63.tar.bz2 opensim-SC_OLD-1302ef44e3c632159378bc4042c753bcf36e9c63.tar.xz |
* Started major restructusing of comms to prepare for better grid and region functionality
* Working towards one shared set of services
* Killed off two projects with very little functionality
Diffstat (limited to 'OpenSim/Framework/Communications/UserManagerBase.cs')
-rw-r--r-- | OpenSim/Framework/Communications/UserManagerBase.cs | 379 |
1 files changed, 379 insertions, 0 deletions
diff --git a/OpenSim/Framework/Communications/UserManagerBase.cs b/OpenSim/Framework/Communications/UserManagerBase.cs new file mode 100644 index 0000000..d1bbde1 --- /dev/null +++ b/OpenSim/Framework/Communications/UserManagerBase.cs | |||
@@ -0,0 +1,379 @@ | |||
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 OpenSim 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 | |||
29 | using System; | ||
30 | using System.Collections; | ||
31 | using System.Collections.Generic; | ||
32 | using System.Reflection; | ||
33 | using System.Security.Cryptography; | ||
34 | using libsecondlife; | ||
35 | using Nwc.XmlRpc; | ||
36 | using OpenSim.Framework.Communications; | ||
37 | using OpenSim.Framework.Configuration; | ||
38 | using OpenSim.Framework.Console; | ||
39 | using OpenSim.Framework.Data; | ||
40 | using OpenSim.Framework.Utilities; | ||
41 | |||
42 | namespace OpenSim.Framework.UserManagement | ||
43 | { | ||
44 | public abstract class UserManagerBase : IUserServices | ||
45 | { | ||
46 | public UserConfig _config; | ||
47 | Dictionary<string, IUserData> _plugins = new Dictionary<string, IUserData>(); | ||
48 | |||
49 | /// <summary> | ||
50 | /// Adds a new user server plugin - user servers will be requested in the order they were loaded. | ||
51 | /// </summary> | ||
52 | /// <param name="FileName">The filename to the user server plugin DLL</param> | ||
53 | public void AddPlugin(string FileName) | ||
54 | { | ||
55 | if (!String.IsNullOrEmpty(FileName)) | ||
56 | { | ||
57 | MainLog.Instance.Verbose("Userstorage: Attempting to load " + FileName); | ||
58 | Assembly pluginAssembly = Assembly.LoadFrom(FileName); | ||
59 | |||
60 | MainLog.Instance.Verbose("Userstorage: Found " + pluginAssembly.GetTypes().Length + " interfaces."); | ||
61 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
62 | { | ||
63 | if (!pluginType.IsAbstract) | ||
64 | { | ||
65 | Type typeInterface = pluginType.GetInterface("IUserData", true); | ||
66 | |||
67 | if (typeInterface != null) | ||
68 | { | ||
69 | IUserData plug = | ||
70 | (IUserData) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
71 | AddPlugin(plug); | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | public void AddPlugin(IUserData plug) | ||
79 | { | ||
80 | plug.Initialise(); | ||
81 | this._plugins.Add(plug.getName(), plug); | ||
82 | MainLog.Instance.Verbose( "Userstorage: Added IUserData Interface"); | ||
83 | } | ||
84 | |||
85 | #region Get UserProfile | ||
86 | /// <summary> | ||
87 | /// Loads a user profile from a database by UUID | ||
88 | /// </summary> | ||
89 | /// <param name="uuid">The target UUID</param> | ||
90 | /// <returns>A user profile</returns> | ||
91 | public UserProfileData GetUserProfile(LLUUID uuid) | ||
92 | { | ||
93 | foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||
94 | { | ||
95 | try | ||
96 | { | ||
97 | UserProfileData profile = plugin.Value.GetUserByUUID(uuid); | ||
98 | profile.currentAgent = getUserAgent(profile.UUID); | ||
99 | return profile; | ||
100 | } | ||
101 | catch (Exception e) | ||
102 | { | ||
103 | MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | return null; | ||
108 | } | ||
109 | |||
110 | |||
111 | /// <summary> | ||
112 | /// Loads a user profile by name | ||
113 | /// </summary> | ||
114 | /// <param name="name">The target name</param> | ||
115 | /// <returns>A user profile</returns> | ||
116 | public UserProfileData GetUserProfile(string name) | ||
117 | { | ||
118 | foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||
119 | { | ||
120 | try | ||
121 | { | ||
122 | UserProfileData profile = plugin.Value.GetUserByName(name); | ||
123 | profile.currentAgent = getUserAgent(profile.UUID); | ||
124 | return profile; | ||
125 | } | ||
126 | catch (Exception e) | ||
127 | { | ||
128 | System.Console.WriteLine("EEK!"); | ||
129 | MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); | ||
130 | } | ||
131 | } | ||
132 | |||
133 | return null; | ||
134 | } | ||
135 | |||
136 | /// <summary> | ||
137 | /// Loads a user profile by name | ||
138 | /// </summary> | ||
139 | /// <param name="fname">First name</param> | ||
140 | /// <param name="lname">Last name</param> | ||
141 | /// <returns>A user profile</returns> | ||
142 | public UserProfileData GetUserProfile(string fname, string lname) | ||
143 | { | ||
144 | foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||
145 | { | ||
146 | try | ||
147 | { | ||
148 | UserProfileData profile = plugin.Value.GetUserByName(fname,lname); | ||
149 | |||
150 | profile.currentAgent = getUserAgent(profile.UUID); | ||
151 | |||
152 | return profile; | ||
153 | } | ||
154 | catch (Exception e) | ||
155 | { | ||
156 | MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | return null; | ||
161 | } | ||
162 | |||
163 | /// <summary> | ||
164 | /// Set's user profile from object | ||
165 | /// </summary> | ||
166 | /// <param name="fname">First name</param> | ||
167 | /// <param name="lname">Last name</param> | ||
168 | /// <returns>A user profile</returns> | ||
169 | public bool setUserProfile(UserProfileData data) | ||
170 | { | ||
171 | foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||
172 | { | ||
173 | try { | ||
174 | plugin.Value.UpdateUserProfile(data); | ||
175 | return true; | ||
176 | } catch (Exception e) { | ||
177 | MainLog.Instance.Verbose( "Unable to set user via " + plugin.Key + "(" + e.ToString() + ")"); | ||
178 | } | ||
179 | } | ||
180 | |||
181 | return false; | ||
182 | } | ||
183 | |||
184 | #endregion | ||
185 | |||
186 | #region Get UserAgent | ||
187 | /// <summary> | ||
188 | /// Loads a user agent by uuid (not called directly) | ||
189 | /// </summary> | ||
190 | /// <param name="uuid">The agents UUID</param> | ||
191 | /// <returns>Agent profiles</returns> | ||
192 | public UserAgentData getUserAgent(LLUUID uuid) | ||
193 | { | ||
194 | foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||
195 | { | ||
196 | try | ||
197 | { | ||
198 | return plugin.Value.GetAgentByUUID(uuid); | ||
199 | } | ||
200 | catch (Exception e) | ||
201 | { | ||
202 | MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | return null; | ||
207 | } | ||
208 | |||
209 | /// <summary> | ||
210 | /// Loads a user agent by name (not called directly) | ||
211 | /// </summary> | ||
212 | /// <param name="name">The agents name</param> | ||
213 | /// <returns>A user agent</returns> | ||
214 | public UserAgentData getUserAgent(string name) | ||
215 | { | ||
216 | foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||
217 | { | ||
218 | try | ||
219 | { | ||
220 | return plugin.Value.GetAgentByName(name); | ||
221 | } | ||
222 | catch (Exception e) | ||
223 | { | ||
224 | MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); | ||
225 | } | ||
226 | } | ||
227 | |||
228 | return null; | ||
229 | } | ||
230 | |||
231 | // TODO: document | ||
232 | public void clearUserAgent(LLUUID agentID) | ||
233 | { | ||
234 | UserProfileData profile = GetUserProfile(agentID); | ||
235 | profile.currentAgent = null; | ||
236 | setUserProfile(profile); | ||
237 | } | ||
238 | |||
239 | |||
240 | /// <summary> | ||
241 | /// Loads a user agent by name (not called directly) | ||
242 | /// </summary> | ||
243 | /// <param name="fname">The agents firstname</param> | ||
244 | /// <param name="lname">The agents lastname</param> | ||
245 | /// <returns>A user agent</returns> | ||
246 | public UserAgentData getUserAgent(string fname, string lname) | ||
247 | { | ||
248 | foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||
249 | { | ||
250 | try | ||
251 | { | ||
252 | return plugin.Value.GetAgentByName(fname,lname); | ||
253 | } | ||
254 | catch (Exception e) | ||
255 | { | ||
256 | MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); | ||
257 | } | ||
258 | } | ||
259 | |||
260 | return null; | ||
261 | } | ||
262 | |||
263 | #endregion | ||
264 | |||
265 | #region CreateAgent | ||
266 | /// <summary> | ||
267 | /// Creates and initialises a new user agent - make sure to use CommitAgent when done to submit to the DB | ||
268 | /// </summary> | ||
269 | /// <param name="profile">The users profile</param> | ||
270 | /// <param name="request">The users loginrequest</param> | ||
271 | public void CreateAgent(UserProfileData profile, XmlRpcRequest request) | ||
272 | { | ||
273 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
274 | |||
275 | UserAgentData agent = new UserAgentData(); | ||
276 | |||
277 | // User connection | ||
278 | agent.agentOnline = true; | ||
279 | |||
280 | // Generate sessions | ||
281 | RNGCryptoServiceProvider rand = new RNGCryptoServiceProvider(); | ||
282 | byte[] randDataS = new byte[16]; | ||
283 | byte[] randDataSS = new byte[16]; | ||
284 | rand.GetBytes(randDataS); | ||
285 | rand.GetBytes(randDataSS); | ||
286 | |||
287 | agent.secureSessionID = new LLUUID(randDataSS, 0); | ||
288 | agent.sessionID = new LLUUID(randDataS, 0); | ||
289 | |||
290 | // Profile UUID | ||
291 | agent.UUID = profile.UUID; | ||
292 | |||
293 | // Current position (from Home) | ||
294 | agent.currentHandle = profile.homeRegion; | ||
295 | agent.currentPos = profile.homeLocation; | ||
296 | |||
297 | // If user specified additional start, use that | ||
298 | if (requestData.ContainsKey("start")) | ||
299 | { | ||
300 | string startLoc = ((string)requestData["start"]).Trim(); | ||
301 | if (!(startLoc == "last" || startLoc == "home")) | ||
302 | { | ||
303 | // Format: uri:Ahern&162&213&34 | ||
304 | try | ||
305 | { | ||
306 | string[] parts = startLoc.Remove(0, 4).Split('&'); | ||
307 | string region = parts[0]; | ||
308 | |||
309 | //////////////////////////////////////////////////// | ||
310 | //SimProfile SimInfo = new SimProfile(); | ||
311 | //SimInfo = SimInfo.LoadFromGrid(theUser.currentAgent.currentHandle, _config.GridServerURL, _config.GridSendKey, _config.GridRecvKey); | ||
312 | } | ||
313 | catch (Exception) | ||
314 | { | ||
315 | |||
316 | } | ||
317 | } | ||
318 | } | ||
319 | |||
320 | // What time did the user login? | ||
321 | agent.loginTime = Util.UnixTimeSinceEpoch(); | ||
322 | agent.logoutTime = 0; | ||
323 | |||
324 | // Current location | ||
325 | agent.regionID = new LLUUID(); // Fill in later | ||
326 | agent.currentRegion = new LLUUID(); // Fill in later | ||
327 | |||
328 | profile.currentAgent = agent; | ||
329 | } | ||
330 | |||
331 | /// <summary> | ||
332 | /// Saves a target agent to the database | ||
333 | /// </summary> | ||
334 | /// <param name="profile">The users profile</param> | ||
335 | /// <returns>Successful?</returns> | ||
336 | public bool CommitAgent(ref UserProfileData profile) | ||
337 | { | ||
338 | // Saves the agent to database | ||
339 | return true; | ||
340 | } | ||
341 | |||
342 | #endregion | ||
343 | |||
344 | /// <summary> | ||
345 | /// | ||
346 | /// </summary> | ||
347 | /// <param name="user"></param> | ||
348 | public void AddUserProfile(string firstName, string lastName, string pass, uint regX, uint regY) | ||
349 | { | ||
350 | UserProfileData user = new UserProfileData(); | ||
351 | user.homeLocation = new LLVector3(128, 128, 100); | ||
352 | user.UUID = LLUUID.Random(); | ||
353 | user.username = firstName; | ||
354 | user.surname = lastName; | ||
355 | user.passwordHash = pass; | ||
356 | user.passwordSalt = ""; | ||
357 | user.created = Util.UnixTimeSinceEpoch(); | ||
358 | user.homeLookAt = new LLVector3(100, 100, 100); | ||
359 | user.homeRegionX = regX; | ||
360 | user.homeRegionY = regY; | ||
361 | |||
362 | foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||
363 | { | ||
364 | try | ||
365 | { | ||
366 | plugin.Value.AddNewUserProfile(user); | ||
367 | |||
368 | } | ||
369 | catch (Exception e) | ||
370 | { | ||
371 | MainLog.Instance.Verbose("Unable to add user via " + plugin.Key + "(" + e.ToString() + ")"); | ||
372 | } | ||
373 | } | ||
374 | } | ||
375 | |||
376 | public abstract UserProfileData SetupMasterUser(string firstName, string lastName); | ||
377 | public abstract UserProfileData SetupMasterUser(string firstName, string lastName, string password); | ||
378 | } | ||
379 | } | ||