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