OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
HGWorldMapModule.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using log4net;
32 using Nini.Config;
33 using OpenMetaverse;
34 using OpenMetaverse.StructuredData;
35 using Mono.Addins;
36 using OpenSim.Framework;
37 using OpenSim.Region.CoreModules.World.WorldMap;
38 using OpenSim.Region.Framework.Interfaces;
39 using OpenSim.Region.Framework.Scenes;
40 using OpenSim.Services.Interfaces;
42 
43 namespace OpenSim.Region.CoreModules.Hypergrid
44 {
45  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HGWorldMapModule")]
47  {
48  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 
50  // Remember the map area that each client has been exposed to in this region
51  private Dictionary<UUID, List<MapBlockData>> m_SeenMapBlocks = new Dictionary<UUID, List<MapBlockData>>();
52 
53  private string m_MapImageServerURL = string.Empty;
54 
55  private IUserManagement m_UserManagement;
56 
57  #region INonSharedRegionModule Members
58 
59  public override void Initialise(IConfigSource source)
60  {
61  if (Util.GetConfigVarFromSections<string>(
62  source, "WorldMapModule", new string[] { "Map", "Startup" }, "WorldMap") == "HGWorldMap")
63  {
64  m_Enabled = true;
65 
66  m_MapImageServerURL = Util.GetConfigVarFromSections<string>(source, "MapTileURL", new string[] {"LoginService", "HGWorldMap", "SimulatorFeatures"});
67 
68  if (!string.IsNullOrEmpty(m_MapImageServerURL))
69  {
70  m_MapImageServerURL = m_MapImageServerURL.Trim();
71  if (!m_MapImageServerURL.EndsWith("/"))
72  m_MapImageServerURL = m_MapImageServerURL + "/";
73  }
74 
75 
76  }
77  }
78 
79  public override void AddRegion(Scene scene)
80  {
81  if (!m_Enabled)
82  return;
83 
84  base.AddRegion(scene);
85 
86  scene.EventManager.OnClientClosed += EventManager_OnClientClosed;
87  }
88 
89  public override void RegionLoaded(Scene scene)
90  {
91  if (!m_Enabled)
92  return;
93 
94  base.RegionLoaded(scene);
95  ISimulatorFeaturesModule featuresModule = m_scene.RequestModuleInterface<ISimulatorFeaturesModule>();
96 
97  if (featuresModule != null)
98  featuresModule.OnSimulatorFeaturesRequest += OnSimulatorFeaturesRequest;
99 
100  m_UserManagement = m_scene.RequestModuleInterface<IUserManagement>();
101 
102  }
103 
104  public override void RemoveRegion(Scene scene)
105  {
106  if (!m_Enabled)
107  return;
108 
109  scene.EventManager.OnClientClosed -= EventManager_OnClientClosed;
110  }
111 
112  public override string Name
113  {
114  get { return "HGWorldMap"; }
115  }
116 
117  #endregion
118 
119  void EventManager_OnClientClosed(UUID clientID, Scene scene)
120  {
121  ScenePresence sp = scene.GetScenePresence(clientID);
122  if (sp != null)
123  {
124  if (m_SeenMapBlocks.ContainsKey(clientID))
125  {
126  List<MapBlockData> mapBlocks = m_SeenMapBlocks[clientID];
127  foreach (MapBlockData b in mapBlocks)
128  {
129  b.Name = string.Empty;
130  // Set 'simulator is offline'. We need this because the viewer ignores SimAccess.Unknown (255)
131  b.Access = (byte)SimAccess.Down;
132  }
133 
134  m_log.DebugFormat("[HG MAP]: Resetting {0} blocks", mapBlocks.Count);
135  sp.ControllingClient.SendMapBlock(mapBlocks, 0);
136  m_SeenMapBlocks.Remove(clientID);
137  }
138  }
139  }
140 
141  protected override List<MapBlockData> GetAndSendBlocksInternal(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag)
142  {
143  List<MapBlockData> mapBlocks = base.GetAndSendBlocksInternal(remoteClient, minX, minY, maxX, maxY, flag);
144  lock (m_SeenMapBlocks)
145  {
146  if (!m_SeenMapBlocks.ContainsKey(remoteClient.AgentId))
147  {
148  m_SeenMapBlocks.Add(remoteClient.AgentId, mapBlocks);
149  }
150  else
151  {
152  List<MapBlockData> seen = m_SeenMapBlocks[remoteClient.AgentId];
153  List<MapBlockData> newBlocks = new List<MapBlockData>();
154  foreach (MapBlockData b in mapBlocks)
155  if (seen.Find(delegate(MapBlockData bdata) { return bdata.X == b.X && bdata.Y == b.Y; }) == null)
156  newBlocks.Add(b);
157  seen.AddRange(newBlocks);
158  }
159  }
160 
161  return mapBlocks;
162  }
163 
164  private void OnSimulatorFeaturesRequest(UUID agentID, ref OSDMap features)
165  {
166  if (m_UserManagement != null && !string.IsNullOrEmpty(m_MapImageServerURL) && !m_UserManagement.IsLocalGridUser(agentID))
167  {
168  OSD extras = new OSDMap();
169  if (features.ContainsKey("OpenSimExtras"))
170  extras = features["OpenSimExtras"];
171  else
172  features["OpenSimExtras"] = extras;
173 
174  ((OSDMap)extras)["map-server-url"] = m_MapImageServerURL;
175 
176  }
177  }
178  }
179 
180  class MapArea
181  {
182  public int minX;
183  public int minY;
184  public int maxX;
185  public int maxY;
186 
187  public MapArea(int mix, int miy, int max, int may)
188  {
189  minX = mix;
190  minY = miy;
191  maxX = max;
192  maxY = may;
193  }
194 
195  public void Print()
196  {
197  Console.WriteLine(String.Format(" --> Area is minX={0} minY={1} minY={2} maxY={3}", minX, minY, maxY, maxY));
198  }
199  }
200 }
override void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
OpenMetaverse.StructuredData.OSDMap OSDMap
Add remove or retrieve Simulator Features that will be given to a viewer via the SimulatorFeatures ca...
override void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
OpenMetaverse.StructuredData.OSD OSD
Interactive OpenSim region server
Definition: OpenSim.cs:55
override void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
override List< MapBlockData > GetAndSendBlocksInternal(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY, uint flag)
OpenSim.Services.Interfaces.GridRegion GridRegion
override void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
This maintains the relationship between a UUID and a user name.
MapArea(int mix, int miy, int max, int may)