diff options
author | Adam Frisby | 2007-07-11 08:10:25 +0000 |
---|---|---|
committer | Adam Frisby | 2007-07-11 08:10:25 +0000 |
commit | e2ff441e31328e60c8bb1d4bb32fa4ac64f91978 (patch) | |
tree | 8405b6cef57b66a58f31a24c859846085d0b81f7 /OpenSim/Framework/Data.DB4o/DB4oUserData.cs | |
parent | * Wiping trunk in prep for Sugilite (diff) | |
parent | * Applying dalien's patches from bug#177 and #179 (diff) | |
download | opensim-SC_OLD-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.zip opensim-SC_OLD-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.gz opensim-SC_OLD-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.bz2 opensim-SC_OLD-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.xz |
* Bringing Sugilite in to trunk
Diffstat (limited to 'OpenSim/Framework/Data.DB4o/DB4oUserData.cs')
-rw-r--r-- | OpenSim/Framework/Data.DB4o/DB4oUserData.cs | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/OpenSim/Framework/Data.DB4o/DB4oUserData.cs b/OpenSim/Framework/Data.DB4o/DB4oUserData.cs new file mode 100644 index 0000000..2e33ab0 --- /dev/null +++ b/OpenSim/Framework/Data.DB4o/DB4oUserData.cs | |||
@@ -0,0 +1,202 @@ | |||
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 | */ | ||
28 | using System; | ||
29 | using libsecondlife; | ||
30 | |||
31 | namespace OpenSim.Framework.Data.DB4o | ||
32 | { | ||
33 | /// <summary> | ||
34 | /// A User storage interface for the DB4o database system | ||
35 | /// </summary> | ||
36 | public class DB4oUserData : IUserData | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// The database manager | ||
40 | /// </summary> | ||
41 | DB4oUserManager manager; | ||
42 | |||
43 | /// <summary> | ||
44 | /// Artificial constructor called upon plugin load | ||
45 | /// </summary> | ||
46 | public void Initialise() | ||
47 | { | ||
48 | manager = new DB4oUserManager("userprofiles.yap"); | ||
49 | } | ||
50 | |||
51 | /// <summary> | ||
52 | /// Loads a specified user profile from a UUID | ||
53 | /// </summary> | ||
54 | /// <param name="uuid">The users UUID</param> | ||
55 | /// <returns>A user profile</returns> | ||
56 | public UserProfileData getUserByUUID(LLUUID uuid) | ||
57 | { | ||
58 | if(manager.userProfiles.ContainsKey(uuid)) | ||
59 | return manager.userProfiles[uuid]; | ||
60 | return null; | ||
61 | } | ||
62 | |||
63 | /// <summary> | ||
64 | /// Returns a user by searching for its name | ||
65 | /// </summary> | ||
66 | /// <param name="name">The users account name</param> | ||
67 | /// <returns>A matching users profile</returns> | ||
68 | public UserProfileData getUserByName(string name) | ||
69 | { | ||
70 | return getUserByName(name.Split(' ')[0], name.Split(' ')[1]); | ||
71 | } | ||
72 | |||
73 | /// <summary> | ||
74 | /// Returns a user by searching for its name | ||
75 | /// </summary> | ||
76 | /// <param name="fname">The first part of the users account name</param> | ||
77 | /// <param name="lname">The second part of the users account name</param> | ||
78 | /// <returns>A matching users profile</returns> | ||
79 | public UserProfileData getUserByName(string fname, string lname) | ||
80 | { | ||
81 | foreach (UserProfileData profile in manager.userProfiles.Values) | ||
82 | { | ||
83 | if (profile.username == fname && profile.surname == lname) | ||
84 | return profile; | ||
85 | } | ||
86 | return null; | ||
87 | } | ||
88 | |||
89 | /// <summary> | ||
90 | /// Returns a user by UUID direct | ||
91 | /// </summary> | ||
92 | /// <param name="uuid">The users account ID</param> | ||
93 | /// <returns>A matching users profile</returns> | ||
94 | public UserAgentData getAgentByUUID(LLUUID uuid) | ||
95 | { | ||
96 | try | ||
97 | { | ||
98 | return getUserByUUID(uuid).currentAgent; | ||
99 | } | ||
100 | catch (Exception) | ||
101 | { | ||
102 | return null; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | /// <summary> | ||
107 | /// Returns a session by account name | ||
108 | /// </summary> | ||
109 | /// <param name="name">The account name</param> | ||
110 | /// <returns>The users session agent</returns> | ||
111 | public UserAgentData getAgentByName(string name) | ||
112 | { | ||
113 | return getAgentByName(name.Split(' ')[0], name.Split(' ')[1]); | ||
114 | } | ||
115 | |||
116 | /// <summary> | ||
117 | /// Returns a session by account name | ||
118 | /// </summary> | ||
119 | /// <param name="fname">The first part of the users account name</param> | ||
120 | /// <param name="lname">The second part of the users account name</param> | ||
121 | /// <returns>A user agent</returns> | ||
122 | public UserAgentData getAgentByName(string fname, string lname) | ||
123 | { | ||
124 | try | ||
125 | { | ||
126 | return getUserByName(fname,lname).currentAgent; | ||
127 | } | ||
128 | catch (Exception) | ||
129 | { | ||
130 | return null; | ||
131 | } | ||
132 | } | ||
133 | |||
134 | /// <summary> | ||
135 | /// Creates a new user profile | ||
136 | /// </summary> | ||
137 | /// <param name="user">The profile to add to the database</param> | ||
138 | public void addNewUserProfile(UserProfileData user) | ||
139 | { | ||
140 | try | ||
141 | { | ||
142 | manager.AddRow(user); | ||
143 | } | ||
144 | catch (Exception e) | ||
145 | { | ||
146 | Console.WriteLine(e.ToString()); | ||
147 | } | ||
148 | } | ||
149 | |||
150 | /// <summary> | ||
151 | /// Creates a new user agent | ||
152 | /// </summary> | ||
153 | /// <param name="agent">The agent to add to the database</param> | ||
154 | public void addNewUserAgent(UserAgentData agent) | ||
155 | { | ||
156 | // Do nothing. yet. | ||
157 | } | ||
158 | |||
159 | /// <summary> | ||
160 | /// Transfers money between two user accounts | ||
161 | /// </summary> | ||
162 | /// <param name="from">Starting account</param> | ||
163 | /// <param name="to">End account</param> | ||
164 | /// <param name="amount">The amount to move</param> | ||
165 | /// <returns>Success?</returns> | ||
166 | public bool moneyTransferRequest(LLUUID from, LLUUID to, uint amount) | ||
167 | { | ||
168 | return true; | ||
169 | } | ||
170 | |||
171 | /// <summary> | ||
172 | /// Transfers inventory between two accounts | ||
173 | /// </summary> | ||
174 | /// <remarks>Move to inventory server</remarks> | ||
175 | /// <param name="from">Senders account</param> | ||
176 | /// <param name="to">Recievers account</param> | ||
177 | /// <param name="item">Inventory item</param> | ||
178 | /// <returns>Success?</returns> | ||
179 | public bool inventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item) | ||
180 | { | ||
181 | return true; | ||
182 | } | ||
183 | |||
184 | /// <summary> | ||
185 | /// Returns the name of the storage provider | ||
186 | /// </summary> | ||
187 | /// <returns>Storage provider name</returns> | ||
188 | public string getName() | ||
189 | { | ||
190 | return "DB4o Userdata"; | ||
191 | } | ||
192 | |||
193 | /// <summary> | ||
194 | /// Returns the version of the storage provider | ||
195 | /// </summary> | ||
196 | /// <returns>Storage provider version</returns> | ||
197 | public string getVersion() | ||
198 | { | ||
199 | return "0.1"; | ||
200 | } | ||
201 | } | ||
202 | } | ||