TestUserDataPlugin.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 OpenMetaverse;
  30. using OpenSim.Framework;
  31. using OpenSim.Data;
  32. namespace OpenSim.Tests.Common.Mock
  33. {
  34. /// <summary>
  35. /// In memory user data provider. Might be quite useful as a proper user data plugin, though getting mono addins
  36. /// to load any plugins when running unit tests has proven impossible so far. Currently no locking since unit
  37. /// tests are single threaded.
  38. /// </summary>
  39. public class TestUserDataPlugin : IUserDataPlugin
  40. {
  41. public string Version { get { return "0"; } }
  42. public string Name { get { return "TestUserDataPlugin"; } }
  43. /// <summary>
  44. /// User profiles keyed by name
  45. /// </summary>
  46. private Dictionary<string, UserProfileData> m_userProfilesByName = new Dictionary<string, UserProfileData>();
  47. /// <summary>
  48. /// User profiles keyed by uuid
  49. /// </summary>
  50. private Dictionary<UUID, UserProfileData> m_userProfilesByUuid = new Dictionary<UUID, UserProfileData>();
  51. /// <summary>
  52. /// User profiles and their agents
  53. /// </summary>
  54. private Dictionary<UUID, UserAgentData> m_agentByProfileUuid = new Dictionary<UUID, UserAgentData>();
  55. /// <summary>
  56. /// Friends list by uuid
  57. /// </summary>
  58. private Dictionary<UUID, List<FriendListItem>> m_friendsListByUuid = new Dictionary<UUID, List<FriendListItem>>();
  59. public void Initialise() {}
  60. public void Dispose() {}
  61. public void AddNewUserProfile(UserProfileData user)
  62. {
  63. UpdateUserProfile(user);
  64. }
  65. public UserProfileData GetUserByUUID(UUID user)
  66. {
  67. UserProfileData userProfile = null;
  68. m_userProfilesByUuid.TryGetValue(user, out userProfile);
  69. return userProfile;
  70. }
  71. public UserProfileData GetUserByName(string fname, string lname)
  72. {
  73. UserProfileData userProfile = null;
  74. m_userProfilesByName.TryGetValue(fname + " " + lname, out userProfile);
  75. return userProfile;
  76. }
  77. public bool UpdateUserProfile(UserProfileData user)
  78. {
  79. m_userProfilesByUuid[user.ID] = user;
  80. m_userProfilesByName[user.FirstName + " " + user.SurName] = user;
  81. return true;
  82. }
  83. public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query) { return null; }
  84. public UserAgentData GetAgentByUUID(UUID user)
  85. {
  86. UserAgentData userAgent = null;
  87. m_agentByProfileUuid.TryGetValue(user, out userAgent);
  88. return userAgent;
  89. }
  90. public UserAgentData GetAgentByName(string name)
  91. {
  92. UserProfileData userProfile = null;
  93. m_userProfilesByName.TryGetValue(name, out userProfile);
  94. UserAgentData userAgent = null;
  95. m_agentByProfileUuid.TryGetValue(userProfile.ID, out userAgent);
  96. return userAgent;
  97. }
  98. public UserAgentData GetAgentByName(string fname, string lname)
  99. {
  100. UserProfileData userProfile = GetUserByName(fname,lname);
  101. UserAgentData userAgent = null;
  102. m_agentByProfileUuid.TryGetValue(userProfile.ID, out userAgent);
  103. return userAgent;
  104. }
  105. public void StoreWebLoginKey(UUID agentID, UUID webLoginKey) {}
  106. public void AddNewUserAgent(UserAgentData agent)
  107. {
  108. m_agentByProfileUuid[agent.ProfileID] = agent;
  109. }
  110. public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
  111. {
  112. FriendListItem newfriend = new FriendListItem();
  113. newfriend.FriendPerms = perms;
  114. newfriend.Friend = friend;
  115. newfriend.FriendListOwner = friendlistowner;
  116. if (!m_friendsListByUuid.ContainsKey(friendlistowner))
  117. {
  118. List<FriendListItem> friendslist = new List<FriendListItem>();
  119. m_friendsListByUuid[friendlistowner] = friendslist;
  120. }
  121. m_friendsListByUuid[friendlistowner].Add(newfriend);
  122. }
  123. public void RemoveUserFriend(UUID friendlistowner, UUID friend)
  124. {
  125. if (m_friendsListByUuid.ContainsKey(friendlistowner))
  126. {
  127. List<FriendListItem> friendslist = m_friendsListByUuid[friendlistowner];
  128. foreach (FriendListItem frienditem in friendslist)
  129. {
  130. if (frienditem.Friend == friend)
  131. {
  132. friendslist.Remove(frienditem);
  133. break;
  134. }
  135. }
  136. }
  137. }
  138. public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
  139. {
  140. if (m_friendsListByUuid.ContainsKey(friendlistowner))
  141. {
  142. List<FriendListItem> friendslist = m_friendsListByUuid[friendlistowner];
  143. foreach (FriendListItem frienditem in friendslist)
  144. {
  145. if (frienditem.Friend == friend)
  146. {
  147. frienditem.FriendPerms = perms;
  148. break;
  149. }
  150. }
  151. }
  152. }
  153. public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
  154. {
  155. if (m_friendsListByUuid.ContainsKey(friendlistowner))
  156. {
  157. return m_friendsListByUuid[friendlistowner];
  158. }
  159. else
  160. return new List<FriendListItem>();
  161. }
  162. public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids) { return null; }
  163. public bool MoneyTransferRequest(UUID from, UUID to, uint amount) { return false; }
  164. public bool InventoryTransferRequest(UUID from, UUID to, UUID inventory) { return false; }
  165. public void Initialise(string connect) { return; }
  166. public AvatarAppearance GetUserAppearance(UUID user) { return null; }
  167. public void UpdateUserAppearance(UUID user, AvatarAppearance appearance) {}
  168. public void ResetAttachments(UUID userID) {}
  169. public void LogoutUsers(UUID regionID) {}
  170. }
  171. }