DB4oUserData.cs 9.2 KB

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