aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/UserManager
diff options
context:
space:
mode:
authorAdam Frisby2007-07-11 08:10:25 +0000
committerAdam Frisby2007-07-11 08:10:25 +0000
commite2ff441e31328e60c8bb1d4bb32fa4ac64f91978 (patch)
tree8405b6cef57b66a58f31a24c859846085d0b81f7 /OpenSim/Framework/UserManager
parent* Wiping trunk in prep for Sugilite (diff)
parent* Applying dalien's patches from bug#177 and #179 (diff)
downloadopensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.zip
opensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.gz
opensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.bz2
opensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.xz
* Bringing Sugilite in to trunk
Diffstat (limited to 'OpenSim/Framework/UserManager')
-rw-r--r--OpenSim/Framework/UserManager/LoginResponse.cs643
-rw-r--r--OpenSim/Framework/UserManager/UserManagerBase.cs630
2 files changed, 1273 insertions, 0 deletions
diff --git a/OpenSim/Framework/UserManager/LoginResponse.cs b/OpenSim/Framework/UserManager/LoginResponse.cs
new file mode 100644
index 0000000..abcbd48
--- /dev/null
+++ b/OpenSim/Framework/UserManager/LoginResponse.cs
@@ -0,0 +1,643 @@
1using System;
2using System.Collections;
3using libsecondlife;
4using Nwc.XmlRpc;
5using OpenSim.Framework.Console;
6
7namespace OpenSim.Framework.UserManagement
8{
9
10 /// <summary>
11 /// A temp class to handle login response.
12 /// Should make use of UserProfileManager where possible.
13 /// </summary>
14
15 public class LoginResponse
16 {
17 private Hashtable loginFlagsHash;
18 private Hashtable globalTexturesHash;
19 private Hashtable loginError;
20 private Hashtable eventCategoriesHash;
21 private Hashtable uiConfigHash;
22 private Hashtable classifiedCategoriesHash;
23
24 private ArrayList loginFlags;
25 private ArrayList globalTextures;
26 private ArrayList eventCategories;
27 private ArrayList uiConfig;
28 private ArrayList classifiedCategories;
29 private ArrayList inventoryRoot;
30 private ArrayList initialOutfit;
31 private ArrayList agentInventory;
32
33 private UserInfo userProfile;
34
35 private LLUUID agentID;
36 private LLUUID sessionID;
37 private LLUUID secureSessionID;
38
39 // Login Flags
40 private string dst;
41 private string stipendSinceLogin;
42 private string gendered;
43 private string everLoggedIn;
44 private string login;
45 private int simPort;
46 private string simAddress;
47 private string agentAccess;
48 private Int32 circuitCode;
49 private uint regionX;
50 private uint regionY;
51
52 // Login
53 private string firstname;
54 private string lastname;
55
56 // Global Textures
57 private string sunTexture;
58 private string cloudTexture;
59 private string moonTexture;
60
61 // Error Flags
62 private string errorReason;
63 private string errorMessage;
64
65 // Response
66 private XmlRpcResponse xmlRpcResponse;
67 private XmlRpcResponse defaultXmlRpcResponse;
68
69 private string welcomeMessage;
70 private string startLocation;
71 private string allowFirstLife;
72 private string home;
73 private string seedCapability;
74 private string lookAt;
75
76 public LoginResponse()
77 {
78 this.loginFlags = new ArrayList();
79 this.globalTextures = new ArrayList();
80 this.eventCategories = new ArrayList();
81 this.uiConfig = new ArrayList();
82 this.classifiedCategories = new ArrayList();
83
84 this.loginError = new Hashtable();
85 this.eventCategoriesHash = new Hashtable();
86 this.classifiedCategoriesHash = new Hashtable();
87 this.uiConfigHash = new Hashtable();
88
89 this.defaultXmlRpcResponse = new XmlRpcResponse();
90 this.userProfile = new UserInfo();
91 this.inventoryRoot = new ArrayList();
92 this.initialOutfit = new ArrayList();
93 this.agentInventory = new ArrayList();
94
95 this.xmlRpcResponse = new XmlRpcResponse();
96 this.defaultXmlRpcResponse = new XmlRpcResponse();
97
98 this.SetDefaultValues();
99 } // LoginServer
100
101 public void SetDefaultValues()
102 {
103 this.DST = "N";
104 this.StipendSinceLogin = "N";
105 this.Gendered = "Y";
106 this.EverLoggedIn = "Y";
107 this.login = "false";
108 this.firstname = "Test";
109 this.lastname = "User";
110 this.agentAccess = "M";
111 this.startLocation = "last";
112 this.allowFirstLife = "Y";
113
114 this.SunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271";
115 this.CloudTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
116 this.MoonTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
117
118 this.ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock.";
119 this.ErrorReason = "key";
120 this.welcomeMessage = "Welcome to OpenSim!";
121 this.seedCapability = "";
122 this.home = "{'region_handle':[r" + (1000 * 256).ToString() + ",r" + (1000 * 256).ToString() + "], 'position':[r" + this.userProfile.homepos.X.ToString() + ",r" + this.userProfile.homepos.Y.ToString() + ",r" + this.userProfile.homepos.Z.ToString() + "], 'look_at':[r" + this.userProfile.homelookat.X.ToString() + ",r" + this.userProfile.homelookat.Y.ToString() + ",r" + this.userProfile.homelookat.Z.ToString() + "]}";
123 this.lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]";
124 this.RegionX = (uint)255232;
125 this.RegionY = (uint)254976;
126
127 // Classifieds;
128 this.AddClassifiedCategory((Int32)1, "Shopping");
129 this.AddClassifiedCategory((Int32)2, "Land Rental");
130 this.AddClassifiedCategory((Int32)3, "Property Rental");
131 this.AddClassifiedCategory((Int32)4, "Special Attraction");
132 this.AddClassifiedCategory((Int32)5, "New Products");
133 this.AddClassifiedCategory((Int32)6, "Employment");
134 this.AddClassifiedCategory((Int32)7, "Wanted");
135 this.AddClassifiedCategory((Int32)8, "Service");
136 this.AddClassifiedCategory((Int32)9, "Personal");
137
138
139 this.SessionID = LLUUID.Random();
140 this.SecureSessionID = LLUUID.Random();
141 this.AgentID = LLUUID.Random();
142
143 Hashtable InitialOutfitHash = new Hashtable();
144 InitialOutfitHash["folder_name"] = "Nightclub Female";
145 InitialOutfitHash["gender"] = "female";
146 this.initialOutfit.Add(InitialOutfitHash);
147
148
149 } // SetDefaultValues
150
151 #region Login Failure Methods
152 public XmlRpcResponse GenerateFailureResponse(string reason, string message, string login)
153 {
154 // Overwrite any default values;
155 this.xmlRpcResponse = new XmlRpcResponse();
156
157 // Ensure Login Failed message/reason;
158 this.ErrorMessage = message;
159 this.ErrorReason = reason;
160
161 this.loginError["reason"] = this.ErrorReason;
162 this.loginError["message"] = this.ErrorMessage;
163 this.loginError["login"] = login;
164 this.xmlRpcResponse.Value = this.loginError;
165 return (this.xmlRpcResponse);
166 } // GenerateResponse
167
168 public XmlRpcResponse CreateFailedResponse()
169 {
170 return (this.CreateLoginFailedResponse());
171 } // CreateErrorConnectingToGridResponse()
172
173 public XmlRpcResponse CreateLoginFailedResponse()
174 {
175 return (this.GenerateFailureResponse("key", "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", "false"));
176 } // LoginFailedResponse
177
178 public XmlRpcResponse CreateAlreadyLoggedInResponse()
179 {
180 return (this.GenerateFailureResponse("presence", "You appear to be already logged in, if this is not the case please wait for your session to timeout, if this takes longer than a few minutes please contact the grid owner", "false"));
181 } // CreateAlreadyLoggedInResponse()
182
183 public XmlRpcResponse CreateDeadRegionResponse()
184 {
185 return (this.GenerateFailureResponse("key", "The region you are attempting to log into is not responding. Please select another region and try again.", "false"));
186 }
187
188 public XmlRpcResponse CreateGridErrorResponse()
189 {
190 return (this.GenerateFailureResponse("key", "Error connecting to grid. Could not percieve credentials from login XML.", "false"));
191 }
192
193 #endregion
194
195 public XmlRpcResponse ToXmlRpcResponse()
196 {
197 try
198 {
199
200 Hashtable responseData = new Hashtable();
201
202 this.loginFlagsHash = new Hashtable();
203 this.loginFlagsHash["daylight_savings"] = this.DST;
204 this.loginFlagsHash["stipend_since_login"] = this.StipendSinceLogin;
205 this.loginFlagsHash["gendered"] = this.Gendered;
206 this.loginFlagsHash["ever_logged_in"] = this.EverLoggedIn;
207 this.loginFlags.Add(this.loginFlagsHash);
208
209 responseData["first_name"] = this.Firstname;
210 responseData["last_name"] = this.Lastname;
211 responseData["agent_access"] = this.agentAccess;
212
213 this.globalTexturesHash = new Hashtable();
214 this.globalTexturesHash["sun_texture_id"] = this.SunTexture;
215 this.globalTexturesHash["cloud_texture_id"] = this.CloudTexture;
216 this.globalTexturesHash["moon_texture_id"] = this.MoonTexture;
217 this.globalTextures.Add(this.globalTexturesHash);
218 this.eventCategories.Add(this.eventCategoriesHash);
219
220 this.AddToUIConfig("allow_first_life", this.allowFirstLife);
221 this.uiConfig.Add(this.uiConfigHash);
222
223 responseData["sim_port"] =(Int32) this.SimPort;
224 responseData["sim_ip"] = this.SimAddress;
225
226 MainLog.Instance.Warn("SIM IP: " + responseData["sim_ip"] + "; SIM PORT: " + responseData["sim_port"]);
227
228 responseData["agent_id"] = this.AgentID.ToStringHyphenated();
229 responseData["session_id"] = this.SessionID.ToStringHyphenated();
230 responseData["secure_session_id"] = this.SecureSessionID.ToStringHyphenated();
231 responseData["circuit_code"] = this.CircuitCode;
232 responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
233 responseData["login-flags"] = this.loginFlags;
234 responseData["global-textures"] = this.globalTextures;
235 responseData["seed_capability"] = this.seedCapability;
236
237 responseData["event_categories"] = this.eventCategories;
238 responseData["event_notifications"] = new ArrayList(); // todo
239 responseData["classified_categories"] = this.classifiedCategories;
240 responseData["ui-config"] = this.uiConfig;
241
242 responseData["inventory-skeleton"] = this.agentInventory;
243 responseData["inventory-skel-lib"] = new ArrayList(); // todo
244 responseData["inventory-root"] = this.inventoryRoot;
245 responseData["gestures"] = new ArrayList(); // todo
246 responseData["inventory-lib-owner"] = new ArrayList(); // todo
247 responseData["initial-outfit"] = this.initialOutfit;
248 responseData["start_location"] = this.startLocation;
249 responseData["seed_capability"] = this.seedCapability;
250 responseData["home"] = this.home;
251 responseData["look_at"] = this.lookAt;
252 responseData["message"] = this.welcomeMessage;
253 responseData["region_x"] = (Int32)this.RegionX * 256;
254 responseData["region_y"] = (Int32)this.RegionY * 256;
255
256 //responseData["inventory-lib-root"] = new ArrayList(); // todo
257 //responseData["buddy-list"] = new ArrayList(); // todo
258
259 responseData["login"] = "true";
260 this.xmlRpcResponse.Value = responseData;
261
262 return (this.xmlRpcResponse);
263 }
264 catch (Exception e)
265 {
266 MainLog.Instance.WriteLine(
267 LogPriority.LOW,
268 "LoginResponse: Error creating XML-RPC Response: " + e.Message
269 );
270 return (this.GenerateFailureResponse("Internal Error", "Error generating Login Response", "false"));
271
272 }
273
274 } // ToXmlRpcResponse
275
276 public void SetEventCategories(string category, string value)
277 {
278 this.eventCategoriesHash[category] = value;
279 } // SetEventCategories
280
281 public void AddToUIConfig(string itemName, string item)
282 {
283 this.uiConfigHash[itemName] = item;
284 } // SetUIConfig
285
286 public void AddClassifiedCategory(Int32 ID, string categoryName)
287 {
288 this.classifiedCategoriesHash["category_name"] = categoryName;
289 this.classifiedCategoriesHash["category_id"] = ID;
290 this.classifiedCategories.Add(this.classifiedCategoriesHash);
291 // this.classifiedCategoriesHash.Clear();
292 } // SetClassifiedCategory
293
294 #region Properties
295 public string Login
296 {
297 get
298 {
299 return this.login;
300 }
301 set
302 {
303 this.login = value;
304 }
305 } // Login
306
307 public string DST
308 {
309 get
310 {
311 return this.dst;
312 }
313 set
314 {
315 this.dst = value;
316 }
317 } // DST
318
319 public string StipendSinceLogin
320 {
321 get
322 {
323 return this.stipendSinceLogin;
324 }
325 set
326 {
327 this.stipendSinceLogin = value;
328 }
329 } // StipendSinceLogin
330
331 public string Gendered
332 {
333 get
334 {
335 return this.gendered;
336 }
337 set
338 {
339 this.gendered = value;
340 }
341 } // Gendered
342
343 public string EverLoggedIn
344 {
345 get
346 {
347 return this.everLoggedIn;
348 }
349 set
350 {
351 this.everLoggedIn = value;
352 }
353 } // EverLoggedIn
354
355 public int SimPort
356 {
357 get
358 {
359 return this.simPort;
360 }
361 set
362 {
363 this.simPort = value;
364 }
365 } // SimPort
366
367 public string SimAddress
368 {
369 get
370 {
371 return this.simAddress;
372 }
373 set
374 {
375 this.simAddress = value;
376 }
377 } // SimAddress
378
379 public LLUUID AgentID
380 {
381 get
382 {
383 return this.agentID;
384 }
385 set
386 {
387 this.agentID = value;
388 }
389 } // AgentID
390
391 public LLUUID SessionID
392 {
393 get
394 {
395 return this.sessionID;
396 }
397 set
398 {
399 this.sessionID = value;
400 }
401 } // SessionID
402
403 public LLUUID SecureSessionID
404 {
405 get
406 {
407 return this.secureSessionID;
408 }
409 set
410 {
411 this.secureSessionID = value;
412 }
413 } // SecureSessionID
414
415 public Int32 CircuitCode
416 {
417 get
418 {
419 return this.circuitCode;
420 }
421 set
422 {
423 this.circuitCode = value;
424 }
425 } // CircuitCode
426
427 public uint RegionX
428 {
429 get
430 {
431 return this.regionX;
432 }
433 set
434 {
435 this.regionX = value;
436 }
437 } // RegionX
438
439 public uint RegionY
440 {
441 get
442 {
443 return this.regionY;
444 }
445 set
446 {
447 this.regionY = value;
448 }
449 } // RegionY
450
451 public string SunTexture
452 {
453 get
454 {
455 return this.sunTexture;
456 }
457 set
458 {
459 this.sunTexture = value;
460 }
461 } // SunTexture
462
463 public string CloudTexture
464 {
465 get
466 {
467 return this.cloudTexture;
468 }
469 set
470 {
471 this.cloudTexture = value;
472 }
473 } // CloudTexture
474
475 public string MoonTexture
476 {
477 get
478 {
479 return this.moonTexture;
480 }
481 set
482 {
483 this.moonTexture = value;
484 }
485 } // MoonTexture
486
487 public string Firstname
488 {
489 get
490 {
491 return this.firstname;
492 }
493 set
494 {
495 this.firstname = value;
496 }
497 } // Firstname
498
499 public string Lastname
500 {
501 get
502 {
503 return this.lastname;
504 }
505 set
506 {
507 this.lastname = value;
508 }
509 } // Lastname
510
511 public string AgentAccess
512 {
513 get
514 {
515 return this.agentAccess;
516 }
517 set
518 {
519 this.agentAccess = value;
520 }
521 }
522
523 public string StartLocation
524 {
525 get
526 {
527 return this.startLocation;
528 }
529 set
530 {
531 this.startLocation = value;
532 }
533 } // StartLocation
534
535 public string LookAt
536 {
537 get
538 {
539 return this.lookAt;
540 }
541 set
542 {
543 this.lookAt = value;
544 }
545 }
546
547 public string SeedCapability
548 {
549 get
550 {
551 return this.seedCapability;
552 }
553 set
554 {
555 this.seedCapability = value;
556 }
557 } // SeedCapability
558
559 public string ErrorReason
560 {
561 get
562 {
563 return this.errorReason;
564 }
565 set
566 {
567 this.errorReason = value;
568 }
569 } // ErrorReason
570
571 public string ErrorMessage
572 {
573 get
574 {
575 return this.errorMessage;
576 }
577 set
578 {
579 this.errorMessage = value;
580 }
581 } // ErrorMessage
582
583 public ArrayList InventoryRoot
584 {
585 get
586 {
587 return this.inventoryRoot;
588 }
589 set
590 {
591 this.inventoryRoot = value;
592 }
593 }
594
595 public ArrayList InventorySkeleton
596 {
597 get
598 {
599 return this.agentInventory;
600 }
601 set
602 {
603 this.agentInventory = value;
604 }
605 }
606
607 public string Home
608 {
609 get
610 {
611 return this.home;
612 }
613 set
614 {
615 this.home = value;
616 }
617 }
618
619 public string Message
620 {
621 get
622 {
623 return this.welcomeMessage;
624 }
625 set
626 {
627 this.welcomeMessage = value;
628 }
629 }
630 #endregion
631
632
633 public class UserInfo
634 {
635 public string firstname;
636 public string lastname;
637 public ulong homeregionhandle;
638 public LLVector3 homepos;
639 public LLVector3 homelookat;
640 }
641 }
642}
643
diff --git a/OpenSim/Framework/UserManager/UserManagerBase.cs b/OpenSim/Framework/UserManager/UserManagerBase.cs
new file mode 100644
index 0000000..df6fbb2
--- /dev/null
+++ b/OpenSim/Framework/UserManager/UserManagerBase.cs
@@ -0,0 +1,630 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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*/
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Reflection;
32using System.Security.Cryptography;
33using libsecondlife;
34using Nwc.XmlRpc;
35using OpenSim.Framework.Console;
36using OpenSim.Framework.Data;
37using OpenSim.Framework.Interfaces;
38using OpenSim.Framework.Inventory;
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 MainLog.Instance.Verbose( "Userstorage: Attempting to load " + FileName);
55 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
56
57 MainLog.Instance.Verbose( "Userstorage: Found " + pluginAssembly.GetTypes().Length + " interfaces.");
58 foreach (Type pluginType in pluginAssembly.GetTypes())
59 {
60 if (!pluginType.IsAbstract)
61 {
62 Type typeInterface = pluginType.GetInterface("IUserData", true);
63
64 if (typeInterface != null)
65 {
66 IUserData plug = (IUserData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
67 plug.Initialise();
68 this._plugins.Add(plug.getName(), plug);
69 MainLog.Instance.Verbose( "Userstorage: Added IUserData Interface");
70 }
71
72 typeInterface = null;
73 }
74 }
75
76 pluginAssembly = null;
77 }
78
79 #region Get UserProfile
80 /// <summary>
81 /// Loads a user profile from a database by UUID
82 /// </summary>
83 /// <param name="uuid">The target UUID</param>
84 /// <returns>A user profile</returns>
85 public UserProfileData getUserProfile(LLUUID uuid)
86 {
87 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
88 {
89 try
90 {
91 UserProfileData profile = plugin.Value.getUserByUUID(uuid);
92 profile.currentAgent = getUserAgent(profile.UUID);
93 return profile;
94 }
95 catch (Exception e)
96 {
97 MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
98 }
99 }
100
101 return null;
102 }
103
104
105 /// <summary>
106 /// Loads a user profile by name
107 /// </summary>
108 /// <param name="name">The target name</param>
109 /// <returns>A user profile</returns>
110 public UserProfileData getUserProfile(string name)
111 {
112 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
113 {
114 try
115 {
116 UserProfileData profile = plugin.Value.getUserByName(name);
117 profile.currentAgent = getUserAgent(profile.UUID);
118 return profile;
119 }
120 catch (Exception e)
121 {
122 MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
123 }
124 }
125
126 return null;
127 }
128
129 /// <summary>
130 /// Loads a user profile by name
131 /// </summary>
132 /// <param name="fname">First name</param>
133 /// <param name="lname">Last name</param>
134 /// <returns>A user profile</returns>
135 public UserProfileData getUserProfile(string fname, string lname)
136 {
137 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
138 {
139 try
140 {
141 UserProfileData profile = plugin.Value.getUserByName(fname,lname);
142
143 profile.currentAgent = getUserAgent(profile.UUID);
144
145 return profile;
146 }
147 catch (Exception e)
148 {
149 MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
150 }
151 }
152
153 return null;
154 }
155 #endregion
156
157 #region Get UserAgent
158 /// <summary>
159 /// Loads a user agent by uuid (not called directly)
160 /// </summary>
161 /// <param name="uuid">The agents UUID</param>
162 /// <returns>Agent profiles</returns>
163 public UserAgentData getUserAgent(LLUUID uuid)
164 {
165 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
166 {
167 try
168 {
169 return plugin.Value.getAgentByUUID(uuid);
170 }
171 catch (Exception e)
172 {
173 MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
174 }
175 }
176
177 return null;
178 }
179
180 /// <summary>
181 /// Loads a user agent by name (not called directly)
182 /// </summary>
183 /// <param name="name">The agents name</param>
184 /// <returns>A user agent</returns>
185 public UserAgentData getUserAgent(string name)
186 {
187 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
188 {
189 try
190 {
191 return plugin.Value.getAgentByName(name);
192 }
193 catch (Exception e)
194 {
195 MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
196 }
197 }
198
199 return null;
200 }
201
202 /// <summary>
203 /// Loads a user agent by name (not called directly)
204 /// </summary>
205 /// <param name="fname">The agents firstname</param>
206 /// <param name="lname">The agents lastname</param>
207 /// <returns>A user agent</returns>
208 public UserAgentData getUserAgent(string fname, string lname)
209 {
210 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
211 {
212 try
213 {
214 return plugin.Value.getAgentByName(fname,lname);
215 }
216 catch (Exception e)
217 {
218 MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
219 }
220 }
221
222 return null;
223 }
224
225 #endregion
226
227 #region CreateAgent
228 /// <summary>
229 /// Creates and initialises a new user agent - make sure to use CommitAgent when done to submit to the DB
230 /// </summary>
231 /// <param name="profile">The users profile</param>
232 /// <param name="request">The users loginrequest</param>
233 public void CreateAgent(UserProfileData profile, XmlRpcRequest request)
234 {
235 Hashtable requestData = (Hashtable)request.Params[0];
236
237 UserAgentData agent = new UserAgentData();
238
239 // User connection
240 agent.agentOnline = true;
241
242 // Generate sessions
243 RNGCryptoServiceProvider rand = new RNGCryptoServiceProvider();
244 byte[] randDataS = new byte[16];
245 byte[] randDataSS = new byte[16];
246 rand.GetBytes(randDataS);
247 rand.GetBytes(randDataSS);
248
249 agent.secureSessionID = new LLUUID(randDataSS, 0);
250 agent.sessionID = new LLUUID(randDataS, 0);
251
252 // Profile UUID
253 agent.UUID = profile.UUID;
254
255 // Current position (from Home)
256 agent.currentHandle = profile.homeRegion;
257 agent.currentPos = profile.homeLocation;
258
259 // If user specified additional start, use that
260 if (requestData.ContainsKey("start"))
261 {
262 string startLoc = ((string)requestData["start"]).Trim();
263 if (!(startLoc == "last" || startLoc == "home"))
264 {
265 // Format: uri:Ahern&162&213&34
266 try
267 {
268 string[] parts = startLoc.Remove(0, 4).Split('&');
269 string region = parts[0];
270
271 ////////////////////////////////////////////////////
272 //SimProfile SimInfo = new SimProfile();
273 //SimInfo = SimInfo.LoadFromGrid(theUser.currentAgent.currentHandle, _config.GridServerURL, _config.GridSendKey, _config.GridRecvKey);
274 }
275 catch (Exception)
276 {
277
278 }
279 }
280 }
281
282 // What time did the user login?
283 agent.loginTime = Util.UnixTimeSinceEpoch();
284 agent.logoutTime = 0;
285
286 // Current location
287 agent.regionID = new LLUUID(); // Fill in later
288 agent.currentRegion = new LLUUID(); // Fill in later
289
290 profile.currentAgent = agent;
291 }
292
293 /// <summary>
294 /// Saves a target agent to the database
295 /// </summary>
296 /// <param name="profile">The users profile</param>
297 /// <returns>Successful?</returns>
298 public bool CommitAgent(ref UserProfileData profile)
299 {
300 // Saves the agent to database
301 return true;
302 }
303
304 #endregion
305
306 /// <summary>
307 /// Checks a user against it's password hash
308 /// </summary>
309 /// <param name="profile">The users profile</param>
310 /// <param name="password">The supplied password</param>
311 /// <returns>Authenticated?</returns>
312 public virtual bool AuthenticateUser(UserProfileData profile, string password)
313 {
314 MainLog.Instance.Verbose(
315 "Authenticating " + profile.username + " " + profile.surname);
316
317 password = password.Remove(0, 3); //remove $1$
318
319 string s = Util.Md5Hash(password + ":" + profile.passwordSalt);
320
321 return profile.passwordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase);
322 }
323
324 #region Xml Response
325
326 /// <summary>
327 ///
328 /// </summary>
329 /// <param name="firstname"></param>
330 /// <param name="lastname"></param>
331 /// <returns></returns>
332 public virtual UserProfileData GetTheUser(string firstname, string lastname)
333 {
334 return getUserProfile(firstname, lastname);
335 }
336
337 /// <summary>
338 ///
339 /// </summary>
340 /// <returns></returns>
341 public virtual string GetMessage()
342 {
343 return _config.DefaultStartupMsg;
344 }
345
346 /// <summary>
347 /// Customises the login response and fills in missing values.
348 /// </summary>
349 /// <param name="response">The existing response</param>
350 /// <param name="theUser">The user profile</param>
351 public abstract void CustomiseResponse( LoginResponse response, UserProfileData theUser);
352
353 /// <summary>
354 /// Main user login function
355 /// </summary>
356 /// <param name="request">The XMLRPC request</param>
357 /// <returns>The response to send</returns>
358 public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
359 {
360
361 System.Console.WriteLine("Attempting login now...");
362 XmlRpcResponse response = new XmlRpcResponse();
363 Hashtable requestData = (Hashtable)request.Params[0];
364
365 bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd"));
366 bool GoodLogin = false;
367 string firstname = "";
368 string lastname = "";
369 string passwd = "";
370
371 UserProfileData userProfile;
372 LoginResponse logResponse = new LoginResponse();
373
374 if (GoodXML)
375 {
376 firstname = (string)requestData["first"];
377 lastname = (string)requestData["last"];
378 passwd = (string)requestData["passwd"];
379
380 userProfile = GetTheUser(firstname, lastname);
381 if (userProfile == null)
382 return logResponse.CreateLoginFailedResponse();
383
384 GoodLogin = AuthenticateUser(userProfile, passwd);
385 }
386 else
387 {
388 return logResponse.CreateGridErrorResponse();
389 }
390
391 if (!GoodLogin)
392 {
393 return logResponse.CreateLoginFailedResponse();
394 }
395 else
396 {
397 // If we already have a session...
398 if (userProfile.currentAgent != null && userProfile.currentAgent.agentOnline)
399 {
400 // Reject the login
401 return logResponse.CreateAlreadyLoggedInResponse();
402 }
403 // Otherwise...
404 // Create a new agent session
405 CreateAgent( userProfile, request);
406
407 try
408 {
409
410 LLUUID AgentID = userProfile.UUID;
411
412 // Inventory Library Section
413 ArrayList AgentInventoryArray = new ArrayList();
414 Hashtable TempHash;
415
416 AgentInventory Library = new AgentInventory();
417 Library.CreateRootFolder(AgentID, true);
418
419 foreach (InventoryFolder InvFolder in Library.InventoryFolders.Values)
420 {
421 TempHash = new Hashtable();
422 TempHash["name"] = InvFolder.FolderName;
423 TempHash["parent_id"] = InvFolder.ParentID.ToStringHyphenated();
424 TempHash["version"] = (Int32)InvFolder.Version;
425 TempHash["type_default"] = (Int32)InvFolder.DefaultType;
426 TempHash["folder_id"] = InvFolder.FolderID.ToStringHyphenated();
427 AgentInventoryArray.Add(TempHash);
428 }
429
430 Hashtable InventoryRootHash = new Hashtable();
431 InventoryRootHash["folder_id"] = Library.InventoryRoot.FolderID.ToStringHyphenated();
432 ArrayList InventoryRoot = new ArrayList();
433 InventoryRoot.Add(InventoryRootHash);
434
435 // Circuit Code
436 uint circode = (uint)(Util.RandomClass.Next());
437
438 logResponse.Lastname = userProfile.surname;
439 logResponse.Firstname = userProfile.username;
440 logResponse.AgentID = AgentID.ToStringHyphenated();
441 logResponse.SessionID = userProfile.currentAgent.sessionID.ToStringHyphenated();
442 logResponse.SecureSessionID = userProfile.currentAgent.secureSessionID.ToStringHyphenated();
443 logResponse.InventoryRoot = InventoryRoot;
444 logResponse.InventorySkeleton = AgentInventoryArray;
445 logResponse.CircuitCode = (Int32)circode;
446 //logResponse.RegionX = 0; //overwritten
447 //logResponse.RegionY = 0; //overwritten
448 logResponse.Home = "!!null temporary value {home}!!"; // Overwritten
449 //logResponse.LookAt = "\n[r" + TheUser.homeLookAt.X.ToString() + ",r" + TheUser.homeLookAt.Y.ToString() + ",r" + TheUser.homeLookAt.Z.ToString() + "]\n";
450 //logResponse.SimAddress = "127.0.0.1"; //overwritten
451 //logResponse.SimPort = 0; //overwritten
452 logResponse.Message = this.GetMessage();
453
454 try
455 {
456 this.CustomiseResponse( logResponse, userProfile);
457 }
458 catch (Exception e)
459 {
460 System.Console.WriteLine(e.ToString());
461 return logResponse.CreateDeadRegionResponse();
462 //return logResponse.ToXmlRpcResponse();
463 }
464 CommitAgent(ref userProfile);
465 return logResponse.ToXmlRpcResponse();
466
467 }
468
469 catch (Exception E)
470 {
471 System.Console.WriteLine(E.ToString());
472 }
473 //}
474 }
475 return response;
476
477 }
478
479 #endregion
480
481 /// <summary>
482 /// Deletes an active agent session
483 /// </summary>
484 /// <param name="request">The request</param>
485 /// <param name="path">The path (eg /bork/narf/test)</param>
486 /// <param name="param">Parameters sent</param>
487 /// <returns>Success "OK" else error</returns>
488 public string RestDeleteUserSessionMethod(string request, string path, string param)
489 {
490 // TODO! Important!
491
492 return "OK";
493 }
494
495 /// <summary>
496 ///
497 /// </summary>
498 /// <param name="user"></param>
499 public void AddUserProfile(string firstName, string lastName, string pass, uint regX, uint regY)
500 {
501 UserProfileData user = new UserProfileData();
502 user.homeLocation = new LLVector3(128, 128, 100);
503 user.UUID = LLUUID.Random();
504 user.username = firstName;
505 user.surname = lastName;
506 user.passwordHash = pass;
507 user.passwordSalt = "";
508 user.created = Util.UnixTimeSinceEpoch();
509 user.homeLookAt = new LLVector3(100, 100, 100);
510 user.homeRegion = Util.UIntsToLong((regX * 256), (regY * 256));
511
512 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
513 {
514 try
515 {
516 plugin.Value.addNewUserProfile(user);
517
518 }
519 catch (Exception e)
520 {
521 MainLog.Instance.Verbose("Unable to add user via " + plugin.Key + "(" + e.ToString() + ")");
522 }
523 }
524 }
525
526 /// <summary>
527 /// Returns an error message that the user could not be found in the database
528 /// </summary>
529 /// <returns>XML string consisting of a error element containing individual error(s)</returns>
530 public XmlRpcResponse CreateUnknownUserErrorResponse()
531 {
532 XmlRpcResponse response = new XmlRpcResponse();
533 Hashtable responseData = new Hashtable();
534 responseData["error_type"] = "unknown_user";
535 responseData["error_desc"] = "The user requested is not in the database";
536
537 response.Value = responseData;
538 return response;
539 }
540
541 /// <summary>
542 /// Converts a user profile to an XML element which can be returned
543 /// </summary>
544 /// <param name="profile">The user profile</param>
545 /// <returns>A string containing an XML Document of the user profile</returns>
546 public XmlRpcResponse ProfileToXmlRPCResponse(UserProfileData profile)
547 {
548 XmlRpcResponse response = new XmlRpcResponse();
549 Hashtable responseData = new Hashtable();
550
551 // Account information
552 responseData["firstname"] = profile.username;
553 responseData["lastname"] = profile.surname;
554 responseData["uuid"] = profile.UUID.ToStringHyphenated();
555 // Server Information
556 responseData["server_inventory"] = profile.userInventoryURI;
557 responseData["server_asset"] = profile.userAssetURI;
558 // Profile Information
559 responseData["profile_about"] = profile.profileAboutText;
560 responseData["profile_firstlife_about"] = profile.profileFirstText;
561 responseData["profile_firstlife_image"] = profile.profileFirstImage.ToStringHyphenated();
562 responseData["profile_can_do"] = profile.profileCanDoMask.ToString();
563 responseData["profile_want_do"] = profile.profileWantDoMask.ToString();
564 responseData["profile_image"] = profile.profileImage.ToStringHyphenated();
565 responseData["profile_created"] = profile.created.ToString();
566 responseData["profile_lastlogin"] = profile.lastLogin.ToString();
567 // Home region information
568 responseData["home_coordinates_x"] = profile.homeLocation.X.ToString();
569 responseData["home_coordinates_y"] = profile.homeLocation.Y.ToString();
570 responseData["home_coordinates_z"] = profile.homeLocation.Z.ToString();
571
572 responseData["home_region"] = profile.homeRegion.ToString();
573
574 responseData["home_look_x"] = profile.homeLookAt.X.ToString();
575 responseData["home_look_y"] = profile.homeLookAt.Y.ToString();
576 responseData["home_look_z"] = profile.homeLookAt.Z.ToString();
577 response.Value = responseData;
578 return response;
579 }
580
581 #region XMLRPC User Methods
582 //should most likely move out of here and into the grid's userserver sub class
583 public XmlRpcResponse XmlRPCGetUserMethodName(XmlRpcRequest request)
584 {
585 XmlRpcResponse response = new XmlRpcResponse();
586 Hashtable requestData = (Hashtable)request.Params[0];
587 UserProfileData userProfile;
588
589 if (requestData.Contains("avatar_name"))
590 {
591 userProfile = getUserProfile((string)requestData["avatar_name"]);
592 if (userProfile == null)
593 {
594 return CreateUnknownUserErrorResponse();
595 }
596 }
597 else
598 {
599 return CreateUnknownUserErrorResponse();
600 }
601
602
603 return ProfileToXmlRPCResponse(userProfile);
604 }
605
606 public XmlRpcResponse XmlRPCGetUserMethodUUID(XmlRpcRequest request)
607 {
608 XmlRpcResponse response = new XmlRpcResponse();
609 Hashtable requestData = (Hashtable)request.Params[0];
610 UserProfileData userProfile;
611 if (requestData.Contains("avatar_uuid"))
612 {
613 userProfile = getUserProfile((LLUUID)requestData["avatar_uuid"]);
614 if (userProfile == null)
615 {
616 return CreateUnknownUserErrorResponse();
617 }
618 }
619 else
620 {
621 return CreateUnknownUserErrorResponse();
622 }
623
624
625 return ProfileToXmlRPCResponse(userProfile);
626 }
627 #endregion
628
629 }
630}