HGWorldMapModule.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**
  2. * Copyright (c) 2008, Contributors. All rights reserved.
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * * Neither the name of the Organizations nor the names of Individual
  14. * Contributors may be used to endorse or promote products derived from
  15. * this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  20. * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  22. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  23. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  25. * OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. using System;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Drawing;
  32. using System.Drawing.Imaging;
  33. using System.IO;
  34. using System.Net;
  35. using System.Reflection;
  36. using System.Threading;
  37. using OpenMetaverse;
  38. using OpenMetaverse.Imaging;
  39. using OpenMetaverse.StructuredData;
  40. using log4net;
  41. using Nini.Config;
  42. using Nwc.XmlRpc;
  43. using OpenSim.Framework;
  44. using OpenSim.Framework.Communications.Cache;
  45. using OpenSim.Framework.Communications.Capabilities;
  46. using OpenSim.Framework.Servers;
  47. using OpenSim.Region.Environment.Interfaces;
  48. using OpenSim.Region.Environment.Modules.World.WorldMap;
  49. using OpenSim.Region.Environment.Scenes;
  50. using OpenSim.Region.Environment.Types;
  51. using Caps = OpenSim.Framework.Communications.Capabilities.Caps;
  52. using OSD = OpenMetaverse.StructuredData.OSD;
  53. using OSDMap = OpenMetaverse.StructuredData.OSDMap;
  54. using OSDArray = OpenMetaverse.StructuredData.OSDArray;
  55. namespace OpenSim.Region.Environment.Modules.Hypergrid
  56. {
  57. public class HGWorldMapModule : WorldMapModule, IRegionModule
  58. {
  59. private static readonly ILog m_log =
  60. LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  61. #region IRegionModule Members
  62. public override void Initialise(Scene scene, IConfigSource config)
  63. {
  64. IConfig startupConfig = config.Configs["Startup"];
  65. if (startupConfig.GetString("WorldMapModule", "WorldMap") == "HGWorldMap")
  66. m_Enabled = true;
  67. if (!m_Enabled)
  68. return;
  69. m_log.Info("[HGMap] Initializing...");
  70. m_scene = scene;
  71. }
  72. public override string Name
  73. {
  74. get { return "HGWorldMap"; }
  75. }
  76. #endregion
  77. /// <summary>
  78. /// Requests map blocks in area of minX, maxX, minY, MaxY in world cordinates
  79. /// </summary>
  80. /// <param name="minX"></param>
  81. /// <param name="minY"></param>
  82. /// <param name="maxX"></param>
  83. /// <param name="maxY"></param>
  84. public override void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag)
  85. {
  86. //
  87. // WARNING!!! COPY & PASTE FROM SUPERCLASS
  88. // The only difference is at the very end
  89. //
  90. m_log.Info("[HGMap]: Request map blocks " + minX + "-" + maxX + " " + minY + "-" + maxY);
  91. //m_scene.ForEachScenePresence(delegate (ScenePresence sp) {
  92. // if (!sp.IsChildAgent && sp.UUID == remoteClient.AgentId)
  93. // {
  94. // Console.WriteLine("XXX Root agent");
  95. // DoRequestMapBlocks(remoteClient, minX, minY, maxX, maxY, flag);
  96. // }
  97. //};
  98. List<MapBlockData> mapBlocks;
  99. if ((flag & 0x10000) != 0) // user clicked on the map a tile that isn't visible
  100. {
  101. List<MapBlockData> response = new List<MapBlockData>();
  102. // this should return one mapblock at most. But make sure: Look whether the one we requested is in there
  103. mapBlocks = m_scene.SceneGridService.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
  104. if (mapBlocks != null)
  105. {
  106. foreach (MapBlockData block in mapBlocks)
  107. {
  108. if (block.X == minX && block.Y == minY)
  109. {
  110. // found it => add it to response
  111. response.Add(block);
  112. break;
  113. }
  114. }
  115. }
  116. response = mapBlocks;
  117. if (response.Count == 0)
  118. {
  119. // response still empty => couldn't find the map-tile the user clicked on => tell the client
  120. MapBlockData block = new MapBlockData();
  121. block.X = (ushort)minX;
  122. block.Y = (ushort)minY;
  123. block.Access = 254; // == not there
  124. response.Add(block);
  125. }
  126. remoteClient.SendMapBlock(response, 0);
  127. }
  128. else
  129. {
  130. // normal mapblock request. Use the provided values
  131. mapBlocks = m_scene.SceneGridService.RequestNeighbourMapBlocks(minX - 4, minY - 4, maxX + 4, maxY + 4);
  132. // Different from super
  133. FillInMap(mapBlocks, minX, minY, maxX, maxY);
  134. //
  135. remoteClient.SendMapBlock(mapBlocks, flag);
  136. }
  137. }
  138. private void FillInMap(List<MapBlockData> mapBlocks, int minX, int minY, int maxX, int maxY)
  139. {
  140. for (int x = minX; x <= maxX; x++)
  141. for (int y = minY; y <= maxY; y++)
  142. {
  143. MapBlockData mblock = mapBlocks.Find(delegate(MapBlockData mb) { return ((mb.X == x) && (mb.Y == y)); });
  144. if (mblock == null)
  145. {
  146. mblock = new MapBlockData();
  147. mblock.X = (ushort)x;
  148. mblock.Y = (ushort)y;
  149. mblock.Name = "";
  150. mblock.Access = 254; // not here???
  151. mblock.MapImageId = UUID.Zero;
  152. mapBlocks.Add(mblock);
  153. }
  154. }
  155. }
  156. }
  157. }