diff options
author | MW | 2007-05-26 13:40:19 +0000 |
---|---|---|
committer | MW | 2007-05-26 13:40:19 +0000 |
commit | 3436961bb5c01d659d09be134368f4f69460cef9 (patch) | |
tree | 3753ba4d7818df2a6bce0bbe863ff033cdfd568a /Common/OpenSim.Framework/UserProfileManagerBase.cs | |
download | opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.zip opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.tar.gz opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.tar.bz2 opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.tar.xz |
Start of rewrite 5279!
Diffstat (limited to 'Common/OpenSim.Framework/UserProfileManagerBase.cs')
-rw-r--r-- | Common/OpenSim.Framework/UserProfileManagerBase.cs | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/Common/OpenSim.Framework/UserProfileManagerBase.cs b/Common/OpenSim.Framework/UserProfileManagerBase.cs new file mode 100644 index 0000000..d1307a5 --- /dev/null +++ b/Common/OpenSim.Framework/UserProfileManagerBase.cs | |||
@@ -0,0 +1,124 @@ | |||
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 | |||
9 | namespace OpenSim.Framework.User | ||
10 | { | ||
11 | public class UserProfileManagerBase | ||
12 | { | ||
13 | |||
14 | public Dictionary<LLUUID, UserProfile> UserProfiles = new Dictionary<LLUUID, UserProfile>(); | ||
15 | |||
16 | public UserProfileManagerBase() | ||
17 | { | ||
18 | } | ||
19 | |||
20 | public virtual void InitUserProfiles() | ||
21 | { | ||
22 | IObjectContainer db; | ||
23 | db = Db4oFactory.OpenFile("userprofiles.yap"); | ||
24 | IObjectSet result = db.Get(typeof(UserProfile)); | ||
25 | foreach (UserProfile userprof in result) | ||
26 | { | ||
27 | UserProfiles.Add(userprof.UUID, userprof); | ||
28 | } | ||
29 | Console.WriteLine("UserProfiles.Cs:InitUserProfiles() - Successfully loaded " + result.Count.ToString() + " from database"); | ||
30 | db.Close(); | ||
31 | } | ||
32 | |||
33 | public virtual void SaveUserProfiles() // ZOMG! INEFFICIENT! | ||
34 | { | ||
35 | IObjectContainer db; | ||
36 | db = Db4oFactory.OpenFile("userprofiles.yap"); | ||
37 | IObjectSet result = db.Get(typeof(UserProfile)); | ||
38 | foreach (UserProfile userprof in result) | ||
39 | { | ||
40 | db.Delete(userprof); | ||
41 | db.Commit(); | ||
42 | } | ||
43 | foreach (UserProfile userprof in UserProfiles.Values) | ||
44 | { | ||
45 | db.Set(userprof); | ||
46 | db.Commit(); | ||
47 | } | ||
48 | db.Close(); | ||
49 | } | ||
50 | |||
51 | public UserProfile GetProfileByName(string firstname, string lastname) | ||
52 | { | ||
53 | foreach (libsecondlife.LLUUID UUID in UserProfiles.Keys) | ||
54 | { | ||
55 | if (UserProfiles[UUID].firstname.Equals(firstname)) if (UserProfiles[UUID].lastname.Equals(lastname)) | ||
56 | { | ||
57 | return UserProfiles[UUID]; | ||
58 | } | ||
59 | } | ||
60 | return null; | ||
61 | } | ||
62 | |||
63 | public UserProfile GetProfileByLLUUID(LLUUID ProfileLLUUID) | ||
64 | { | ||
65 | return UserProfiles[ProfileLLUUID]; | ||
66 | } | ||
67 | |||
68 | public virtual bool AuthenticateUser(string firstname, string lastname, string passwd) | ||
69 | { | ||
70 | UserProfile TheUser = GetProfileByName(firstname, lastname); | ||
71 | passwd = passwd.Remove(0, 3); //remove $1$ | ||
72 | if (TheUser != null) | ||
73 | { | ||
74 | if (TheUser.MD5passwd == passwd) | ||
75 | { | ||
76 | Console.WriteLine("UserProfile - authorised " + firstname + " " + lastname); | ||
77 | return true; | ||
78 | } | ||
79 | else | ||
80 | { | ||
81 | Console.WriteLine("UserProfile - not authorised, password not match " + TheUser.MD5passwd + " and " + passwd); | ||
82 | return false; | ||
83 | } | ||
84 | } | ||
85 | else | ||
86 | { | ||
87 | Console.WriteLine("UserProfile - not authorised , unkown: " + firstname + " , " + lastname); | ||
88 | return false; | ||
89 | } | ||
90 | |||
91 | } | ||
92 | |||
93 | public void SetGod(LLUUID GodID) | ||
94 | { | ||
95 | this.UserProfiles[GodID].IsGridGod = true; | ||
96 | } | ||
97 | |||
98 | public virtual UserProfile CreateNewProfile(string firstname, string lastname, string MD5passwd) | ||
99 | { | ||
100 | Console.WriteLine("creating new profile for : " + firstname + " , " + lastname); | ||
101 | UserProfile newprofile = new UserProfile(); | ||
102 | newprofile.homeregionhandle = Helpers.UIntsToLong((997 * 256), (996 * 256)); | ||
103 | newprofile.firstname = firstname; | ||
104 | newprofile.lastname = lastname; | ||
105 | newprofile.MD5passwd = MD5passwd; | ||
106 | newprofile.UUID = LLUUID.Random(); | ||
107 | newprofile.Inventory.CreateRootFolder(newprofile.UUID, true); | ||
108 | this.UserProfiles.Add(newprofile.UUID, newprofile); | ||
109 | return newprofile; | ||
110 | } | ||
111 | |||
112 | public virtual AgentInventory GetUsersInventory(LLUUID agentID) | ||
113 | { | ||
114 | UserProfile user = this.GetProfileByLLUUID(agentID); | ||
115 | if (user != null) | ||
116 | { | ||
117 | return user.Inventory; | ||
118 | } | ||
119 | |||
120 | return null; | ||
121 | } | ||
122 | |||
123 | } | ||
124 | } | ||