CommunicationsManager.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 libsecondlife;
  30. using OpenSim.Framework.Communications.Cache;
  31. using OpenSim.Framework.Console;
  32. using OpenSim.Framework.Servers;
  33. namespace OpenSim.Framework.Communications
  34. {
  35. public class CommunicationsManager
  36. {
  37. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  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 AgentAssetTransactionsManager m_transactionsManager;
  64. // public AgentAssetTransactionsManager 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 AgentAssetTransactionsManager(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 = MainConsole.Instance.CmdPrompt("First name", "Default");
  99. lastName = MainConsole.Instance.CmdPrompt("Last name", "User");
  100. password = MainConsole.Instance.PasswdPrompt("Password");
  101. regX = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region X", "1000"));
  102. regY = Convert.ToUInt32(MainConsole.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. if (null == m_userService.GetUserProfile(firstName, lastName))
  113. {
  114. AddUser(firstName, lastName, password, regX, regY);
  115. }
  116. else
  117. {
  118. m_log.ErrorFormat("[USERS]: A user with the name {0} {1} already exists!", firstName, lastName);
  119. }
  120. break;
  121. }
  122. }
  123. /// <summary>
  124. /// Persistently adds a user to OpenSim.
  125. /// </summary>
  126. /// <param name="firstName"></param>
  127. /// <param name="lastName"></param>
  128. /// <param name="password"></param>
  129. /// <param name="regX"></param>
  130. /// <param name="regY"></param>
  131. /// <returns>The UUID of the added user. Returns null if the add was unsuccessful</returns>
  132. public LLUUID AddUser(string firstName, string lastName, string password, uint regX, uint regY)
  133. {
  134. string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) + ":" + String.Empty);
  135. m_userService.AddUserProfile(firstName, lastName, md5PasswdHash, regX, regY);
  136. UserProfileData userProf = UserService.GetUserProfile(firstName, lastName);
  137. if (userProf == null)
  138. {
  139. return LLUUID.Zero;
  140. }
  141. else
  142. {
  143. m_inventoryService.CreateNewUserInventory(userProf.UUID);
  144. m_log.Info("[USERS]: Created new inventory set for " + firstName + " " + lastName);
  145. return userProf.UUID;
  146. }
  147. }
  148. #region Friend Methods
  149. /// <summary>
  150. /// Adds a new friend to the database for XUser
  151. /// </summary>
  152. /// <param name="friendlistowner">The agent that who's friends list is being added to</param>
  153. /// <param name="friend">The agent that being added to the friends list of the friends list owner</param>
  154. /// <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>
  155. public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms)
  156. {
  157. m_userService.AddNewUserFriend(friendlistowner, friend, perms);
  158. }
  159. /// <summary>
  160. /// Logs off a user and does the appropriate communications
  161. /// </summary>
  162. /// <param name="userid"></param>
  163. /// <param name="regionid"></param>
  164. /// <param name="regionhandle"></param>
  165. /// <param name="posx"></param>
  166. /// <param name="posy"></param>
  167. /// <param name="posz"></param>
  168. public void LogOffUser(LLUUID userid, LLUUID regionid, ulong regionhandle, float posx, float posy, float posz)
  169. {
  170. m_userService.LogOffUser(userid, regionid, regionhandle, posx, posy, posz);
  171. }
  172. /// <summary>
  173. /// Delete friend on friendlistowner's friendlist.
  174. /// </summary>
  175. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  176. /// <param name="friend">The Ex-friend agent</param>
  177. public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend)
  178. {
  179. m_userService.RemoveUserFriend(friendlistowner, friend);
  180. }
  181. /// <summary>
  182. /// Update permissions for friend on friendlistowner's friendlist.
  183. /// </summary>
  184. /// <param name="friendlistowner">The agent that who's friends list is being updated</param>
  185. /// <param name="friend">The agent that is getting or loosing permissions</param>
  186. /// <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>
  187. public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms)
  188. {
  189. m_userService.UpdateUserFriendPerms(friendlistowner, friend, perms);
  190. }
  191. /// <summary>
  192. /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for LLUUID friendslistowner
  193. /// </summary>
  194. /// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param>
  195. public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner)
  196. {
  197. return m_userService.GetUserFriendList(friendlistowner);
  198. }
  199. #endregion
  200. #region Packet Handlers
  201. public void UpdateAvatarPropertiesRequest(IClientAPI remote_client, UserProfileData UserProfile)
  202. {
  203. m_userService.UpdateUserProfileProperties(UserProfile);
  204. return;
  205. }
  206. public void HandleUUIDNameRequest(LLUUID uuid, IClientAPI remote_client)
  207. {
  208. if (uuid == m_userProfileCacheService.libraryRoot.agentID)
  209. {
  210. remote_client.SendNameReply(uuid, "Mr", "OpenSim");
  211. }
  212. else
  213. {
  214. UserProfileData profileData = m_userService.GetUserProfile(uuid);
  215. if (profileData != null)
  216. {
  217. LLUUID profileId = profileData.UUID;
  218. string firstname = profileData.username;
  219. string lastname = profileData.surname;
  220. remote_client.SendNameReply(profileId, firstname, lastname);
  221. }
  222. }
  223. }
  224. public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(LLUUID queryID, string query)
  225. {
  226. List<AvatarPickerAvatar> pickerlist = m_userService.GenerateAgentPickerRequestResponse(queryID, query);
  227. return pickerlist;
  228. }
  229. #endregion
  230. }
  231. }