UserManagerBase.cs 26 KB

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