UserAccountService.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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 OpenSimulator 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 log4net;
  31. using Nini.Config;
  32. using OpenMetaverse;
  33. using OpenSim.Data;
  34. using OpenSim.Framework;
  35. using OpenSim.Services.Interfaces;
  36. using OpenSim.Framework.Console;
  37. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  38. using PermissionMask = OpenSim.Framework.PermissionMask;
  39. namespace OpenSim.Services.UserAccountService
  40. {
  41. public class UserAccountService : UserAccountServiceBase, IUserAccountService
  42. {
  43. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. private static UserAccountService m_RootInstance;
  45. /// <summary>
  46. /// Should we create default entries (minimum body parts/clothing, avatar wearable entries) for a new avatar?
  47. /// </summary>
  48. private bool m_CreateDefaultAvatarEntries;
  49. protected IGridService m_GridService;
  50. protected IAuthenticationService m_AuthenticationService;
  51. protected IGridUserService m_GridUserService;
  52. protected IInventoryService m_InventoryService;
  53. protected IAvatarService m_AvatarService;
  54. public UserAccountService(IConfigSource config)
  55. : base(config)
  56. {
  57. IConfig userConfig = config.Configs["UserAccountService"];
  58. if (userConfig == null)
  59. throw new Exception("No UserAccountService configuration");
  60. string gridServiceDll = userConfig.GetString("GridService", string.Empty);
  61. if (gridServiceDll != string.Empty)
  62. m_GridService = LoadPlugin<IGridService>(gridServiceDll, new Object[] { config });
  63. string authServiceDll = userConfig.GetString("AuthenticationService", string.Empty);
  64. if (authServiceDll != string.Empty)
  65. m_AuthenticationService = LoadPlugin<IAuthenticationService>(authServiceDll, new Object[] { config });
  66. string presenceServiceDll = userConfig.GetString("GridUserService", string.Empty);
  67. if (presenceServiceDll != string.Empty)
  68. m_GridUserService = LoadPlugin<IGridUserService>(presenceServiceDll, new Object[] { config });
  69. string invServiceDll = userConfig.GetString("InventoryService", string.Empty);
  70. if (invServiceDll != string.Empty)
  71. m_InventoryService = LoadPlugin<IInventoryService>(invServiceDll, new Object[] { config });
  72. string avatarServiceDll = userConfig.GetString("AvatarService", string.Empty);
  73. if (avatarServiceDll != string.Empty)
  74. m_AvatarService = LoadPlugin<IAvatarService>(avatarServiceDll, new Object[] { config });
  75. m_CreateDefaultAvatarEntries = userConfig.GetBoolean("CreateDefaultAvatarEntries", false);
  76. // In case there are several instances of this class in the same process,
  77. // the console commands are only registered for the root instance
  78. if (m_RootInstance == null && MainConsole.Instance != null)
  79. {
  80. m_RootInstance = this;
  81. MainConsole.Instance.Commands.AddCommand("Users", false,
  82. "create user",
  83. "create user [<first> [<last> [<pass> [<email> [<user id>]]]]]",
  84. "Create a new user", HandleCreateUser);
  85. MainConsole.Instance.Commands.AddCommand("Users", false,
  86. "reset user password",
  87. "reset user password [<first> [<last> [<password>]]]",
  88. "Reset a user password", HandleResetUserPassword);
  89. MainConsole.Instance.Commands.AddCommand("Users", false,
  90. "reset user email",
  91. "reset user email [<first> [<last> [<email>]]]",
  92. "Reset a user email address", HandleResetUserEmail);
  93. MainConsole.Instance.Commands.AddCommand("Users", false,
  94. "set user level",
  95. "set user level [<first> [<last> [<level>]]]",
  96. "Set user level. If >= 200 and 'allow_grid_gods = true' in OpenSim.ini, "
  97. + "this account will be treated as god-moded. "
  98. + "It will also affect the 'login level' command. ",
  99. HandleSetUserLevel);
  100. MainConsole.Instance.Commands.AddCommand("Users", false,
  101. "show account",
  102. "show account <first> <last>",
  103. "Show account details for the given user", HandleShowAccount);
  104. }
  105. }
  106. #region IUserAccountService
  107. public UserAccount GetUserAccount(UUID scopeID, string firstName,
  108. string lastName)
  109. {
  110. // m_log.DebugFormat(
  111. // "[USER ACCOUNT SERVICE]: Retrieving account by username for {0} {1}, scope {2}",
  112. // firstName, lastName, scopeID);
  113. UserAccountData[] d;
  114. if (scopeID != UUID.Zero)
  115. {
  116. d = m_Database.Get(
  117. new string[] { "ScopeID", "FirstName", "LastName" },
  118. new string[] { scopeID.ToString(), firstName, lastName });
  119. if (d.Length < 1)
  120. {
  121. d = m_Database.Get(
  122. new string[] { "ScopeID", "FirstName", "LastName" },
  123. new string[] { UUID.Zero.ToString(), firstName, lastName });
  124. }
  125. }
  126. else
  127. {
  128. d = m_Database.Get(
  129. new string[] { "FirstName", "LastName" },
  130. new string[] { firstName, lastName });
  131. }
  132. if (d.Length < 1)
  133. return null;
  134. return MakeUserAccount(d[0]);
  135. }
  136. private UserAccount MakeUserAccount(UserAccountData d)
  137. {
  138. UserAccount u = new UserAccount();
  139. u.FirstName = d.FirstName;
  140. u.LastName = d.LastName;
  141. u.PrincipalID = d.PrincipalID;
  142. u.ScopeID = d.ScopeID;
  143. if (d.Data.ContainsKey("Email") && d.Data["Email"] != null)
  144. u.Email = d.Data["Email"].ToString();
  145. else
  146. u.Email = string.Empty;
  147. u.Created = Convert.ToInt32(d.Data["Created"].ToString());
  148. if (d.Data.ContainsKey("UserTitle") && d.Data["UserTitle"] != null)
  149. u.UserTitle = d.Data["UserTitle"].ToString();
  150. else
  151. u.UserTitle = string.Empty;
  152. if (d.Data.ContainsKey("UserLevel") && d.Data["UserLevel"] != null)
  153. Int32.TryParse(d.Data["UserLevel"], out u.UserLevel);
  154. if (d.Data.ContainsKey("UserFlags") && d.Data["UserFlags"] != null)
  155. Int32.TryParse(d.Data["UserFlags"], out u.UserFlags);
  156. if (d.Data.ContainsKey("UserCountry") && d.Data["UserCountry"] != null)
  157. u.UserCountry = d.Data["UserCountry"].ToString();
  158. else
  159. u.UserTitle = string.Empty;
  160. if (d.Data.ContainsKey("ServiceURLs") && d.Data["ServiceURLs"] != null)
  161. {
  162. string[] URLs = d.Data["ServiceURLs"].ToString().Split(new char[] { ' ' });
  163. u.ServiceURLs = new Dictionary<string, object>();
  164. foreach (string url in URLs)
  165. {
  166. string[] parts = url.Split(new char[] { '=' });
  167. if (parts.Length != 2)
  168. continue;
  169. string name = System.Web.HttpUtility.UrlDecode(parts[0]);
  170. string val = System.Web.HttpUtility.UrlDecode(parts[1]);
  171. u.ServiceURLs[name] = val;
  172. }
  173. }
  174. else
  175. u.ServiceURLs = new Dictionary<string, object>();
  176. return u;
  177. }
  178. public UserAccount GetUserAccount(UUID scopeID, string email)
  179. {
  180. UserAccountData[] d;
  181. if (scopeID != UUID.Zero)
  182. {
  183. d = m_Database.Get(
  184. new string[] { "ScopeID", "Email" },
  185. new string[] { scopeID.ToString(), email });
  186. if (d.Length < 1)
  187. {
  188. d = m_Database.Get(
  189. new string[] { "ScopeID", "Email" },
  190. new string[] { UUID.Zero.ToString(), email });
  191. }
  192. }
  193. else
  194. {
  195. d = m_Database.Get(
  196. new string[] { "Email" },
  197. new string[] { email });
  198. }
  199. if (d.Length < 1)
  200. return null;
  201. return MakeUserAccount(d[0]);
  202. }
  203. public UserAccount GetUserAccount(UUID scopeID, UUID principalID)
  204. {
  205. UserAccountData[] d;
  206. if (scopeID != UUID.Zero)
  207. {
  208. d = m_Database.Get(
  209. new string[] { "ScopeID", "PrincipalID" },
  210. new string[] { scopeID.ToString(), principalID.ToString() });
  211. if (d.Length < 1)
  212. {
  213. d = m_Database.Get(
  214. new string[] { "ScopeID", "PrincipalID" },
  215. new string[] { UUID.Zero.ToString(), principalID.ToString() });
  216. }
  217. }
  218. else
  219. {
  220. d = m_Database.Get(
  221. new string[] { "PrincipalID" },
  222. new string[] { principalID.ToString() });
  223. }
  224. if (d.Length < 1)
  225. {
  226. return null;
  227. }
  228. return MakeUserAccount(d[0]);
  229. }
  230. public void InvalidateCache(UUID userID)
  231. {
  232. }
  233. public bool StoreUserAccount(UserAccount data)
  234. {
  235. // m_log.DebugFormat(
  236. // "[USER ACCOUNT SERVICE]: Storing user account for {0} {1} {2}, scope {3}",
  237. // data.FirstName, data.LastName, data.PrincipalID, data.ScopeID);
  238. UserAccountData d = new UserAccountData();
  239. d.FirstName = data.FirstName;
  240. d.LastName = data.LastName;
  241. d.PrincipalID = data.PrincipalID;
  242. d.ScopeID = data.ScopeID;
  243. d.Data = new Dictionary<string, string>();
  244. d.Data["Email"] = data.Email;
  245. d.Data["Created"] = data.Created.ToString();
  246. d.Data["UserLevel"] = data.UserLevel.ToString();
  247. d.Data["UserFlags"] = data.UserFlags.ToString();
  248. if (data.UserTitle != null)
  249. d.Data["UserTitle"] = data.UserTitle.ToString();
  250. List<string> parts = new List<string>();
  251. foreach (KeyValuePair<string, object> kvp in data.ServiceURLs)
  252. {
  253. string key = System.Web.HttpUtility.UrlEncode(kvp.Key);
  254. string val = System.Web.HttpUtility.UrlEncode(kvp.Value.ToString());
  255. parts.Add(key + "=" + val);
  256. }
  257. d.Data["ServiceURLs"] = string.Join(" ", parts.ToArray());
  258. return m_Database.Store(d);
  259. }
  260. public List<UserAccount> GetUserAccounts(UUID scopeID, string query)
  261. {
  262. UserAccountData[] d = m_Database.GetUsers(scopeID, query.Trim());
  263. if (d == null)
  264. return new List<UserAccount>();
  265. List<UserAccount> ret = new List<UserAccount>();
  266. foreach (UserAccountData data in d)
  267. ret.Add(MakeUserAccount(data));
  268. return ret;
  269. }
  270. public List<UserAccount> GetUserAccountsWhere(UUID scopeID, string where)
  271. {
  272. UserAccountData[] d = m_Database.GetUsersWhere(scopeID, where);
  273. if (d == null)
  274. return new List<UserAccount>();
  275. List<UserAccount> ret = new List<UserAccount>();
  276. foreach (UserAccountData data in d)
  277. ret.Add(MakeUserAccount(data));
  278. return ret;
  279. }
  280. #endregion
  281. #region Console commands
  282. /// <summary>
  283. /// Handle the create user command from the console.
  284. /// </summary>
  285. /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param>
  286. protected void HandleCreateUser(string module, string[] cmdparams)
  287. {
  288. string firstName;
  289. string lastName;
  290. string password;
  291. string email;
  292. string rawPrincipalId;
  293. List<char> excluded = new List<char>(new char[]{' '});
  294. if (cmdparams.Length < 3)
  295. firstName = MainConsole.Instance.CmdPrompt("First name", "Default", excluded);
  296. else firstName = cmdparams[2];
  297. if (cmdparams.Length < 4)
  298. lastName = MainConsole.Instance.CmdPrompt("Last name", "User", excluded);
  299. else lastName = cmdparams[3];
  300. if (cmdparams.Length < 5)
  301. password = MainConsole.Instance.PasswdPrompt("Password");
  302. else password = cmdparams[4];
  303. if (cmdparams.Length < 6)
  304. email = MainConsole.Instance.CmdPrompt("Email", "");
  305. else email = cmdparams[5];
  306. if (cmdparams.Length < 7)
  307. rawPrincipalId = MainConsole.Instance.CmdPrompt("User ID", UUID.Random().ToString());
  308. else
  309. rawPrincipalId = cmdparams[6];
  310. UUID principalId = UUID.Zero;
  311. if (!UUID.TryParse(rawPrincipalId, out principalId))
  312. throw new Exception(string.Format("ID {0} is not a valid UUID", rawPrincipalId));
  313. CreateUser(UUID.Zero, principalId, firstName, lastName, password, email);
  314. }
  315. protected void HandleShowAccount(string module, string[] cmdparams)
  316. {
  317. if (cmdparams.Length != 4)
  318. {
  319. MainConsole.Instance.Output("Usage: show account <first-name> <last-name>");
  320. return;
  321. }
  322. string firstName = cmdparams[2];
  323. string lastName = cmdparams[3];
  324. UserAccount ua = GetUserAccount(UUID.Zero, firstName, lastName);
  325. if (ua == null)
  326. {
  327. MainConsole.Instance.OutputFormat("No user named {0} {1}", firstName, lastName);
  328. return;
  329. }
  330. MainConsole.Instance.OutputFormat("Name: {0}", ua.Name);
  331. MainConsole.Instance.OutputFormat("ID: {0}", ua.PrincipalID);
  332. MainConsole.Instance.OutputFormat("Title: {0}", ua.UserTitle);
  333. MainConsole.Instance.OutputFormat("E-mail: {0}", ua.Email);
  334. MainConsole.Instance.OutputFormat("Created: {0}", Utils.UnixTimeToDateTime(ua.Created));
  335. MainConsole.Instance.OutputFormat("Level: {0}", ua.UserLevel);
  336. MainConsole.Instance.OutputFormat("Flags: {0}", ua.UserFlags);
  337. foreach (KeyValuePair<string, Object> kvp in ua.ServiceURLs)
  338. MainConsole.Instance.OutputFormat("{0}: {1}", kvp.Key, kvp.Value);
  339. }
  340. protected void HandleResetUserPassword(string module, string[] cmdparams)
  341. {
  342. string firstName;
  343. string lastName;
  344. string newPassword;
  345. if (cmdparams.Length < 4)
  346. firstName = MainConsole.Instance.CmdPrompt("First name");
  347. else firstName = cmdparams[3];
  348. if (cmdparams.Length < 5)
  349. lastName = MainConsole.Instance.CmdPrompt("Last name");
  350. else lastName = cmdparams[4];
  351. if (cmdparams.Length < 6)
  352. newPassword = MainConsole.Instance.PasswdPrompt("New password");
  353. else newPassword = cmdparams[5];
  354. UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
  355. if (account == null)
  356. {
  357. MainConsole.Instance.OutputFormat("No such user as {0} {1}", firstName, lastName);
  358. return;
  359. }
  360. bool success = false;
  361. if (m_AuthenticationService != null)
  362. success = m_AuthenticationService.SetPassword(account.PrincipalID, newPassword);
  363. if (!success)
  364. MainConsole.Instance.OutputFormat("Unable to reset password for account {0} {1}.", firstName, lastName);
  365. else
  366. MainConsole.Instance.OutputFormat("Password reset for user {0} {1}", firstName, lastName);
  367. }
  368. protected void HandleResetUserEmail(string module, string[] cmdparams)
  369. {
  370. string firstName;
  371. string lastName;
  372. string newEmail;
  373. if (cmdparams.Length < 4)
  374. firstName = MainConsole.Instance.CmdPrompt("First name");
  375. else firstName = cmdparams[3];
  376. if (cmdparams.Length < 5)
  377. lastName = MainConsole.Instance.CmdPrompt("Last name");
  378. else lastName = cmdparams[4];
  379. if (cmdparams.Length < 6)
  380. newEmail = MainConsole.Instance.PasswdPrompt("New Email");
  381. else newEmail = cmdparams[5];
  382. UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
  383. if (account == null)
  384. {
  385. MainConsole.Instance.OutputFormat("No such user as {0} {1}", firstName, lastName);
  386. return;
  387. }
  388. bool success = false;
  389. account.Email = newEmail;
  390. success = StoreUserAccount(account);
  391. if (!success)
  392. MainConsole.Instance.OutputFormat("Unable to set Email for account {0} {1}.", firstName, lastName);
  393. else
  394. MainConsole.Instance.OutputFormat("User Email set for user {0} {1} to {2}", firstName, lastName, account.Email);
  395. }
  396. protected void HandleSetUserLevel(string module, string[] cmdparams)
  397. {
  398. string firstName;
  399. string lastName;
  400. string rawLevel;
  401. int level;
  402. if (cmdparams.Length < 4)
  403. firstName = MainConsole.Instance.CmdPrompt("First name");
  404. else firstName = cmdparams[3];
  405. if (cmdparams.Length < 5)
  406. lastName = MainConsole.Instance.CmdPrompt("Last name");
  407. else lastName = cmdparams[4];
  408. UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
  409. if (account == null) {
  410. MainConsole.Instance.OutputFormat("No such user");
  411. return;
  412. }
  413. if (cmdparams.Length < 6)
  414. rawLevel = MainConsole.Instance.CmdPrompt("User level");
  415. else rawLevel = cmdparams[5];
  416. if(int.TryParse(rawLevel, out level) == false) {
  417. MainConsole.Instance.OutputFormat("Invalid user level");
  418. return;
  419. }
  420. account.UserLevel = level;
  421. bool success = StoreUserAccount(account);
  422. if (!success)
  423. MainConsole.Instance.OutputFormat("Unable to set user level for account {0} {1}.", firstName, lastName);
  424. else
  425. MainConsole.Instance.OutputFormat("User level set for user {0} {1} to {2}", firstName, lastName, level);
  426. }
  427. #endregion
  428. /// <summary>
  429. /// Create a user
  430. /// </summary>
  431. /// <param name="scopeID">Allows hosting of multiple grids in a single database. Normally left as UUID.Zero</param>
  432. /// <param name="principalID">ID of the user</param>
  433. /// <param name="firstName"></param>
  434. /// <param name="lastName"></param>
  435. /// <param name="password"></param>
  436. /// <param name="email"></param>
  437. public UserAccount CreateUser(UUID scopeID, UUID principalID, string firstName, string lastName, string password, string email)
  438. {
  439. UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
  440. if (null == account)
  441. {
  442. account = new UserAccount(UUID.Zero, principalID, firstName, lastName, email);
  443. if (account.ServiceURLs == null || (account.ServiceURLs != null && account.ServiceURLs.Count == 0))
  444. {
  445. account.ServiceURLs = new Dictionary<string, object>();
  446. account.ServiceURLs["HomeURI"] = string.Empty;
  447. account.ServiceURLs["InventoryServerURI"] = string.Empty;
  448. account.ServiceURLs["AssetServerURI"] = string.Empty;
  449. }
  450. if (StoreUserAccount(account))
  451. {
  452. bool success;
  453. if (m_AuthenticationService != null)
  454. {
  455. success = m_AuthenticationService.SetPassword(account.PrincipalID, password);
  456. if (!success)
  457. m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set password for account {0} {1}.",
  458. firstName, lastName);
  459. }
  460. GridRegion home = null;
  461. if (m_GridService != null)
  462. {
  463. List<GridRegion> defaultRegions = m_GridService.GetDefaultRegions(UUID.Zero);
  464. if (defaultRegions != null && defaultRegions.Count >= 1)
  465. home = defaultRegions[0];
  466. if (m_GridUserService != null && home != null)
  467. m_GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
  468. else
  469. m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.",
  470. firstName, lastName);
  471. }
  472. else
  473. {
  474. m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to retrieve home region for account {0} {1}.",
  475. firstName, lastName);
  476. }
  477. if (m_InventoryService != null)
  478. {
  479. success = m_InventoryService.CreateUserInventory(account.PrincipalID);
  480. if (!success)
  481. {
  482. m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to create inventory for account {0} {1}.",
  483. firstName, lastName);
  484. }
  485. else
  486. {
  487. m_log.DebugFormat(
  488. "[USER ACCOUNT SERVICE]: Created user inventory for {0} {1}", firstName, lastName);
  489. }
  490. if (m_CreateDefaultAvatarEntries)
  491. CreateDefaultAppearanceEntries(account.PrincipalID);
  492. }
  493. m_log.InfoFormat(
  494. "[USER ACCOUNT SERVICE]: Account {0} {1} {2} created successfully",
  495. firstName, lastName, account.PrincipalID);
  496. }
  497. else
  498. {
  499. m_log.ErrorFormat("[USER ACCOUNT SERVICE]: Account creation failed for account {0} {1}", firstName, lastName);
  500. }
  501. }
  502. else
  503. {
  504. m_log.ErrorFormat("[USER ACCOUNT SERVICE]: A user with the name {0} {1} already exists!", firstName, lastName);
  505. }
  506. return account;
  507. }
  508. protected void CreateDefaultAppearanceEntries(UUID principalID)
  509. {
  510. m_log.DebugFormat("[USER ACCOUNT SERVICE]: Creating default appearance items for {0}", principalID);
  511. InventoryFolderBase bodyPartsFolder = m_InventoryService.GetFolderForType(principalID, FolderType.BodyPart);
  512. InventoryItemBase eyes = new InventoryItemBase(UUID.Random(), principalID);
  513. eyes.AssetID = new UUID("4bb6fa4d-1cd2-498a-a84c-95c1a0e745a7");
  514. eyes.Name = "Default Eyes";
  515. eyes.CreatorId = principalID.ToString();
  516. eyes.AssetType = (int)AssetType.Bodypart;
  517. eyes.InvType = (int)InventoryType.Wearable;
  518. eyes.Folder = bodyPartsFolder.ID;
  519. eyes.BasePermissions = (uint)PermissionMask.All;
  520. eyes.CurrentPermissions = (uint)PermissionMask.All;
  521. eyes.EveryOnePermissions = (uint)PermissionMask.All;
  522. eyes.GroupPermissions = (uint)PermissionMask.All;
  523. eyes.NextPermissions = (uint)PermissionMask.All;
  524. eyes.Flags = (uint)WearableType.Eyes;
  525. m_InventoryService.AddItem(eyes);
  526. InventoryItemBase shape = new InventoryItemBase(UUID.Random(), principalID);
  527. shape.AssetID = AvatarWearable.DEFAULT_BODY_ASSET;
  528. shape.Name = "Default Shape";
  529. shape.CreatorId = principalID.ToString();
  530. shape.AssetType = (int)AssetType.Bodypart;
  531. shape.InvType = (int)InventoryType.Wearable;
  532. shape.Folder = bodyPartsFolder.ID;
  533. shape.BasePermissions = (uint)PermissionMask.All;
  534. shape.CurrentPermissions = (uint)PermissionMask.All;
  535. shape.EveryOnePermissions = (uint)PermissionMask.All;
  536. shape.GroupPermissions = (uint)PermissionMask.All;
  537. shape.NextPermissions = (uint)PermissionMask.All;
  538. shape.Flags = (uint)WearableType.Shape;
  539. m_InventoryService.AddItem(shape);
  540. InventoryItemBase skin = new InventoryItemBase(UUID.Random(), principalID);
  541. skin.AssetID = AvatarWearable.DEFAULT_SKIN_ASSET;
  542. skin.Name = "Default Skin";
  543. skin.CreatorId = principalID.ToString();
  544. skin.AssetType = (int)AssetType.Bodypart;
  545. skin.InvType = (int)InventoryType.Wearable;
  546. skin.Folder = bodyPartsFolder.ID;
  547. skin.BasePermissions = (uint)PermissionMask.All;
  548. skin.CurrentPermissions = (uint)PermissionMask.All;
  549. skin.EveryOnePermissions = (uint)PermissionMask.All;
  550. skin.GroupPermissions = (uint)PermissionMask.All;
  551. skin.NextPermissions = (uint)PermissionMask.All;
  552. skin.Flags = (uint)WearableType.Skin;
  553. m_InventoryService.AddItem(skin);
  554. InventoryItemBase hair = new InventoryItemBase(UUID.Random(), principalID);
  555. hair.AssetID = AvatarWearable.DEFAULT_HAIR_ASSET;
  556. hair.Name = "Default Hair";
  557. hair.CreatorId = principalID.ToString();
  558. hair.AssetType = (int)AssetType.Bodypart;
  559. hair.InvType = (int)InventoryType.Wearable;
  560. hair.Folder = bodyPartsFolder.ID;
  561. hair.BasePermissions = (uint)PermissionMask.All;
  562. hair.CurrentPermissions = (uint)PermissionMask.All;
  563. hair.EveryOnePermissions = (uint)PermissionMask.All;
  564. hair.GroupPermissions = (uint)PermissionMask.All;
  565. hair.NextPermissions = (uint)PermissionMask.All;
  566. hair.Flags = (uint)WearableType.Hair;
  567. m_InventoryService.AddItem(hair);
  568. InventoryFolderBase clothingFolder = m_InventoryService.GetFolderForType(principalID, FolderType.Clothing);
  569. InventoryItemBase shirt = new InventoryItemBase(UUID.Random(), principalID);
  570. shirt.AssetID = AvatarWearable.DEFAULT_SHIRT_ASSET;
  571. shirt.Name = "Default Shirt";
  572. shirt.CreatorId = principalID.ToString();
  573. shirt.AssetType = (int)AssetType.Clothing;
  574. shirt.InvType = (int)InventoryType.Wearable;
  575. shirt.Folder = clothingFolder.ID;
  576. shirt.BasePermissions = (uint)PermissionMask.All;
  577. shirt.CurrentPermissions = (uint)PermissionMask.All;
  578. shirt.EveryOnePermissions = (uint)PermissionMask.All;
  579. shirt.GroupPermissions = (uint)PermissionMask.All;
  580. shirt.NextPermissions = (uint)PermissionMask.All;
  581. shirt.Flags = (uint)WearableType.Shirt;
  582. m_InventoryService.AddItem(shirt);
  583. InventoryItemBase pants = new InventoryItemBase(UUID.Random(), principalID);
  584. pants.AssetID = AvatarWearable.DEFAULT_PANTS_ASSET;
  585. pants.Name = "Default Pants";
  586. pants.CreatorId = principalID.ToString();
  587. pants.AssetType = (int)AssetType.Clothing;
  588. pants.InvType = (int)InventoryType.Wearable;
  589. pants.Folder = clothingFolder.ID;
  590. pants.BasePermissions = (uint)PermissionMask.All;
  591. pants.CurrentPermissions = (uint)PermissionMask.All;
  592. pants.EveryOnePermissions = (uint)PermissionMask.All;
  593. pants.GroupPermissions = (uint)PermissionMask.All;
  594. pants.NextPermissions = (uint)PermissionMask.All;
  595. pants.Flags = (uint)WearableType.Pants;
  596. m_InventoryService.AddItem(pants);
  597. if (m_AvatarService != null)
  598. {
  599. m_log.DebugFormat("[USER ACCOUNT SERVICE]: Creating default avatar entries for {0}", principalID);
  600. AvatarWearable[] wearables = new AvatarWearable[6];
  601. wearables[AvatarWearable.EYES] = new AvatarWearable(eyes.ID, eyes.AssetID);
  602. wearables[AvatarWearable.BODY] = new AvatarWearable(shape.ID, shape.AssetID);
  603. wearables[AvatarWearable.SKIN] = new AvatarWearable(skin.ID, skin.AssetID);
  604. wearables[AvatarWearable.HAIR] = new AvatarWearable(hair.ID, hair.AssetID);
  605. wearables[AvatarWearable.SHIRT] = new AvatarWearable(shirt.ID, shirt.AssetID);
  606. wearables[AvatarWearable.PANTS] = new AvatarWearable(pants.ID, pants.AssetID);
  607. AvatarAppearance ap = new AvatarAppearance();
  608. for (int i = 0; i < 6; i++)
  609. {
  610. ap.SetWearable(i, wearables[i]);
  611. }
  612. m_AvatarService.SetAppearance(principalID, ap);
  613. }
  614. }
  615. }
  616. }