UserProfileManagerBase.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. using Db4objects.Db4o;
  8. namespace OpenSim.Framework.User
  9. {
  10. public class UserProfileManagerBase
  11. {
  12. public Dictionary<LLUUID, UserProfile> UserProfiles = new Dictionary<LLUUID, UserProfile>();
  13. public UserProfileManagerBase()
  14. {
  15. }
  16. public virtual void InitUserProfiles()
  17. {
  18. IObjectContainer db;
  19. db = Db4oFactory.OpenFile("userprofiles.yap");
  20. IObjectSet result = db.Get(typeof(UserProfile));
  21. foreach (UserProfile userprof in result)
  22. {
  23. UserProfiles.Add(userprof.UUID, userprof);
  24. }
  25. Console.WriteLine("UserProfiles.Cs:InitUserProfiles() - Successfully loaded " + result.Count.ToString() + " from database");
  26. db.Close();
  27. }
  28. public virtual void SaveUserProfiles() // ZOMG! INEFFICIENT!
  29. {
  30. IObjectContainer db;
  31. db = Db4oFactory.OpenFile("userprofiles.yap");
  32. IObjectSet result = db.Get(typeof(UserProfile));
  33. foreach (UserProfile userprof in result)
  34. {
  35. db.Delete(userprof);
  36. db.Commit();
  37. }
  38. foreach (UserProfile userprof in UserProfiles.Values)
  39. {
  40. db.Set(userprof);
  41. db.Commit();
  42. }
  43. db.Close();
  44. }
  45. public UserProfile GetProfileByName(string firstname, string lastname)
  46. {
  47. foreach (libsecondlife.LLUUID UUID in UserProfiles.Keys)
  48. {
  49. if ((UserProfiles[UUID].firstname == firstname) && (UserProfiles[UUID].lastname == lastname))
  50. {
  51. return UserProfiles[UUID];
  52. }
  53. }
  54. return null;
  55. }
  56. public UserProfile GetProfileByLLUUID(LLUUID ProfileLLUUID)
  57. {
  58. return UserProfiles[ProfileLLUUID];
  59. }
  60. public virtual bool AuthenticateUser(string firstname, string lastname, string passwd)
  61. {
  62. UserProfile TheUser = GetProfileByName(firstname, lastname);
  63. passwd = passwd.Remove(0, 3); //remove $1$
  64. if (TheUser != null)
  65. {
  66. if (TheUser.MD5passwd == passwd)
  67. {
  68. Console.WriteLine("UserProfile - authorised ");
  69. return true;
  70. }
  71. else
  72. {
  73. Console.WriteLine("UserProfile - not authorised, password not match " + TheUser.MD5passwd + " and " + passwd);
  74. return false;
  75. }
  76. }
  77. else
  78. {
  79. Console.WriteLine("UserProfile - not authorised , unkown: " + firstname + " , " + lastname);
  80. return false;
  81. }
  82. }
  83. public void SetGod(LLUUID GodID)
  84. {
  85. this.UserProfiles[GodID].IsGridGod = true;
  86. }
  87. public virtual UserProfile CreateNewProfile(string firstname, string lastname, string MD5passwd)
  88. {
  89. Console.WriteLine("creating new profile for : " + firstname + " , " + lastname);
  90. UserProfile newprofile = new UserProfile();
  91. newprofile.homeregionhandle = Helpers.UIntsToLong((997 * 256), (996 * 256));
  92. newprofile.firstname = firstname;
  93. newprofile.lastname = lastname;
  94. newprofile.MD5passwd = MD5passwd;
  95. newprofile.UUID = LLUUID.Random();
  96. newprofile.Inventory.CreateRootFolder(newprofile.UUID, true);
  97. this.UserProfiles.Add(newprofile.UUID, newprofile);
  98. return newprofile;
  99. }
  100. public virtual AgentInventory GetUsersInventory(LLUUID agentID)
  101. {
  102. UserProfile user = this.GetProfileByLLUUID(agentID);
  103. if (user != null)
  104. {
  105. return user.Inventory;
  106. }
  107. return null;
  108. }
  109. }
  110. }