UserAccountService.cs 29 KB

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