29 using System.Collections.Generic;
30 using System.Reflection;
35 using OpenSim.Framework;
36 using OpenSim.Services.Interfaces;
37 using OpenSim.Framework.Console;
41 namespace OpenSim.Services.UserAccountService
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 private bool m_CreateDefaultAvatarEntries;
62 IConfig userConfig = config.Configs[
"UserAccountService"];
63 if (userConfig == null)
64 throw new Exception(
"No UserAccountService configuration");
66 string gridServiceDll = userConfig.GetString(
"GridService", string.Empty);
67 if (gridServiceDll !=
string.Empty)
68 m_GridService = LoadPlugin<IGridService>(gridServiceDll,
new Object[] { config });
70 string authServiceDll = userConfig.GetString(
"AuthenticationService", string.Empty);
71 if (authServiceDll !=
string.Empty)
72 m_AuthenticationService = LoadPlugin<IAuthenticationService>(authServiceDll,
new Object[] { config });
74 string presenceServiceDll = userConfig.GetString(
"GridUserService", string.Empty);
75 if (presenceServiceDll !=
string.Empty)
76 m_GridUserService = LoadPlugin<IGridUserService>(presenceServiceDll,
new Object[] { config });
78 string invServiceDll = userConfig.GetString(
"InventoryService", string.Empty);
79 if (invServiceDll !=
string.Empty)
80 m_InventoryService = LoadPlugin<IInventoryService>(invServiceDll,
new Object[] { config });
82 string avatarServiceDll = userConfig.GetString(
"AvatarService", string.Empty);
83 if (avatarServiceDll !=
string.Empty)
84 m_AvatarService = LoadPlugin<IAvatarService>(avatarServiceDll,
new Object[] { config });
86 m_CreateDefaultAvatarEntries = userConfig.GetBoolean(
"CreateDefaultAvatarEntries",
false);
92 m_RootInstance =
this;
93 MainConsole.Instance.Commands.AddCommand(
"Users",
false,
95 "create user [<first> [<last> [<pass> [<email> [<user id>]]]]]",
96 "Create a new user", HandleCreateUser);
98 MainConsole.Instance.Commands.AddCommand(
"Users",
false,
99 "reset user password",
100 "reset user password [<first> [<last> [<password>]]]",
101 "Reset a user password", HandleResetUserPassword);
103 MainConsole.Instance.Commands.AddCommand(
"Users",
false,
105 "reset user email [<first> [<last> [<email>]]]",
106 "Reset a user email address", HandleResetUserEmail);
108 MainConsole.Instance.Commands.AddCommand(
"Users",
false,
110 "set user level [<first> [<last> [<level>]]]",
111 "Set user level. If >= 200 and 'allow_grid_gods = true' in OpenSim.ini, "
112 +
"this account will be treated as god-moded. "
113 +
"It will also affect the 'login level' command. ",
116 MainConsole.Instance.Commands.AddCommand(
"Users",
false,
118 "show account <first> <last>",
119 "Show account details for the given user", HandleShowAccount);
123 #region IUserAccountService
134 if (scopeID != UUID.Zero)
137 new string[] {
"ScopeID",
"FirstName",
"LastName" },
138 new string[] { scopeID.ToString(), firstName, lastName });
142 new string[] {
"ScopeID",
"FirstName",
"LastName" },
143 new string[] { UUID.Zero.ToString(), firstName, lastName });
149 new string[] {
"FirstName",
"LastName" },
150 new string[] { firstName, lastName });
156 return MakeUserAccount(d[0]);
162 u.FirstName = d.FirstName;
163 u.LastName = d.LastName;
164 u.PrincipalID = d.PrincipalID;
165 u.ScopeID = d.ScopeID;
166 if (d.
Data.ContainsKey(
"Email") && d.Data[
"Email"] != null)
169 u.Email = string.Empty;
170 u.Created = Convert.ToInt32(d.Data[
"Created"].ToString());
171 if (d.
Data.ContainsKey(
"UserTitle") && d.Data[
"UserTitle"] != null)
174 u.UserTitle = string.Empty;
175 if (d.
Data.ContainsKey(
"UserLevel") && d.Data[
"UserLevel"] != null)
177 if (d.
Data.ContainsKey(
"UserFlags") && d.Data[
"UserFlags"] != null)
179 if (d.
Data.ContainsKey(
"UserCountry") && d.Data[
"UserCountry"] != null)
182 u.UserTitle = string.Empty;
184 if (d.
Data.ContainsKey(
"ServiceURLs") && d.Data[
"ServiceURLs"] != null)
186 string[] URLs = d.Data[
"ServiceURLs"].ToString().Split(
new char[] {
' ' });
187 u.ServiceURLs =
new Dictionary<string, object>();
189 foreach (
string url
in URLs)
191 string[] parts = url.Split(
new char[] {
'=' });
193 if (parts.Length != 2)
196 string name = System.Web.HttpUtility.UrlDecode(parts[0]);
197 string val = System.Web.HttpUtility.UrlDecode(parts[1]);
199 u.ServiceURLs[name] = val;
203 u.ServiceURLs =
new Dictionary<string, object>();
212 if (scopeID != UUID.Zero)
215 new string[] {
"ScopeID",
"Email" },
216 new string[] { scopeID.ToString(), email });
220 new string[] {
"ScopeID",
"Email" },
221 new string[] { UUID.Zero.ToString(), email });
227 new string[] {
"Email" },
228 new string[] { email });
234 return MakeUserAccount(d[0]);
241 if (scopeID != UUID.Zero)
244 new string[] {
"ScopeID",
"PrincipalID" },
245 new string[] { scopeID.ToString(), principalID.ToString() });
249 new string[] {
"ScopeID",
"PrincipalID" },
250 new string[] { UUID.Zero.ToString(), principalID.ToString() });
256 new string[] {
"PrincipalID" },
257 new string[] { principalID.ToString() });
265 return MakeUserAccount(d[0]);
280 d.FirstName = data.FirstName;
281 d.LastName = data.LastName;
282 d.PrincipalID = data.PrincipalID;
283 d.ScopeID = data.ScopeID;
284 d.Data =
new Dictionary<string, string>();
285 d.Data[
"Email"] = data.Email;
286 d.Data[
"Created"] = data.Created.ToString();
287 d.Data[
"UserLevel"] = data.UserLevel.ToString();
288 d.Data[
"UserFlags"] = data.UserFlags.ToString();
290 d.Data[
"UserTitle"] = data.UserTitle.ToString();
292 List<string> parts =
new List<string>();
294 foreach (KeyValuePair<string, object> kvp
in data.ServiceURLs)
296 string key = System.Web.HttpUtility.UrlEncode(kvp.Key);
297 string val = System.Web.HttpUtility.UrlEncode(kvp.Value.ToString());
298 parts.Add(key +
"=" + val);
301 d.Data[
"ServiceURLs"] = string.Join(
" ", parts.ToArray());
303 return m_Database.Store(d);
311 return new List<UserAccount>();
313 List<UserAccount> ret =
new List<UserAccount>();
316 ret.Add(MakeUserAccount(data));
326 return new List<UserAccount>();
328 List<UserAccount> ret =
new List<UserAccount>();
331 ret.Add(MakeUserAccount(data));
338 #region Console commands
350 string rawPrincipalId;
352 List<char> excluded =
new List<char>(
new char[]{
' '});
354 if (cmdparams.Length < 3)
355 firstName = MainConsole.Instance.CmdPrompt(
"First name",
"Default", excluded);
356 else firstName = cmdparams[2];
358 if (cmdparams.Length < 4)
359 lastName = MainConsole.Instance.CmdPrompt(
"Last name",
"User", excluded);
360 else lastName = cmdparams[3];
362 if (cmdparams.Length < 5)
363 password = MainConsole.Instance.PasswdPrompt(
"Password");
364 else password = cmdparams[4];
366 if (cmdparams.Length < 6)
367 email = MainConsole.Instance.CmdPrompt(
"Email",
"");
368 else email = cmdparams[5];
370 if (cmdparams.Length < 7)
371 rawPrincipalId = MainConsole.Instance.CmdPrompt(
"User ID", UUID.Random().ToString());
373 rawPrincipalId = cmdparams[6];
375 UUID principalId = UUID.Zero;
376 if (!UUID.TryParse(rawPrincipalId, out principalId))
377 throw new Exception(
string.Format(
"ID {0} is not a valid UUID", rawPrincipalId));
379 CreateUser(UUID.Zero, principalId, firstName, lastName, password, email);
384 if (cmdparams.Length != 4)
386 MainConsole.Instance.Output(
"Usage: show account <first-name> <last-name>");
390 string firstName = cmdparams[2];
391 string lastName = cmdparams[3];
393 UserAccount ua = GetUserAccount(UUID.Zero, firstName, lastName);
397 MainConsole.Instance.OutputFormat(
"No user named {0} {1}", firstName, lastName);
401 MainConsole.Instance.OutputFormat(
"Name: {0}", ua.Name);
402 MainConsole.Instance.OutputFormat(
"ID: {0}", ua.PrincipalID);
403 MainConsole.Instance.OutputFormat(
"Title: {0}", ua.UserTitle);
404 MainConsole.Instance.OutputFormat(
"E-mail: {0}", ua.Email);
405 MainConsole.Instance.OutputFormat(
"Created: {0}", Utils.UnixTimeToDateTime(ua.Created));
406 MainConsole.Instance.OutputFormat(
"Level: {0}", ua.UserLevel);
407 MainConsole.Instance.OutputFormat(
"Flags: {0}", ua.UserFlags);
408 foreach (KeyValuePair<string, Object> kvp
in ua.ServiceURLs)
409 MainConsole.Instance.OutputFormat(
"{0}: {1}", kvp.Key, kvp.Value);
418 if (cmdparams.Length < 4)
419 firstName = MainConsole.Instance.CmdPrompt(
"First name");
420 else firstName = cmdparams[3];
422 if (cmdparams.Length < 5)
423 lastName = MainConsole.Instance.CmdPrompt(
"Last name");
424 else lastName = cmdparams[4];
426 if (cmdparams.Length < 6)
427 newPassword = MainConsole.Instance.PasswdPrompt(
"New password");
428 else newPassword = cmdparams[5];
430 UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
433 MainConsole.Instance.OutputFormat(
"No such user as {0} {1}", firstName, lastName);
437 bool success =
false;
438 if (m_AuthenticationService != null)
439 success = m_AuthenticationService.SetPassword(account.PrincipalID, newPassword);
442 MainConsole.Instance.OutputFormat(
"Unable to reset password for account {0} {1}.", firstName, lastName);
444 MainConsole.Instance.OutputFormat(
"Password reset for user {0} {1}", firstName, lastName);
453 if (cmdparams.Length < 4)
454 firstName = MainConsole.Instance.CmdPrompt(
"First name");
455 else firstName = cmdparams[3];
457 if (cmdparams.Length < 5)
458 lastName = MainConsole.Instance.CmdPrompt(
"Last name");
459 else lastName = cmdparams[4];
461 if (cmdparams.Length < 6)
462 newEmail = MainConsole.Instance.PasswdPrompt(
"New Email");
463 else newEmail = cmdparams[5];
465 UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
468 MainConsole.Instance.OutputFormat(
"No such user as {0} {1}", firstName, lastName);
472 bool success =
false;
474 account.Email = newEmail;
476 success = StoreUserAccount(account);
478 MainConsole.Instance.OutputFormat(
"Unable to set Email for account {0} {1}.", firstName, lastName);
480 MainConsole.Instance.OutputFormat(
"User Email set for user {0} {1} to {2}", firstName, lastName, account.Email);
491 if (cmdparams.Length < 4)
492 firstName = MainConsole.Instance.CmdPrompt(
"First name");
493 else firstName = cmdparams[3];
495 if (cmdparams.Length < 5)
496 lastName = MainConsole.Instance.CmdPrompt(
"Last name");
497 else lastName = cmdparams[4];
499 UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
500 if (account == null) {
501 MainConsole.Instance.OutputFormat(
"No such user");
505 if (cmdparams.Length < 6)
506 rawLevel = MainConsole.Instance.CmdPrompt(
"User level");
507 else rawLevel = cmdparams[5];
509 if(
int.TryParse(rawLevel, out level) ==
false) {
510 MainConsole.Instance.OutputFormat(
"Invalid user level");
514 account.UserLevel = level;
516 bool success = StoreUserAccount(account);
518 MainConsole.Instance.OutputFormat(
"Unable to set user level for account {0} {1}.", firstName, lastName);
520 MainConsole.Instance.OutputFormat(
"User level set for user {0} {1} to {2}", firstName, lastName, level);
534 public UserAccount CreateUser(UUID scopeID, UUID principalID,
string firstName,
string lastName,
string password,
string email)
536 UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
539 account =
new UserAccount(UUID.Zero, principalID, firstName, lastName, email);
542 account.ServiceURLs =
new Dictionary<string, object>();
543 account.ServiceURLs[
"HomeURI"] = string.Empty;
544 account.ServiceURLs[
"InventoryServerURI"] = string.Empty;
545 account.ServiceURLs[
"AssetServerURI"] = string.Empty;
548 if (StoreUserAccount(account))
551 if (m_AuthenticationService != null)
553 success = m_AuthenticationService.SetPassword(account.PrincipalID, password);
555 m_log.WarnFormat(
"[USER ACCOUNT SERVICE]: Unable to set password for account {0} {1}.",
556 firstName, lastName);
560 if (m_GridService != null)
562 List<GridRegion> defaultRegions = m_GridService.GetDefaultRegions(UUID.Zero);
563 if (defaultRegions != null && defaultRegions.Count >= 1)
564 home = defaultRegions[0];
566 if (m_GridUserService != null && home != null)
567 m_GridUserService.SetHome(account.PrincipalID.ToString(), home.
RegionID,
new Vector3(128, 128, 0),
new Vector3(0, 1, 0));
569 m_log.WarnFormat(
"[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.",
570 firstName, lastName);
574 m_log.WarnFormat(
"[USER ACCOUNT SERVICE]: Unable to retrieve home region for account {0} {1}.",
575 firstName, lastName);
578 if (m_InventoryService != null)
580 success = m_InventoryService.CreateUserInventory(account.PrincipalID);
583 m_log.WarnFormat(
"[USER ACCOUNT SERVICE]: Unable to create inventory for account {0} {1}.",
584 firstName, lastName);
589 "[USER ACCOUNT SERVICE]: Created user inventory for {0} {1}", firstName, lastName);
592 if (m_CreateDefaultAvatarEntries)
593 CreateDefaultAppearanceEntries(account.
PrincipalID);
597 "[USER ACCOUNT SERVICE]: Account {0} {1} {2} created successfully",
598 firstName, lastName, account.PrincipalID);
602 m_log.ErrorFormat(
"[USER ACCOUNT SERVICE]: Account creation failed for account {0} {1}", firstName, lastName);
607 m_log.ErrorFormat(
"[USER ACCOUNT SERVICE]: A user with the name {0} {1} already exists!", firstName, lastName);
615 m_log.DebugFormat(
"[USER ACCOUNT SERVICE]: Creating default appearance items for {0}", principalID);
617 InventoryFolderBase bodyPartsFolder = m_InventoryService.GetFolderForType(principalID, FolderType.BodyPart);
620 eyes.AssetID =
new UUID(
"4bb6fa4d-1cd2-498a-a84c-95c1a0e745a7");
621 eyes.Name =
"Default Eyes";
622 eyes.CreatorId = principalID.ToString();
623 eyes.AssetType = (int)AssetType.Bodypart;
624 eyes.InvType = (
int)InventoryType.Wearable;
625 eyes.Folder = bodyPartsFolder.ID;
627 eyes.CurrentPermissions = (uint)PermissionMask.All;
629 eyes.GroupPermissions = (uint)PermissionMask.All;
631 eyes.Flags = (uint)WearableType.Eyes;
632 m_InventoryService.AddItem(eyes);
635 shape.AssetID = AvatarWearable.DEFAULT_BODY_ASSET;
636 shape.Name =
"Default Shape";
637 shape.CreatorId = principalID.ToString();
638 shape.AssetType = (int)AssetType.Bodypart;
639 shape.
InvType = (
int)InventoryType.Wearable;
640 shape.Folder = bodyPartsFolder.ID;
642 shape.CurrentPermissions = (uint)PermissionMask.All;
644 shape.GroupPermissions = (uint)PermissionMask.All;
646 shape.Flags = (uint)WearableType.Shape;
647 m_InventoryService.AddItem(shape);
650 skin.AssetID = AvatarWearable.DEFAULT_SKIN_ASSET;
651 skin.Name =
"Default Skin";
652 skin.CreatorId = principalID.ToString();
653 skin.AssetType = (int)AssetType.Bodypart;
654 skin.
InvType = (
int)InventoryType.Wearable;
655 skin.Folder = bodyPartsFolder.ID;
657 skin.CurrentPermissions = (uint)PermissionMask.All;
659 skin.GroupPermissions = (uint)PermissionMask.All;
661 skin.Flags = (uint)WearableType.Skin;
662 m_InventoryService.AddItem(skin);
665 hair.AssetID = AvatarWearable.DEFAULT_HAIR_ASSET;
666 hair.Name =
"Default Hair";
667 hair.CreatorId = principalID.ToString();
668 hair.AssetType = (int)AssetType.Bodypart;
669 hair.
InvType = (
int)InventoryType.Wearable;
670 hair.Folder = bodyPartsFolder.ID;
672 hair.CurrentPermissions = (uint)PermissionMask.All;
674 hair.GroupPermissions = (uint)PermissionMask.All;
676 hair.Flags = (uint)WearableType.Hair;
677 m_InventoryService.AddItem(hair);
679 InventoryFolderBase clothingFolder = m_InventoryService.GetFolderForType(principalID, FolderType.Clothing);
682 shirt.AssetID = AvatarWearable.DEFAULT_SHIRT_ASSET;
683 shirt.Name =
"Default Shirt";
684 shirt.CreatorId = principalID.ToString();
685 shirt.AssetType = (int)AssetType.Clothing;
686 shirt.
InvType = (
int)InventoryType.Wearable;
687 shirt.Folder = clothingFolder.ID;
689 shirt.CurrentPermissions = (uint)PermissionMask.All;
691 shirt.GroupPermissions = (uint)PermissionMask.All;
693 shirt.Flags = (uint)WearableType.Shirt;
694 m_InventoryService.AddItem(shirt);
697 pants.AssetID = AvatarWearable.DEFAULT_PANTS_ASSET;
698 pants.Name =
"Default Pants";
699 pants.CreatorId = principalID.ToString();
700 pants.AssetType = (int)AssetType.Clothing;
701 pants.
InvType = (
int)InventoryType.Wearable;
702 pants.Folder = clothingFolder.ID;
704 pants.CurrentPermissions = (uint)PermissionMask.All;
706 pants.GroupPermissions = (uint)PermissionMask.All;
708 pants.Flags = (uint)WearableType.Pants;
709 m_InventoryService.AddItem(pants);
711 if (m_AvatarService != null)
713 m_log.DebugFormat(
"[USER ACCOUNT SERVICE]: Creating default avatar entries for {0}", principalID);
716 wearables[AvatarWearable.EYES] =
new AvatarWearable(eyes.ID, eyes.AssetID);
717 wearables[AvatarWearable.BODY] =
new AvatarWearable(shape.ID, shape.AssetID);
718 wearables[AvatarWearable.SKIN] =
new AvatarWearable(skin.ID, skin.AssetID);
719 wearables[AvatarWearable.HAIR] =
new AvatarWearable(hair.ID, hair.AssetID);
720 wearables[AvatarWearable.SHIRT] =
new AvatarWearable(shirt.ID, shirt.AssetID);
721 wearables[AvatarWearable.PANTS] =
new AvatarWearable(pants.ID, pants.AssetID);
724 for (
int i = 0; i < 6; i++)
726 ap.SetWearable(i, wearables[i]);
729 m_AvatarService.SetAppearance(principalID, ap);
OpenSim.Services.Interfaces.GridRegion GridRegion
List< UserAccount > GetUserAccountsWhere(UUID scopeID, string where)
OpenSim.Framework.PermissionMask PermissionMask
List< UserAccount > GetUserAccounts(UUID scopeID, string query)
Returns the list of avatars that matches both the search criterion and the scope ID passed ...
void CreateDefaultAppearanceEntries(UUID principalID)
Contains the Avatar's Appearance and methods to manipulate the appearance.
UserAccount GetUserAccount(UUID scopeID, UUID principalID)
UserAccount CreateUser(UUID scopeID, UUID principalID, string firstName, string lastName, string password, string email)
Create a user
IAuthenticationService m_AuthenticationService
void HandleResetUserEmail(string module, string[] cmdparams)
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString key
IGridService m_GridService
IGridUserService m_GridUserService
UserAccountService(IConfigSource config)
Dictionary< string, string > Data
void HandleResetUserPassword(string module, string[] cmdparams)
Inventory Item - contains all the properties associated with an individual inventory piece...
static ICommandConsole Instance
bool StoreUserAccount(UserAccount data)
Store the data given, wich replaces the stored data, therefore must be complete.
void HandleShowAccount(string module, string[] cmdparams)
IInventoryService m_InventoryService
UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
UserAccount GetUserAccount(UUID scopeID, string email)
Dictionary< string, object > ServiceURLs
void HandleCreateUser(string module, string[] cmdparams)
Handle the create user command from the console.
void HandleSetUserLevel(string module, string[] cmdparams)
IAvatarService m_AvatarService
void InvalidateCache(UUID userID)