HGWorldMapModule.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.Reflection;
  30. using log4net;
  31. using Nini.Config;
  32. using OpenMetaverse;
  33. using Mono.Addins;
  34. using OpenSim.Framework;
  35. using OpenSim.Region.CoreModules.World.WorldMap;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Region.Framework.Scenes;
  38. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  39. namespace OpenSim.Region.CoreModules.Hypergrid
  40. {
  41. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HGWorldMapModule")]
  42. public class HGWorldMapModule : WorldMapModule
  43. {
  44. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. // Remember the map area that each client has been exposed to in this region
  46. private Dictionary<UUID, List<MapBlockData>> m_SeenMapBlocks = new Dictionary<UUID, List<MapBlockData>>();
  47. #region INonSharedRegionModule Members
  48. public override void Initialise(IConfigSource config)
  49. {
  50. IConfig startupConfig = config.Configs["Startup"];
  51. if (startupConfig.GetString("WorldMapModule", "WorldMap") == "HGWorldMap")
  52. m_Enabled = true;
  53. }
  54. public override void AddRegion(Scene scene)
  55. {
  56. base.AddRegion(scene);
  57. scene.EventManager.OnClientClosed += new EventManager.ClientClosed(EventManager_OnClientClosed);
  58. }
  59. public override string Name
  60. {
  61. get { return "HGWorldMap"; }
  62. }
  63. #endregion
  64. void EventManager_OnClientClosed(UUID clientID, Scene scene)
  65. {
  66. ScenePresence sp = scene.GetScenePresence(clientID);
  67. if (sp != null)
  68. {
  69. if (m_SeenMapBlocks.ContainsKey(clientID))
  70. {
  71. List<MapBlockData> mapBlocks = m_SeenMapBlocks[clientID];
  72. foreach (MapBlockData b in mapBlocks)
  73. {
  74. b.Name = string.Empty;
  75. b.Access = 254; // means 'simulator is offline'. We need this because the viewer ignores 255's
  76. }
  77. m_log.DebugFormat("[HG MAP]: Reseting {0} blocks", mapBlocks.Count);
  78. sp.ControllingClient.SendMapBlock(mapBlocks, 0);
  79. m_SeenMapBlocks.Remove(clientID);
  80. }
  81. }
  82. }
  83. protected override List<MapBlockData> GetAndSendBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag)
  84. {
  85. List<MapBlockData> mapBlocks = base.GetAndSendBlocks(remoteClient, minX, minY, maxX, maxY, flag);
  86. lock (m_SeenMapBlocks)
  87. {
  88. if (!m_SeenMapBlocks.ContainsKey(remoteClient.AgentId))
  89. {
  90. m_SeenMapBlocks.Add(remoteClient.AgentId, mapBlocks);
  91. }
  92. else
  93. {
  94. List<MapBlockData> seen = m_SeenMapBlocks[remoteClient.AgentId];
  95. List<MapBlockData> newBlocks = new List<MapBlockData>();
  96. foreach (MapBlockData b in mapBlocks)
  97. if (seen.Find(delegate(MapBlockData bdata) { return bdata.X == b.X && bdata.Y == b.Y; }) == null)
  98. newBlocks.Add(b);
  99. seen.AddRange(newBlocks);
  100. }
  101. }
  102. return mapBlocks;
  103. }
  104. }
  105. class MapArea
  106. {
  107. public int minX;
  108. public int minY;
  109. public int maxX;
  110. public int maxY;
  111. public MapArea(int mix, int miy, int max, int may)
  112. {
  113. minX = mix;
  114. minY = miy;
  115. maxX = max;
  116. maxY = may;
  117. }
  118. public void Print()
  119. {
  120. Console.WriteLine(String.Format(" --> Area is minX={0} minY={1} minY={2} maxY={3}", minX, minY, maxY, maxY));
  121. }
  122. }
  123. }