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