UserManagementModule.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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 && userdata.ServerURLs.ContainsKey(serverType) && userdata.ServerURLs[serverType] != null)
  386. {
  387. return userdata.ServerURLs[serverType].ToString();
  388. }
  389. if (!string.IsNullOrEmpty(userdata.HomeURL))
  390. {
  391. //m_log.DebugFormat(
  392. // "[USER MANAGEMENT MODULE]: Did not find url type {0} so requesting urls from '{1}' for {2}",
  393. // serverType, userdata.HomeURL, userID);
  394. UserAgentServiceConnector uConn = new UserAgentServiceConnector(userdata.HomeURL);
  395. try
  396. {
  397. userdata.ServerURLs = uConn.GetServerURLs(userID);
  398. }
  399. catch (Exception e)
  400. {
  401. m_log.Debug("[USER MANAGEMENT MODULE]: GetServerURLs call failed ", e);
  402. userdata.ServerURLs = new Dictionary<string, object>();
  403. }
  404. if (userdata.ServerURLs != null && userdata.ServerURLs.ContainsKey(serverType) && userdata.ServerURLs[serverType] != null)
  405. return userdata.ServerURLs[serverType].ToString();
  406. }
  407. }
  408. return string.Empty;
  409. }
  410. public string GetUserUUI(UUID userID)
  411. {
  412. UserData ud;
  413. lock (m_UserCache)
  414. m_UserCache.TryGetValue(userID, out ud);
  415. if (ud == null) // It's not in the cache
  416. {
  417. string[] names = new string[2];
  418. // This will pull the data from either UserAccounts or GridUser
  419. // and stick it into the cache
  420. TryGetUserNamesFromServices(userID, names);
  421. lock (m_UserCache)
  422. m_UserCache.TryGetValue(userID, out ud);
  423. }
  424. if (ud != null)
  425. {
  426. string homeURL = ud.HomeURL;
  427. string first = ud.FirstName, last = ud.LastName;
  428. if (ud.LastName.StartsWith("@"))
  429. {
  430. string[] parts = ud.FirstName.Split('.');
  431. if (parts.Length >= 2)
  432. {
  433. first = parts[0];
  434. last = parts[1];
  435. }
  436. return userID + ";" + homeURL + ";" + first + " " + last;
  437. }
  438. }
  439. return userID.ToString();
  440. }
  441. public void AddUser(UUID uuid, string first, string last)
  442. {
  443. lock (m_UserCache)
  444. {
  445. if (m_UserCache.ContainsKey(uuid))
  446. return;
  447. }
  448. UserData user = new UserData();
  449. user.Id = uuid;
  450. user.FirstName = first;
  451. user.LastName = last;
  452. AddUserInternal(user);
  453. }
  454. public void AddUser(UUID uuid, string first, string last, string homeURL)
  455. {
  456. //m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, first {1}, last {2}, url {3}", uuid, first, last, homeURL);
  457. if (homeURL == string.Empty)
  458. return;
  459. AddUser(uuid, homeURL + ";" + first + " " + last);
  460. }
  461. public void AddUser(UUID id, string creatorData)
  462. {
  463. //m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, creatorData {1}", id, creatorData);
  464. UserData oldUser;
  465. lock (m_UserCache)
  466. m_UserCache.TryGetValue(id, out oldUser);
  467. if (oldUser != null)
  468. {
  469. if (string.IsNullOrEmpty(creatorData))
  470. {
  471. //ignore updates without creator data
  472. return;
  473. }
  474. //try update unknown users, but don't update anyone else
  475. if (oldUser.FirstName == "Unknown" && !creatorData.Contains("Unknown"))
  476. {
  477. lock (m_UserCache)
  478. m_UserCache.Remove(id);
  479. m_log.DebugFormat("[USER MANAGEMENT MODULE]: Re-adding user with id {0}, creatorData [{1}] and old HomeURL {2}", id, creatorData, oldUser.HomeURL);
  480. }
  481. else
  482. {
  483. //we have already a valid user within the cache
  484. return;
  485. }
  486. }
  487. UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, id);
  488. if (account != null)
  489. {
  490. AddUser(id, account.FirstName, account.LastName);
  491. }
  492. else
  493. {
  494. UserData user = new UserData();
  495. user.Id = id;
  496. if (!string.IsNullOrEmpty(creatorData))
  497. {
  498. //creatorData = <endpoint>;<name>
  499. string[] parts = creatorData.Split(';');
  500. if (parts.Length >= 1)
  501. {
  502. user.HomeURL = parts[0];
  503. try
  504. {
  505. Uri uri = new Uri(parts[0]);
  506. user.LastName = "@" + uri.Authority;
  507. }
  508. catch (UriFormatException)
  509. {
  510. m_log.DebugFormat("[SCENE]: Unable to parse Uri {0}", parts[0]);
  511. user.LastName = "@unknown";
  512. }
  513. }
  514. if (parts.Length >= 2)
  515. user.FirstName = parts[1].Replace(' ', '.');
  516. }
  517. else
  518. {
  519. // Temporarily add unknown user entries of this type into the cache so that we can distinguish
  520. // this source from other recent (hopefully resolved) bugs that fail to retrieve a user name binding
  521. // TODO: Can be removed when GUN* unknown users have definitely dropped significantly or
  522. // disappeared.
  523. user.FirstName = "Unknown";
  524. user.LastName = "UserUMMAU4";
  525. }
  526. AddUserInternal(user);
  527. }
  528. }
  529. void AddUserInternal(UserData user)
  530. {
  531. lock (m_UserCache)
  532. m_UserCache[user.Id] = user;
  533. //m_log.DebugFormat(
  534. // "[USER MANAGEMENT MODULE]: Added user {0} {1} {2} {3}",
  535. // user.Id, user.FirstName, user.LastName, user.HomeURL);
  536. }
  537. public bool IsLocalGridUser(UUID uuid)
  538. {
  539. UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, uuid);
  540. if (account == null || (account != null && !account.LocalToGrid))
  541. return false;
  542. return true;
  543. }
  544. #endregion IUserManagement
  545. protected void Init()
  546. {
  547. AddUser(UUID.Zero, "Unknown", "User");
  548. RegisterConsoleCmds();
  549. }
  550. protected void RegisterConsoleCmds()
  551. {
  552. MainConsole.Instance.Commands.AddCommand("Users", true,
  553. "show name",
  554. "show name <uuid>",
  555. "Show the bindings between a single user UUID and a user name",
  556. String.Empty,
  557. HandleShowUser);
  558. MainConsole.Instance.Commands.AddCommand("Users", true,
  559. "show names",
  560. "show names",
  561. "Show the bindings between user UUIDs and user names",
  562. String.Empty,
  563. HandleShowUsers);
  564. }
  565. private void HandleShowUser(string module, string[] cmd)
  566. {
  567. if (cmd.Length < 3)
  568. {
  569. MainConsole.Instance.OutputFormat("Usage: show name <uuid>");
  570. return;
  571. }
  572. UUID userId;
  573. if (!ConsoleUtil.TryParseConsoleUuid(MainConsole.Instance, cmd[2], out userId))
  574. return;
  575. string[] names;
  576. UserData ud;
  577. lock (m_UserCache)
  578. {
  579. if (!m_UserCache.TryGetValue(userId, out ud))
  580. {
  581. MainConsole.Instance.OutputFormat("No name known for user with id {0}", userId);
  582. return;
  583. }
  584. }
  585. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  586. cdt.AddColumn("UUID", 36);
  587. cdt.AddColumn("Name", 30);
  588. cdt.AddColumn("HomeURL", 40);
  589. cdt.AddRow(userId, string.Format("{0} {1}", ud.FirstName, ud.LastName), ud.HomeURL);
  590. MainConsole.Instance.Output(cdt.ToString());
  591. }
  592. private void HandleShowUsers(string module, string[] cmd)
  593. {
  594. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  595. cdt.AddColumn("UUID", 36);
  596. cdt.AddColumn("Name", 30);
  597. cdt.AddColumn("HomeURL", 40);
  598. lock (m_UserCache)
  599. {
  600. foreach (KeyValuePair<UUID, UserData> kvp in m_UserCache)
  601. cdt.AddRow(kvp.Key, string.Format("{0} {1}", kvp.Value.FirstName, kvp.Value.LastName), kvp.Value.HomeURL);
  602. }
  603. MainConsole.Instance.Output(cdt.ToString());
  604. }
  605. }
  606. }