UserAccountService.cs 29 KB

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