DB4oUserData.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. namespace OpenSim.Framework.Data.DB4o
  31. {
  32. /// <summary>
  33. /// A User storage interface for the DB4o database system
  34. /// </summary>
  35. public class DB4oUserData : IUserData
  36. {
  37. /// <summary>
  38. /// The database manager
  39. /// </summary>
  40. DB4oUserManager manager;
  41. /// <summary>
  42. /// Artificial constructor called upon plugin load
  43. /// </summary>
  44. public void Initialise()
  45. {
  46. manager = new DB4oUserManager("userprofiles.yap");
  47. }
  48. /// <summary>
  49. /// Loads a specified user profile from a UUID
  50. /// </summary>
  51. /// <param name="uuid">The users UUID</param>
  52. /// <returns>A user profile</returns>
  53. public UserProfileData getUserByUUID(LLUUID uuid)
  54. {
  55. if(manager.userProfiles.ContainsKey(uuid))
  56. return manager.userProfiles[uuid];
  57. return null;
  58. }
  59. /// <summary>
  60. /// Returns a user by searching for its name
  61. /// </summary>
  62. /// <param name="name">The users account name</param>
  63. /// <returns>A matching users profile</returns>
  64. public UserProfileData getUserByName(string name)
  65. {
  66. return getUserByName(name.Split(' ')[0], name.Split(' ')[1]);
  67. }
  68. /// <summary>
  69. /// Returns a user by searching for its name
  70. /// </summary>
  71. /// <param name="fname">The first part of the users account name</param>
  72. /// <param name="lname">The second part of the users account name</param>
  73. /// <returns>A matching users profile</returns>
  74. public UserProfileData getUserByName(string fname, string lname)
  75. {
  76. foreach (UserProfileData profile in manager.userProfiles.Values)
  77. {
  78. if (profile.username == fname && profile.surname == lname)
  79. return profile;
  80. }
  81. return null;
  82. }
  83. /// <summary>
  84. /// Returns a user by UUID direct
  85. /// </summary>
  86. /// <param name="uuid">The users account ID</param>
  87. /// <returns>A matching users profile</returns>
  88. public UserAgentData getAgentByUUID(LLUUID uuid)
  89. {
  90. try
  91. {
  92. return getUserByUUID(uuid).currentAgent;
  93. }
  94. catch (Exception)
  95. {
  96. return null;
  97. }
  98. }
  99. /// <summary>
  100. /// Returns a session by account name
  101. /// </summary>
  102. /// <param name="name">The account name</param>
  103. /// <returns>The users session agent</returns>
  104. public UserAgentData getAgentByName(string name)
  105. {
  106. return getAgentByName(name.Split(' ')[0], name.Split(' ')[1]);
  107. }
  108. /// <summary>
  109. /// Returns a session by account name
  110. /// </summary>
  111. /// <param name="fname">The first part of the users account name</param>
  112. /// <param name="lname">The second part of the users account name</param>
  113. /// <returns>A user agent</returns>
  114. public UserAgentData getAgentByName(string fname, string lname)
  115. {
  116. try
  117. {
  118. return getUserByName(fname,lname).currentAgent;
  119. }
  120. catch (Exception)
  121. {
  122. return null;
  123. }
  124. }
  125. /// <summary>
  126. /// Creates a new user profile
  127. /// </summary>
  128. /// <param name="user">The profile to add to the database</param>
  129. public void addNewUserProfile(UserProfileData user)
  130. {
  131. try
  132. {
  133. manager.AddRow(user);
  134. }
  135. catch (Exception e)
  136. {
  137. Console.WriteLine(e.ToString());
  138. }
  139. }
  140. /// <summary>
  141. /// Creates a new user agent
  142. /// </summary>
  143. /// <param name="agent">The agent to add to the database</param>
  144. public void addNewUserAgent(UserAgentData agent)
  145. {
  146. // Do nothing. yet.
  147. }
  148. /// <summary>
  149. /// Transfers money between two user accounts
  150. /// </summary>
  151. /// <param name="from">Starting account</param>
  152. /// <param name="to">End account</param>
  153. /// <param name="amount">The amount to move</param>
  154. /// <returns>Success?</returns>
  155. public bool moneyTransferRequest(LLUUID from, LLUUID to, uint amount)
  156. {
  157. return true;
  158. }
  159. /// <summary>
  160. /// Transfers inventory between two accounts
  161. /// </summary>
  162. /// <remarks>Move to inventory server</remarks>
  163. /// <param name="from">Senders account</param>
  164. /// <param name="to">Recievers account</param>
  165. /// <param name="item">Inventory item</param>
  166. /// <returns>Success?</returns>
  167. public bool inventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
  168. {
  169. return true;
  170. }
  171. /// <summary>
  172. /// Returns the name of the storage provider
  173. /// </summary>
  174. /// <returns>Storage provider name</returns>
  175. public string getName()
  176. {
  177. return "DB4o Userdata";
  178. }
  179. /// <summary>
  180. /// Returns the version of the storage provider
  181. /// </summary>
  182. /// <returns>Storage provider version</returns>
  183. public string getVersion()
  184. {
  185. return "0.1";
  186. }
  187. }
  188. }