UserAccountService.cs 28 KB

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