clockwerk-opensim – Blame information for rev 1

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