UserManagementModule.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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. // As least upto September 2013, clients permanently cache UUID -> Name bindings. Some clients
  155. // appear to clear this when the user asks it to clear the cache, but others may not.
  156. //
  157. // So to avoid clients
  158. // (particularly Hypergrid clients) permanently binding "Unknown User" to a given UUID, we will
  159. // instead drop the request entirely.
  160. if (TryGetUserNames(uuid, names))
  161. client.SendNameReply(uuid, names[0], names[1]);
  162. // else
  163. // m_log.DebugFormat(
  164. // "[USER MANAGEMENT MODULE]: No bound name for {0} found, ignoring request from {1}",
  165. // uuid, client.Name);
  166. });
  167. }
  168. }
  169. public void HandleAvatarPickerRequest(IClientAPI client, UUID avatarID, UUID RequestID, string query)
  170. {
  171. //EventManager.TriggerAvatarPickerRequest();
  172. m_log.DebugFormat("[USER MANAGEMENT MODULE]: HandleAvatarPickerRequest for {0}", query);
  173. List<UserData> users = GetUserData(query, 500, 1);
  174. AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply);
  175. // TODO: don't create new blocks if recycling an old packet
  176. AvatarPickerReplyPacket.DataBlock[] searchData =
  177. new AvatarPickerReplyPacket.DataBlock[users.Count];
  178. AvatarPickerReplyPacket.AgentDataBlock agentData = new AvatarPickerReplyPacket.AgentDataBlock();
  179. agentData.AgentID = avatarID;
  180. agentData.QueryID = RequestID;
  181. replyPacket.AgentData = agentData;
  182. //byte[] bytes = new byte[AvatarResponses.Count*32];
  183. int i = 0;
  184. foreach (UserData item in users)
  185. {
  186. UUID translatedIDtem = item.Id;
  187. searchData[i] = new AvatarPickerReplyPacket.DataBlock();
  188. searchData[i].AvatarID = translatedIDtem;
  189. searchData[i].FirstName = Utils.StringToBytes((string)item.FirstName);
  190. searchData[i].LastName = Utils.StringToBytes((string)item.LastName);
  191. i++;
  192. }
  193. if (users.Count == 0)
  194. {
  195. searchData = new AvatarPickerReplyPacket.DataBlock[0];
  196. }
  197. replyPacket.Data = searchData;
  198. AvatarPickerReplyAgentDataArgs agent_data = new AvatarPickerReplyAgentDataArgs();
  199. agent_data.AgentID = replyPacket.AgentData.AgentID;
  200. agent_data.QueryID = replyPacket.AgentData.QueryID;
  201. List<AvatarPickerReplyDataArgs> data_args = new List<AvatarPickerReplyDataArgs>();
  202. for (i = 0; i < replyPacket.Data.Length; i++)
  203. {
  204. AvatarPickerReplyDataArgs data_arg = new AvatarPickerReplyDataArgs();
  205. data_arg.AvatarID = replyPacket.Data[i].AvatarID;
  206. data_arg.FirstName = replyPacket.Data[i].FirstName;
  207. data_arg.LastName = replyPacket.Data[i].LastName;
  208. data_args.Add(data_arg);
  209. }
  210. client.SendAvatarPickerReply(agent_data, data_args);
  211. }
  212. protected virtual void AddAdditionalUsers(string query, List<UserData> users)
  213. {
  214. }
  215. #endregion Event Handlers
  216. #region IPeople
  217. public List<UserData> GetUserData(string query, int page_size, int page_number)
  218. {
  219. // search the user accounts service
  220. List<UserAccount> accs = m_Scenes[0].UserAccountService.GetUserAccounts(m_Scenes[0].RegionInfo.ScopeID, query);
  221. List<UserData> users = new List<UserData>();
  222. if (accs != null)
  223. {
  224. foreach (UserAccount acc in accs)
  225. {
  226. UserData ud = new UserData();
  227. ud.FirstName = acc.FirstName;
  228. ud.LastName = acc.LastName;
  229. ud.Id = acc.PrincipalID;
  230. users.Add(ud);
  231. }
  232. }
  233. // search the local cache
  234. lock (m_UserCache)
  235. {
  236. foreach (UserData data in m_UserCache.Values)
  237. {
  238. if (data.Id != UUID.Zero &&
  239. users.Find(delegate(UserData d) { return d.Id == data.Id; }) == null &&
  240. (data.FirstName.ToLower().StartsWith(query.ToLower()) || data.LastName.ToLower().StartsWith(query.ToLower())))
  241. users.Add(data);
  242. }
  243. }
  244. AddAdditionalUsers(query, users);
  245. return users;
  246. }
  247. #endregion IPeople
  248. private void CacheCreators(SceneObjectGroup sog)
  249. {
  250. //m_log.DebugFormat("[USER MANAGEMENT MODULE]: processing {0} {1}; {2}", sog.RootPart.Name, sog.RootPart.CreatorData, sog.RootPart.CreatorIdentification);
  251. AddUser(sog.RootPart.CreatorID, sog.RootPart.CreatorData);
  252. foreach (SceneObjectPart sop in sog.Parts)
  253. {
  254. AddUser(sop.CreatorID, sop.CreatorData);
  255. foreach (TaskInventoryItem item in sop.TaskInventory.Values)
  256. AddUser(item.CreatorID, item.CreatorData);
  257. }
  258. }
  259. /// <summary>
  260. ///
  261. /// </summary>
  262. /// <param name="uuid"></param>
  263. /// <param name="names">Caller please provide a properly instantiated array for names, string[2]</param>
  264. /// <returns></returns>
  265. private bool TryGetUserNames(UUID uuid, string[] names)
  266. {
  267. if (names == null)
  268. names = new string[2];
  269. if (TryGetUserNamesFromCache(uuid, names))
  270. return true;
  271. if (TryGetUserNamesFromServices(uuid, names))
  272. return true;
  273. return false;
  274. }
  275. private bool TryGetUserNamesFromCache(UUID uuid, string[] names)
  276. {
  277. lock (m_UserCache)
  278. {
  279. if (m_UserCache.ContainsKey(uuid))
  280. {
  281. names[0] = m_UserCache[uuid].FirstName;
  282. names[1] = m_UserCache[uuid].LastName;
  283. return true;
  284. }
  285. }
  286. return false;
  287. }
  288. /// <summary>
  289. /// Try to get the names bound to the given uuid, from the services.
  290. /// </summary>
  291. /// <returns>True if the name was found, false if not.</returns>
  292. /// <param name='uuid'></param>
  293. /// <param name='names'>The array of names if found. If not found, then names[0] = "Unknown" and names[1] = "User"</param>
  294. private bool TryGetUserNamesFromServices(UUID uuid, string[] names)
  295. {
  296. UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(UUID.Zero, uuid);
  297. if (account != null)
  298. {
  299. names[0] = account.FirstName;
  300. names[1] = account.LastName;
  301. UserData user = new UserData();
  302. user.FirstName = account.FirstName;
  303. user.LastName = account.LastName;
  304. lock (m_UserCache)
  305. m_UserCache[uuid] = user;
  306. return true;
  307. }
  308. else
  309. {
  310. // Let's try the GridUser service
  311. GridUserInfo uInfo = m_Scenes[0].GridUserService.GetGridUserInfo(uuid.ToString());
  312. if (uInfo != null)
  313. {
  314. string url, first, last, tmp;
  315. UUID u;
  316. if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out u, out url, out first, out last, out tmp))
  317. {
  318. AddUser(uuid, first, last, url);
  319. if (m_UserCache.ContainsKey(uuid))
  320. {
  321. names[0] = m_UserCache[uuid].FirstName;
  322. names[1] = m_UserCache[uuid].LastName;
  323. return true;
  324. }
  325. }
  326. else
  327. m_log.DebugFormat("[USER MANAGEMENT MODULE]: Unable to parse UUI {0}", uInfo.UserID);
  328. }
  329. else
  330. {
  331. m_log.DebugFormat("[USER MANAGEMENT MODULE]: No grid user found for {0}", uuid);
  332. }
  333. names[0] = "Unknown";
  334. names[1] = "UserUMMTGUN9";
  335. return false;
  336. }
  337. }
  338. #region IUserManagement
  339. public UUID GetUserIdByName(string name)
  340. {
  341. string[] parts = name.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
  342. if (parts.Length < 2)
  343. throw new Exception("Name must have 2 components");
  344. return GetUserIdByName(parts[0], parts[1]);
  345. }
  346. public UUID GetUserIdByName(string firstName, string lastName)
  347. {
  348. // TODO: Optimize for reverse lookup if this gets used by non-console commands.
  349. lock (m_UserCache)
  350. {
  351. foreach (UserData user in m_UserCache.Values)
  352. {
  353. if (user.FirstName == firstName && user.LastName == lastName)
  354. return user.Id;
  355. }
  356. }
  357. UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(UUID.Zero, firstName, lastName);
  358. if (account != null)
  359. return account.PrincipalID;
  360. return UUID.Zero;
  361. }
  362. public string GetUserName(UUID uuid)
  363. {
  364. string[] names = new string[2];
  365. TryGetUserNames(uuid, names);
  366. return names[0] + " " + names[1];
  367. }
  368. public string GetUserHomeURL(UUID userID)
  369. {
  370. lock (m_UserCache)
  371. {
  372. if (m_UserCache.ContainsKey(userID))
  373. return m_UserCache[userID].HomeURL;
  374. }
  375. return string.Empty;
  376. }
  377. public string GetUserServerURL(UUID userID, string serverType)
  378. {
  379. UserData userdata;
  380. lock (m_UserCache)
  381. m_UserCache.TryGetValue(userID, out userdata);
  382. if (userdata != null)
  383. {
  384. // m_log.DebugFormat("[USER MANAGEMENT MODULE]: Requested url type {0} for {1}", serverType, userID);
  385. if (userdata.ServerURLs != null)
  386. {
  387. object url;
  388. if (userdata.ServerURLs.TryGetValue(serverType, out url))
  389. return url.ToString();
  390. }
  391. else if (!string.IsNullOrEmpty(userdata.HomeURL))
  392. {
  393. //m_log.DebugFormat(
  394. // "[USER MANAGEMENT MODULE]: Did not find url type {0} so requesting urls from '{1}' for {2}",
  395. // serverType, userdata.HomeURL, userID);
  396. UserAgentServiceConnector uConn = new UserAgentServiceConnector(userdata.HomeURL);
  397. try
  398. {
  399. userdata.ServerURLs = uConn.GetServerURLs(userID);
  400. }
  401. catch (Exception e)
  402. {
  403. m_log.Debug("[USER MANAGEMENT MODULE]: GetServerURLs call failed ", e);
  404. userdata.ServerURLs = new Dictionary<string, object>();
  405. }
  406. object url;
  407. if (userdata.ServerURLs.TryGetValue(serverType, out url))
  408. return url.ToString();
  409. }
  410. }
  411. return string.Empty;
  412. }
  413. public string GetUserUUI(UUID userID)
  414. {
  415. UserData ud;
  416. lock (m_UserCache)
  417. m_UserCache.TryGetValue(userID, out ud);
  418. if (ud == null) // It's not in the cache
  419. {
  420. string[] names = new string[2];
  421. // This will pull the data from either UserAccounts or GridUser
  422. // and stick it into the cache
  423. TryGetUserNamesFromServices(userID, names);
  424. lock (m_UserCache)
  425. m_UserCache.TryGetValue(userID, out ud);
  426. }
  427. if (ud != null)
  428. {
  429. string homeURL = ud.HomeURL;
  430. string first = ud.FirstName, last = ud.LastName;
  431. if (ud.LastName.StartsWith("@"))
  432. {
  433. string[] parts = ud.FirstName.Split('.');
  434. if (parts.Length >= 2)
  435. {
  436. first = parts[0];
  437. last = parts[1];
  438. }
  439. return userID + ";" + homeURL + ";" + first + " " + last;
  440. }
  441. }
  442. return userID.ToString();
  443. }
  444. public void AddUser(UUID uuid, string first, string last)
  445. {
  446. lock (m_UserCache)
  447. {
  448. if (m_UserCache.ContainsKey(uuid))
  449. return;
  450. }
  451. UserData user = new UserData();
  452. user.Id = uuid;
  453. user.FirstName = first;
  454. user.LastName = last;
  455. AddUserInternal(user);
  456. }
  457. public void AddUser(UUID uuid, string first, string last, string homeURL)
  458. {
  459. //m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, first {1}, last {2}, url {3}", uuid, first, last, homeURL);
  460. if (homeURL == string.Empty)
  461. return;
  462. AddUser(uuid, homeURL + ";" + first + " " + last);
  463. }
  464. public void AddUser(UUID id, string creatorData)
  465. {
  466. //m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, creatorData {1}", id, creatorData);
  467. UserData oldUser;
  468. lock (m_UserCache)
  469. m_UserCache.TryGetValue(id, out oldUser);
  470. if (oldUser != null)
  471. {
  472. if (string.IsNullOrEmpty(creatorData))
  473. {
  474. //ignore updates without creator data
  475. return;
  476. }
  477. //try update unknown users, but don't update anyone else
  478. if (oldUser.FirstName == "Unknown" && !creatorData.Contains("Unknown"))
  479. {
  480. lock (m_UserCache)
  481. m_UserCache.Remove(id);
  482. m_log.DebugFormat("[USER MANAGEMENT MODULE]: Re-adding user with id {0}, creatorData [{1}] and old HomeURL {2}", id, creatorData, oldUser.HomeURL);
  483. }
  484. else
  485. {
  486. //we have already a valid user within the cache
  487. return;
  488. }
  489. }
  490. UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, id);
  491. if (account != null)
  492. {
  493. AddUser(id, account.FirstName, account.LastName);
  494. }
  495. else
  496. {
  497. UserData user = new UserData();
  498. user.Id = id;
  499. if (!string.IsNullOrEmpty(creatorData))
  500. {
  501. //creatorData = <endpoint>;<name>
  502. string[] parts = creatorData.Split(';');
  503. if (parts.Length >= 2)
  504. user.FirstName = parts[1].Replace(' ', '.');
  505. if (parts.Length >= 1)
  506. {
  507. user.HomeURL = parts[0];
  508. try
  509. {
  510. Uri uri = new Uri(parts[0]);
  511. user.LastName = "@" + uri.Authority;
  512. }
  513. catch (UriFormatException)
  514. {
  515. m_log.DebugFormat(
  516. "[USER MANAGEMENT MODULE]: Unable to parse home URL {0} for user name {1}, ID {2} from original creator data {3} when adding user info.",
  517. parts[0], user.FirstName ?? "Unknown", id, creatorData);
  518. user.LastName = "@unknown";
  519. }
  520. }
  521. }
  522. else
  523. {
  524. // Temporarily add unknown user entries of this type into the cache so that we can distinguish
  525. // this source from other recent (hopefully resolved) bugs that fail to retrieve a user name binding
  526. // TODO: Can be removed when GUN* unknown users have definitely dropped significantly or
  527. // disappeared.
  528. user.FirstName = "Unknown";
  529. user.LastName = "UserUMMAU4";
  530. }
  531. AddUserInternal(user);
  532. }
  533. }
  534. void AddUserInternal(UserData user)
  535. {
  536. lock (m_UserCache)
  537. m_UserCache[user.Id] = user;
  538. //m_log.DebugFormat(
  539. // "[USER MANAGEMENT MODULE]: Added user {0} {1} {2} {3}",
  540. // user.Id, user.FirstName, user.LastName, user.HomeURL);
  541. }
  542. public bool IsLocalGridUser(UUID uuid)
  543. {
  544. UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, uuid);
  545. if (account == null || (account != null && !account.LocalToGrid))
  546. return false;
  547. return true;
  548. }
  549. #endregion IUserManagement
  550. protected void Init()
  551. {
  552. AddUser(UUID.Zero, "Unknown", "User");
  553. RegisterConsoleCmds();
  554. }
  555. protected void RegisterConsoleCmds()
  556. {
  557. MainConsole.Instance.Commands.AddCommand("Users", true,
  558. "show name",
  559. "show name <uuid>",
  560. "Show the bindings between a single user UUID and a user name",
  561. String.Empty,
  562. HandleShowUser);
  563. MainConsole.Instance.Commands.AddCommand("Users", true,
  564. "show names",
  565. "show names",
  566. "Show the bindings between user UUIDs and user names",
  567. String.Empty,
  568. HandleShowUsers);
  569. MainConsole.Instance.Commands.AddCommand("Users", true,
  570. "reset user cache",
  571. "reset user cache",
  572. "reset user cache to allow changed settings to be applied",
  573. String.Empty,
  574. HandleResetUserCache);
  575. }
  576. private void HandleResetUserCache(string module, string[] cmd)
  577. {
  578. lock(m_UserCache)
  579. {
  580. m_UserCache.Clear();
  581. }
  582. }
  583. private void HandleShowUser(string module, string[] cmd)
  584. {
  585. if (cmd.Length < 3)
  586. {
  587. MainConsole.Instance.OutputFormat("Usage: show name <uuid>");
  588. return;
  589. }
  590. UUID userId;
  591. if (!ConsoleUtil.TryParseConsoleUuid(MainConsole.Instance, cmd[2], out userId))
  592. return;
  593. UserData ud;
  594. lock (m_UserCache)
  595. {
  596. if (!m_UserCache.TryGetValue(userId, out ud))
  597. {
  598. MainConsole.Instance.OutputFormat("No name known for user with id {0}", userId);
  599. return;
  600. }
  601. }
  602. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  603. cdt.AddColumn("UUID", 36);
  604. cdt.AddColumn("Name", 30);
  605. cdt.AddColumn("HomeURL", 40);
  606. cdt.AddRow(userId, string.Format("{0} {1}", ud.FirstName, ud.LastName), ud.HomeURL);
  607. MainConsole.Instance.Output(cdt.ToString());
  608. }
  609. private void HandleShowUsers(string module, string[] cmd)
  610. {
  611. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  612. cdt.AddColumn("UUID", 36);
  613. cdt.AddColumn("Name", 30);
  614. cdt.AddColumn("HomeURL", 40);
  615. lock (m_UserCache)
  616. {
  617. foreach (KeyValuePair<UUID, UserData> kvp in m_UserCache)
  618. cdt.AddRow(kvp.Key, string.Format("{0} {1}", kvp.Value.FirstName, kvp.Value.LastName), kvp.Value.HomeURL);
  619. }
  620. MainConsole.Instance.Output(cdt.ToString());
  621. }
  622. }
  623. }