aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/DB4o/DB4oUserData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/DB4o/DB4oUserData.cs')
-rw-r--r--OpenSim/Data/DB4o/DB4oUserData.cs270
1 files changed, 270 insertions, 0 deletions
diff --git a/OpenSim/Data/DB4o/DB4oUserData.cs b/OpenSim/Data/DB4o/DB4oUserData.cs
new file mode 100644
index 0000000..3072e81
--- /dev/null
+++ b/OpenSim/Data/DB4o/DB4oUserData.cs
@@ -0,0 +1,270 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.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.Generic;
30using System.IO;
31using libsecondlife;
32
33namespace OpenSim.Framework.Data.DB4o
34{
35 /// <summary>
36 /// A User storage interface for the DB4o database system
37 /// </summary>
38 public class DB4oUserData : IUserData
39 {
40 //private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
41
42 /// <summary>
43 /// The database manager
44 /// </summary>
45 private DB4oUserManager manager;
46
47 /// <summary>
48 /// Artificial constructor called upon plugin load
49 /// </summary>
50 public void Initialise()
51 {
52 manager = new DB4oUserManager(Path.Combine(Util.dataDir(), "userprofiles.yap"));
53 }
54
55 /// <summary>
56 /// Loads a specified user profile from a UUID
57 /// </summary>
58 /// <param name="uuid">The users UUID</param>
59 /// <returns>A user profile</returns>
60 public UserProfileData GetUserByUUID(LLUUID uuid)
61 {
62 if (manager.userProfiles.ContainsKey(uuid))
63 return manager.userProfiles[uuid];
64 return null;
65 }
66
67 /// <summary>
68 /// Returns a user by searching for its name
69 /// </summary>
70 /// <param name="name">The users account name</param>
71 /// <returns>A matching users profile</returns>
72 public UserProfileData GetUserByName(string name)
73 {
74 return GetUserByName(name.Split(' ')[0], name.Split(' ')[1]);
75 }
76
77 /// <summary>
78 /// Returns a user by searching for its name
79 /// </summary>
80 /// <param name="fname">The first part of the users account name</param>
81 /// <param name="lname">The second part of the users account name</param>
82 /// <returns>A matching users profile</returns>
83 public UserProfileData GetUserByName(string fname, string lname)
84 {
85 foreach (UserProfileData profile in manager.userProfiles.Values)
86 {
87 if (profile.username == fname && profile.surname == lname)
88 return profile;
89 }
90 return null;
91 }
92
93 /// <summary>
94 /// Returns a user by UUID direct
95 /// </summary>
96 /// <param name="uuid">The users account ID</param>
97 /// <returns>A matching users profile</returns>
98 public UserAgentData GetAgentByUUID(LLUUID uuid)
99 {
100 try
101 {
102 return GetUserByUUID(uuid).currentAgent;
103 }
104 catch (Exception)
105 {
106 return null;
107 }
108 }
109
110 /// <summary>
111 /// Returns a session by account name
112 /// </summary>
113 /// <param name="name">The account name</param>
114 /// <returns>The users session agent</returns>
115 public UserAgentData GetAgentByName(string name)
116 {
117 return GetAgentByName(name.Split(' ')[0], name.Split(' ')[1]);
118 }
119
120 /// <summary>
121 /// Returns a session by account name
122 /// </summary>
123 /// <param name="fname">The first part of the users account name</param>
124 /// <param name="lname">The second part of the users account name</param>
125 /// <returns>A user agent</returns>
126 public UserAgentData GetAgentByName(string fname, string lname)
127 {
128 try
129 {
130 return GetUserByName(fname, lname).currentAgent;
131 }
132 catch (Exception)
133 {
134 return null;
135 }
136 }
137 public void StoreWebLoginKey(LLUUID AgentID, LLUUID WebLoginKey)
138 {
139 UserProfileData user = GetUserByUUID(AgentID);
140 user.webLoginKey = WebLoginKey;
141 UpdateUserProfile(user);
142
143 }
144 #region User Friends List Data
145
146 public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms)
147 {
148 //m_log.Info("[FRIEND]: Stub AddNewUserFriend called");
149 }
150
151 public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend)
152 {
153 //m_log.Info("[FRIEND]: Stub RemoveUserFriend called");
154 }
155 public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms)
156 {
157 //m_log.Info("[FRIEND]: Stub UpdateUserFriendPerms called");
158 }
159
160
161 public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner)
162 {
163 //m_log.Info("[FRIEND]: Stub GetUserFriendList called");
164 return new List<FriendListItem>();
165 }
166
167 #endregion
168
169 public void UpdateUserCurrentRegion(LLUUID avatarid, LLUUID regionuuid)
170 {
171 //m_log.Info("[USER]: Stub UpdateUserCUrrentRegion called");
172 }
173
174
175
176 public List<Framework.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query)
177 {
178 //Do nothing yet
179 List<Framework.AvatarPickerAvatar> returnlist = new List<Framework.AvatarPickerAvatar>();
180 return returnlist;
181 }
182
183 /// <summary>
184 /// Creates a new user profile
185 /// </summary>
186 /// <param name="user">The profile to add to the database</param>
187 public void AddNewUserProfile(UserProfileData user)
188 {
189 try
190 {
191 manager.UpdateRecord(user);
192 }
193 catch (Exception e)
194 {
195 Console.WriteLine(e.ToString());
196 }
197 }
198
199 /// <summary>
200 /// Creates a new user profile
201 /// </summary>
202 /// <param name="user">The profile to add to the database</param>
203 /// <returns>True on success, false on error</returns>
204 public bool UpdateUserProfile(UserProfileData user)
205 {
206 try
207 {
208 return manager.UpdateRecord(user);
209 }
210 catch (Exception e)
211 {
212 Console.WriteLine(e.ToString());
213 return false;
214 }
215 }
216
217
218 /// <summary>
219 /// Creates a new user agent
220 /// </summary>
221 /// <param name="agent">The agent to add to the database</param>
222 public void AddNewUserAgent(UserAgentData agent)
223 {
224 // Do nothing. yet.
225 }
226
227 /// <summary>
228 /// Transfers money between two user accounts
229 /// </summary>
230 /// <param name="from">Starting account</param>
231 /// <param name="to">End account</param>
232 /// <param name="amount">The amount to move</param>
233 /// <returns>Success?</returns>
234 public bool MoneyTransferRequest(LLUUID from, LLUUID to, uint amount)
235 {
236 return true;
237 }
238
239 /// <summary>
240 /// Transfers inventory between two accounts
241 /// </summary>
242 /// <remarks>Move to inventory server</remarks>
243 /// <param name="from">Senders account</param>
244 /// <param name="to">Receivers account</param>
245 /// <param name="item">Inventory item</param>
246 /// <returns>Success?</returns>
247 public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
248 {
249 return true;
250 }
251
252 /// <summary>
253 /// Returns the name of the storage provider
254 /// </summary>
255 /// <returns>Storage provider name</returns>
256 public string getName()
257 {
258 return "DB4o Userdata";
259 }
260
261 /// <summary>
262 /// Returns the version of the storage provider
263 /// </summary>
264 /// <returns>Storage provider version</returns>
265 public string GetVersion()
266 {
267 return "0.1";
268 }
269 }
270}