diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs | 547 |
1 files changed, 337 insertions, 210 deletions
diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs index e2f525c..2184a59 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs | |||
@@ -66,7 +66,11 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
66 | private static readonly UUID STOP_UUID = UUID.Random(); | 66 | private static readonly UUID STOP_UUID = UUID.Random(); |
67 | private static readonly string m_mapLayerPath = "0001/"; | 67 | private static readonly string m_mapLayerPath = "0001/"; |
68 | 68 | ||
69 | private OpenSim.Framework.BlockingQueue<MapRequestState> requests = new OpenSim.Framework.BlockingQueue<MapRequestState>(); | 69 | private ManualResetEvent queueEvent = new ManualResetEvent(false); |
70 | private Queue<MapRequestState> requests = new Queue<MapRequestState>(); | ||
71 | |||
72 | private ManualResetEvent m_mapBlockRequestEvent = new ManualResetEvent(false); | ||
73 | private Dictionary<UUID, Queue<MapBlockRequestData>> m_mapBlockRequests = new Dictionary<UUID, Queue<MapBlockRequestData>>(); | ||
70 | 74 | ||
71 | protected Scene m_scene; | 75 | protected Scene m_scene; |
72 | private List<MapBlockData> cachedMapBlocks = new List<MapBlockData>(); | 76 | private List<MapBlockData> cachedMapBlocks = new List<MapBlockData>(); |
@@ -74,7 +78,6 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
74 | private int blacklistTimeout = 10*60*1000; // 10 minutes | 78 | private int blacklistTimeout = 10*60*1000; // 10 minutes |
75 | private byte[] myMapImageJPEG; | 79 | private byte[] myMapImageJPEG; |
76 | protected volatile bool m_Enabled = false; | 80 | protected volatile bool m_Enabled = false; |
77 | private Dictionary<UUID, MapRequestState> m_openRequests = new Dictionary<UUID, MapRequestState>(); | ||
78 | private Dictionary<string, int> m_blacklistedurls = new Dictionary<string, int>(); | 81 | private Dictionary<string, int> m_blacklistedurls = new Dictionary<string, int>(); |
79 | private Dictionary<ulong, int> m_blacklistedregions = new Dictionary<ulong, int>(); | 82 | private Dictionary<ulong, int> m_blacklistedregions = new Dictionary<ulong, int>(); |
80 | private Dictionary<ulong, string> m_cachedRegionMapItemsAddress = new Dictionary<ulong, string>(); | 83 | private Dictionary<ulong, string> m_cachedRegionMapItemsAddress = new Dictionary<ulong, string>(); |
@@ -231,54 +234,54 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
231 | // 6/8/2011 -- I'm adding an explicit 2048 check, so that we never forget that there is | 234 | // 6/8/2011 -- I'm adding an explicit 2048 check, so that we never forget that there is |
232 | // a hack here, and so that regions below 4096 don't get spammed with unnecessary map blocks. | 235 | // a hack here, and so that regions below 4096 don't get spammed with unnecessary map blocks. |
233 | 236 | ||
234 | if (m_scene.RegionInfo.RegionLocX >= 2048 || m_scene.RegionInfo.RegionLocY >= 2048) | 237 | //if (m_scene.RegionInfo.RegionLocX >= 2048 || m_scene.RegionInfo.RegionLocY >= 2048) |
235 | { | 238 | //{ |
236 | ScenePresence avatarPresence = null; | 239 | // ScenePresence avatarPresence = null; |
237 | 240 | ||
238 | m_scene.TryGetScenePresence(agentID, out avatarPresence); | 241 | // m_scene.TryGetScenePresence(agentID, out avatarPresence); |
239 | 242 | ||
240 | if (avatarPresence != null) | 243 | // if (avatarPresence != null) |
241 | { | 244 | // { |
242 | bool lookup = false; | 245 | // bool lookup = false; |
243 | 246 | ||
244 | lock (cachedMapBlocks) | 247 | // lock (cachedMapBlocks) |
245 | { | 248 | // { |
246 | if (cachedMapBlocks.Count > 0 && ((cachedTime + 1800) > Util.UnixTimeSinceEpoch())) | 249 | // if (cachedMapBlocks.Count > 0 && ((cachedTime + 1800) > Util.UnixTimeSinceEpoch())) |
247 | { | 250 | // { |
248 | List<MapBlockData> mapBlocks; | 251 | // List<MapBlockData> mapBlocks; |
249 | 252 | ||
250 | mapBlocks = cachedMapBlocks; | 253 | // mapBlocks = cachedMapBlocks; |
251 | avatarPresence.ControllingClient.SendMapBlock(mapBlocks, 0); | 254 | // avatarPresence.ControllingClient.SendMapBlock(mapBlocks, 0); |
252 | } | 255 | // } |
253 | else | 256 | // else |
254 | { | 257 | // { |
255 | lookup = true; | 258 | // lookup = true; |
256 | } | 259 | // } |
257 | } | 260 | // } |
258 | if (lookup) | 261 | // if (lookup) |
259 | { | 262 | // { |
260 | List<MapBlockData> mapBlocks = new List<MapBlockData>(); ; | 263 | // List<MapBlockData> mapBlocks = new List<MapBlockData>(); ; |
261 | 264 | ||
262 | List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, | 265 | // List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, |
263 | (int)(m_scene.RegionInfo.RegionLocX - 8) * (int)Constants.RegionSize, | 266 | // (int)(m_scene.RegionInfo.RegionLocX - 8) * (int)Constants.RegionSize, |
264 | (int)(m_scene.RegionInfo.RegionLocX + 8) * (int)Constants.RegionSize, | 267 | // (int)(m_scene.RegionInfo.RegionLocX + 8) * (int)Constants.RegionSize, |
265 | (int)(m_scene.RegionInfo.RegionLocY - 8) * (int)Constants.RegionSize, | 268 | // (int)(m_scene.RegionInfo.RegionLocY - 8) * (int)Constants.RegionSize, |
266 | (int)(m_scene.RegionInfo.RegionLocY + 8) * (int)Constants.RegionSize); | 269 | // (int)(m_scene.RegionInfo.RegionLocY + 8) * (int)Constants.RegionSize); |
267 | foreach (GridRegion r in regions) | 270 | // foreach (GridRegion r in regions) |
268 | { | 271 | // { |
269 | MapBlockData block = new MapBlockData(); | 272 | // MapBlockData block = new MapBlockData(); |
270 | MapBlockFromGridRegion(block, r, 0); | 273 | // MapBlockFromGridRegion(block, r, 0); |
271 | mapBlocks.Add(block); | 274 | // mapBlocks.Add(block); |
272 | } | 275 | // } |
273 | avatarPresence.ControllingClient.SendMapBlock(mapBlocks, 0); | 276 | // avatarPresence.ControllingClient.SendMapBlock(mapBlocks, 0); |
274 | 277 | ||
275 | lock (cachedMapBlocks) | 278 | // lock (cachedMapBlocks) |
276 | cachedMapBlocks = mapBlocks; | 279 | // cachedMapBlocks = mapBlocks; |
277 | 280 | ||
278 | cachedTime = Util.UnixTimeSinceEpoch(); | 281 | // cachedTime = Util.UnixTimeSinceEpoch(); |
279 | } | 282 | // } |
280 | } | 283 | // } |
281 | } | 284 | //} |
282 | 285 | ||
283 | LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse(); | 286 | LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse(); |
284 | mapResponse.LayerData.Array.Add(GetOSDMapLayerResponse()); | 287 | mapResponse.LayerData.Array.Add(GetOSDMapLayerResponse()); |
@@ -305,8 +308,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
305 | protected static OSDMapLayer GetOSDMapLayerResponse() | 308 | protected static OSDMapLayer GetOSDMapLayerResponse() |
306 | { | 309 | { |
307 | OSDMapLayer mapLayer = new OSDMapLayer(); | 310 | OSDMapLayer mapLayer = new OSDMapLayer(); |
308 | mapLayer.Right = 5000; | 311 | mapLayer.Right = 2048; |
309 | mapLayer.Top = 5000; | 312 | mapLayer.Top = 2048; |
310 | mapLayer.ImageID = new UUID("00000000-0000-1111-9999-000000000006"); | 313 | mapLayer.ImageID = new UUID("00000000-0000-1111-9999-000000000006"); |
311 | 314 | ||
312 | return mapLayer; | 315 | return mapLayer; |
@@ -335,6 +338,11 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
335 | { | 338 | { |
336 | m_rootAgents.Remove(AgentId); | 339 | m_rootAgents.Remove(AgentId); |
337 | } | 340 | } |
341 | lock (m_mapBlockRequestEvent) | ||
342 | { | ||
343 | if (m_mapBlockRequests.ContainsKey(AgentId)) | ||
344 | m_mapBlockRequests.Remove(AgentId); | ||
345 | } | ||
338 | } | 346 | } |
339 | #endregion | 347 | #endregion |
340 | 348 | ||
@@ -357,6 +365,12 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
357 | ThreadPriority.BelowNormal, | 365 | ThreadPriority.BelowNormal, |
358 | true, | 366 | true, |
359 | true); | 367 | true); |
368 | Watchdog.StartThread( | ||
369 | MapBlockSendThread, | ||
370 | string.Format("MapBlockSendThread ({0})", m_scene.RegionInfo.RegionName), | ||
371 | ThreadPriority.BelowNormal, | ||
372 | true, | ||
373 | true); | ||
360 | } | 374 | } |
361 | 375 | ||
362 | /// <summary> | 376 | /// <summary> |
@@ -372,7 +386,27 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
372 | st.itemtype=0; | 386 | st.itemtype=0; |
373 | st.regionhandle=0; | 387 | st.regionhandle=0; |
374 | 388 | ||
375 | requests.Enqueue(st); | 389 | lock (requests) |
390 | { | ||
391 | queueEvent.Set(); | ||
392 | requests.Enqueue(st); | ||
393 | } | ||
394 | |||
395 | MapBlockRequestData req = new MapBlockRequestData(); | ||
396 | |||
397 | req.client = null; | ||
398 | req.minX = 0; | ||
399 | req.maxX = 0; | ||
400 | req.minY = 0; | ||
401 | req.maxY = 0; | ||
402 | req.flags = 0; | ||
403 | |||
404 | lock (m_mapBlockRequestEvent) | ||
405 | { | ||
406 | m_mapBlockRequests[UUID.Zero] = new Queue<MapBlockRequestData>(); | ||
407 | m_mapBlockRequests[UUID.Zero].Enqueue(req); | ||
408 | m_mapBlockRequestEvent.Set(); | ||
409 | } | ||
376 | } | 410 | } |
377 | 411 | ||
378 | public virtual void HandleMapItemRequest(IClientAPI remoteClient, uint flags, | 412 | public virtual void HandleMapItemRequest(IClientAPI remoteClient, uint flags, |
@@ -528,7 +562,21 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
528 | { | 562 | { |
529 | while (true) | 563 | while (true) |
530 | { | 564 | { |
531 | MapRequestState st = requests.Dequeue(1000); | 565 | MapRequestState st = new MapRequestState(); |
566 | bool valid = false; | ||
567 | queueEvent.WaitOne(); | ||
568 | lock (requests) | ||
569 | { | ||
570 | if (requests.Count > 0) | ||
571 | { | ||
572 | st = requests.Dequeue(); | ||
573 | valid = true; | ||
574 | } | ||
575 | if (requests.Count == 0) | ||
576 | queueEvent.Reset(); | ||
577 | } | ||
578 | if (!valid) | ||
579 | continue; | ||
532 | 580 | ||
533 | // end gracefully | 581 | // end gracefully |
534 | if (st.agentID == STOP_UUID) | 582 | if (st.agentID == STOP_UUID) |
@@ -546,13 +594,13 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
546 | if (dorequest && !m_blacklistedregions.ContainsKey(st.regionhandle)) | 594 | if (dorequest && !m_blacklistedregions.ContainsKey(st.regionhandle)) |
547 | { | 595 | { |
548 | while (nAsyncRequests >= MAX_ASYNC_REQUESTS) // hit the break | 596 | while (nAsyncRequests >= MAX_ASYNC_REQUESTS) // hit the break |
549 | Thread.Sleep(80); | 597 | Thread.Sleep(100); |
550 | 598 | ||
551 | RequestMapItemsDelegate d = RequestMapItemsAsync; | ||
552 | d.BeginInvoke(st.agentID, st.flags, st.EstateID, st.godlike, st.itemtype, st.regionhandle, RequestMapItemsCompleted, null); | ||
553 | //OSDMap response = RequestMapItemsAsync(st.agentID, st.flags, st.EstateID, st.godlike, st.itemtype, st.regionhandle); | ||
554 | //RequestMapItemsCompleted(response); | ||
555 | Interlocked.Increment(ref nAsyncRequests); | 599 | Interlocked.Increment(ref nAsyncRequests); |
600 | Util.FireAndForget(x => | ||
601 | { | ||
602 | RequestMapItemsAsync(st.agentID, st.flags, st.EstateID, st.godlike, st.itemtype, st.regionhandle); | ||
603 | }); | ||
556 | } | 604 | } |
557 | } | 605 | } |
558 | 606 | ||
@@ -574,110 +622,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
574 | /// <param name="state"></param> | 622 | /// <param name="state"></param> |
575 | public void EnqueueMapItemRequest(MapRequestState state) | 623 | public void EnqueueMapItemRequest(MapRequestState state) |
576 | { | 624 | { |
577 | requests.Enqueue(state); | 625 | lock (requests) |
578 | } | ||
579 | |||
580 | /// <summary> | ||
581 | /// Sends the mapitem response to the IClientAPI | ||
582 | /// </summary> | ||
583 | /// <param name="response">The OSDMap Response for the mapitem</param> | ||
584 | private void RequestMapItemsCompleted(IAsyncResult iar) | ||
585 | { | ||
586 | AsyncResult result = (AsyncResult)iar; | ||
587 | RequestMapItemsDelegate icon = (RequestMapItemsDelegate)result.AsyncDelegate; | ||
588 | |||
589 | OSDMap response = (OSDMap)icon.EndInvoke(iar); | ||
590 | |||
591 | Interlocked.Decrement(ref nAsyncRequests); | ||
592 | |||
593 | if (!response.ContainsKey("requestID")) | ||
594 | return; | ||
595 | |||
596 | UUID requestID = response["requestID"].AsUUID(); | ||
597 | |||
598 | if (requestID != UUID.Zero) | ||
599 | { | 626 | { |
600 | MapRequestState mrs = new MapRequestState(); | 627 | queueEvent.Set(); |
601 | mrs.agentID = UUID.Zero; | 628 | requests.Enqueue(state); |
602 | lock (m_openRequests) | ||
603 | { | ||
604 | if (m_openRequests.ContainsKey(requestID)) | ||
605 | { | ||
606 | mrs = m_openRequests[requestID]; | ||
607 | m_openRequests.Remove(requestID); | ||
608 | } | ||
609 | } | ||
610 | |||
611 | if (mrs.agentID != UUID.Zero) | ||
612 | { | ||
613 | ScenePresence av = null; | ||
614 | m_scene.TryGetScenePresence(mrs.agentID, out av); | ||
615 | if (av != null) | ||
616 | { | ||
617 | if (response.ContainsKey(mrs.itemtype.ToString())) | ||
618 | { | ||
619 | List<mapItemReply> returnitems = new List<mapItemReply>(); | ||
620 | OSDArray itemarray = (OSDArray)response[mrs.itemtype.ToString()]; | ||
621 | for (int i = 0; i < itemarray.Count; i++) | ||
622 | { | ||
623 | OSDMap mapitem = (OSDMap)itemarray[i]; | ||
624 | mapItemReply mi = new mapItemReply(); | ||
625 | mi.x = (uint)mapitem["X"].AsInteger(); | ||
626 | mi.y = (uint)mapitem["Y"].AsInteger(); | ||
627 | mi.id = mapitem["ID"].AsUUID(); | ||
628 | mi.Extra = mapitem["Extra"].AsInteger(); | ||
629 | mi.Extra2 = mapitem["Extra2"].AsInteger(); | ||
630 | mi.name = mapitem["Name"].AsString(); | ||
631 | returnitems.Add(mi); | ||
632 | } | ||
633 | av.ControllingClient.SendMapItemReply(returnitems.ToArray(), mrs.itemtype, mrs.flags); | ||
634 | } | ||
635 | |||
636 | // Service 7 (MAP_ITEM_LAND_FOR_SALE) | ||
637 | uint itemtype = 7; | ||
638 | |||
639 | if (response.ContainsKey(itemtype.ToString())) | ||
640 | { | ||
641 | List<mapItemReply> returnitems = new List<mapItemReply>(); | ||
642 | OSDArray itemarray = (OSDArray)response[itemtype.ToString()]; | ||
643 | for (int i = 0; i < itemarray.Count; i++) | ||
644 | { | ||
645 | OSDMap mapitem = (OSDMap)itemarray[i]; | ||
646 | mapItemReply mi = new mapItemReply(); | ||
647 | mi.x = (uint)mapitem["X"].AsInteger(); | ||
648 | mi.y = (uint)mapitem["Y"].AsInteger(); | ||
649 | mi.id = mapitem["ID"].AsUUID(); | ||
650 | mi.Extra = mapitem["Extra"].AsInteger(); | ||
651 | mi.Extra2 = mapitem["Extra2"].AsInteger(); | ||
652 | mi.name = mapitem["Name"].AsString(); | ||
653 | returnitems.Add(mi); | ||
654 | } | ||
655 | av.ControllingClient.SendMapItemReply(returnitems.ToArray(), itemtype, mrs.flags); | ||
656 | } | ||
657 | |||
658 | // Service 1 (MAP_ITEM_TELEHUB) | ||
659 | itemtype = 1; | ||
660 | |||
661 | if (response.ContainsKey(itemtype.ToString())) | ||
662 | { | ||
663 | List<mapItemReply> returnitems = new List<mapItemReply>(); | ||
664 | OSDArray itemarray = (OSDArray)response[itemtype.ToString()]; | ||
665 | for (int i = 0; i < itemarray.Count; i++) | ||
666 | { | ||
667 | OSDMap mapitem = (OSDMap)itemarray[i]; | ||
668 | mapItemReply mi = new mapItemReply(); | ||
669 | mi.x = (uint)mapitem["X"].AsInteger(); | ||
670 | mi.y = (uint)mapitem["Y"].AsInteger(); | ||
671 | mi.id = mapitem["ID"].AsUUID(); | ||
672 | mi.Extra = mapitem["Extra"].AsInteger(); | ||
673 | mi.Extra2 = mapitem["Extra2"].AsInteger(); | ||
674 | mi.name = mapitem["Name"].AsString(); | ||
675 | returnitems.Add(mi); | ||
676 | } | ||
677 | av.ControllingClient.SendMapItemReply(returnitems.ToArray(), itemtype, mrs.flags); | ||
678 | } | ||
679 | } | ||
680 | } | ||
681 | } | 629 | } |
682 | } | 630 | } |
683 | 631 | ||
@@ -704,8 +652,6 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
704 | EnqueueMapItemRequest(st); | 652 | EnqueueMapItemRequest(st); |
705 | } | 653 | } |
706 | 654 | ||
707 | private delegate OSDMap RequestMapItemsDelegate(UUID id, uint flags, | ||
708 | uint EstateID, bool godlike, uint itemtype, ulong regionhandle); | ||
709 | /// <summary> | 655 | /// <summary> |
710 | /// Does the actual remote mapitem request | 656 | /// Does the actual remote mapitem request |
711 | /// This should be called from an asynchronous thread | 657 | /// This should be called from an asynchronous thread |
@@ -720,7 +666,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
720 | /// <param name="itemtype">passed in from packet</param> | 666 | /// <param name="itemtype">passed in from packet</param> |
721 | /// <param name="regionhandle">Region we're looking up</param> | 667 | /// <param name="regionhandle">Region we're looking up</param> |
722 | /// <returns></returns> | 668 | /// <returns></returns> |
723 | private OSDMap RequestMapItemsAsync(UUID id, uint flags, | 669 | private void RequestMapItemsAsync(UUID id, uint flags, |
724 | uint EstateID, bool godlike, uint itemtype, ulong regionhandle) | 670 | uint EstateID, bool godlike, uint itemtype, ulong regionhandle) |
725 | { | 671 | { |
726 | // m_log.DebugFormat("[WORLDMAP]: RequestMapItemsAsync; region handle: {0} {1}", regionhandle, itemtype); | 672 | // m_log.DebugFormat("[WORLDMAP]: RequestMapItemsAsync; region handle: {0} {1}", regionhandle, itemtype); |
@@ -743,7 +689,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
743 | } | 689 | } |
744 | 690 | ||
745 | if (blacklisted) | 691 | if (blacklisted) |
746 | return new OSDMap(); | 692 | { |
693 | Interlocked.Decrement(ref nAsyncRequests); | ||
694 | return; | ||
695 | } | ||
747 | 696 | ||
748 | UUID requestID = UUID.Random(); | 697 | UUID requestID = UUID.Random(); |
749 | lock (m_cachedRegionMapItemsAddress) | 698 | lock (m_cachedRegionMapItemsAddress) |
@@ -751,6 +700,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
751 | if (m_cachedRegionMapItemsAddress.ContainsKey(regionhandle)) | 700 | if (m_cachedRegionMapItemsAddress.ContainsKey(regionhandle)) |
752 | httpserver = m_cachedRegionMapItemsAddress[regionhandle]; | 701 | httpserver = m_cachedRegionMapItemsAddress[regionhandle]; |
753 | } | 702 | } |
703 | |||
754 | if (httpserver.Length == 0) | 704 | if (httpserver.Length == 0) |
755 | { | 705 | { |
756 | uint x = 0, y = 0; | 706 | uint x = 0, y = 0; |
@@ -795,18 +745,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
795 | 745 | ||
796 | // Can't find the http server | 746 | // Can't find the http server |
797 | if (httpserver.Length == 0 || blacklisted) | 747 | if (httpserver.Length == 0 || blacklisted) |
798 | return new OSDMap(); | 748 | { |
799 | 749 | Interlocked.Decrement(ref nAsyncRequests); | |
800 | MapRequestState mrs = new MapRequestState(); | 750 | return; |
801 | mrs.agentID = id; | 751 | } |
802 | mrs.EstateID = EstateID; | ||
803 | mrs.flags = flags; | ||
804 | mrs.godlike = godlike; | ||
805 | mrs.itemtype=itemtype; | ||
806 | mrs.regionhandle = regionhandle; | ||
807 | |||
808 | lock (m_openRequests) | ||
809 | m_openRequests.Add(requestID, mrs); | ||
810 | 752 | ||
811 | WebRequest mapitemsrequest = null; | 753 | WebRequest mapitemsrequest = null; |
812 | try | 754 | try |
@@ -816,7 +758,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
816 | catch (Exception e) | 758 | catch (Exception e) |
817 | { | 759 | { |
818 | m_log.DebugFormat("[WORLD MAP]: Access to {0} failed with {1}", httpserver, e); | 760 | m_log.DebugFormat("[WORLD MAP]: Access to {0} failed with {1}", httpserver, e); |
819 | return new OSDMap(); | 761 | Interlocked.Decrement(ref nAsyncRequests); |
762 | return; | ||
820 | } | 763 | } |
821 | 764 | ||
822 | mapitemsrequest.Method = "POST"; | 765 | mapitemsrequest.Method = "POST"; |
@@ -841,7 +784,6 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
841 | catch (WebException ex) | 784 | catch (WebException ex) |
842 | { | 785 | { |
843 | m_log.WarnFormat("[WORLD MAP]: Bad send on GetMapItems {0}", ex.Message); | 786 | m_log.WarnFormat("[WORLD MAP]: Bad send on GetMapItems {0}", ex.Message); |
844 | responseMap["connect"] = OSD.FromBoolean(false); | ||
845 | lock (m_blacklistedurls) | 787 | lock (m_blacklistedurls) |
846 | { | 788 | { |
847 | if (!m_blacklistedurls.ContainsKey(httpserver)) | 789 | if (!m_blacklistedurls.ContainsKey(httpserver)) |
@@ -850,13 +792,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
850 | 792 | ||
851 | m_log.WarnFormat("[WORLD MAP]: Blacklisted {0}", httpserver); | 793 | m_log.WarnFormat("[WORLD MAP]: Blacklisted {0}", httpserver); |
852 | 794 | ||
853 | return responseMap; | 795 | Interlocked.Decrement(ref nAsyncRequests); |
796 | return; | ||
854 | } | 797 | } |
855 | catch | 798 | catch |
856 | { | 799 | { |
857 | m_log.DebugFormat("[WORLD MAP]: RequestMapItems failed for {0}", httpserver); | 800 | m_log.DebugFormat("[WORLD MAP]: RequestMapItems failed for {0}", httpserver); |
858 | responseMap["connect"] = OSD.FromBoolean(false); | 801 | Interlocked.Decrement(ref nAsyncRequests); |
859 | return responseMap; | 802 | return; |
860 | } | 803 | } |
861 | finally | 804 | finally |
862 | { | 805 | { |
@@ -877,12 +820,12 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
877 | } | 820 | } |
878 | else | 821 | else |
879 | { | 822 | { |
880 | return new OSDMap(); | 823 | Interlocked.Decrement(ref nAsyncRequests); |
824 | return; | ||
881 | } | 825 | } |
882 | } | 826 | } |
883 | catch (WebException) | 827 | catch (WebException) |
884 | { | 828 | { |
885 | responseMap["connect"] = OSD.FromBoolean(false); | ||
886 | lock (m_blacklistedurls) | 829 | lock (m_blacklistedurls) |
887 | { | 830 | { |
888 | if (!m_blacklistedurls.ContainsKey(httpserver)) | 831 | if (!m_blacklistedurls.ContainsKey(httpserver)) |
@@ -891,19 +834,20 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
891 | 834 | ||
892 | m_log.WarnFormat("[WORLD MAP]: Blacklisted {0}", httpserver); | 835 | m_log.WarnFormat("[WORLD MAP]: Blacklisted {0}", httpserver); |
893 | 836 | ||
894 | return responseMap; | 837 | Interlocked.Decrement(ref nAsyncRequests); |
838 | return; | ||
895 | } | 839 | } |
896 | catch | 840 | catch |
897 | { | 841 | { |
898 | m_log.DebugFormat("[WORLD MAP]: RequestMapItems failed for {0}", httpserver); | 842 | m_log.DebugFormat("[WORLD MAP]: RequestMapItems failed for {0}", httpserver); |
899 | responseMap["connect"] = OSD.FromBoolean(false); | ||
900 | lock (m_blacklistedregions) | 843 | lock (m_blacklistedregions) |
901 | { | 844 | { |
902 | if (!m_blacklistedregions.ContainsKey(regionhandle)) | 845 | if (!m_blacklistedregions.ContainsKey(regionhandle)) |
903 | m_blacklistedregions.Add(regionhandle, Environment.TickCount); | 846 | m_blacklistedregions.Add(regionhandle, Environment.TickCount); |
904 | } | 847 | } |
905 | 848 | ||
906 | return responseMap; | 849 | Interlocked.Decrement(ref nAsyncRequests); |
850 | return; | ||
907 | } | 851 | } |
908 | finally | 852 | finally |
909 | { | 853 | { |
@@ -922,14 +866,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
922 | catch (Exception ex) | 866 | catch (Exception ex) |
923 | { | 867 | { |
924 | m_log.InfoFormat("[WORLD MAP]: exception on parse of RequestMapItems reply from {0}: {1}", httpserver, ex.Message); | 868 | m_log.InfoFormat("[WORLD MAP]: exception on parse of RequestMapItems reply from {0}: {1}", httpserver, ex.Message); |
925 | responseMap["connect"] = OSD.FromBoolean(false); | ||
926 | lock (m_blacklistedregions) | 869 | lock (m_blacklistedregions) |
927 | { | 870 | { |
928 | if (!m_blacklistedregions.ContainsKey(regionhandle)) | 871 | if (!m_blacklistedregions.ContainsKey(regionhandle)) |
929 | m_blacklistedregions.Add(regionhandle, Environment.TickCount); | 872 | m_blacklistedregions.Add(regionhandle, Environment.TickCount); |
930 | } | 873 | } |
931 | 874 | ||
932 | return responseMap; | 875 | Interlocked.Decrement(ref nAsyncRequests); |
876 | return; | ||
933 | } | 877 | } |
934 | } | 878 | } |
935 | 879 | ||
@@ -943,7 +887,78 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
943 | } | 887 | } |
944 | } | 888 | } |
945 | 889 | ||
946 | return responseMap; | 890 | Interlocked.Decrement(ref nAsyncRequests); |
891 | |||
892 | if (id != UUID.Zero) | ||
893 | { | ||
894 | ScenePresence av = null; | ||
895 | m_scene.TryGetScenePresence(id, out av); | ||
896 | if (av != null) | ||
897 | { | ||
898 | if (responseMap.ContainsKey(itemtype.ToString())) | ||
899 | { | ||
900 | List<mapItemReply> returnitems = new List<mapItemReply>(); | ||
901 | OSDArray itemarray = (OSDArray)responseMap[itemtype.ToString()]; | ||
902 | for (int i = 0; i < itemarray.Count; i++) | ||
903 | { | ||
904 | OSDMap mapitem = (OSDMap)itemarray[i]; | ||
905 | mapItemReply mi = new mapItemReply(); | ||
906 | mi.x = (uint)mapitem["X"].AsInteger(); | ||
907 | mi.y = (uint)mapitem["Y"].AsInteger(); | ||
908 | mi.id = mapitem["ID"].AsUUID(); | ||
909 | mi.Extra = mapitem["Extra"].AsInteger(); | ||
910 | mi.Extra2 = mapitem["Extra2"].AsInteger(); | ||
911 | mi.name = mapitem["Name"].AsString(); | ||
912 | returnitems.Add(mi); | ||
913 | } | ||
914 | av.ControllingClient.SendMapItemReply(returnitems.ToArray(), itemtype, flags); | ||
915 | } | ||
916 | |||
917 | // Service 7 (MAP_ITEM_LAND_FOR_SALE) | ||
918 | itemtype = 7; | ||
919 | |||
920 | if (responseMap.ContainsKey(itemtype.ToString())) | ||
921 | { | ||
922 | List<mapItemReply> returnitems = new List<mapItemReply>(); | ||
923 | OSDArray itemarray = (OSDArray)responseMap[itemtype.ToString()]; | ||
924 | for (int i = 0; i < itemarray.Count; i++) | ||
925 | { | ||
926 | OSDMap mapitem = (OSDMap)itemarray[i]; | ||
927 | mapItemReply mi = new mapItemReply(); | ||
928 | mi.x = (uint)mapitem["X"].AsInteger(); | ||
929 | mi.y = (uint)mapitem["Y"].AsInteger(); | ||
930 | mi.id = mapitem["ID"].AsUUID(); | ||
931 | mi.Extra = mapitem["Extra"].AsInteger(); | ||
932 | mi.Extra2 = mapitem["Extra2"].AsInteger(); | ||
933 | mi.name = mapitem["Name"].AsString(); | ||
934 | returnitems.Add(mi); | ||
935 | } | ||
936 | av.ControllingClient.SendMapItemReply(returnitems.ToArray(), itemtype, flags); | ||
937 | } | ||
938 | |||
939 | // Service 1 (MAP_ITEM_TELEHUB) | ||
940 | itemtype = 1; | ||
941 | |||
942 | if (responseMap.ContainsKey(itemtype.ToString())) | ||
943 | { | ||
944 | List<mapItemReply> returnitems = new List<mapItemReply>(); | ||
945 | OSDArray itemarray = (OSDArray)responseMap[itemtype.ToString()]; | ||
946 | for (int i = 0; i < itemarray.Count; i++) | ||
947 | { | ||
948 | OSDMap mapitem = (OSDMap)itemarray[i]; | ||
949 | mapItemReply mi = new mapItemReply(); | ||
950 | mi.x = (uint)mapitem["X"].AsInteger(); | ||
951 | mi.y = (uint)mapitem["Y"].AsInteger(); | ||
952 | mi.id = mapitem["ID"].AsUUID(); | ||
953 | mi.Extra = mapitem["Extra"].AsInteger(); | ||
954 | mi.Extra2 = mapitem["Extra2"].AsInteger(); | ||
955 | mi.name = mapitem["Name"].AsString(); | ||
956 | returnitems.Add(mi); | ||
957 | } | ||
958 | av.ControllingClient.SendMapItemReply(returnitems.ToArray(), itemtype, flags); | ||
959 | } | ||
960 | } | ||
961 | } | ||
947 | } | 962 | } |
948 | 963 | ||
949 | /// <summary> | 964 | /// <summary> |
@@ -953,7 +968,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
953 | /// <param name="minY"></param> | 968 | /// <param name="minY"></param> |
954 | /// <param name="maxX"></param> | 969 | /// <param name="maxX"></param> |
955 | /// <param name="maxY"></param> | 970 | /// <param name="maxY"></param> |
956 | public virtual void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag) | 971 | public void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag) |
957 | { | 972 | { |
958 | //m_log.ErrorFormat("[YYY] RequestMapBlocks {0}={1}={2}={3} {4}", minX, minY, maxX, maxY, flag); | 973 | //m_log.ErrorFormat("[YYY] RequestMapBlocks {0}={1}={2}={3} {4}", minX, minY, maxX, maxY, flag); |
959 | if ((flag & 0x10000) != 0) // user clicked on qthe map a tile that isn't visible | 974 | if ((flag & 0x10000) != 0) // user clicked on qthe map a tile that isn't visible |
@@ -1006,21 +1021,91 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
1006 | 1021 | ||
1007 | protected virtual List<MapBlockData> GetAndSendBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag) | 1022 | protected virtual List<MapBlockData> GetAndSendBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag) |
1008 | { | 1023 | { |
1024 | MapBlockRequestData req = new MapBlockRequestData(); | ||
1025 | |||
1026 | req.client = remoteClient; | ||
1027 | req.minX = minX; | ||
1028 | req.maxX = maxX; | ||
1029 | req.minY = minY; | ||
1030 | req.maxY = maxY; | ||
1031 | req.flags = flag; | ||
1032 | |||
1033 | lock (m_mapBlockRequestEvent) | ||
1034 | { | ||
1035 | if (!m_mapBlockRequests.ContainsKey(remoteClient.AgentId)) | ||
1036 | m_mapBlockRequests[remoteClient.AgentId] = new Queue<MapBlockRequestData>(); | ||
1037 | m_mapBlockRequests[remoteClient.AgentId].Enqueue(req); | ||
1038 | m_mapBlockRequestEvent.Set(); | ||
1039 | } | ||
1040 | |||
1041 | return new List<MapBlockData>(); | ||
1042 | } | ||
1043 | |||
1044 | protected void MapBlockSendThread() | ||
1045 | { | ||
1046 | while (true) | ||
1047 | { | ||
1048 | List<MapBlockRequestData> thisRunData = new List<MapBlockRequestData>(); | ||
1049 | |||
1050 | m_mapBlockRequestEvent.WaitOne(); | ||
1051 | lock (m_mapBlockRequestEvent) | ||
1052 | { | ||
1053 | int total = 0; | ||
1054 | foreach (Queue<MapBlockRequestData> q in m_mapBlockRequests.Values) | ||
1055 | { | ||
1056 | if (q.Count > 0) | ||
1057 | thisRunData.Add(q.Dequeue()); | ||
1058 | |||
1059 | total += q.Count; | ||
1060 | } | ||
1061 | |||
1062 | if (total == 0) | ||
1063 | m_mapBlockRequestEvent.Reset(); | ||
1064 | } | ||
1065 | |||
1066 | foreach (MapBlockRequestData req in thisRunData) | ||
1067 | { | ||
1068 | // Null client stops thread | ||
1069 | if (req.client == null) | ||
1070 | return; | ||
1071 | |||
1072 | GetAndSendBlocksInternal(req.client, req.minX, req.minY, req.maxX, req.maxY, req.flags); | ||
1073 | } | ||
1074 | |||
1075 | Thread.Sleep(50); | ||
1076 | } | ||
1077 | } | ||
1078 | |||
1079 | protected virtual List<MapBlockData> GetAndSendBlocksInternal(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag) | ||
1080 | { | ||
1081 | List<MapBlockData> allBlocks = new List<MapBlockData>(); | ||
1009 | List<MapBlockData> mapBlocks = new List<MapBlockData>(); | 1082 | List<MapBlockData> mapBlocks = new List<MapBlockData>(); |
1010 | List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, | 1083 | List<GridRegion> regions = m_scene.GridService.GetRegionRange(m_scene.RegionInfo.ScopeID, |
1011 | (minX - 4) * (int)Constants.RegionSize, | 1084 | minX * (int)Constants.RegionSize, |
1012 | (maxX + 4) * (int)Constants.RegionSize, | 1085 | maxX * (int)Constants.RegionSize, |
1013 | (minY - 4) * (int)Constants.RegionSize, | 1086 | minY * (int)Constants.RegionSize, |
1014 | (maxY + 4) * (int)Constants.RegionSize); | 1087 | maxY * (int)Constants.RegionSize); |
1088 | // (minX - 4) * (int)Constants.RegionSize, | ||
1089 | // (maxX + 4) * (int)Constants.RegionSize, | ||
1090 | // (minY - 4) * (int)Constants.RegionSize, | ||
1091 | // (maxY + 4) * (int)Constants.RegionSize); | ||
1015 | foreach (GridRegion r in regions) | 1092 | foreach (GridRegion r in regions) |
1016 | { | 1093 | { |
1017 | MapBlockData block = new MapBlockData(); | 1094 | MapBlockData block = new MapBlockData(); |
1018 | MapBlockFromGridRegion(block, r, flag); | 1095 | MapBlockFromGridRegion(block, r, flag); |
1019 | mapBlocks.Add(block); | 1096 | mapBlocks.Add(block); |
1097 | allBlocks.Add(block); | ||
1098 | if (mapBlocks.Count >= 10) | ||
1099 | { | ||
1100 | remoteClient.SendMapBlock(mapBlocks, flag & 0xffff); | ||
1101 | mapBlocks.Clear(); | ||
1102 | Thread.Sleep(50); | ||
1103 | } | ||
1020 | } | 1104 | } |
1021 | remoteClient.SendMapBlock(mapBlocks, flag & 0xffff); | 1105 | if (mapBlocks.Count > 0) |
1106 | remoteClient.SendMapBlock(mapBlocks, flag & 0xffff); | ||
1022 | 1107 | ||
1023 | return mapBlocks; | 1108 | return allBlocks; |
1024 | } | 1109 | } |
1025 | 1110 | ||
1026 | protected void MapBlockFromGridRegion(MapBlockData block, GridRegion r, uint flag) | 1111 | protected void MapBlockFromGridRegion(MapBlockData block, GridRegion r, uint flag) |
@@ -1244,7 +1329,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
1244 | } | 1329 | } |
1245 | else | 1330 | else |
1246 | { | 1331 | { |
1247 | OSDArray responsearr = new OSDArray(m_scene.GetRootAgentCount()); | 1332 | OSDArray responsearr = new OSDArray(); // Don't preallocate. MT (m_scene.GetRootAgentCount()); |
1248 | m_scene.ForEachRootScenePresence(delegate(ScenePresence sp) | 1333 | m_scene.ForEachRootScenePresence(delegate(ScenePresence sp) |
1249 | { | 1334 | { |
1250 | OSDMap responsemapdata = new OSDMap(); | 1335 | OSDMap responsemapdata = new OSDMap(); |
@@ -1420,6 +1505,12 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
1420 | { | 1505 | { |
1421 | m_rootAgents.Remove(avatar.UUID); | 1506 | m_rootAgents.Remove(avatar.UUID); |
1422 | } | 1507 | } |
1508 | |||
1509 | lock (m_mapBlockRequestEvent) | ||
1510 | { | ||
1511 | if (m_mapBlockRequests.ContainsKey(avatar.UUID)) | ||
1512 | m_mapBlockRequests.Remove(avatar.UUID); | ||
1513 | } | ||
1423 | } | 1514 | } |
1424 | 1515 | ||
1425 | public void OnRegionUp(GridRegion otherRegion) | 1516 | public void OnRegionUp(GridRegion otherRegion) |
@@ -1464,9 +1555,10 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
1464 | Color background = Color.FromArgb(0, 0, 0, 0); | 1555 | Color background = Color.FromArgb(0, 0, 0, 0); |
1465 | SolidBrush transparent = new SolidBrush(background); | 1556 | SolidBrush transparent = new SolidBrush(background); |
1466 | Graphics g = Graphics.FromImage(overlay); | 1557 | Graphics g = Graphics.FromImage(overlay); |
1467 | g.FillRectangle(transparent, 0, 0, 256, 256); | 1558 | g.FillRectangle(transparent, 0, 0, 255, 255); |
1468 | 1559 | ||
1469 | SolidBrush yellow = new SolidBrush(Color.FromArgb(255, 249, 223, 9)); | 1560 | SolidBrush yellow = new SolidBrush(Color.FromArgb(255, 249, 223, 9)); |
1561 | Pen grey = new Pen(Color.FromArgb(255, 92, 92, 92)); | ||
1470 | 1562 | ||
1471 | foreach (ILandObject land in parcels) | 1563 | foreach (ILandObject land in parcels) |
1472 | { | 1564 | { |
@@ -1474,8 +1566,42 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
1474 | if ((land.LandData.Flags & (uint)ParcelFlags.ForSale) != 0) | 1566 | if ((land.LandData.Flags & (uint)ParcelFlags.ForSale) != 0) |
1475 | { | 1567 | { |
1476 | landForSale = true; | 1568 | landForSale = true; |
1569 | |||
1570 | bool[,] landBitmap = land.GetLandBitmap(); | ||
1571 | |||
1572 | for (int x = 0 ; x < 64 ; x++) | ||
1573 | { | ||
1574 | for (int y = 0 ; y < 64 ; y++) | ||
1575 | { | ||
1576 | if (landBitmap[x, y]) | ||
1577 | { | ||
1578 | g.FillRectangle(yellow, x * 4, 252 - (y * 4), 4, 4); | ||
1579 | |||
1580 | if (x > 0) | ||
1581 | { | ||
1582 | if ((saleBitmap[x - 1, y] || landBitmap[x - 1, y]) == false) | ||
1583 | g.DrawLine(grey, x * 4, 252 - (y * 4), x * 4, 255 - (y * 4)); | ||
1584 | } | ||
1585 | if (y > 0) | ||
1586 | { | ||
1587 | if ((saleBitmap[x, y-1] || landBitmap[x, y-1]) == false) | ||
1588 | g.DrawLine(grey, x * 4, 255 - (y * 4), x * 4 + 3, 255 - (y * 4)); | ||
1589 | } | ||
1590 | if (x < 63) | ||
1591 | { | ||
1592 | if ((saleBitmap[x + 1, y] || landBitmap[x + 1, y]) == false) | ||
1593 | g.DrawLine(grey, x * 4 + 3, 252 - (y * 4), x * 4 + 3, 255 - (y * 4)); | ||
1594 | } | ||
1595 | if (y < 63) | ||
1596 | { | ||
1597 | if ((saleBitmap[x, y + 1] || landBitmap[x, y + 1]) == false) | ||
1598 | g.DrawLine(grey, x * 4, 252 - (y * 4), x * 4 + 3, 252 - (y * 4)); | ||
1599 | } | ||
1600 | } | ||
1601 | } | ||
1602 | } | ||
1477 | 1603 | ||
1478 | saleBitmap = land.MergeLandBitmaps(saleBitmap, land.GetLandBitmap()); | 1604 | saleBitmap = land.MergeLandBitmaps(saleBitmap, landBitmap); |
1479 | } | 1605 | } |
1480 | } | 1606 | } |
1481 | 1607 | ||
@@ -1487,15 +1613,6 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
1487 | 1613 | ||
1488 | m_log.DebugFormat("[WORLD MAP]: Region {0} has parcels for sale, generating overlay", m_scene.RegionInfo.RegionName); | 1614 | m_log.DebugFormat("[WORLD MAP]: Region {0} has parcels for sale, generating overlay", m_scene.RegionInfo.RegionName); |
1489 | 1615 | ||
1490 | for (int x = 0 ; x < 64 ; x++) | ||
1491 | { | ||
1492 | for (int y = 0 ; y < 64 ; y++) | ||
1493 | { | ||
1494 | if (saleBitmap[x, y]) | ||
1495 | g.FillRectangle(yellow, x * 4, 252 - (y * 4), 4, 4); | ||
1496 | } | ||
1497 | } | ||
1498 | |||
1499 | try | 1616 | try |
1500 | { | 1617 | { |
1501 | return OpenJPEG.EncodeFromImage(overlay, true); | 1618 | return OpenJPEG.EncodeFromImage(overlay, true); |
@@ -1517,4 +1634,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap | |||
1517 | public uint itemtype; | 1634 | public uint itemtype; |
1518 | public ulong regionhandle; | 1635 | public ulong regionhandle; |
1519 | } | 1636 | } |
1637 | |||
1638 | public struct MapBlockRequestData | ||
1639 | { | ||
1640 | public IClientAPI client; | ||
1641 | public int minX; | ||
1642 | public int minY; | ||
1643 | public int maxX; | ||
1644 | public int maxY; | ||
1645 | public uint flags; | ||
1646 | } | ||
1520 | } | 1647 | } |