diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs | 177 |
1 files changed, 60 insertions, 117 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index 61c1e70..73b59d3 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs | |||
@@ -56,16 +56,10 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement | |||
56 | protected bool m_Enabled; | 56 | protected bool m_Enabled; |
57 | protected List<Scene> m_Scenes = new List<Scene>(); | 57 | protected List<Scene> m_Scenes = new List<Scene>(); |
58 | 58 | ||
59 | protected IServiceThrottleModule m_ServiceThrottle; | ||
59 | // The cache | 60 | // The cache |
60 | protected Dictionary<UUID, UserData> m_UserCache = new Dictionary<UUID, UserData>(); | 61 | protected Dictionary<UUID, UserData> m_UserCache = new Dictionary<UUID, UserData>(); |
61 | 62 | ||
62 | // Throttle the name requests | ||
63 | //private OpenSim.Framework.BlockingQueue<NameRequest> m_RequestQueue = new OpenSim.Framework.BlockingQueue<NameRequest>(); | ||
64 | //private OpenSim.Framework.DoubleQueue<NameRequest> m_RequestQueue = new OpenSim.Framework.DoubleQueue<NameRequest>(); | ||
65 | private Queue<NameRequest> m_RequestQueue = new Queue<NameRequest>(); | ||
66 | |||
67 | private System.Timers.Timer m_timer; | ||
68 | |||
69 | #region ISharedRegionModule | 63 | #region ISharedRegionModule |
70 | 64 | ||
71 | public void Initialise(IConfigSource config) | 65 | public void Initialise(IConfigSource config) |
@@ -118,6 +112,8 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement | |||
118 | 112 | ||
119 | public void RegionLoaded(Scene s) | 113 | public void RegionLoaded(Scene s) |
120 | { | 114 | { |
115 | if (m_Enabled && m_ServiceThrottle == null) | ||
116 | m_ServiceThrottle = s.RequestModuleInterface<IServiceThrottleModule>(); | ||
121 | } | 117 | } |
122 | 118 | ||
123 | public void PostInitialise() | 119 | public void PostInitialise() |
@@ -157,7 +153,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement | |||
157 | client.OnAvatarPickerRequest -= new AvatarPickerRequest(HandleAvatarPickerRequest); | 153 | client.OnAvatarPickerRequest -= new AvatarPickerRequest(HandleAvatarPickerRequest); |
158 | } | 154 | } |
159 | 155 | ||
160 | void HandleUUIDNameRequest(UUID uuid, IClientAPI remote_client) | 156 | void HandleUUIDNameRequest(UUID uuid, IClientAPI client) |
161 | { | 157 | { |
162 | // m_log.DebugFormat( | 158 | // m_log.DebugFormat( |
163 | // "[USER MANAGEMENT MODULE]: Handling request for name binding of UUID {0} from {1}", | 159 | // "[USER MANAGEMENT MODULE]: Handling request for name binding of UUID {0} from {1}", |
@@ -165,12 +161,33 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement | |||
165 | 161 | ||
166 | if (m_Scenes[0].LibraryService != null && (m_Scenes[0].LibraryService.LibraryRootFolder.Owner == uuid)) | 162 | if (m_Scenes[0].LibraryService != null && (m_Scenes[0].LibraryService.LibraryRootFolder.Owner == uuid)) |
167 | { | 163 | { |
168 | remote_client.SendNameReply(uuid, "Mr", "OpenSim"); | 164 | client.SendNameReply(uuid, "Mr", "OpenSim"); |
169 | } | 165 | } |
170 | else | 166 | else |
171 | { | 167 | { |
172 | NameRequest request = new NameRequest(remote_client, uuid); | 168 | string[] names = new string[2]; |
173 | m_RequestQueue.Enqueue(request); | 169 | if (TryGetUserNamesFromCache(uuid, names)) |
170 | { | ||
171 | client.SendNameReply(uuid, names[0], names[1]); | ||
172 | return; | ||
173 | } | ||
174 | |||
175 | // Not found in cache, get it from services | ||
176 | m_ServiceThrottle.Enqueue(delegate | ||
177 | { | ||
178 | m_log.DebugFormat("[YYY]: Name request {0}", uuid); | ||
179 | bool foundRealName = TryGetUserNamesFromServices(uuid, names); | ||
180 | |||
181 | if (names.Length == 2) | ||
182 | { | ||
183 | if (!foundRealName) | ||
184 | 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); | ||
185 | else | ||
186 | m_log.DebugFormat("[YYY]: Found user {0} {1} for uuid {2}", names[0], names[1], uuid); | ||
187 | |||
188 | client.SendNameReply(uuid, names[0], names[1]); | ||
189 | } | ||
190 | }); | ||
174 | 191 | ||
175 | } | 192 | } |
176 | } | 193 | } |
@@ -286,15 +303,27 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement | |||
286 | } | 303 | } |
287 | 304 | ||
288 | /// <summary> | 305 | /// <summary> |
289 | /// Try to get the names bound to the given uuid. | 306 | /// |
290 | /// </summary> | 307 | /// </summary> |
291 | /// <returns>True if the name was found, false if not.</returns> | 308 | /// <param name="uuid"></param> |
292 | /// <param name='uuid'></param> | 309 | /// <param name="names">Caller please provide a properly instantiated array for names, string[2]</param> |
293 | /// <param name='names'>The array of names if found. If not found, then names[0] = "Unknown" and names[1] = "User"</param> | 310 | /// <returns></returns> |
294 | private bool TryGetUserNames(UUID uuid, out string[] names) | 311 | private bool TryGetUserNames(UUID uuid, string[] names) |
295 | { | 312 | { |
296 | names = new string[2]; | 313 | if (names == null) |
314 | names = new string[2]; | ||
315 | |||
316 | if (TryGetUserNamesFromCache(uuid, names)) | ||
317 | return true; | ||
318 | |||
319 | if (TryGetUserNamesFromServices(uuid, names)) | ||
320 | return true; | ||
321 | |||
322 | return false; | ||
323 | } | ||
297 | 324 | ||
325 | private bool TryGetUserNamesFromCache(UUID uuid, string[] names) | ||
326 | { | ||
298 | lock (m_UserCache) | 327 | lock (m_UserCache) |
299 | { | 328 | { |
300 | if (m_UserCache.ContainsKey(uuid)) | 329 | if (m_UserCache.ContainsKey(uuid)) |
@@ -306,6 +335,17 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement | |||
306 | } | 335 | } |
307 | } | 336 | } |
308 | 337 | ||
338 | return false; | ||
339 | } | ||
340 | |||
341 | /// <summary> | ||
342 | /// Try to get the names bound to the given uuid, from the services. | ||
343 | /// </summary> | ||
344 | /// <returns>True if the name was found, false if not.</returns> | ||
345 | /// <param name='uuid'></param> | ||
346 | /// <param name='names'>The array of names if found. If not found, then names[0] = "Unknown" and names[1] = "User"</param> | ||
347 | private bool TryGetUserNamesFromServices(UUID uuid, string[] names) | ||
348 | { | ||
309 | UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(UUID.Zero, uuid); | 349 | UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(UUID.Zero, uuid); |
310 | 350 | ||
311 | if (account != null) | 351 | if (account != null) |
@@ -390,18 +430,11 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement | |||
390 | 430 | ||
391 | public string GetUserName(UUID uuid) | 431 | public string GetUserName(UUID uuid) |
392 | { | 432 | { |
393 | string[] names; | 433 | string[] names = new string[2]; |
394 | TryGetUserNames(uuid, out names); | 434 | TryGetUserNames(uuid, names); |
395 | 435 | ||
396 | if (names.Length == 2) | 436 | return names[0] + " " + names[1]; |
397 | { | ||
398 | string firstname = names[0]; | ||
399 | string lastname = names[1]; | ||
400 | |||
401 | return firstname + " " + lastname; | ||
402 | } | ||
403 | 437 | ||
404 | return "(hippos)"; | ||
405 | } | 438 | } |
406 | 439 | ||
407 | public string GetUserHomeURL(UUID userID) | 440 | public string GetUserHomeURL(UUID userID) |
@@ -601,19 +634,6 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement | |||
601 | protected void Init() | 634 | protected void Init() |
602 | { | 635 | { |
603 | RegisterConsoleCmds(); | 636 | RegisterConsoleCmds(); |
604 | //Watchdog.StartThread( | ||
605 | // ProcessQueue, | ||
606 | // "NameRequestThread", | ||
607 | // ThreadPriority.BelowNormal, | ||
608 | // true, | ||
609 | // false); | ||
610 | |||
611 | m_timer = new System.Timers.Timer(); | ||
612 | m_timer.AutoReset = false; | ||
613 | m_timer.Interval = 15000; // 15 secs at first | ||
614 | m_timer.Elapsed += ProcessQueue; | ||
615 | m_timer.Start(); | ||
616 | |||
617 | } | 637 | } |
618 | 638 | ||
619 | protected void RegisterConsoleCmds() | 639 | protected void RegisterConsoleCmds() |
@@ -683,83 +703,6 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement | |||
683 | MainConsole.Instance.Output(cdt.ToString()); | 703 | MainConsole.Instance.Output(cdt.ToString()); |
684 | } | 704 | } |
685 | 705 | ||
686 | private void ProcessQueue() | ||
687 | { | ||
688 | while (true) | ||
689 | { | ||
690 | Watchdog.UpdateThread(); | ||
691 | |||
692 | NameRequest request = m_RequestQueue.Dequeue(); | ||
693 | if (request != null) | ||
694 | { | ||
695 | string[] names; | ||
696 | bool foundRealName = TryGetUserNames(request.uuid, out names); | ||
697 | |||
698 | if (names.Length == 2) | ||
699 | { | ||
700 | if (!foundRealName) | ||
701 | m_log.DebugFormat("[USER MANAGEMENT MODULE]: Sending {0} {1} for {2} to {3} since no bound name found", names[0], names[1], request.uuid, request.client.Name); | ||
702 | |||
703 | request.client.SendNameReply(request.uuid, names[0], names[1]); | ||
704 | } | ||
705 | } | ||
706 | } | ||
707 | } | ||
708 | |||
709 | private bool AreThereRootAgents() | ||
710 | { | ||
711 | foreach (Scene s in m_Scenes) | ||
712 | { | ||
713 | if (s.GetRootAgentCount() > 0) | ||
714 | return true; | ||
715 | } | ||
716 | |||
717 | return false; | ||
718 | } | ||
719 | |||
720 | private void ProcessQueue(object sender, System.Timers.ElapsedEventArgs e) | ||
721 | { | ||
722 | while (m_RequestQueue.Count > 0) | ||
723 | { | ||
724 | NameRequest request = null; | ||
725 | lock (m_RequestQueue) | ||
726 | request = m_RequestQueue.Dequeue(); | ||
727 | |||
728 | if (request != null) | ||
729 | { | ||
730 | string[] names; | ||
731 | bool foundRealName = TryGetUserNames(request.uuid, out names); | ||
732 | |||
733 | if (names.Length == 2) | ||
734 | { | ||
735 | if (!foundRealName) | ||
736 | m_log.DebugFormat("[USER MANAGEMENT MODULE]: Sending {0} {1} for {2} to {3} since no bound name found", names[0], names[1], request.uuid, request.client.Name); | ||
737 | |||
738 | request.client.SendNameReply(request.uuid, names[0], names[1]); | ||
739 | } | ||
740 | } | ||
741 | } | ||
742 | |||
743 | if (AreThereRootAgents()) | ||
744 | m_timer.Interval = 1000; // 1 sec | ||
745 | else | ||
746 | m_timer.Interval = 10000; // 10 secs | ||
747 | |||
748 | m_timer.Start(); | ||
749 | |||
750 | } | ||
751 | } | ||
752 | |||
753 | class NameRequest | ||
754 | { | ||
755 | public IClientAPI client; | ||
756 | public UUID uuid; | ||
757 | |||
758 | public NameRequest(IClientAPI c, UUID n) | ||
759 | { | ||
760 | client = c; | ||
761 | uuid = n; | ||
762 | } | ||
763 | } | 706 | } |
764 | 707 | ||
765 | } \ No newline at end of file | 708 | } \ No newline at end of file |