UserAccountService.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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("ServiceURLs") && d.Data["ServiceURLs"] != null)
  157. {
  158. string[] URLs = d.Data["ServiceURLs"].ToString().Split(new char[] { ' ' });
  159. u.ServiceURLs = new Dictionary<string, object>();
  160. foreach (string url in URLs)
  161. {
  162. string[] parts = url.Split(new char[] { '=' });
  163. if (parts.Length != 2)
  164. continue;
  165. string name = System.Web.HttpUtility.UrlDecode(parts[0]);
  166. string val = System.Web.HttpUtility.UrlDecode(parts[1]);
  167. u.ServiceURLs[name] = val;
  168. }
  169. }
  170. else
  171. u.ServiceURLs = new Dictionary<string, object>();
  172. return u;
  173. }
  174. public UserAccount GetUserAccount(UUID scopeID, string email)
  175. {
  176. UserAccountData[] d;
  177. if (scopeID != UUID.Zero)
  178. {
  179. d = m_Database.Get(
  180. new string[] { "ScopeID", "Email" },
  181. new string[] { scopeID.ToString(), email });
  182. if (d.Length < 1)
  183. {
  184. d = m_Database.Get(
  185. new string[] { "ScopeID", "Email" },
  186. new string[] { UUID.Zero.ToString(), email });
  187. }
  188. }
  189. else
  190. {
  191. d = m_Database.Get(
  192. new string[] { "Email" },
  193. new string[] { email });
  194. }
  195. if (d.Length < 1)
  196. return null;
  197. return MakeUserAccount(d[0]);
  198. }
  199. public UserAccount GetUserAccount(UUID scopeID, UUID principalID)
  200. {
  201. UserAccountData[] d;
  202. if (scopeID != UUID.Zero)
  203. {
  204. d = m_Database.Get(
  205. new string[] { "ScopeID", "PrincipalID" },
  206. new string[] { scopeID.ToString(), principalID.ToString() });
  207. if (d.Length < 1)
  208. {
  209. d = m_Database.Get(
  210. new string[] { "ScopeID", "PrincipalID" },
  211. new string[] { UUID.Zero.ToString(), principalID.ToString() });
  212. }
  213. }
  214. else
  215. {
  216. d = m_Database.Get(
  217. new string[] { "PrincipalID" },
  218. new string[] { principalID.ToString() });
  219. }
  220. if (d.Length < 1)
  221. {
  222. return null;
  223. }
  224. return MakeUserAccount(d[0]);
  225. }
  226. public void InvalidateCache(UUID userID)
  227. {
  228. }
  229. public bool StoreUserAccount(UserAccount data)
  230. {
  231. // m_log.DebugFormat(
  232. // "[USER ACCOUNT SERVICE]: Storing user account for {0} {1} {2}, scope {3}",
  233. // data.FirstName, data.LastName, data.PrincipalID, data.ScopeID);
  234. UserAccountData d = new UserAccountData();
  235. d.FirstName = data.FirstName;
  236. d.LastName = data.LastName;
  237. d.PrincipalID = data.PrincipalID;
  238. d.ScopeID = data.ScopeID;
  239. d.Data = new Dictionary<string, string>();
  240. d.Data["Email"] = data.Email;
  241. d.Data["Created"] = data.Created.ToString();
  242. d.Data["UserLevel"] = data.UserLevel.ToString();
  243. d.Data["UserFlags"] = data.UserFlags.ToString();
  244. if (data.UserTitle != null)
  245. d.Data["UserTitle"] = data.UserTitle.ToString();
  246. List<string> parts = new List<string>();
  247. foreach (KeyValuePair<string, object> kvp in data.ServiceURLs)
  248. {
  249. string key = System.Web.HttpUtility.UrlEncode(kvp.Key);
  250. string val = System.Web.HttpUtility.UrlEncode(kvp.Value.ToString());
  251. parts.Add(key + "=" + val);
  252. }
  253. d.Data["ServiceURLs"] = string.Join(" ", parts.ToArray());
  254. return m_Database.Store(d);
  255. }
  256. public List<UserAccount> GetUserAccounts(UUID scopeID, string query)
  257. {
  258. UserAccountData[] d = m_Database.GetUsers(scopeID, query);
  259. if (d == null)
  260. return new List<UserAccount>();
  261. List<UserAccount> ret = new List<UserAccount>();
  262. foreach (UserAccountData data in d)
  263. ret.Add(MakeUserAccount(data));
  264. return ret;
  265. }
  266. #endregion
  267. #region Console commands
  268. /// <summary>
  269. /// Handle the create user command from the console.
  270. /// </summary>
  271. /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param>
  272. protected void HandleCreateUser(string module, string[] cmdparams)
  273. {
  274. string firstName;
  275. string lastName;
  276. string password;
  277. string email;
  278. string rawPrincipalId;
  279. List<char> excluded = new List<char>(new char[]{' '});
  280. if (cmdparams.Length < 3)
  281. firstName = MainConsole.Instance.CmdPrompt("First name", "Default", excluded);
  282. else firstName = cmdparams[2];
  283. if (cmdparams.Length < 4)
  284. lastName = MainConsole.Instance.CmdPrompt("Last name", "User", excluded);
  285. else lastName = cmdparams[3];
  286. if (cmdparams.Length < 5)
  287. password = MainConsole.Instance.PasswdPrompt("Password");
  288. else password = cmdparams[4];
  289. if (cmdparams.Length < 6)
  290. email = MainConsole.Instance.CmdPrompt("Email", "");
  291. else email = cmdparams[5];
  292. if (cmdparams.Length < 7)
  293. rawPrincipalId = MainConsole.Instance.CmdPrompt("User ID", UUID.Random().ToString());
  294. else
  295. rawPrincipalId = cmdparams[6];
  296. UUID principalId = UUID.Zero;
  297. if (!UUID.TryParse(rawPrincipalId, out principalId))
  298. throw new Exception(string.Format("ID {0} is not a valid UUID", rawPrincipalId));
  299. CreateUser(UUID.Zero, principalId, firstName, lastName, password, email);
  300. }
  301. protected void HandleShowAccount(string module, string[] cmdparams)
  302. {
  303. if (cmdparams.Length != 4)
  304. {
  305. MainConsole.Instance.Output("Usage: show account <first-name> <last-name>");
  306. return;
  307. }
  308. string firstName = cmdparams[2];
  309. string lastName = cmdparams[3];
  310. UserAccount ua = GetUserAccount(UUID.Zero, firstName, lastName);
  311. if (ua == null)
  312. {
  313. MainConsole.Instance.OutputFormat("No user named {0} {1}", firstName, lastName);
  314. return;
  315. }
  316. MainConsole.Instance.OutputFormat("Name: {0}", ua.Name);
  317. MainConsole.Instance.OutputFormat("ID: {0}", ua.PrincipalID);
  318. MainConsole.Instance.OutputFormat("Title: {0}", ua.UserTitle);
  319. MainConsole.Instance.OutputFormat("E-mail: {0}", ua.Email);
  320. MainConsole.Instance.OutputFormat("Created: {0}", Utils.UnixTimeToDateTime(ua.Created));
  321. MainConsole.Instance.OutputFormat("Level: {0}", ua.UserLevel);
  322. MainConsole.Instance.OutputFormat("Flags: {0}", ua.UserFlags);
  323. foreach (KeyValuePair<string, Object> kvp in ua.ServiceURLs)
  324. MainConsole.Instance.OutputFormat("{0}: {1}", kvp.Key, kvp.Value);
  325. }
  326. protected void HandleResetUserPassword(string module, string[] cmdparams)
  327. {
  328. string firstName;
  329. string lastName;
  330. string newPassword;
  331. if (cmdparams.Length < 4)
  332. firstName = MainConsole.Instance.CmdPrompt("First name");
  333. else firstName = cmdparams[3];
  334. if (cmdparams.Length < 5)
  335. lastName = MainConsole.Instance.CmdPrompt("Last name");
  336. else lastName = cmdparams[4];
  337. if (cmdparams.Length < 6)
  338. newPassword = MainConsole.Instance.PasswdPrompt("New password");
  339. else newPassword = cmdparams[5];
  340. UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
  341. if (account == null)
  342. {
  343. MainConsole.Instance.OutputFormat("No such user as {0} {1}", firstName, lastName);
  344. return;
  345. }
  346. bool success = false;
  347. if (m_AuthenticationService != null)
  348. success = m_AuthenticationService.SetPassword(account.PrincipalID, newPassword);
  349. if (!success)
  350. MainConsole.Instance.OutputFormat("Unable to reset password for account {0} {1}.", firstName, lastName);
  351. else
  352. MainConsole.Instance.OutputFormat("Password reset for user {0} {1}", firstName, lastName);
  353. }
  354. protected void HandleResetUserEmail(string module, string[] cmdparams)
  355. {
  356. string firstName;
  357. string lastName;
  358. string newEmail;
  359. if (cmdparams.Length < 4)
  360. firstName = MainConsole.Instance.CmdPrompt("First name");
  361. else firstName = cmdparams[3];
  362. if (cmdparams.Length < 5)
  363. lastName = MainConsole.Instance.CmdPrompt("Last name");
  364. else lastName = cmdparams[4];
  365. if (cmdparams.Length < 6)
  366. newEmail = MainConsole.Instance.PasswdPrompt("New Email");
  367. else newEmail = cmdparams[5];
  368. UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
  369. if (account == null)
  370. {
  371. MainConsole.Instance.OutputFormat("No such user as {0} {1}", firstName, lastName);
  372. return;
  373. }
  374. bool success = false;
  375. account.Email = newEmail;
  376. success = StoreUserAccount(account);
  377. if (!success)
  378. MainConsole.Instance.OutputFormat("Unable to set Email for account {0} {1}.", firstName, lastName);
  379. else
  380. MainConsole.Instance.OutputFormat("User Email set for user {0} {1} to {2}", firstName, lastName, account.Email);
  381. }
  382. protected void HandleSetUserLevel(string module, string[] cmdparams)
  383. {
  384. string firstName;
  385. string lastName;
  386. string rawLevel;
  387. int level;
  388. if (cmdparams.Length < 4)
  389. firstName = MainConsole.Instance.CmdPrompt("First name");
  390. else firstName = cmdparams[3];
  391. if (cmdparams.Length < 5)
  392. lastName = MainConsole.Instance.CmdPrompt("Last name");
  393. else lastName = cmdparams[4];
  394. UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
  395. if (account == null) {
  396. MainConsole.Instance.OutputFormat("No such user");
  397. return;
  398. }
  399. if (cmdparams.Length < 6)
  400. rawLevel = MainConsole.Instance.CmdPrompt("User level");
  401. else rawLevel = cmdparams[5];
  402. if(int.TryParse(rawLevel, out level) == false) {
  403. MainConsole.Instance.OutputFormat("Invalid user level");
  404. return;
  405. }
  406. account.UserLevel = level;
  407. bool success = StoreUserAccount(account);
  408. if (!success)
  409. MainConsole.Instance.OutputFormat("Unable to set user level for account {0} {1}.", firstName, lastName);
  410. else
  411. MainConsole.Instance.OutputFormat("User level set for user {0} {1} to {2}", firstName, lastName, level);
  412. }
  413. #endregion
  414. /// <summary>
  415. /// Create a user
  416. /// </summary>
  417. /// <param name="scopeID">Allows hosting of multiple grids in a single database. Normally left as UUID.Zero</param>
  418. /// <param name="principalID">ID of the user</param>
  419. /// <param name="firstName"></param>
  420. /// <param name="lastName"></param>
  421. /// <param name="password"></param>
  422. /// <param name="email"></param>
  423. public UserAccount CreateUser(UUID scopeID, UUID principalID, string firstName, string lastName, string password, string email)
  424. {
  425. UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
  426. if (null == account)
  427. {
  428. account = new UserAccount(UUID.Zero, principalID, firstName, lastName, email);
  429. if (account.ServiceURLs == null || (account.ServiceURLs != null && account.ServiceURLs.Count == 0))
  430. {
  431. account.ServiceURLs = new Dictionary<string, object>();
  432. account.ServiceURLs["HomeURI"] = string.Empty;
  433. account.ServiceURLs["InventoryServerURI"] = string.Empty;
  434. account.ServiceURLs["AssetServerURI"] = string.Empty;
  435. }
  436. if (StoreUserAccount(account))
  437. {
  438. bool success;
  439. if (m_AuthenticationService != null)
  440. {
  441. success = m_AuthenticationService.SetPassword(account.PrincipalID, password);
  442. if (!success)
  443. m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set password for account {0} {1}.",
  444. firstName, lastName);
  445. }
  446. GridRegion home = null;
  447. if (m_GridService != null)
  448. {
  449. List<GridRegion> defaultRegions = m_GridService.GetDefaultRegions(UUID.Zero);
  450. if (defaultRegions != null && defaultRegions.Count >= 1)
  451. home = defaultRegions[0];
  452. if (m_GridUserService != null && home != null)
  453. m_GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
  454. else
  455. m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.",
  456. firstName, lastName);
  457. }
  458. else
  459. {
  460. m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to retrieve home region for account {0} {1}.",
  461. firstName, lastName);
  462. }
  463. if (m_InventoryService != null)
  464. {
  465. success = m_InventoryService.CreateUserInventory(account.PrincipalID);
  466. if (!success)
  467. {
  468. m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to create inventory for account {0} {1}.",
  469. firstName, lastName);
  470. }
  471. else
  472. {
  473. m_log.DebugFormat(
  474. "[USER ACCOUNT SERVICE]: Created user inventory for {0} {1}", firstName, lastName);
  475. }
  476. if (m_CreateDefaultAvatarEntries)
  477. CreateDefaultAppearanceEntries(account.PrincipalID);
  478. }
  479. m_log.InfoFormat(
  480. "[USER ACCOUNT SERVICE]: Account {0} {1} {2} created successfully",
  481. firstName, lastName, account.PrincipalID);
  482. }
  483. else
  484. {
  485. m_log.ErrorFormat("[USER ACCOUNT SERVICE]: Account creation failed for account {0} {1}", firstName, lastName);
  486. }
  487. }
  488. else
  489. {
  490. m_log.ErrorFormat("[USER ACCOUNT SERVICE]: A user with the name {0} {1} already exists!", firstName, lastName);
  491. }
  492. return account;
  493. }
  494. protected void CreateDefaultAppearanceEntries(UUID principalID)
  495. {
  496. m_log.DebugFormat("[USER ACCOUNT SERVICE]: Creating default appearance items for {0}", principalID);
  497. InventoryFolderBase bodyPartsFolder = m_InventoryService.GetFolderForType(principalID, AssetType.Bodypart);
  498. InventoryItemBase eyes = new InventoryItemBase(UUID.Random(), principalID);
  499. eyes.AssetID = new UUID("4bb6fa4d-1cd2-498a-a84c-95c1a0e745a7");
  500. eyes.Name = "Default Eyes";
  501. eyes.CreatorId = principalID.ToString();
  502. eyes.AssetType = (int)AssetType.Bodypart;
  503. eyes.InvType = (int)InventoryType.Wearable;
  504. eyes.Folder = bodyPartsFolder.ID;
  505. eyes.BasePermissions = (uint)PermissionMask.All;
  506. eyes.CurrentPermissions = (uint)PermissionMask.All;
  507. eyes.EveryOnePermissions = (uint)PermissionMask.All;
  508. eyes.GroupPermissions = (uint)PermissionMask.All;
  509. eyes.NextPermissions = (uint)PermissionMask.All;
  510. eyes.Flags = (uint)WearableType.Eyes;
  511. m_InventoryService.AddItem(eyes);
  512. InventoryItemBase shape = new InventoryItemBase(UUID.Random(), principalID);
  513. shape.AssetID = AvatarWearable.DEFAULT_BODY_ASSET;
  514. shape.Name = "Default Shape";
  515. shape.CreatorId = principalID.ToString();
  516. shape.AssetType = (int)AssetType.Bodypart;
  517. shape.InvType = (int)InventoryType.Wearable;
  518. shape.Folder = bodyPartsFolder.ID;
  519. shape.BasePermissions = (uint)PermissionMask.All;
  520. shape.CurrentPermissions = (uint)PermissionMask.All;
  521. shape.EveryOnePermissions = (uint)PermissionMask.All;
  522. shape.GroupPermissions = (uint)PermissionMask.All;
  523. shape.NextPermissions = (uint)PermissionMask.All;
  524. shape.Flags = (uint)WearableType.Shape;
  525. m_InventoryService.AddItem(shape);
  526. InventoryItemBase skin = new InventoryItemBase(UUID.Random(), principalID);
  527. skin.AssetID = AvatarWearable.DEFAULT_SKIN_ASSET;
  528. skin.Name = "Default Skin";
  529. skin.CreatorId = principalID.ToString();
  530. skin.AssetType = (int)AssetType.Bodypart;
  531. skin.InvType = (int)InventoryType.Wearable;
  532. skin.Folder = bodyPartsFolder.ID;
  533. skin.BasePermissions = (uint)PermissionMask.All;
  534. skin.CurrentPermissions = (uint)PermissionMask.All;
  535. skin.EveryOnePermissions = (uint)PermissionMask.All;
  536. skin.GroupPermissions = (uint)PermissionMask.All;
  537. skin.NextPermissions = (uint)PermissionMask.All;
  538. skin.Flags = (uint)WearableType.Skin;
  539. m_InventoryService.AddItem(skin);
  540. InventoryItemBase hair = new InventoryItemBase(UUID.Random(), principalID);
  541. hair.AssetID = AvatarWearable.DEFAULT_HAIR_ASSET;
  542. hair.Name = "Default Hair";
  543. hair.CreatorId = principalID.ToString();
  544. hair.AssetType = (int)AssetType.Bodypart;
  545. hair.InvType = (int)InventoryType.Wearable;
  546. hair.Folder = bodyPartsFolder.ID;
  547. hair.BasePermissions = (uint)PermissionMask.All;
  548. hair.CurrentPermissions = (uint)PermissionMask.All;
  549. hair.EveryOnePermissions = (uint)PermissionMask.All;
  550. hair.GroupPermissions = (uint)PermissionMask.All;
  551. hair.NextPermissions = (uint)PermissionMask.All;
  552. hair.Flags = (uint)WearableType.Hair;
  553. m_InventoryService.AddItem(hair);
  554. InventoryFolderBase clothingFolder = m_InventoryService.GetFolderForType(principalID, AssetType.Clothing);
  555. InventoryItemBase shirt = new InventoryItemBase(UUID.Random(), principalID);
  556. shirt.AssetID = AvatarWearable.DEFAULT_SHIRT_ASSET;
  557. shirt.Name = "Default Shirt";
  558. shirt.CreatorId = principalID.ToString();
  559. shirt.AssetType = (int)AssetType.Clothing;
  560. shirt.InvType = (int)InventoryType.Wearable;
  561. shirt.Folder = clothingFolder.ID;
  562. shirt.BasePermissions = (uint)PermissionMask.All;
  563. shirt.CurrentPermissions = (uint)PermissionMask.All;
  564. shirt.EveryOnePermissions = (uint)PermissionMask.All;
  565. shirt.GroupPermissions = (uint)PermissionMask.All;
  566. shirt.NextPermissions = (uint)PermissionMask.All;
  567. shirt.Flags = (uint)WearableType.Shirt;
  568. m_InventoryService.AddItem(shirt);
  569. InventoryItemBase pants = new InventoryItemBase(UUID.Random(), principalID);
  570. pants.AssetID = AvatarWearable.DEFAULT_PANTS_ASSET;
  571. pants.Name = "Default Pants";
  572. pants.CreatorId = principalID.ToString();
  573. pants.AssetType = (int)AssetType.Clothing;
  574. pants.InvType = (int)InventoryType.Wearable;
  575. pants.Folder = clothingFolder.ID;
  576. pants.BasePermissions = (uint)PermissionMask.All;
  577. pants.CurrentPermissions = (uint)PermissionMask.All;
  578. pants.EveryOnePermissions = (uint)PermissionMask.All;
  579. pants.GroupPermissions = (uint)PermissionMask.All;
  580. pants.NextPermissions = (uint)PermissionMask.All;
  581. pants.Flags = (uint)WearableType.Pants;
  582. m_InventoryService.AddItem(pants);
  583. if (m_AvatarService != null)
  584. {
  585. m_log.DebugFormat("[USER ACCOUNT SERVICE]: Creating default avatar entries for {0}", principalID);
  586. AvatarWearable[] wearables = new AvatarWearable[6];
  587. wearables[AvatarWearable.EYES] = new AvatarWearable(eyes.ID, eyes.AssetID);
  588. wearables[AvatarWearable.BODY] = new AvatarWearable(shape.ID, shape.AssetID);
  589. wearables[AvatarWearable.SKIN] = new AvatarWearable(skin.ID, skin.AssetID);
  590. wearables[AvatarWearable.HAIR] = new AvatarWearable(hair.ID, hair.AssetID);
  591. wearables[AvatarWearable.SHIRT] = new AvatarWearable(shirt.ID, shirt.AssetID);
  592. wearables[AvatarWearable.PANTS] = new AvatarWearable(pants.ID, pants.AssetID);
  593. AvatarAppearance ap = new AvatarAppearance();
  594. for (int i = 0; i < 6; i++)
  595. {
  596. ap.SetWearable(i, wearables[i]);
  597. }
  598. m_AvatarService.SetAppearance(principalID, ap);
  599. }
  600. }
  601. }
  602. }