UserAccountService.cs 28 KB

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