DB4oUserData.cs 9.2 KB

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