UserManagerBase.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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;
  29. using System.Collections.Generic;
  30. using System.Net;
  31. using System.Reflection;
  32. using System.Security.Cryptography;
  33. using OpenMetaverse;
  34. using OpenMetaverse.StructuredData;
  35. using log4net;
  36. using Nwc.XmlRpc;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Statistics;
  39. namespace OpenSim.Framework.Communications
  40. {
  41. /// <summary>
  42. /// Base class for user management (create, read, etc)
  43. /// </summary>
  44. public abstract class UserManagerBase : IUserService, IUserAdminService, IAvatarService, IMessagingService
  45. {
  46. private static readonly ILog m_log
  47. = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. /// <value>
  49. /// List of plugins to search for user data
  50. /// </value>
  51. private List<IUserDataPlugin> _plugins = new List<IUserDataPlugin>();
  52. protected IInterServiceInventoryServices m_interServiceInventoryService;
  53. /// <summary>
  54. /// Constructor
  55. /// </summary>
  56. /// <param name="interServiceInventoryService"></param>
  57. public UserManagerBase(IInterServiceInventoryServices interServiceInventoryService)
  58. {
  59. m_interServiceInventoryService = interServiceInventoryService;
  60. }
  61. /// <summary>
  62. /// Add a new user data plugin - plugins will be requested in the order they were added.
  63. /// </summary>
  64. /// <param name="plugin">The plugin that will provide user data</param>
  65. public void AddPlugin(IUserDataPlugin plugin)
  66. {
  67. _plugins.Add(plugin);
  68. }
  69. /// <summary>
  70. /// Add a new user data plugin - plugins will be requested in the order they were added.
  71. /// </summary>
  72. /// <param name="provider">The filename to the user data plugin DLL</param>
  73. /// <param name="connect"></param>
  74. public void AddPlugin(string provider, string connect)
  75. {
  76. PluginLoader<IUserDataPlugin> loader =
  77. new PluginLoader<IUserDataPlugin>(new UserDataInitialiser(connect));
  78. // loader will try to load all providers (MySQL, MSSQL, etc)
  79. // unless it is constrainted to the correct "Provider" entry in the addin.xml
  80. loader.Add("/OpenSim/UserData", new PluginProviderFilter(provider));
  81. loader.Load();
  82. _plugins.AddRange(loader.Plugins);
  83. }
  84. #region Get UserProfile
  85. // see IUserService
  86. public UserProfileData GetUserProfile(string fname, string lname)
  87. {
  88. foreach (IUserDataPlugin plugin in _plugins)
  89. {
  90. UserProfileData profile = plugin.GetUserByName(fname, lname);
  91. if (profile != null)
  92. {
  93. profile.CurrentAgent = GetUserAgent(profile.ID);
  94. return profile;
  95. }
  96. }
  97. return null;
  98. }
  99. public void LogoutUsers(UUID regionID)
  100. {
  101. foreach (IUserDataPlugin plugin in _plugins)
  102. {
  103. plugin.LogoutUsers(regionID);
  104. }
  105. }
  106. public void ResetAttachments(UUID userID)
  107. {
  108. foreach (IUserDataPlugin plugin in _plugins)
  109. {
  110. plugin.ResetAttachments(userID);
  111. }
  112. }
  113. public UserAgentData GetAgentByUUID(UUID userId)
  114. {
  115. foreach (IUserDataPlugin plugin in _plugins)
  116. {
  117. UserAgentData agent = plugin.GetAgentByUUID(userId);
  118. if (agent != null)
  119. {
  120. return agent;
  121. }
  122. }
  123. return null;
  124. }
  125. // see IUserService
  126. public virtual UserProfileData GetUserProfile(UUID uuid)
  127. {
  128. foreach (IUserDataPlugin plugin in _plugins)
  129. {
  130. UserProfileData profile = plugin.GetUserByUUID(uuid);
  131. if (null != profile)
  132. {
  133. profile.CurrentAgent = GetUserAgent(profile.ID);
  134. return profile;
  135. }
  136. }
  137. return null;
  138. }
  139. public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(UUID queryID, string query)
  140. {
  141. List<AvatarPickerAvatar> pickerlist = new List<AvatarPickerAvatar>();
  142. foreach (IUserDataPlugin plugin in _plugins)
  143. {
  144. try
  145. {
  146. pickerlist = plugin.GeneratePickerResults(queryID, query);
  147. }
  148. catch (Exception)
  149. {
  150. m_log.Info("[USERSTORAGE]: Unable to generate AgentPickerData via " + plugin.Name + "(" + query + ")");
  151. return new List<AvatarPickerAvatar>();
  152. }
  153. }
  154. return pickerlist;
  155. }
  156. /// <summary>
  157. /// Updates a user profile from data object
  158. /// </summary>
  159. /// <param name="data"></param>
  160. /// <returns></returns>
  161. public bool UpdateUserProfile(UserProfileData data)
  162. {
  163. foreach (IUserDataPlugin plugin in _plugins)
  164. {
  165. try
  166. {
  167. plugin.UpdateUserProfile(data);
  168. return true;
  169. }
  170. catch (Exception e)
  171. {
  172. m_log.InfoFormat("[USERSTORAGE]: Unable to set user {0} {1} via {2}: {3}", data.FirstName, data.SurName,
  173. plugin.Name, e.ToString());
  174. }
  175. }
  176. return false;
  177. }
  178. #endregion
  179. #region Get UserAgent
  180. /// <summary>
  181. /// Loads a user agent by uuid (not called directly)
  182. /// </summary>
  183. /// <param name="uuid">The agent's UUID</param>
  184. /// <returns>Agent profiles</returns>
  185. public UserAgentData GetUserAgent(UUID uuid)
  186. {
  187. foreach (IUserDataPlugin plugin in _plugins)
  188. {
  189. try
  190. {
  191. UserAgentData result = plugin.GetAgentByUUID(uuid);
  192. if (result != null)
  193. {
  194. return result;
  195. }
  196. }
  197. catch (Exception e)
  198. {
  199. m_log.Info("[USERSTORAGE]: Unable to find user via " + plugin.Name + "(" + e.ToString() + ")");
  200. }
  201. }
  202. return null;
  203. }
  204. /// <summary>
  205. /// Loads a user agent by name (not called directly)
  206. /// </summary>
  207. /// <param name="name">The agent's name</param>
  208. /// <returns>A user agent</returns>
  209. public UserAgentData GetUserAgent(string name)
  210. {
  211. foreach (IUserDataPlugin plugin in _plugins)
  212. {
  213. try
  214. {
  215. return plugin.GetAgentByName(name);
  216. }
  217. catch (Exception e)
  218. {
  219. m_log.Info("[USERSTORAGE]: Unable to find user via " + plugin.Name + "(" + e.ToString() + ")");
  220. }
  221. }
  222. return null;
  223. }
  224. /// <summary>
  225. /// Loads a user agent by name (not called directly)
  226. /// </summary>
  227. /// <param name="fname">The agent's firstname</param>
  228. /// <param name="lname">The agent's lastname</param>
  229. /// <returns>A user agent</returns>
  230. public UserAgentData GetUserAgent(string fname, string lname)
  231. {
  232. foreach (IUserDataPlugin plugin in _plugins)
  233. {
  234. try
  235. {
  236. return plugin.GetAgentByName(fname, lname);
  237. }
  238. catch (Exception e)
  239. {
  240. m_log.Info("[USERSTORAGE]: Unable to find user via " + plugin.Name + "(" + e.ToString() + ")");
  241. }
  242. }
  243. return null;
  244. }
  245. /// <summary>
  246. /// Loads a user's friend list
  247. /// </summary>
  248. /// <param name="name">the UUID of the friend list owner</param>
  249. /// <returns>A List of FriendListItems that contains info about the user's friends</returns>
  250. public List<FriendListItem> GetUserFriendList(UUID ownerID)
  251. {
  252. foreach (IUserDataPlugin plugin in _plugins)
  253. {
  254. try
  255. {
  256. List<FriendListItem> result = plugin.GetUserFriendList(ownerID);
  257. if (result != null)
  258. {
  259. return result;
  260. }
  261. }
  262. catch (Exception e)
  263. {
  264. m_log.Info("[USERSTORAGE]: Unable to GetUserFriendList via " + plugin.Name + "(" + e.ToString() + ")");
  265. }
  266. }
  267. return null;
  268. }
  269. public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos (List<UUID> uuids)
  270. {
  271. foreach (IUserDataPlugin plugin in _plugins)
  272. {
  273. try
  274. {
  275. Dictionary<UUID, FriendRegionInfo> result = plugin.GetFriendRegionInfos(uuids);
  276. if (result != null)
  277. {
  278. return result;
  279. }
  280. }
  281. catch (Exception e)
  282. {
  283. m_log.Info("[USERSTORAGE]: Unable to GetFriendRegionInfos via " + plugin.Name + "(" + e.ToString() + ")");
  284. }
  285. }
  286. return null;
  287. }
  288. public void StoreWebLoginKey(UUID agentID, UUID webLoginKey)
  289. {
  290. foreach (IUserDataPlugin plugin in _plugins)
  291. {
  292. try
  293. {
  294. plugin.StoreWebLoginKey(agentID, webLoginKey);
  295. }
  296. catch (Exception e)
  297. {
  298. m_log.Info("[USERSTORAGE]: Unable to Store WebLoginKey via " + plugin.Name + "(" + e.ToString() + ")");
  299. }
  300. }
  301. }
  302. public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
  303. {
  304. foreach (IUserDataPlugin plugin in _plugins)
  305. {
  306. try
  307. {
  308. plugin.AddNewUserFriend(friendlistowner,friend,perms);
  309. }
  310. catch (Exception e)
  311. {
  312. m_log.Info("[USERSTORAGE]: Unable to AddNewUserFriend via " + plugin.Name + "(" + e.ToString() + ")");
  313. }
  314. }
  315. }
  316. public void RemoveUserFriend(UUID friendlistowner, UUID friend)
  317. {
  318. foreach (IUserDataPlugin plugin in _plugins)
  319. {
  320. try
  321. {
  322. plugin.RemoveUserFriend(friendlistowner, friend);
  323. }
  324. catch (Exception e)
  325. {
  326. m_log.Info("[USERSTORAGE]: Unable to RemoveUserFriend via " + plugin.Name + "(" + e.ToString() + ")");
  327. }
  328. }
  329. }
  330. public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
  331. {
  332. foreach (IUserDataPlugin plugin in _plugins)
  333. {
  334. try
  335. {
  336. plugin.UpdateUserFriendPerms(friendlistowner, friend, perms);
  337. }
  338. catch (Exception e)
  339. {
  340. m_log.Info("[USERSTORAGE]: Unable to UpdateUserFriendPerms via " + plugin.Name + "(" + e.ToString() + ")");
  341. }
  342. }
  343. }
  344. /// <summary>
  345. /// Resets the currentAgent in the user profile
  346. /// </summary>
  347. /// <param name="agentID">The agent's ID</param>
  348. public void ClearUserAgent(UUID agentID)
  349. {
  350. UserProfileData profile = GetUserProfile(agentID);
  351. if (profile == null)
  352. {
  353. return;
  354. }
  355. profile.CurrentAgent = null;
  356. UpdateUserProfile(profile);
  357. }
  358. #endregion
  359. #region CreateAgent
  360. /// <summary>
  361. /// Creates and initialises a new user agent - make sure to use CommitAgent when done to submit to the DB
  362. /// </summary>
  363. /// <param name="profile">The users profile</param>
  364. /// <param name="request">The users loginrequest</param>
  365. public void CreateAgent(UserProfileData profile, XmlRpcRequest request)
  366. {
  367. UserAgentData agent = new UserAgentData();
  368. // User connection
  369. agent.AgentOnline = true;
  370. if (request.Params.Count > 1)
  371. {
  372. if (request.Params[1] != null)
  373. {
  374. IPEndPoint RemoteIPEndPoint = (IPEndPoint)request.Params[1];
  375. agent.AgentIP = RemoteIPEndPoint.Address.ToString();
  376. agent.AgentPort = (uint)RemoteIPEndPoint.Port;
  377. }
  378. }
  379. // Generate sessions
  380. RNGCryptoServiceProvider rand = new RNGCryptoServiceProvider();
  381. byte[] randDataS = new byte[16];
  382. byte[] randDataSS = new byte[16];
  383. rand.GetBytes(randDataS);
  384. rand.GetBytes(randDataSS);
  385. agent.SecureSessionID = new UUID(randDataSS, 0);
  386. agent.SessionID = new UUID(randDataS, 0);
  387. // Profile UUID
  388. agent.ProfileID = profile.ID;
  389. // Current location/position/alignment
  390. if (profile.CurrentAgent != null)
  391. {
  392. agent.Region = profile.CurrentAgent.Region;
  393. agent.Handle = profile.CurrentAgent.Handle;
  394. agent.Position = profile.CurrentAgent.Position;
  395. agent.LookAt = profile.CurrentAgent.LookAt;
  396. }
  397. else
  398. {
  399. agent.Region = profile.HomeRegionID;
  400. agent.Handle = profile.HomeRegion;
  401. agent.Position = profile.HomeLocation;
  402. agent.LookAt = profile.HomeLookAt;
  403. }
  404. // What time did the user login?
  405. agent.LoginTime = Util.UnixTimeSinceEpoch();
  406. agent.LogoutTime = 0;
  407. profile.CurrentAgent = agent;
  408. }
  409. public void CreateAgent(UserProfileData profile, OSD request)
  410. {
  411. UserAgentData agent = new UserAgentData();
  412. // User connection
  413. agent.AgentOnline = true;
  414. //if (request.Params.Count > 1)
  415. //{
  416. // IPEndPoint RemoteIPEndPoint = (IPEndPoint)request.Params[1];
  417. // agent.AgentIP = RemoteIPEndPoint.Address.ToString();
  418. // agent.AgentPort = (uint)RemoteIPEndPoint.Port;
  419. //}
  420. // Generate sessions
  421. RNGCryptoServiceProvider rand = new RNGCryptoServiceProvider();
  422. byte[] randDataS = new byte[16];
  423. byte[] randDataSS = new byte[16];
  424. rand.GetBytes(randDataS);
  425. rand.GetBytes(randDataSS);
  426. agent.SecureSessionID = new UUID(randDataSS, 0);
  427. agent.SessionID = new UUID(randDataS, 0);
  428. // Profile UUID
  429. agent.ProfileID = profile.ID;
  430. // Current location/position/alignment
  431. if (profile.CurrentAgent != null)
  432. {
  433. agent.Region = profile.CurrentAgent.Region;
  434. agent.Handle = profile.CurrentAgent.Handle;
  435. agent.Position = profile.CurrentAgent.Position;
  436. agent.LookAt = profile.CurrentAgent.LookAt;
  437. }
  438. else
  439. {
  440. agent.Region = profile.HomeRegionID;
  441. agent.Handle = profile.HomeRegion;
  442. agent.Position = profile.HomeLocation;
  443. agent.LookAt = profile.HomeLookAt;
  444. }
  445. // What time did the user login?
  446. agent.LoginTime = Util.UnixTimeSinceEpoch();
  447. agent.LogoutTime = 0;
  448. profile.CurrentAgent = agent;
  449. }
  450. /// <summary>
  451. /// Saves a target agent to the database
  452. /// </summary>
  453. /// <param name="profile">The users profile</param>
  454. /// <returns>Successful?</returns>
  455. public bool CommitAgent(ref UserProfileData profile)
  456. {
  457. // TODO: how is this function different from setUserProfile? -> Add AddUserAgent() here and commit both tables "users" and "agents"
  458. // TODO: what is the logic should be?
  459. bool ret = false;
  460. ret = AddUserAgent(profile.CurrentAgent);
  461. ret = ret & UpdateUserProfile(profile);
  462. return ret;
  463. }
  464. /// <summary>
  465. /// Process a user logoff from OpenSim.
  466. /// </summary>
  467. /// <param name="userid"></param>
  468. /// <param name="regionid"></param>
  469. /// <param name="regionhandle"></param>
  470. /// <param name="position"></param>
  471. /// <param name="lookat"></param>
  472. public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, Vector3 position, Vector3 lookat)
  473. {
  474. if (StatsManager.UserStats != null)
  475. StatsManager.UserStats.AddLogout();
  476. UserProfileData userProfile = GetUserProfile(userid);
  477. if (userProfile != null)
  478. {
  479. // This line needs to be in side the above if statement or the UserServer will crash on some logouts.
  480. m_log.Info("[LOGOUT]: " + userProfile.FirstName + " " + userProfile.SurName + " from " + regionhandle + "(" + position.X + "," + position.Y + "," + position.Z + ")");
  481. UserAgentData userAgent = userProfile.CurrentAgent;
  482. if (userAgent != null)
  483. {
  484. userAgent.AgentOnline = false;
  485. userAgent.LogoutTime = Util.UnixTimeSinceEpoch();
  486. //userAgent.sessionID = UUID.Zero;
  487. if (regionid != UUID.Zero)
  488. {
  489. userAgent.Region = regionid;
  490. }
  491. userAgent.Handle = regionhandle;
  492. userAgent.Position = position;
  493. userAgent.LookAt = lookat;
  494. //userProfile.CurrentAgent = userAgent;
  495. userProfile.LastLogin = userAgent.LogoutTime;
  496. CommitAgent(ref userProfile);
  497. }
  498. else
  499. {
  500. // If currentagent is null, we can't reference it here or the UserServer crashes!
  501. m_log.Info("[LOGOUT]: didn't save logout position: " + userid.ToString());
  502. }
  503. }
  504. else
  505. {
  506. m_log.Warn("[LOGOUT]: Unknown User logged out");
  507. }
  508. }
  509. /// <summary>
  510. /// Process a user logoff from OpenSim (deprecated as of 2008-08-27)
  511. /// </summary>
  512. /// <param name="userid"></param>
  513. /// <param name="regionid"></param>
  514. /// <param name="regionhandle"></param>
  515. /// <param name="posx"></param>
  516. /// <param name="posy"></param>
  517. /// <param name="posz"></param>
  518. public void LogOffUser(UUID userid, UUID regionid, ulong regionhandle, float posx, float posy, float posz)
  519. {
  520. LogOffUser(userid, regionid, regionhandle, new Vector3(posx, posy, posz), new Vector3());
  521. }
  522. #endregion
  523. /// <summary>
  524. /// Add a new user
  525. /// </summary>
  526. /// <param name="firstName">first name</param>
  527. /// <param name="lastName">last name</param>
  528. /// <param name="password">password</param>
  529. /// <param name="email">email</param>
  530. /// <param name="regX">location X</param>
  531. /// <param name="regY">location Y</param>
  532. /// <returns>The UUID of the created user profile. On failure, returns UUID.Zero</returns>
  533. public UUID AddUser(string firstName, string lastName, string password, string email, uint regX, uint regY)
  534. {
  535. return AddUser(firstName, lastName, password, email, regX, regY, UUID.Random());
  536. }
  537. /// <summary>
  538. /// Add a new user
  539. /// </summary>
  540. /// <param name="firstName">first name</param>
  541. /// <param name="lastName">last name</param>
  542. /// <param name="password">password</param>
  543. /// <param name="email">email</param>
  544. /// <param name="regX">location X</param>
  545. /// <param name="regY">location Y</param>
  546. /// <param name="SetUUID">UUID of avatar.</param>
  547. /// <returns>The UUID of the created user profile. On failure, returns UUID.Zero</returns>
  548. public UUID AddUser(
  549. string firstName, string lastName, string password, string email, uint regX, uint regY, UUID SetUUID)
  550. {
  551. string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) + ":" + String.Empty);
  552. UserProfileData user = new UserProfileData();
  553. user.HomeLocation = new Vector3(128, 128, 100);
  554. user.ID = SetUUID;
  555. user.FirstName = firstName;
  556. user.SurName = lastName;
  557. user.PasswordHash = md5PasswdHash;
  558. user.PasswordSalt = String.Empty;
  559. user.Created = Util.UnixTimeSinceEpoch();
  560. user.HomeLookAt = new Vector3(100, 100, 100);
  561. user.HomeRegionX = regX;
  562. user.HomeRegionY = regY;
  563. user.Email = email;
  564. foreach (IUserDataPlugin plugin in _plugins)
  565. {
  566. try
  567. {
  568. plugin.AddNewUserProfile(user);
  569. }
  570. catch (Exception e)
  571. {
  572. m_log.Error("[USERSTORAGE]: Unable to add user via " + plugin.Name + "(" + e.ToString() + ")");
  573. }
  574. }
  575. UserProfileData userProf = GetUserProfile(firstName, lastName);
  576. if (userProf == null)
  577. {
  578. return UUID.Zero;
  579. }
  580. else
  581. {
  582. m_interServiceInventoryService.CreateNewUserInventory(userProf.ID);
  583. return userProf.ID;
  584. }
  585. }
  586. /// <summary>
  587. /// Reset a user password
  588. /// </summary>
  589. /// <param name="firstName"></param>
  590. /// <param name="lastName"></param>
  591. /// <param name="newPassword"></param>
  592. /// <returns>true if the update was successful, false otherwise</returns>
  593. public bool ResetUserPassword(string firstName, string lastName, string newPassword)
  594. {
  595. string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(newPassword) + ":" + String.Empty);
  596. UserProfileData profile = GetUserProfile(firstName, lastName);
  597. if (null == profile)
  598. {
  599. m_log.ErrorFormat("[USERSTORAGE]: Could not find user {0} {1}", firstName, lastName);
  600. return false;
  601. }
  602. profile.PasswordHash = md5PasswdHash;
  603. profile.PasswordSalt = String.Empty;
  604. UpdateUserProfile(profile);
  605. return true;
  606. }
  607. public abstract UserProfileData SetupMasterUser(string firstName, string lastName);
  608. public abstract UserProfileData SetupMasterUser(string firstName, string lastName, string password);
  609. public abstract UserProfileData SetupMasterUser(UUID uuid);
  610. /// <summary>
  611. /// Add agent to DB
  612. /// </summary>
  613. /// <param name="agentdata">The agent data to be added</param>
  614. public bool AddUserAgent(UserAgentData agentdata)
  615. {
  616. foreach (IUserDataPlugin plugin in _plugins)
  617. {
  618. try
  619. {
  620. plugin.AddNewUserAgent(agentdata);
  621. return true;
  622. }
  623. catch (Exception e)
  624. {
  625. m_log.Info("[USERSTORAGE]: Unable to add agent via " + plugin.Name + "(" + e.ToString() + ")");
  626. }
  627. }
  628. return false;
  629. }
  630. /// <summary>
  631. /// Get avatar appearance information
  632. /// </summary>
  633. /// <param name="user"></param>
  634. /// <returns></returns>
  635. public AvatarAppearance GetUserAppearance(UUID user)
  636. {
  637. foreach (IUserDataPlugin plugin in _plugins)
  638. {
  639. try
  640. {
  641. return plugin.GetUserAppearance(user);
  642. }
  643. catch (Exception e)
  644. {
  645. m_log.InfoFormat("[USERSTORAGE]: Unable to find user appearance {0} via {1} ({2})", user.ToString(), plugin.Name, e.ToString());
  646. }
  647. }
  648. return null;
  649. }
  650. /// <summary>
  651. /// Update avatar appearance information
  652. /// </summary>
  653. /// <param name="user"></param>
  654. /// <param name="appearance"></param>
  655. public void UpdateUserAppearance(UUID user, AvatarAppearance appearance)
  656. {
  657. foreach (IUserDataPlugin plugin in _plugins)
  658. {
  659. try
  660. {
  661. plugin.UpdateUserAppearance(user, appearance);
  662. }
  663. catch (Exception e)
  664. {
  665. m_log.InfoFormat("[USERSTORAGE]: Unable to update user appearance {0} via {1} ({2})", user.ToString(), plugin.Name, e.ToString());
  666. }
  667. }
  668. }
  669. }
  670. }