UserManagementModule.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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.IO;
  30. using System.Reflection;
  31. using System.Threading;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Console;
  34. using OpenSim.Framework.Monitoring;
  35. using OpenSim.Region.ClientStack.LindenUDP;
  36. using OpenSim.Region.Framework;
  37. using OpenSim.Region.Framework.Interfaces;
  38. using OpenSim.Region.Framework.Scenes;
  39. using OpenSim.Services.Interfaces;
  40. using OpenSim.Services.Connectors.Hypergrid;
  41. using OpenMetaverse;
  42. using OpenMetaverse.Packets;
  43. using log4net;
  44. using Nini.Config;
  45. using Mono.Addins;
  46. using DirFindFlags = OpenMetaverse.DirectoryManager.DirFindFlags;
  47. namespace OpenSim.Region.CoreModules.Framework.UserManagement
  48. {
  49. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UserManagementModule")]
  50. public class UserManagementModule : ISharedRegionModule, IUserManagement, IPeople
  51. {
  52. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  53. protected bool m_Enabled;
  54. protected List<Scene> m_Scenes = new List<Scene>();
  55. protected IServiceThrottleModule m_ServiceThrottle;
  56. // The cache
  57. protected Dictionary<UUID, UserData> m_UserCache = new Dictionary<UUID, UserData>();
  58. #region ISharedRegionModule
  59. public void Initialise(IConfigSource config)
  60. {
  61. string umanmod = config.Configs["Modules"].GetString("UserManagementModule", Name);
  62. if (umanmod == Name)
  63. {
  64. m_Enabled = true;
  65. Init();
  66. m_log.DebugFormat("[USER MANAGEMENT MODULE]: {0} is enabled", Name);
  67. }
  68. }
  69. public bool IsSharedModule
  70. {
  71. get { return true; }
  72. }
  73. public virtual string Name
  74. {
  75. get { return "BasicUserManagementModule"; }
  76. }
  77. public Type ReplaceableInterface
  78. {
  79. get { return null; }
  80. }
  81. public void AddRegion(Scene scene)
  82. {
  83. if (m_Enabled)
  84. {
  85. m_Scenes.Add(scene);
  86. scene.RegisterModuleInterface<IUserManagement>(this);
  87. scene.RegisterModuleInterface<IPeople>(this);
  88. scene.EventManager.OnNewClient += new EventManager.OnNewClientDelegate(EventManager_OnNewClient);
  89. scene.EventManager.OnPrimsLoaded += new EventManager.PrimsLoaded(EventManager_OnPrimsLoaded);
  90. }
  91. }
  92. public void RemoveRegion(Scene scene)
  93. {
  94. if (m_Enabled)
  95. {
  96. scene.UnregisterModuleInterface<IUserManagement>(this);
  97. m_Scenes.Remove(scene);
  98. }
  99. }
  100. public void RegionLoaded(Scene s)
  101. {
  102. if (m_Enabled && m_ServiceThrottle == null)
  103. m_ServiceThrottle = s.RequestModuleInterface<IServiceThrottleModule>();
  104. }
  105. public void PostInitialise()
  106. {
  107. }
  108. public void Close()
  109. {
  110. m_Scenes.Clear();
  111. lock (m_UserCache)
  112. m_UserCache.Clear();
  113. }
  114. #endregion ISharedRegionModule
  115. #region Event Handlers
  116. void EventManager_OnPrimsLoaded(Scene s)
  117. {
  118. // let's sniff all the user names referenced by objects in the scene
  119. m_log.DebugFormat("[USER MANAGEMENT MODULE]: Caching creators' data from {0} ({1} objects)...", s.RegionInfo.RegionName, s.GetEntities().Length);
  120. s.ForEachSOG(delegate(SceneObjectGroup sog) { CacheCreators(sog); });
  121. }
  122. void EventManager_OnNewClient(IClientAPI client)
  123. {
  124. client.OnConnectionClosed += new Action<IClientAPI>(HandleConnectionClosed);
  125. client.OnNameFromUUIDRequest += new UUIDNameRequest(HandleUUIDNameRequest);
  126. client.OnAvatarPickerRequest += new AvatarPickerRequest(HandleAvatarPickerRequest);
  127. }
  128. void HandleConnectionClosed(IClientAPI client)
  129. {
  130. client.OnNameFromUUIDRequest -= new UUIDNameRequest(HandleUUIDNameRequest);
  131. client.OnAvatarPickerRequest -= new AvatarPickerRequest(HandleAvatarPickerRequest);
  132. }
  133. void HandleUUIDNameRequest(UUID uuid, IClientAPI client)
  134. {
  135. // m_log.DebugFormat(
  136. // "[USER MANAGEMENT MODULE]: Handling request for name binding of UUID {0} from {1}",
  137. // uuid, remote_client.Name);
  138. if (m_Scenes[0].LibraryService != null && (m_Scenes[0].LibraryService.LibraryRootFolder.Owner == uuid))
  139. {
  140. client.SendNameReply(uuid, "Mr", "OpenSim");
  141. }
  142. else
  143. {
  144. string[] names = new string[2];
  145. if (TryGetUserNamesFromCache(uuid, names))
  146. {
  147. client.SendNameReply(uuid, names[0], names[1]);
  148. return;
  149. }
  150. // Not found in cache, queue continuation
  151. m_ServiceThrottle.Enqueue("name", uuid.ToString(), delegate
  152. {
  153. //m_log.DebugFormat("[YYY]: Name request {0}", uuid);
  154. bool foundRealName = TryGetUserNames(uuid, names);
  155. if (names.Length == 2)
  156. {
  157. if (!foundRealName)
  158. m_log.DebugFormat("[USER MANAGEMENT MODULE]: Sending {0} {1} for {2} to {3} since no bound name found", names[0], names[1], uuid, client.Name);
  159. client.SendNameReply(uuid, names[0], names[1]);
  160. }
  161. });
  162. }
  163. }
  164. public void HandleAvatarPickerRequest(IClientAPI client, UUID avatarID, UUID RequestID, string query)
  165. {
  166. //EventManager.TriggerAvatarPickerRequest();
  167. m_log.DebugFormat("[USER MANAGEMENT MODULE]: HandleAvatarPickerRequest for {0}", query);
  168. List<UserData> users = GetUserData(query, 500, 1);
  169. AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply);
  170. // TODO: don't create new blocks if recycling an old packet
  171. AvatarPickerReplyPacket.DataBlock[] searchData =
  172. new AvatarPickerReplyPacket.DataBlock[users.Count];
  173. AvatarPickerReplyPacket.AgentDataBlock agentData = new AvatarPickerReplyPacket.AgentDataBlock();
  174. agentData.AgentID = avatarID;
  175. agentData.QueryID = RequestID;
  176. replyPacket.AgentData = agentData;
  177. //byte[] bytes = new byte[AvatarResponses.Count*32];
  178. int i = 0;
  179. foreach (UserData item in users)
  180. {
  181. UUID translatedIDtem = item.Id;
  182. searchData[i] = new AvatarPickerReplyPacket.DataBlock();
  183. searchData[i].AvatarID = translatedIDtem;
  184. searchData[i].FirstName = Utils.StringToBytes((string)item.FirstName);
  185. searchData[i].LastName = Utils.StringToBytes((string)item.LastName);
  186. i++;
  187. }
  188. if (users.Count == 0)
  189. {
  190. searchData = new AvatarPickerReplyPacket.DataBlock[0];
  191. }
  192. replyPacket.Data = searchData;
  193. AvatarPickerReplyAgentDataArgs agent_data = new AvatarPickerReplyAgentDataArgs();
  194. agent_data.AgentID = replyPacket.AgentData.AgentID;
  195. agent_data.QueryID = replyPacket.AgentData.QueryID;
  196. List<AvatarPickerReplyDataArgs> data_args = new List<AvatarPickerReplyDataArgs>();
  197. for (i = 0; i < replyPacket.Data.Length; i++)
  198. {
  199. AvatarPickerReplyDataArgs data_arg = new AvatarPickerReplyDataArgs();
  200. data_arg.AvatarID = replyPacket.Data[i].AvatarID;
  201. data_arg.FirstName = replyPacket.Data[i].FirstName;
  202. data_arg.LastName = replyPacket.Data[i].LastName;
  203. data_args.Add(data_arg);
  204. }
  205. client.SendAvatarPickerReply(agent_data, data_args);
  206. }
  207. protected virtual void AddAdditionalUsers(string query, List<UserData> users)
  208. {
  209. }
  210. #endregion Event Handlers
  211. #region IPeople
  212. public List<UserData> GetUserData(string query, int page_size, int page_number)
  213. {
  214. // search the user accounts service
  215. List<UserAccount> accs = m_Scenes[0].UserAccountService.GetUserAccounts(m_Scenes[0].RegionInfo.ScopeID, query);
  216. List<UserData> users = new List<UserData>();
  217. if (accs != null)
  218. {
  219. foreach (UserAccount acc in accs)
  220. {
  221. UserData ud = new UserData();
  222. ud.FirstName = acc.FirstName;
  223. ud.LastName = acc.LastName;
  224. ud.Id = acc.PrincipalID;
  225. users.Add(ud);
  226. }
  227. }
  228. // search the local cache
  229. lock (m_UserCache)
  230. {
  231. foreach (UserData data in m_UserCache.Values)
  232. {
  233. if (users.Find(delegate(UserData d) { return d.Id == data.Id; }) == null &&
  234. (data.FirstName.ToLower().StartsWith(query.ToLower()) || data.LastName.ToLower().StartsWith(query.ToLower())))
  235. users.Add(data);
  236. }
  237. }
  238. AddAdditionalUsers(query, users);
  239. return users;
  240. }
  241. #endregion IPeople
  242. private void CacheCreators(SceneObjectGroup sog)
  243. {
  244. //m_log.DebugFormat("[USER MANAGEMENT MODULE]: processing {0} {1}; {2}", sog.RootPart.Name, sog.RootPart.CreatorData, sog.RootPart.CreatorIdentification);
  245. AddUser(sog.RootPart.CreatorID, sog.RootPart.CreatorData);
  246. foreach (SceneObjectPart sop in sog.Parts)
  247. {
  248. AddUser(sop.CreatorID, sop.CreatorData);
  249. foreach (TaskInventoryItem item in sop.TaskInventory.Values)
  250. AddUser(item.CreatorID, item.CreatorData);
  251. }
  252. }
  253. /// <summary>
  254. ///
  255. /// </summary>
  256. /// <param name="uuid"></param>
  257. /// <param name="names">Caller please provide a properly instantiated array for names, string[2]</param>
  258. /// <returns></returns>
  259. private bool TryGetUserNames(UUID uuid, string[] names)
  260. {
  261. if (names == null)
  262. names = new string[2];
  263. if (TryGetUserNamesFromCache(uuid, names))
  264. return true;
  265. if (TryGetUserNamesFromServices(uuid, names))
  266. return true;
  267. return false;
  268. }
  269. private bool TryGetUserNamesFromCache(UUID uuid, string[] names)
  270. {
  271. lock (m_UserCache)
  272. {
  273. if (m_UserCache.ContainsKey(uuid))
  274. {
  275. names[0] = m_UserCache[uuid].FirstName;
  276. names[1] = m_UserCache[uuid].LastName;
  277. return true;
  278. }
  279. }
  280. return false;
  281. }
  282. /// <summary>
  283. /// Try to get the names bound to the given uuid, from the services.
  284. /// </summary>
  285. /// <returns>True if the name was found, false if not.</returns>
  286. /// <param name='uuid'></param>
  287. /// <param name='names'>The array of names if found. If not found, then names[0] = "Unknown" and names[1] = "User"</param>
  288. private bool TryGetUserNamesFromServices(UUID uuid, string[] names)
  289. {
  290. UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(UUID.Zero, uuid);
  291. if (account != null)
  292. {
  293. names[0] = account.FirstName;
  294. names[1] = account.LastName;
  295. UserData user = new UserData();
  296. user.FirstName = account.FirstName;
  297. user.LastName = account.LastName;
  298. lock (m_UserCache)
  299. m_UserCache[uuid] = user;
  300. return true;
  301. }
  302. else
  303. {
  304. // Let's try the GridUser service
  305. GridUserInfo uInfo = m_Scenes[0].GridUserService.GetGridUserInfo(uuid.ToString());
  306. if (uInfo != null)
  307. {
  308. string url, first, last, tmp;
  309. UUID u;
  310. if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out u, out url, out first, out last, out tmp))
  311. {
  312. AddUser(uuid, first, last, url);
  313. if (m_UserCache.ContainsKey(uuid))
  314. {
  315. names[0] = m_UserCache[uuid].FirstName;
  316. names[1] = m_UserCache[uuid].LastName;
  317. return true;
  318. }
  319. }
  320. else
  321. m_log.DebugFormat("[USER MANAGEMENT MODULE]: Unable to parse UUI {0}", uInfo.UserID);
  322. }
  323. else
  324. {
  325. m_log.DebugFormat("[USER MANAGEMENT MODULE]: No grid user found for {0}", uuid);
  326. }
  327. names[0] = "Unknown";
  328. names[1] = "UserUMMTGUN8";
  329. return false;
  330. }
  331. }
  332. #region IUserManagement
  333. public UUID GetUserIdByName(string name)
  334. {
  335. string[] parts = name.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
  336. if (parts.Length < 2)
  337. throw new Exception("Name must have 2 components");
  338. return GetUserIdByName(parts[0], parts[1]);
  339. }
  340. public UUID GetUserIdByName(string firstName, string lastName)
  341. {
  342. // TODO: Optimize for reverse lookup if this gets used by non-console commands.
  343. lock (m_UserCache)
  344. {
  345. foreach (UserData user in m_UserCache.Values)
  346. {
  347. if (user.FirstName == firstName && user.LastName == lastName)
  348. return user.Id;
  349. }
  350. }
  351. UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(UUID.Zero, firstName, lastName);
  352. if (account != null)
  353. return account.PrincipalID;
  354. return UUID.Zero;
  355. }
  356. public string GetUserName(UUID uuid)
  357. {
  358. string[] names = new string[2];
  359. TryGetUserNames(uuid, names);
  360. return names[0] + " " + names[1];
  361. }
  362. public string GetUserHomeURL(UUID userID)
  363. {
  364. lock (m_UserCache)
  365. {
  366. if (m_UserCache.ContainsKey(userID))
  367. return m_UserCache[userID].HomeURL;
  368. }
  369. return string.Empty;
  370. }
  371. public string GetUserServerURL(UUID userID, string serverType)
  372. {
  373. UserData userdata;
  374. lock (m_UserCache)
  375. m_UserCache.TryGetValue(userID, out userdata);
  376. if (userdata != null)
  377. {
  378. // m_log.DebugFormat("[USER MANAGEMENT MODULE]: Requested url type {0} for {1}", serverType, userID);
  379. if (userdata.ServerURLs != null && userdata.ServerURLs.ContainsKey(serverType) && userdata.ServerURLs[serverType] != null)
  380. {
  381. return userdata.ServerURLs[serverType].ToString();
  382. }
  383. if (userdata.HomeURL != null && userdata.HomeURL != string.Empty)
  384. {
  385. //m_log.DebugFormat(
  386. // "[USER MANAGEMENT MODULE]: Did not find url type {0} so requesting urls from '{1}' for {2}",
  387. // serverType, userdata.HomeURL, userID);
  388. UserAgentServiceConnector uConn = new UserAgentServiceConnector(userdata.HomeURL);
  389. userdata.ServerURLs = uConn.GetServerURLs(userID);
  390. if (userdata.ServerURLs != null && userdata.ServerURLs.ContainsKey(serverType) && userdata.ServerURLs[serverType] != null)
  391. return userdata.ServerURLs[serverType].ToString();
  392. }
  393. }
  394. return string.Empty;
  395. }
  396. public string GetUserUUI(UUID userID)
  397. {
  398. UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, userID);
  399. if (account != null)
  400. return userID.ToString();
  401. UserData ud;
  402. lock (m_UserCache)
  403. m_UserCache.TryGetValue(userID, out ud);
  404. if (ud != null)
  405. {
  406. string homeURL = ud.HomeURL;
  407. string first = ud.FirstName, last = ud.LastName;
  408. if (ud.LastName.StartsWith("@"))
  409. {
  410. string[] parts = ud.FirstName.Split('.');
  411. if (parts.Length >= 2)
  412. {
  413. first = parts[0];
  414. last = parts[1];
  415. }
  416. return userID + ";" + homeURL + ";" + first + " " + last;
  417. }
  418. }
  419. return userID.ToString();
  420. }
  421. public void AddUser(UUID uuid, string first, string last)
  422. {
  423. lock (m_UserCache)
  424. {
  425. if (m_UserCache.ContainsKey(uuid))
  426. return;
  427. }
  428. UserData user = new UserData();
  429. user.Id = uuid;
  430. user.FirstName = first;
  431. user.LastName = last;
  432. AddUserInternal(user);
  433. }
  434. public void AddUser(UUID uuid, string first, string last, string homeURL)
  435. {
  436. //m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, first {1}, last {2}, url {3}", uuid, first, last, homeURL);
  437. if (homeURL == string.Empty)
  438. return;
  439. AddUser(uuid, homeURL + ";" + first + " " + last);
  440. }
  441. public void AddUser (UUID id, string creatorData)
  442. {
  443. //m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, creatorData {1}", id, creatorData);
  444. UserData oldUser;
  445. lock (m_UserCache)
  446. m_UserCache.TryGetValue(id, out oldUser);
  447. if (oldUser != null)
  448. {
  449. if (creatorData == null || creatorData == String.Empty)
  450. {
  451. //ignore updates without creator data
  452. return;
  453. }
  454. //try update unknown users, but don't update anyone else
  455. if (oldUser.FirstName == "Unknown" && !creatorData.Contains("Unknown"))
  456. {
  457. lock (m_UserCache)
  458. m_UserCache.Remove(id);
  459. m_log.DebugFormat("[USER MANAGEMENT MODULE]: Re-adding user with id {0}, creatorData [{1}] and old HomeURL {2}", id, creatorData, oldUser.HomeURL);
  460. }
  461. else
  462. {
  463. //we have already a valid user within the cache
  464. return;
  465. }
  466. }
  467. UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, id);
  468. if (account != null)
  469. {
  470. AddUser(id, account.FirstName, account.LastName);
  471. }
  472. else
  473. {
  474. UserData user = new UserData();
  475. user.Id = id;
  476. if (!string.IsNullOrEmpty(creatorData))
  477. {
  478. //creatorData = <endpoint>;<name>
  479. string[] parts = creatorData.Split(';');
  480. if (parts.Length >= 1)
  481. {
  482. user.HomeURL = parts[0];
  483. try
  484. {
  485. Uri uri = new Uri(parts[0]);
  486. user.LastName = "@" + uri.Authority;
  487. }
  488. catch (UriFormatException)
  489. {
  490. m_log.DebugFormat("[SCENE]: Unable to parse Uri {0}", parts[0]);
  491. user.LastName = "@unknown";
  492. }
  493. }
  494. if (parts.Length >= 2)
  495. user.FirstName = parts[1].Replace(' ', '.');
  496. }
  497. else
  498. {
  499. // Temporarily add unknown user entries of this type into the cache so that we can distinguish
  500. // this source from other recent (hopefully resolved) bugs that fail to retrieve a user name binding
  501. // TODO: Can be removed when GUN* unknown users have definitely dropped significantly or
  502. // disappeared.
  503. user.FirstName = "Unknown";
  504. user.LastName = "UserUMMAU4";
  505. }
  506. AddUserInternal(user);
  507. }
  508. }
  509. void AddUserInternal(UserData user)
  510. {
  511. lock (m_UserCache)
  512. m_UserCache[user.Id] = user;
  513. //m_log.DebugFormat(
  514. // "[USER MANAGEMENT MODULE]: Added user {0} {1} {2} {3}",
  515. // user.Id, user.FirstName, user.LastName, user.HomeURL);
  516. }
  517. public bool IsLocalGridUser(UUID uuid)
  518. {
  519. UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, uuid);
  520. if (account == null || (account != null && !account.LocalToGrid))
  521. return false;
  522. return true;
  523. }
  524. #endregion IUserManagement
  525. protected void Init()
  526. {
  527. RegisterConsoleCmds();
  528. }
  529. protected void RegisterConsoleCmds()
  530. {
  531. MainConsole.Instance.Commands.AddCommand("Users", true,
  532. "show name",
  533. "show name <uuid>",
  534. "Show the bindings between a single user UUID and a user name",
  535. String.Empty,
  536. HandleShowUser);
  537. MainConsole.Instance.Commands.AddCommand("Users", true,
  538. "show names",
  539. "show names",
  540. "Show the bindings between user UUIDs and user names",
  541. String.Empty,
  542. HandleShowUsers);
  543. }
  544. private void HandleShowUser(string module, string[] cmd)
  545. {
  546. if (cmd.Length < 3)
  547. {
  548. MainConsole.Instance.OutputFormat("Usage: show name <uuid>");
  549. return;
  550. }
  551. UUID userId;
  552. if (!ConsoleUtil.TryParseConsoleUuid(MainConsole.Instance, cmd[2], out userId))
  553. return;
  554. string[] names;
  555. UserData ud;
  556. lock (m_UserCache)
  557. {
  558. if (!m_UserCache.TryGetValue(userId, out ud))
  559. {
  560. MainConsole.Instance.OutputFormat("No name known for user with id {0}", userId);
  561. return;
  562. }
  563. }
  564. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  565. cdt.AddColumn("UUID", 36);
  566. cdt.AddColumn("Name", 30);
  567. cdt.AddColumn("HomeURL", 40);
  568. cdt.AddRow(userId, string.Format("{0} {1}", ud.FirstName, ud.LastName), ud.HomeURL);
  569. MainConsole.Instance.Output(cdt.ToString());
  570. }
  571. private void HandleShowUsers(string module, string[] cmd)
  572. {
  573. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  574. cdt.AddColumn("UUID", 36);
  575. cdt.AddColumn("Name", 30);
  576. cdt.AddColumn("HomeURL", 40);
  577. lock (m_UserCache)
  578. {
  579. foreach (KeyValuePair<UUID, UserData> kvp in m_UserCache)
  580. cdt.AddRow(kvp.Key, string.Format("{0} {1}", kvp.Value.FirstName, kvp.Value.LastName), kvp.Value.HomeURL);
  581. }
  582. MainConsole.Instance.Output(cdt.ToString());
  583. }
  584. }
  585. }