1
0

TestUserDataPlugin.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 OpenSimulator 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 AddTemporaryUserProfile(UserProfileData userProfile)
  62. {
  63. // Not interested
  64. }
  65. public void AddNewUserProfile(UserProfileData user)
  66. {
  67. UpdateUserProfile(user);
  68. }
  69. public UserProfileData GetUserByUUID(UUID user)
  70. {
  71. UserProfileData userProfile = null;
  72. m_userProfilesByUuid.TryGetValue(user, out userProfile);
  73. return userProfile;
  74. }
  75. public UserProfileData GetUserByName(string fname, string lname)
  76. {
  77. UserProfileData userProfile = null;
  78. m_userProfilesByName.TryGetValue(fname + " " + lname, out userProfile);
  79. return userProfile;
  80. }
  81. public UserProfileData GetUserByUri(Uri uri) { return null; }
  82. public bool UpdateUserProfile(UserProfileData user)
  83. {
  84. m_userProfilesByUuid[user.ID] = user;
  85. m_userProfilesByName[user.FirstName + " " + user.SurName] = user;
  86. return true;
  87. }
  88. public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query) { return null; }
  89. public UserAgentData GetAgentByUUID(UUID user)
  90. {
  91. UserAgentData userAgent = null;
  92. m_agentByProfileUuid.TryGetValue(user, out userAgent);
  93. return userAgent;
  94. }
  95. public UserAgentData GetAgentByName(string name)
  96. {
  97. UserProfileData userProfile = null;
  98. m_userProfilesByName.TryGetValue(name, out userProfile);
  99. UserAgentData userAgent = null;
  100. m_agentByProfileUuid.TryGetValue(userProfile.ID, out userAgent);
  101. return userAgent;
  102. }
  103. public UserAgentData GetAgentByName(string fname, string lname)
  104. {
  105. UserProfileData userProfile = GetUserByName(fname,lname);
  106. UserAgentData userAgent = null;
  107. m_agentByProfileUuid.TryGetValue(userProfile.ID, out userAgent);
  108. return userAgent;
  109. }
  110. public void StoreWebLoginKey(UUID agentID, UUID webLoginKey) {}
  111. public void AddNewUserAgent(UserAgentData agent)
  112. {
  113. m_agentByProfileUuid[agent.ProfileID] = agent;
  114. }
  115. public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
  116. {
  117. FriendListItem newfriend = new FriendListItem();
  118. newfriend.FriendPerms = perms;
  119. newfriend.Friend = friend;
  120. newfriend.FriendListOwner = friendlistowner;
  121. if (!m_friendsListByUuid.ContainsKey(friendlistowner))
  122. {
  123. List<FriendListItem> friendslist = new List<FriendListItem>();
  124. m_friendsListByUuid[friendlistowner] = friendslist;
  125. }
  126. m_friendsListByUuid[friendlistowner].Add(newfriend);
  127. }
  128. public void RemoveUserFriend(UUID friendlistowner, UUID friend)
  129. {
  130. if (m_friendsListByUuid.ContainsKey(friendlistowner))
  131. {
  132. List<FriendListItem> friendslist = m_friendsListByUuid[friendlistowner];
  133. foreach (FriendListItem frienditem in friendslist)
  134. {
  135. if (frienditem.Friend == friend)
  136. {
  137. friendslist.Remove(frienditem);
  138. break;
  139. }
  140. }
  141. }
  142. }
  143. public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
  144. {
  145. if (m_friendsListByUuid.ContainsKey(friendlistowner))
  146. {
  147. List<FriendListItem> friendslist = m_friendsListByUuid[friendlistowner];
  148. foreach (FriendListItem frienditem in friendslist)
  149. {
  150. if (frienditem.Friend == friend)
  151. {
  152. frienditem.FriendPerms = perms;
  153. break;
  154. }
  155. }
  156. }
  157. }
  158. public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
  159. {
  160. if (m_friendsListByUuid.ContainsKey(friendlistowner))
  161. {
  162. return m_friendsListByUuid[friendlistowner];
  163. }
  164. else
  165. return new List<FriendListItem>();
  166. }
  167. public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids) { return null; }
  168. public bool MoneyTransferRequest(UUID from, UUID to, uint amount) { return false; }
  169. public bool InventoryTransferRequest(UUID from, UUID to, UUID inventory) { return false; }
  170. public void Initialise(string connect) { return; }
  171. public AvatarAppearance GetUserAppearance(UUID user) { return null; }
  172. public void UpdateUserAppearance(UUID user, AvatarAppearance appearance) {}
  173. public void ResetAttachments(UUID userID) {}
  174. public void LogoutUsers(UUID regionID) {}
  175. }
  176. }