UserProfileManagerBase.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using libsecondlife;
  5. using OpenSim.Framework.Utilities;
  6. using OpenSim.Framework.Inventory;
  7. namespace OpenSim.Framework.User
  8. {
  9. public class UserProfileManagerBase
  10. {
  11. public Dictionary<LLUUID, UserProfile> UserProfiles = new Dictionary<LLUUID, UserProfile>();
  12. public UserProfileManagerBase()
  13. {
  14. }
  15. public virtual void InitUserProfiles()
  16. {
  17. // TODO: need to load from database
  18. }
  19. public UserProfile GetProfileByName(string firstname, string lastname)
  20. {
  21. foreach (libsecondlife.LLUUID UUID in UserProfiles.Keys)
  22. {
  23. if ((UserProfiles[UUID].firstname == firstname) && (UserProfiles[UUID].lastname == lastname))
  24. {
  25. return UserProfiles[UUID];
  26. }
  27. }
  28. return null;
  29. }
  30. public UserProfile GetProfileByLLUUID(LLUUID ProfileLLUUID)
  31. {
  32. return UserProfiles[ProfileLLUUID];
  33. }
  34. public virtual bool AuthenticateUser(string firstname, string lastname, string passwd)
  35. {
  36. UserProfile TheUser = GetProfileByName(firstname, lastname);
  37. passwd = passwd.Remove(0, 3); //remove $1$
  38. if (TheUser != null)
  39. {
  40. if (TheUser.MD5passwd == passwd)
  41. {
  42. Console.WriteLine("UserProfile - authorised ");
  43. return true;
  44. }
  45. else
  46. {
  47. Console.WriteLine("UserProfile - not authorised, password not match "+ TheUser.MD5passwd +" and "+ passwd);
  48. return false;
  49. }
  50. }
  51. else
  52. {
  53. Console.WriteLine("UserProfile - not authorised , unkown: "+ firstname +" , " + lastname);
  54. return false;
  55. }
  56. }
  57. public void SetGod(LLUUID GodID)
  58. {
  59. this.UserProfiles[GodID].IsGridGod = true;
  60. }
  61. public virtual UserProfile CreateNewProfile(string firstname, string lastname, string MD5passwd)
  62. {
  63. Console.WriteLine("creating new profile for : " + firstname + " , " + lastname);
  64. UserProfile newprofile = new UserProfile();
  65. newprofile.homeregionhandle = Helpers.UIntsToLong((997 * 256), (996 * 256));
  66. newprofile.firstname = firstname;
  67. newprofile.lastname = lastname;
  68. newprofile.MD5passwd = MD5passwd;
  69. newprofile.UUID = LLUUID.Random();
  70. newprofile.Inventory.CreateRootFolder(newprofile.UUID, true);
  71. this.UserProfiles.Add(newprofile.UUID, newprofile);
  72. return newprofile;
  73. }
  74. public virtual AgentInventory GetUsersInventory(LLUUID agentID)
  75. {
  76. UserProfile user = this.GetProfileByLLUUID(agentID);
  77. if (user != null)
  78. {
  79. return user.Inventory;
  80. }
  81. return null;
  82. }
  83. }
  84. }