CommunicationsManager.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. */
  28. using System;
  29. using System.Collections.Generic;
  30. using libsecondlife;
  31. using OpenSim.Framework.Communications.Cache;
  32. using OpenSim.Framework.Console;
  33. using OpenSim.Framework.Servers;
  34. namespace OpenSim.Framework.Communications
  35. {
  36. public class CommunicationsManager
  37. {
  38. protected IUserService m_userService;
  39. public IUserService UserService
  40. {
  41. get { return m_userService; }
  42. }
  43. protected IGridServices m_gridService;
  44. public IGridServices GridService
  45. {
  46. get { return m_gridService; }
  47. }
  48. protected IInventoryServices m_inventoryService;
  49. public IInventoryServices InventoryService
  50. {
  51. get { return m_inventoryService; }
  52. }
  53. protected IInterRegionCommunications m_interRegion;
  54. public IInterRegionCommunications InterRegion
  55. {
  56. get { return m_interRegion; }
  57. }
  58. protected UserProfileCacheService m_userProfileCacheService;
  59. public UserProfileCacheService UserProfileCacheService
  60. {
  61. get { return m_userProfileCacheService; }
  62. }
  63. protected AssetTransactionManager m_transactionsManager;
  64. public AssetTransactionManager TransactionsManager
  65. {
  66. get { return m_transactionsManager; }
  67. }
  68. protected AssetCache m_assetCache;
  69. public AssetCache AssetCache
  70. {
  71. get { return m_assetCache; }
  72. }
  73. protected NetworkServersInfo m_networkServersInfo;
  74. public NetworkServersInfo NetworkServersInfo
  75. {
  76. get { return m_networkServersInfo; }
  77. }
  78. public CommunicationsManager(NetworkServersInfo serversInfo, BaseHttpServer httpServer, AssetCache assetCache,
  79. bool dumpAssetsToFile)
  80. {
  81. m_networkServersInfo = serversInfo;
  82. m_assetCache = assetCache;
  83. m_userProfileCacheService = new UserProfileCacheService(this);
  84. m_transactionsManager = new AssetTransactionManager(this, dumpAssetsToFile);
  85. }
  86. public void doCreate(string[] cmmdParams)
  87. {
  88. switch (cmmdParams[0])
  89. {
  90. case "user":
  91. string firstName;
  92. string lastName;
  93. string password;
  94. uint regX = 1000;
  95. uint regY = 1000;
  96. if (cmmdParams.Length < 2)
  97. {
  98. firstName = MainLog.Instance.CmdPrompt("First name", "Default");
  99. lastName = MainLog.Instance.CmdPrompt("Last name", "User");
  100. password = MainLog.Instance.PasswdPrompt("Password");
  101. regX = Convert.ToUInt32(MainLog.Instance.CmdPrompt("Start Region X", "1000"));
  102. regY = Convert.ToUInt32(MainLog.Instance.CmdPrompt("Start Region Y", "1000"));
  103. }
  104. else
  105. {
  106. firstName = cmmdParams[1];
  107. lastName = cmmdParams[2];
  108. password = cmmdParams[3];
  109. regX = Convert.ToUInt32(cmmdParams[4]);
  110. regY = Convert.ToUInt32(cmmdParams[5]);
  111. }
  112. AddUser(firstName, lastName, password, regX, regY);
  113. break;
  114. }
  115. }
  116. public LLUUID AddUser(string firstName, string lastName, string password, uint regX, uint regY)
  117. {
  118. string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) + ":" + "");
  119. m_userService.AddUserProfile(firstName, lastName, md5PasswdHash, regX, regY);
  120. UserProfileData userProf = UserService.GetUserProfile(firstName, lastName, "");
  121. if (userProf == null)
  122. {
  123. return LLUUID.Zero;
  124. }
  125. else
  126. {
  127. m_inventoryService.CreateNewUserInventory(userProf.UUID);
  128. System.Console.WriteLine("Created new inventory set for " + firstName + " " + lastName);
  129. return userProf.UUID;
  130. }
  131. }
  132. #region Friend Methods
  133. /// <summary>
  134. /// Adds a new friend to the database for XUser
  135. /// </summary>
  136. /// <param name="friendlistowner">The agent that who's friends list is being added to</param>
  137. /// <param name="friend">The agent that being added to the friends list of the friends list owner</param>
  138. /// <param name="perms">A uint bit vector for set perms that the friend being added has; 0 = none, 1=This friend can see when they sign on, 2 = map, 4 edit objects </param>
  139. public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms)
  140. {
  141. m_userService.AddNewUserFriend(friendlistowner, friend, perms);
  142. }
  143. /// <summary>
  144. /// Delete friend on friendlistowner's friendlist.
  145. /// </summary>
  146. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  147. /// <param name="friend">The Ex-friend agent</param>
  148. public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend)
  149. {
  150. m_userService.RemoveUserFriend(friendlistowner, friend);
  151. }
  152. /// <summary>
  153. /// Update permissions for friend on friendlistowner's friendlist.
  154. /// </summary>
  155. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  156. /// <param name="friend">The agent that is getting or loosing permissions</param>
  157. /// <param name="perms">A uint bit vector for set perms that the friend being added has; 0 = none, 1=This friend can see when they sign on, 2 = map, 4 edit objects </param>
  158. public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms)
  159. {
  160. m_userService.UpdateUserFriendPerms(friendlistowner, friend, perms);
  161. }
  162. /// <summary>
  163. /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for LLUUID friendslistowner
  164. /// </summary>
  165. /// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param>
  166. public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner)
  167. {
  168. return m_userService.GetUserFriendList(friendlistowner);
  169. }
  170. #endregion
  171. #region Packet Handlers
  172. public void HandleUUIDNameRequest(LLUUID uuid, IClientAPI remote_client)
  173. {
  174. if (uuid == m_userProfileCacheService.libraryRoot.agentID)
  175. {
  176. remote_client.SendNameReply(uuid, "Mr", "OpenSim");
  177. }
  178. else
  179. {
  180. UserProfileData profileData = m_userService.GetUserProfile(uuid, "");
  181. if (profileData != null)
  182. {
  183. LLUUID profileId = profileData.UUID;
  184. string firstname = profileData.username;
  185. string lastname = profileData.surname;
  186. remote_client.SendNameReply(profileId, firstname, lastname);
  187. }
  188. }
  189. }
  190. public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(LLUUID queryID, string query)
  191. {
  192. List<AvatarPickerAvatar> pickerlist = m_userService.GenerateAgentPickerRequestResponse(queryID, query);
  193. return pickerlist;
  194. }
  195. #endregion
  196. }
  197. }