CommunicationsManager.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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.Reflection;
  30. using libsecondlife;
  31. using log4net;
  32. using OpenSim.Framework.Communications.Cache;
  33. using OpenSim.Framework.Console;
  34. using OpenSim.Framework.Servers;
  35. namespace OpenSim.Framework.Communications
  36. {
  37. public class CommunicationsManager
  38. {
  39. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  40. protected IUserService m_userService;
  41. public IUserService UserService
  42. {
  43. get { return m_userService; }
  44. }
  45. protected IGridServices m_gridService;
  46. public IGridServices GridService
  47. {
  48. get { return m_gridService; }
  49. }
  50. protected IInventoryServices m_inventoryService;
  51. public IInventoryServices InventoryService
  52. {
  53. get { return m_inventoryService; }
  54. }
  55. protected IInterRegionCommunications m_interRegion;
  56. public IInterRegionCommunications InterRegion
  57. {
  58. get { return m_interRegion; }
  59. }
  60. protected UserProfileCacheService m_userProfileCacheService;
  61. public UserProfileCacheService UserProfileCacheService
  62. {
  63. get { return m_userProfileCacheService; }
  64. }
  65. // protected AgentAssetTransactionsManager m_transactionsManager;
  66. // public AgentAssetTransactionsManager TransactionsManager
  67. // {
  68. // get { return m_transactionsManager; }
  69. // }
  70. protected AssetCache m_assetCache;
  71. public AssetCache AssetCache
  72. {
  73. get { return m_assetCache; }
  74. }
  75. protected NetworkServersInfo m_networkServersInfo;
  76. public NetworkServersInfo NetworkServersInfo
  77. {
  78. get { return m_networkServersInfo; }
  79. }
  80. public CommunicationsManager(NetworkServersInfo serversInfo, BaseHttpServer httpServer, AssetCache assetCache,
  81. bool dumpAssetsToFile)
  82. {
  83. m_networkServersInfo = serversInfo;
  84. m_assetCache = assetCache;
  85. m_userProfileCacheService = new UserProfileCacheService(this);
  86. // m_transactionsManager = new AgentAssetTransactionsManager(this, dumpAssetsToFile);
  87. }
  88. public void doCreate(string[] cmmdParams)
  89. {
  90. switch (cmmdParams[0])
  91. {
  92. case "user":
  93. string firstName;
  94. string lastName;
  95. string password;
  96. uint regX = 1000;
  97. uint regY = 1000;
  98. if (cmmdParams.Length < 2)
  99. {
  100. firstName = MainConsole.Instance.CmdPrompt("First name", "Default");
  101. lastName = MainConsole.Instance.CmdPrompt("Last name", "User");
  102. password = MainConsole.Instance.PasswdPrompt("Password");
  103. regX = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region X", "1000"));
  104. regY = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region Y", "1000"));
  105. }
  106. else
  107. {
  108. firstName = cmmdParams[1];
  109. lastName = cmmdParams[2];
  110. password = cmmdParams[3];
  111. regX = Convert.ToUInt32(cmmdParams[4]);
  112. regY = Convert.ToUInt32(cmmdParams[5]);
  113. }
  114. if (null == m_userService.GetUserProfile(firstName, lastName))
  115. {
  116. AddUser(firstName, lastName, password, regX, regY);
  117. }
  118. else
  119. {
  120. m_log.ErrorFormat("[USERS]: A user with the name {0} {1} already exists!", firstName, lastName);
  121. }
  122. break;
  123. }
  124. }
  125. /// <summary>
  126. /// Persistently adds a user to OpenSim.
  127. /// </summary>
  128. /// <param name="firstName"></param>
  129. /// <param name="lastName"></param>
  130. /// <param name="password"></param>
  131. /// <param name="regX"></param>
  132. /// <param name="regY"></param>
  133. /// <returns>The UUID of the added user. Returns null if the add was unsuccessful</returns>
  134. public LLUUID AddUser(string firstName, string lastName, string password, uint regX, uint regY)
  135. {
  136. string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) + ":" + String.Empty);
  137. m_userService.AddUserProfile(firstName, lastName, md5PasswdHash, regX, regY);
  138. UserProfileData userProf = UserService.GetUserProfile(firstName, lastName);
  139. if (userProf == null)
  140. {
  141. return LLUUID.Zero;
  142. }
  143. else
  144. {
  145. m_inventoryService.CreateNewUserInventory(userProf.ID);
  146. m_log.Info("[USERS]: Created new inventory set for " + firstName + " " + lastName);
  147. return userProf.ID;
  148. }
  149. }
  150. #region Friend Methods
  151. /// <summary>
  152. /// Adds a new friend to the database for XUser
  153. /// </summary>
  154. /// <param name="friendlistowner">The agent that who's friends list is being added to</param>
  155. /// <param name="friend">The agent that being added to the friends list of the friends list owner</param>
  156. /// <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>
  157. public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms)
  158. {
  159. m_userService.AddNewUserFriend(friendlistowner, friend, perms);
  160. }
  161. /// <summary>
  162. /// Logs off a user and does the appropriate communications
  163. /// </summary>
  164. /// <param name="userid"></param>
  165. /// <param name="regionid"></param>
  166. /// <param name="regionhandle"></param>
  167. /// <param name="posx"></param>
  168. /// <param name="posy"></param>
  169. /// <param name="posz"></param>
  170. public void LogOffUser(LLUUID userid, LLUUID regionid, ulong regionhandle, float posx, float posy, float posz)
  171. {
  172. m_userService.LogOffUser(userid, regionid, regionhandle, posx, posy, posz);
  173. }
  174. /// <summary>
  175. /// Delete friend on friendlistowner's friendlist.
  176. /// </summary>
  177. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  178. /// <param name="friend">The Ex-friend agent</param>
  179. public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend)
  180. {
  181. m_userService.RemoveUserFriend(friendlistowner, friend);
  182. }
  183. /// <summary>
  184. /// Update permissions for friend on friendlistowner's friendlist.
  185. /// </summary>
  186. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  187. /// <param name="friend">The agent that is getting or loosing permissions</param>
  188. /// <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>
  189. public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms)
  190. {
  191. m_userService.UpdateUserFriendPerms(friendlistowner, friend, perms);
  192. }
  193. /// <summary>
  194. /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for LLUUID friendslistowner
  195. /// </summary>
  196. /// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param>
  197. public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner)
  198. {
  199. return m_userService.GetUserFriendList(friendlistowner);
  200. }
  201. #endregion
  202. #region Packet Handlers
  203. public void UpdateAvatarPropertiesRequest(IClientAPI remote_client, UserProfileData UserProfile)
  204. {
  205. m_userService.UpdateUserProfileProperties(UserProfile);
  206. return;
  207. }
  208. public void HandleUUIDNameRequest(LLUUID uuid, IClientAPI remote_client)
  209. {
  210. if (uuid == m_userProfileCacheService.libraryRoot.Owner)
  211. {
  212. remote_client.SendNameReply(uuid, "Mr", "OpenSim");
  213. }
  214. else
  215. {
  216. UserProfileData profileData = m_userService.GetUserProfile(uuid);
  217. if (profileData != null)
  218. {
  219. LLUUID profileId = profileData.ID;
  220. string firstname = profileData.FirstName;
  221. string lastname = profileData.SurName;
  222. remote_client.SendNameReply(profileId, firstname, lastname);
  223. }
  224. }
  225. }
  226. public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(LLUUID queryID, string query)
  227. {
  228. List<AvatarPickerAvatar> pickerlist = m_userService.GenerateAgentPickerRequestResponse(queryID, query);
  229. return pickerlist;
  230. }
  231. #endregion
  232. }
  233. }